如何解决模拟骆驼路由端点时断言失败
在模拟这条路线中的所有骆驼端点时,我遇到了一个问题,如下所述:
<route id="servicetoCougarInboundRouting" streamCache="true">
<from uri="cxfrs:bean:oab_servicetoOab?loggingFeatureEnabled={{gestioncougar.wscall.log.enable}}&loggingSizeLimit={{gestioncougar.wscall.log.size}}"/>
<to uri="bean:log?method=info(*,'Service exposé à COUGAR: ')"/>
<to uri="bean:log?method=info(*,'Body : ${body}')"/>
<to uri="bean:log?method=info(*,'Apigee est appelé')"/>
<setProperty propertyName="savedInitialBody">
<simple>${body}</simple>
</setProperty>
<setHeader headerName="Content-Type">
<constant>application/x-www-form-urlencoded</constant>
</setHeader>
<setHeader headerName="CamelHttpMethod">
<constant>POST</constant>
</setHeader>
<setHeader headerName="CamelHttpPath">
<constant>/accesstoken</constant>
</setHeader>
<setBody>
<simple>bean:encodedApigeeBody?method=getEncodedApigeeBody</simple>
</setBody>
<setExchangePattern pattern="InOut"/>
<to uri="bean:log?method=info(*,'Apigee est appelé')"/>
<to uri="cxfrs:bean:apigee_serviceApigee?loggingFeatureEnabled={{gestioncougar.wscall.log.enable}}&loggingSizeLimit={{gestioncougar.wscall.log.size}}"/>
<to uri="bean:log?method=info(*,'Apigee access_token: ${body}')"/>
<unmarshal ref="formatJsonApigeeResponse"/>
<bean ref="traiterCallFromApigee" method="saveAccesstoken"/>
<setBody>
<simple>${property.savedInitialBody}</simple>
</setBody>
<convertBodyTo type="java.lang.String"/> <!-- type texte pour publication JMS -->
<bean ref="traiterCallFromCustomerlink" method="nettoyageCaracteresInterdits"/>
<choice>
<when>
<simple>${header.operationName} == 'createNewDeal'</simple>
<to uri="activemq:queue:q.gestioncougar.cougar.creation?disableReplyTo=true"/>
</when>
</choice>
<!-- Gestion d'erreur -->
<onException>
<exception>java.lang.Exception</exception>
<handled>
<constant>true</constant>
</handled>
<to uri="bean:log?method=error(*,'Erreur technique : ${exception.stacktrace}')"/>
<bean ref="traiterCallFromCustomerlink" method="construireReponseKo"/>
</onException>
</route>
我为上述路由写了一个单元测试:
@RunWith(MockitoJUnitRunner.class)
public class TestRouteCougarInbound extends CamelBlueprintTestSupport {
static brokerService brokerJms;
protected static String JMS_URL = "tcp://localhost:61615";
protected static String QUEUE_OAB_CREATION = "q.gestioncougar.cougar.creation";
@EndpointInject(uri = "direct:start")
protected ProducerTemplate RSServer;
@Mock
EncodedApigeeBody encodedApigeeBody;
@Mock
CallFromApigee callFromApigee;
@Mock
CallFromCustomerlinks callFromCustomerlinks;
@Test
public void should_return_converted_contribution_when_creating_new_deal() throws Exception {
context.getRouteDeFinition("servicetoCougarInboundRouting").adviceWith(context,new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// mock log endpoints
replaceFromWith("direct:start");
mockEndpoints();
}
});
MockEndpoint mockEndpointQCreation = getMockEndpoint("mock:activemq:queue:"+QUEUE_OAB_CREATION);
mockEndpointQCreation.expectedMessageCount(1);
String msg = readFileAsstring("json/createNewDeal/createNewDeal.json");
HashMap<String,String> params = new HashMap<>();
params.put("grant_type","client_credentials");
params.put("client_id","xxxxx");
params.put("client_secret","xxxxx");
when(encodedApigeeBody.getEncodedApigeeBody()).thenReturn(getDataString(params));
when(callFromApigee.saveAccesstoken(any())).thenReturn("Bearer xxxxx");
when(callFromCustomerlinks.nettoyageCaracteresInterdits(any())).thenReturn(msg);
RSServer.sendBodyAndHeader("direct:start",msg,"operationName","createNewDeal");
assertMockEndpointsSatisfied();
}
@BeforeClass
public static void configure() throws Exception {
System.setProperty("server.port",String.valueOf(AvailablePortFinder.getNextAvailable()));
// Embedded JMS brokerl
brokerJms = new brokerService();
TransportConnector connector = new TransportConnector();
connector.setUri(new URI(JMS_URL));
brokerJms.setbrokerName("activemq_local");
brokerJms.addConnector(connector);
brokerJms.setPersistent(false);
brokerJms.start();
}
@Override
protected void addServicesOnStartup(Map<String,keyvalueHolder<Object,Dictionary>> services) {
/*Dictionary<String,String> dictOpportunityJsonMapper = new Hashtable<>();
dictOpportunityJsonMapper.put("fr.oab.sie.esb.gestioncougar.cougar.service.OpportunityJsonParser",null);*/
services.put("opportunityJsonParser",asService(new OpportunityJsonParser(),null,null));
services.put("opportunityMapper",asService(new OpportunityMapperImpl(),null));
services.put("encodedApigeeBody",asService(new EncodedApigeeBody(),null));
services.put("traiterCallFromApigee",asService(new CallFromApigee(),null));
services.put("traiterCallFromCustomerlink",asService(new CallFromCustomerlinks(),"opportunityJsonParser","opportunityMapper",null));
}
@AfterClass
public static void stop() throws Exception {
brokerJms.stop();
System.out.println("[TestRouteOab] teardown");
}
@Override
public boolean isUseAdviceWith() {
return true;
}
@Override
public String isMockEndpointsAndSkip() {
return "((cxf)|(cxfrs)|(activemq:queue)):(.*)";
// return "cxf:(.*)";
}
@Override
public boolean isUseDebugger() {
// must enable debugger
return true;
}
@Override
protected String getBlueprintDescriptor() {
return "Osgi-INF/blueprint/gestion-cougar-oab.xml,Osgi-INF/blueprint/gestion-cougar-commun.xml,Osgi-INF/blueprint/gestion-cougar-conf-test.xml";
}
@Override
protected String getBundleFilter() {
return "(!(Bundle-SymbolicName= org.test.junit.bundleTest))";
}
}
请注意,我在蓝图容器中运行这些路由!
我断言失败,我不知道为什么模拟端点 "mock:activemq:queue:"+QUEUE_OAB_CREATION 没有消耗发送到 "direct:start 的正文"端点,即入口端点cxfrs:bean:oab_servicetoOab !!
下面的消息错误:
java.lang.AssertionError: mock://activemq:queue:q.gestioncougar.cougar.creation 收到的消息 数数。预期: 但为: 预期: 实际:
非常感谢任何帮助,谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。