2025-10-15 12:24:17 +08:00
|
|
|
package cn.hezhaohui.rabbitmq.amqp;
|
|
|
|
|
|
|
|
|
|
import cn.hezhaohui.rabbitmq.entity.Message;
|
|
|
|
|
import jakarta.annotation.Resource;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SpringBootTest
|
|
|
|
|
class MessageProducerTest {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private MessageProducer messageProducer;
|
|
|
|
|
|
2025-10-15 14:47:43 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 测试方法:用于发送电子邮件消息
|
|
|
|
|
* 该方法使用messageProducer对象调用sendEmailMessage方法
|
|
|
|
|
* 传入一个Message对象,其中包含电子邮件地址"hello@example.com"
|
|
|
|
|
*/
|
2025-10-15 12:24:17 +08:00
|
|
|
@Test
|
2025-10-15 14:47:43 +08:00
|
|
|
void sendEmailMessage() throws InterruptedException { // 测试用例:验证电子邮件消息发送功能
|
|
|
|
|
messageProducer.sendEmailMessage(new Message("hello@example.com")); // 创建并发送电子邮件消息
|
|
|
|
|
Thread.sleep(1000);
|
2025-10-15 12:24:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2025-10-15 14:47:43 +08:00
|
|
|
void sendSmsMessage() throws InterruptedException {
|
2025-10-15 12:24:17 +08:00
|
|
|
messageProducer.sendSmsMessage(new Message("1234567890"));
|
2025-10-15 14:47:43 +08:00
|
|
|
Thread.sleep(1000);
|
2025-10-15 12:24:17 +08:00
|
|
|
}
|
|
|
|
|
}
|