代码拉取完成,页面将自动刷新
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);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。