标签: camel-test

Spring Boot Camel 测试

我需要在 Spring Boot 应用程序中测试 Camel 路由。我有 Spring boot 主类,其中声明了所有必需的 bean。我正在使用 CamelSpringJUnit4ClassRunner.class。在 @ContextConfiguration 中添加了我的 Spring boot 主类,因为它包含所有配置。我没有单独的配置类。

我在我的测试类中自动装配了 CamelContext:

@Autowired
CamelContext camelContext;
Run Code Online (Sandbox Code Playgroud)

但是测试失败并显示错误:

引起:org.springframework.beans.factory.NoSuchBeanDefinitionException:

没有可用的“org.apache.camel.CamelContext”类型的合格 bean:预计至少有 1 个 bean 有资格作为自动装配候选。

依赖注解:{@org.springframework.beans.factory.annotation.Autowired(required=true)}

apache-camel spring-boot junit5 camel-test

4
推荐指数
1
解决办法
5977
查看次数

骆驼:模拟并从路径中的组件返回值

我的服务中有以下路线:

public void configure() {

    /*
     * Scheduled Camel route to produce a monthly report from the audit table. 
     * This is scheduled to run the first day of every month.
     */

    // @formatter:off
    from(reportUri)
        .routeId("monthly-report-route")
        .log("Audit report processing started...")
        .to("mybatis:updateProcessControl?statementType=Update")
        .choice()
            /*
             * If the rows updated is 1, this service instance wins and can run the report.
             * If the rows updated is zero, go to sleep and wait for the next scheduled run.  
             */
            .when(header("CamelMyBatisResult").isEqualTo(1))
                .process(reportDateProcessor)
                .to("mybatis:selectReport?statementType=SelectList&consumer.routeEmptyResultSet=true") …
Run Code Online (Sandbox Code Playgroud)

java mocking apache-camel camel-test

1
推荐指数
1
解决办法
3180
查看次数

Camel 测试 - java.lang.IllegalArgumentException:必须指定 defaultEndpoint

我正在尝试使用http://camel.apache.org/mock.html为我的骆驼路线创建测试用例。我需要验证路由中的处理器。但是简单的测试对我不起作用。

public class CamelRouteTest  extends CamelTestSupport {

  @Override
  public String isMockEndpointsAndSkip() {
    // override this method and return the pattern for which endpoints to mock,
    // and skip sending to the original endpoint.
    return "mock:result";
  }

  @Test
  public void verifyMessageCount() throws Exception {
    template.sendBody("Test");
    getMockEndpoint("mock:result").expectedMessageCount(1);
    assertMockEndpointsSatisfied();
  }

  @Override
  protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").to("mock:result");
        }
    };
  }
}
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪:

java.lang.IllegalArgumentException: defaultEndpoint must be specified
    at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:308) …
Run Code Online (Sandbox Code Playgroud)

java apache-camel camel-test

1
推荐指数
1
解决办法
5190
查看次数

Spring Boot Apache Camel Routes 测试

我有一个 Springboot 应用程序,其中配置了一些 Camel 路由。

public class CamelConfig {
    private static final Logger LOG = LoggerFactory.getLogger(CamelConfig.class);

    @Value("${activemq.broker.url:tcp://localhost:61616}")
    String brokerUrl;

    @Value("${activemq.broker.maxconnections:1}")
    int maxConnections;

    @Bean
    ConnectionFactory jmsConnectionFactory() {
        PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory(new ActiveMQConnectionFactory(brokerUrl));
        pooledConnectionFactory.setMaxConnections(maxConnections);
        return pooledConnectionFactory;
    }

    @Bean
    public RoutesBuilder route() {
        LOG.info("Initializing camel routes......................");
        return new SpringRouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("activemq:testQueue")
                  .to("bean:queueEventHandler?method=handleQueueEvent");
            }
        };
    }
}
Run Code Online (Sandbox Code Playgroud)

我想测试从activemq:testQueue到 的这条路线queueEventHandler::handleQueueEvent。我尝试了这里提到的不同内容http://camel.apache.org/camel-test.html,但似乎没有让它工作。

我正在尝试做这样的事情:

    @RunWith(SpringRunner.class)
    @SpringBootTest(classes = {CamelConfig.class,   CamelTestContextBootstrapper.class})
    public class CamelRouteConfigTest {

    @Produce(uri …
Run Code Online (Sandbox Code Playgroud)

apache-camel spring-boot camel-test

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

apache-camel ×4

camel-test ×4

java ×2

spring-boot ×2

junit5 ×1

mocking ×1