编写测试以验证在 jms 侦听器中收到的消息(Spring-Boot)
Writing tests to verify received msg in jms listener (Spring-Boot)
我想为下面的内容编写测试;
src/main
中有一个名为state-info-1
的侦听器。
它对收到的任何消息进行一些更改,并在 activemq 主题 state-info-2
.
上发布新消息
我将构建一条虚拟消息并发布到 activemq 主题 state-info-1
。
最后验证一下,收到的关于主题 state-info-2
的消息和我预期的一样。
我的听众喜欢;
@JmsListener(destination = "state-info-1", containerFactory = "connFactory")
public void receiveMessage(Message payload) {
// Do Stuff and Publish to state-info-2
}
我可以为此编写测试吗?或者我必须以其他方式来做?
但这不是我所期待的。
向正确的方向提供任何帮助或推动就足够了。
感谢您的宝贵时间。
@SpringBootApplication
public class So42803627Application {
public static void main(String[] args) {
SpringApplication.run(So42803627Application.class, args);
}
@Autowired
private JmsTemplate jmsTemplate;
@JmsListener(destination = "foo")
public void handle(String in) {
this.jmsTemplate.convertAndSend("bar", in.toUpperCase());
}
}
和
@RunWith(SpringRunner.class)
@SpringBootTest
public class So42803627ApplicationTests {
@Autowired
private JmsTemplate jmsTemplate;
@Test
public void test() {
this.jmsTemplate.convertAndSend("foo", "Hello, world!");
this.jmsTemplate.setReceiveTimeout(10_000);
assertThat(this.jmsTemplate.receiveAndConvert("bar")).isEqualTo("HELLO, WORLD!");
}
}
我想为下面的内容编写测试;
src/main
中有一个名为state-info-1
的侦听器。它对收到的任何消息进行一些更改,并在 activemq 主题
state-info-2
. 上发布新消息
我将构建一条虚拟消息并发布到 activemq 主题
state-info-1
。最后验证一下,收到的关于主题
state-info-2
的消息和我预期的一样。
我的听众喜欢;
@JmsListener(destination = "state-info-1", containerFactory = "connFactory")
public void receiveMessage(Message payload) {
// Do Stuff and Publish to state-info-2
}
我可以为此编写测试吗?或者我必须以其他方式来做?
但这不是我所期待的。
向正确的方向提供任何帮助或推动就足够了。
感谢您的宝贵时间。
@SpringBootApplication
public class So42803627Application {
public static void main(String[] args) {
SpringApplication.run(So42803627Application.class, args);
}
@Autowired
private JmsTemplate jmsTemplate;
@JmsListener(destination = "foo")
public void handle(String in) {
this.jmsTemplate.convertAndSend("bar", in.toUpperCase());
}
}
和
@RunWith(SpringRunner.class)
@SpringBootTest
public class So42803627ApplicationTests {
@Autowired
private JmsTemplate jmsTemplate;
@Test
public void test() {
this.jmsTemplate.convertAndSend("foo", "Hello, world!");
this.jmsTemplate.setReceiveTimeout(10_000);
assertThat(this.jmsTemplate.receiveAndConvert("bar")).isEqualTo("HELLO, WORLD!");
}
}