用于jms的JUnit测试配置类的bean

时间:2019-06-21 19:13:12

标签: junit jms spring-jms spring-test

我如何为下面的类编写单元测试用例,该类基本上是我们启用了jms的配置类-检查是否创建了bean。

@Configuration
@EnableJms
public class MQConfig {
  @Autowired ErrorHandler myErrorHandler;

  @Bean
  public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() throws JMSException {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setErrorHandler(myErrorHandler);
    return factory;
  }

  @Bean
  @Autowired
  MQConnectionFactory mqConnectionFactory() throws JMSException {
    MQConnectionFactory mqConnectionFactory = new MQConnectionFactory();

    // my code for setting connection factory properties
    return mqConnectionFactory;

  }

  @Bean
  @Autowired
  JmsTemplate jmsTemplate(CachingConnectionFactory mqConnectionFactory) throws JMSException {
    JmsTemplate jmsTemplate = new JmsTemplate(mqConnectionFactory);
    return jmsTemplate;
  }
}

0 个答案:

没有答案