使用弹簧启动模拟配置不会拾取属性文件



我正在尝试编写一个集成流测试。它是这样的:

JMS(in) -> (在 db 中查找以前的版本) -> reduce(in,1...n) -> (to db) -> JMS(out)

所以,毫不奇怪:我想嘲笑数据库调用;它们是道豆。但是,我也希望它通过组件扫描拾取其他豆子;我将有选择地扫描除 dao 之外的所有包。

  • 创建一个测试配置并模拟 Daos。没关系
  • 按照 Spring 引导说明进行测试,以获得组件扫描的 bean。没关系

我只想验证步骤顺序和结果输出,因为出站 JMS 队列会看到它。有人可以帮我填空吗?

不能强悍!模拟的使用似乎是有问题的,因为很多基本领域都是最终的。我到处都在阅读有关此的内容,只是没有想出一条清晰的道路。顺便说一句,我继承了这段代码

我的错误:

org.springframework.integration.MessageDispatchingException: Dispatcher 没有订阅者

这是我的代码

@Configuration
@ImportResource("classpath:retry-context.xml")
public class LifecycleConfig {
    @Autowired
    private MessageProducerSupport inbound;
    @Autowired
    private MessageHandler outbound;
    @Autowired
    @Qualifier("reducer")
    private GenericTransformer<Collection<ExtendedClaim>,ExtendedClaim> reducer;
    @Autowired
    @Qualifier("claimIdToPojo")
    private GenericTransformer<String,ClaimDomain> toPojo;
    @Autowired
    @Qualifier("findPreviousVersion")
    private GenericTransformer<ExtendedClaim,Collection<ExtendedClaim>> previousVersions;
    @Autowired
    @Qualifier("saveToDb")
    private GenericHandler<ExtendedClaim> toDb;
    @Bean
    public DirectChannel getChannel() {
        return new DirectChannel();
    }
    @Bean
    @Autowired
    public StandardIntegrationFlow processClaim() {
        return IntegrationFlows.from(inbound).
                channel(getChannel()).
                transform(previousVersions).
                transform(reducer).
                handle(ExtendedClaim.class,toDb).
                transform(toPojo).
                handle(outbound).get();
    }
}

测试配置

@Configuration
public class TestConfig extends AbstractClsTest {

    @Bean(name = "claimIdToPojo")
    public ClaimIdToPojo getClaimIdToPojo() {
        return spy(new ClaimIdToPojo());
    }
    @Bean
    public ClaimToId getClaimToIdPojo() {
        return spy(new ClaimToId());
    }
    @Bean(name = "findPreviousVersion")
    public FindPreviousVersion getFindPreviousVersion() {
        return spy(new FindPreviousVersion());
    }
    @Bean(name = "reducer")
    public Reducer getReducer() {
        return spy(new Reducer());
    }
    @Bean(name = "saveToDb")
    public SaveToDb getSaveToDb() {
        return spy(new SaveToDb());
    }
    @Bean
    public  MessageProducerSupport getInbound() {
        MessageProducerSupport mock = mock(MessageProducerSupport.class);
//        when(mock.isRunning()).thenReturn(true);
        return mock;
    }
    @Bean
    public PaymentDAO getPaymentDao() {
        return mock(PaymentDAO.class);
    }
    @Bean
    public ClaimDAO getClaimDao() {
        return mock(ClaimDAO.class);
    }
    @Bean
    public MessageHandler getOutbound() {
        return new CaptureHandler<ExtendedClaim>();
    }
}

实际测试不会加载

   @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestConfig.class, LifecycleConfig.class})
public class ClaimLifecycleApplicationTest extends AbstractClsTest {

    @Autowired
    private MessageHandler outbound;
    @Autowired
    @Qualifier("reducer")
    private GenericTransformer<Collection<ExtendedClaim>,ExtendedClaim> reducer;
    @Autowired
    @Qualifier("claimIdToPojo")
    private GenericTransformer<String,ClaimDomain> toPojo;
    @Autowired
    @Qualifier("findPreviousVersion")
    private GenericTransformer<ExtendedClaim,Collection<ExtendedClaim>> previousVersions;
    @Autowired
    @Qualifier("saveToDb")
    private GenericHandler<ExtendedClaim> toDb;
    @Autowired
    private DirectChannel defaultChannel;
    @Test
    public void testFlow() throws Exception {
        ExtendedClaim claim = getClaim();
        Message<ExtendedClaim> message = MessageBuilder.withPayload(claim).build();
        List<ExtendedClaim> previousClaims = Arrays.asList(claim);
        defaultChannel.send(message);
        verify(previousVersions).transform(claim);
        verify(reducer).transform(previousClaims);
        verify(toDb).handle(claim, anyMap());
        verify(toPojo).transform(claim.getSubmitterClaimId());
        verify(outbound);
    }

}

有很多特定于域的对象,所以我无法测试它以重现或发现您的代码的其他问题。

但我看到你没有在@Configuration的类上使用@EnableIntegration

相关内容

  • 没有找到相关文章

最新更新