我正在尝试编写IntegrationFlow测试。它是这样的:
JMS(in) - > (在db中查找以前的版本) - > reduce(in,1 ... n) - > (对于db) - > JMS(下)
所以,不要惊讶:我想嘲笑数据库电话;他们是道豆。但是,我也希望它通过组件扫描来拾取其他bean;我将有选择地扫描除dao之外的所有包。
我只想验证步骤的顺序以及结果输出,因为出站JMS队列会看到它。有人可以帮我填空吗?
这 CANT 很难!使用模拟似乎是有问题的,因为许多必要的领域是最终的。我到处都在读这个,只是没有提出一条明确的道路。我继承了这段代码BTW
我的错误:
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);
}
}
答案 0 :(得分:0)
有很多针对特定领域的对象,因此我无法对其进行测试以重现或找到代码中的其他问题。
但我发现您在@EnableIntegration
课程中没有使用@Configuration
。