Search in sources :

Example 1 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class CustomIdIssuesTest method testCustomId.

public void testCustomId() {
    RouteDefinition route = context.getRouteDefinition("myRoute");
    assertNotNull(route);
    assertTrue(route.hasCustomIdAssigned());
    FromDefinition from = route.getInputs().get(0);
    assertEquals("fromFile", from.getId());
    assertTrue(from.hasCustomIdAssigned());
    ChoiceDefinition choice = (ChoiceDefinition) route.getOutputs().get(0);
    assertEquals("myChoice", choice.getId());
    assertTrue(choice.hasCustomIdAssigned());
    WhenDefinition when = choice.getWhenClauses().get(0);
    assertTrue(when.hasCustomIdAssigned());
    assertEquals("UK", when.getId());
    LogDefinition log = (LogDefinition) choice.getOtherwise().getOutputs().get(0);
    assertFalse(log.hasCustomIdAssigned());
}
Also used : FromDefinition(org.apache.camel.model.FromDefinition) RouteDefinition(org.apache.camel.model.RouteDefinition) ChoiceDefinition(org.apache.camel.model.ChoiceDefinition) LogDefinition(org.apache.camel.model.LogDefinition) WhenDefinition(org.apache.camel.model.WhenDefinition)

Example 2 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class JdbcMessageIdRepositoryTest method testFailedExchangesNotAdded.

@Test
public void testFailedExchangesNotAdded() throws Exception {
    RouteBuilder interceptor = new RouteBuilder(context) {

        @Override
        public void configure() throws Exception {
            interceptSendToEndpoint("mock:result").process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    String id = exchange.getIn().getHeader("messageId", String.class);
                    if (id.equals("2")) {
                        throw new IllegalArgumentException("Damn I cannot handle id 2");
                    }
                }
            });
        }
    };
    RouteDefinition routeDefinition = context.getRouteDefinition("JdbcMessageIdRepositoryTest");
    routeDefinition.adviceWith(context, interceptor);
    // we send in 2 messages with id 2 that fails
    errorEndpoint.expectedMessageCount(2);
    resultEndpoint.expectedBodiesReceived("one", "three");
    template.sendBodyAndHeader("direct:start", "one", "messageId", "1");
    template.sendBodyAndHeader("direct:start", "two", "messageId", "2");
    template.sendBodyAndHeader("direct:start", "one", "messageId", "1");
    template.sendBodyAndHeader("direct:start", "two", "messageId", "2");
    template.sendBodyAndHeader("direct:start", "one", "messageId", "1");
    template.sendBodyAndHeader("direct:start", "three", "messageId", "3");
    assertMockEndpointsSatisfied();
    jdbcTemplate.update(CLEAR_STRING, PROCESSOR_NAME);
    // only message 1 and 3 should be in jdbc repo
    List<String> receivedMessageIds = jdbcTemplate.queryForList(SELECT_ALL_STRING, String.class, PROCESSOR_NAME);
    assertEquals(0, receivedMessageIds.size());
    assertFalse("Should not contain message 1", receivedMessageIds.contains("1"));
    assertFalse("Should not contain message 3", receivedMessageIds.contains("3"));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) RouteDefinition(org.apache.camel.model.RouteDefinition) Test(org.junit.Test)

Example 3 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class OnExceptionRouteIdTest method testOnExceptionRouteId.

@Test
public void testOnExceptionRouteId() throws Exception {
    getMockEndpoint("mock:error").expectedMessageCount(0);
    getMockEndpoint("mock:foo").expectedMessageCount(1);
    template.sendBody("direct:foo", "Hello World");
    assertMockEndpointsSatisfied();
    RouteDefinition route = context.getRouteDefinition("foo");
    assertNotNull(route);
    assertEquals("foo", route.getId());
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) Test(org.junit.Test)

Example 4 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class SpringScheduledRoutePolicyTest method startRouteWithPolicy.

@SuppressWarnings("unchecked")
private CamelContext startRouteWithPolicy(String policyBeanName) throws Exception {
    CamelContext context = new DefaultCamelContext();
    List<RouteDefinition> routes = (List<RouteDefinition>) applicationContext.getBean("testRouteContext");
    RoutePolicy policy = applicationContext.getBean(policyBeanName, RoutePolicy.class);
    assertTrue(getTestType() == TestType.SIMPLE ? policy instanceof SimpleScheduledRoutePolicy : policy instanceof CronScheduledRoutePolicy);
    routes.get(0).routePolicy(policy);
    ((ModelCamelContext) context).addRouteDefinitions(routes);
    context.start();
    return context;
}
Also used : CamelContext(org.apache.camel.CamelContext) ModelCamelContext(org.apache.camel.model.ModelCamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) RouteDefinition(org.apache.camel.model.RouteDefinition) List(java.util.List) RoutePolicy(org.apache.camel.spi.RoutePolicy) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ModelCamelContext(org.apache.camel.model.ModelCamelContext)

Example 5 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class RoutesCollector method loadXmlRests.

private void loadXmlRests(ApplicationContext applicationContext, CamelContext camelContext, String directory) {
    LOG.info("Loading additional Camel XML rests from: {}", directory);
    try {
        final Resource[] xmlRests = applicationContext.getResources(directory);
        for (final Resource xmlRest : xmlRests) {
            final RestsDefinition xmlDefinitions = camelContext.loadRestsDefinition(xmlRest.getInputStream());
            camelContext.addRestDefinitions(xmlDefinitions.getRests());
            for (final RestDefinition xmlDefinition : xmlDefinitions.getRests()) {
                final List<RouteDefinition> routeDefinitions = xmlDefinition.asRouteDefinition(camelContext);
                camelContext.addRouteDefinitions(routeDefinitions);
            }
        }
    } catch (FileNotFoundException e) {
        LOG.debug("No XML rests found in {}. Skipping XML rests detection.", directory);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : RestDefinition(org.apache.camel.model.rest.RestDefinition) RouteDefinition(org.apache.camel.model.RouteDefinition) Resource(org.springframework.core.io.Resource) RestsDefinition(org.apache.camel.model.rest.RestsDefinition) FileNotFoundException(java.io.FileNotFoundException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

RouteDefinition (org.apache.camel.model.RouteDefinition)129 RouteBuilder (org.apache.camel.builder.RouteBuilder)25 Test (org.junit.Test)25 AdviceWithRouteBuilder (org.apache.camel.builder.AdviceWithRouteBuilder)18 ArrayList (java.util.ArrayList)11 CamelContext (org.apache.camel.CamelContext)10 FromDefinition (org.apache.camel.model.FromDefinition)10 ModelCamelContext (org.apache.camel.model.ModelCamelContext)10 ProcessorDefinition (org.apache.camel.model.ProcessorDefinition)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 File (java.io.File)7 HashMap (java.util.HashMap)7 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)6 Processor (org.apache.camel.Processor)6 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)6 FileReader (java.io.FileReader)5 IOException (java.io.IOException)5 ConnectException (java.net.ConnectException)5 RoutesDefinition (org.apache.camel.model.RoutesDefinition)5 Map (java.util.Map)4