编写apache camel测试时遇到问题

k4emjkb1  于 2023-01-13  发布在  Apache
关注(0)|答案(1)|浏览(142)

我正在为apache camel路由编写测试用例,并且在运行它时收到此错误(堆栈正在使用错误的部分代码指向建议。)

@Test
    public void testRoute() throws Exception {

        AdviceWith.adviceWith(context, Endpoints.SEDA_SEND_ENDPOINT, a -> {
            a.mockEndpoints(Endpoints.SEDA_SEND_ENDPOINT);
        });
    //     Set up the expectations for the mock endpoint

       getMockEndpoint("mock:" + Endpoints.SEDA_SEND_ENDPOINT).expectedMessageCount(1);

        // Send a message to the seda:sendMessage endpoint
        template.sendBody(Endpoints.SEDA_SEND_ENDPOINT, "test message");

        // Verify that the mock endpoint expectations are met
        assertMockEndpointsSatisfied();
     //   


    }

java. lang.非法参数异常:无法通知路线,因为在org. apache. camel. builder中没有路线。在org. apache. camel. builder中没有路线定义(AdviceWith.java:262)。在com.sams.pricing.prism.data.processor.CamelRouteTests1.testRoute(CamelRouteTests1.java:26)中没有路线定义(AdviceWith.java:74)。
我曾想过端点可能写得不正确,但经过仔细检查,甚至将其写出来,仍然会遇到问题
SEDA_SEND_ENDPOINT ="seda:发送消息?块当满=真且并发使用者= 100时"

qacovj5a

qacovj5a1#

如果您想要测试routeContext,如下所示:

<camelcontext>
   <routeContext>
       <route id="test">
           <from uri="direct:test"/>
           <to uri="bean:check"/>
       </route>
   </routeContext>
</camelcontext>

按照如下所示执行测试用例:

@Test
public void testRoute() throws Exception {
   RouteDefinition route = context.getRouteDefinition("test");
   AdviceWith.adviceWith(route, context, new AdviceWithRouteBuilder() {
       @Override
       public void configure() throws Exception {
           weaveAddLast().to(Endpoints.SEDA_SEND_ENDPOINT);
       }
   });
   
   MockEndpoint mockEndpoint =getMockEndpoint(Endpoints.SEDA_SEND_ENDPOINT).expectedMessageCount(1);
   LeapCoreTestUtils.template.sendBody("direct:test", "test message");
   mockEndpoint.assertIsSatisfied();
}

相关问题