模拟骆驼路由端点时断言失败

问题描述

在模拟这条路线中的所有骆驼端点时,我遇到了一个问题,如下所述:

<route id="servicetoCougarInboundRouting" streamCache="true">
            <from uri="cxfrs:bean:oab_servicetoOab?loggingFeatureEnabled={{gestioncougar.wscall.log.enable}}&amp;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}}&amp;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 (将#修改为@)