116 Star 574 Fork 223

apple888/boot-master

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
DemoApplicationTests.java 2.39 KB
一键复制 编辑 原始数据 按行查看 历史
apple888 提交于 2018-07-03 13:29 +08:00 . 优化mq队列
package com.qdone;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import javax.jms.Destination;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import com.qdone.common.mq.JMSProducer;
import com.qdone.module.controller.HelloController;
/**
* 简单MockMVC测试
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class DemoApplicationTests {
private MockMvc mockMvc;
@Autowired
private JMSProducer jmsProducer;
@Before
public void setUp() throws Exception {
/**
* 简单测试controller
*/
mockMvc = MockMvcBuilders.standaloneSetup(new HelloController()).build();
}
@Test
public void testHello() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.post("/testJson").accept(MediaType.APPLICATION_JSON_UTF8))
.andDo(print());
}
@Test
public void testJmsQueue() {
Destination destination = new ActiveMQQueue("springboot.queue.test");
for (int i = 0; i < 5; i++) {
jmsProducer.sendMessage(destination, "生成队列消息"+i);
jmsProducer.sendMessage(new ActiveMQQueue("qghappy"), "qghappy通用生成队列消息"+i);
jmsProducer.sendMessage(new ActiveMQQueue("edgm"), "edgm通用生成队列消息"+i);
}
}
@Test
public void testJmsTopic() {
Destination topic = new ActiveMQTopic("springboot.topic.test");
for (int i = 0; i < 10; i++) {
jmsProducer.publish(topic, "发布主题消息" + i);
}
}
@Test
public void testJms() {
Destination destination = new ActiveMQQueue("springboot.queue.test");
Destination topic = new ActiveMQTopic("springboot.topic.test");
for (int i = 0; i < 10; i++) {
jmsProducer.sendMessage(destination, "生成队列消息"+i);
jmsProducer.sendMessage("springboot.queue.test", "队列消息"+i);
jmsProducer.publish(topic, "发布主题消息" + i);
jmsProducer.publish("springboot.topic.test", "主题消息"+i);
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/bootstrap2table/boot_master.git
git@gitee.com:bootstrap2table/boot_master.git
bootstrap2table
boot_master
boot-master
master

搜索帮助