Search in sources :

Example 6 with RoutesDefinition

use of org.apache.camel.model.RoutesDefinition in project syndesis by syndesisio.

the class IntegrationRouteBuilder method loadFragments.

@SuppressWarnings("PMD")
private void loadFragments(Step step) {
    if (StepKind.extension != step.getStepKind()) {
        return;
    }
    final StepAction action = step.getAction().filter(StepAction.class::isInstance).map(StepAction.class::cast).get();
    if (action.getDescriptor().getKind() == StepAction.Kind.ENDPOINT) {
        final CamelContext context = getContext();
        final String resource = action.getDescriptor().getResource();
        if (ObjectHelper.isNotEmpty(resource) && resources.add(resource)) {
            final Object instance = mandatoryloadResource(context, resource);
            final RoutesDefinition definitions = mandatoryConvertToRoutesDefinition(resource, instance);
            LOGGER.debug("Resolved resource: {} as {}", resource, instance.getClass());
            try {
                context.addRouteDefinitions(definitions.getRoutes());
            } catch (Exception e) {
                throw new IllegalStateException(e);
            }
        }
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) StepAction(io.syndesis.common.model.action.StepAction) RoutesDefinition(org.apache.camel.model.RoutesDefinition) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 7 with RoutesDefinition

use of org.apache.camel.model.RoutesDefinition in project syndesis by syndesisio.

the class IntegrationRouteBuilderTest method testBuilder.

@Test
public void testBuilder() throws Exception {
    IntegrationRuntimeConfiguration configuration = new IntegrationRuntimeConfiguration();
    IntegrationRouteBuilder routeBuilder = new IntegrationRouteBuilder(configuration.getConfigurationLocation(), Collections.emptyList());
    // initialize routes
    routeBuilder.configure();
    RoutesDefinition routes = routeBuilder.getRouteCollection();
    assertThat(routes.getRoutes()).hasSize(1);
    RouteDefinition routeDefinition = routes.getRoutes().get(0);
    assertThat(routeDefinition.getInputs()).hasSize(1);
    assertThat(routeDefinition.getInputs().get(0)).isInstanceOf(FromDefinition.class);
    assertThat(routeDefinition.getOutputs()).hasSize(2);
    assertThat(routeDefinition.getOutputs().get(0)).isInstanceOf(ProcessDefinition.class);
    assertThat(routeDefinition.getOutputs().get(1)).isInstanceOf(SplitDefinition.class);
    ProcessorDefinition<?> processDefinition = routeDefinition.getOutputs().get(1);
    assertThat(processDefinition.getOutputs()).hasSize(3);
    assertThat(processDefinition.getOutputs().get(0)).isInstanceOf(ProcessDefinition.class);
    assertThat(processDefinition.getOutputs().get(1)).isInstanceOf(ToDefinition.class);
    assertThat(processDefinition.getOutputs().get(2)).isInstanceOf(ProcessDefinition.class);
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) RoutesDefinition(org.apache.camel.model.RoutesDefinition) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with RoutesDefinition

use of org.apache.camel.model.RoutesDefinition in project ddf by codice.

the class MetacardStorageRouteTest method setUp.

@Before
public void setUp() {
    RoutesDefinition mockRoutesDefinition = mock(RoutesDefinition.class);
    when(storageRoute.getRouteCollection()).thenReturn(mockRoutesDefinition);
    when(mockRoutesDefinition.toString()).thenReturn("test");
    storageRoute.setBackupMetacardTags(DEFAULT_TAGS);
}
Also used : RoutesDefinition(org.apache.camel.model.RoutesDefinition) Before(org.junit.Before)

Example 9 with RoutesDefinition

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

the class DuplicateNamespacePrefixIssueTest method testRoutesNamespacePrefixesNotDuplicated.

@Test
public void testRoutesNamespacePrefixesNotDuplicated() throws Exception {
    CamelContext context = new BlueprintCamelContext(bundleContext, blueprintContainer);
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:foo").id("foo").choice().when(xpath("foo:foo/foo:foo = 'foo'")).log("Matched foo").when(xpath("foo:foo/foo:bar = 'bar'")).log("Matched bar").when(xpath("foo:foo/foo:cheese = 'cheese'")).log("Matched cheese");
        }
    });
    // Dump the model XML
    String originalModelXML = ModelHelper.dumpModelAsXml(context, context.getRouteDefinition("foo"));
    // Reload routes from dumped XML
    InputStream stream = new ByteArrayInputStream(originalModelXML.getBytes("UTF-8"));
    RoutesDefinition routesDefinition = ModelHelper.loadRoutesDefinition(context, stream);
    // Verify namespaces are as we expect
    String modifiedModelXML = ModelHelper.dumpModelAsXml(context, routesDefinition);
    String modifiedRoutesElementXML = modifiedModelXML.split("\n")[1];
    String expectedRoutesElementXML = "<routes xmlns=\"http://camel.apache.org/schema/spring\">";
    Assert.assertEquals(expectedRoutesElementXML, modifiedRoutesElementXML);
}
Also used : CamelContext(org.apache.camel.CamelContext) BlueprintCamelContext(org.apache.camel.blueprint.BlueprintCamelContext) BlueprintCamelContext(org.apache.camel.blueprint.BlueprintCamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RoutesDefinition(org.apache.camel.model.RoutesDefinition) Test(org.junit.Test) AbstractFeatureTest(org.apache.camel.test.karaf.AbstractFeatureTest)

Example 10 with RoutesDefinition

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

the class SpringLoadRouteFromXmlTest method testLoadRouteFromXml.

@Test
public void testLoadRouteFromXml() throws Exception {
    assertNotNull("Existing foo route should be there", context.getRoute("foo"));
    assertEquals(1, context.getRoutes().size());
    // test that existing route works
    MockEndpoint foo = getMockEndpoint("mock:foo");
    foo.expectedBodiesReceived("Hello World");
    template.sendBody("direct:foo", "Hello World");
    foo.assertIsSatisfied();
    // load bar route from classpath using JAXB
    JAXBContext jaxb = new DefaultModelJAXBContextFactory().newJAXBContext();
    Unmarshaller unmarshaller = jaxb.createUnmarshaller();
    Resource rs = new ClassPathResource("org/apache/camel/itest/jaxb/BarRoute.xml");
    Object value = unmarshaller.unmarshal(rs.getInputStream());
    // it should be a RoutesDefinition (we can have multiple routes in the same XML file)
    RoutesDefinition routes = (RoutesDefinition) value;
    assertNotNull("Should load routes from XML", routes);
    assertEquals(1, routes.getRoutes().size());
    // add the routes to existing CamelContext
    context.addRouteDefinitions(routes.getRoutes());
    assertNotNull("Loaded bar route should be there", context.getRoute("bar"));
    assertEquals(2, context.getRoutes().size());
    // test that loaded route works
    MockEndpoint bar = getMockEndpoint("mock:bar");
    bar.expectedBodiesReceived("Bye World");
    template.sendBody("direct:bar", "Bye World");
    bar.assertIsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) RoutesDefinition(org.apache.camel.model.RoutesDefinition) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) DefaultModelJAXBContextFactory(org.apache.camel.impl.DefaultModelJAXBContextFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Aggregations

RoutesDefinition (org.apache.camel.model.RoutesDefinition)20 Test (org.junit.Test)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)5 RouteDefinition (org.apache.camel.model.RouteDefinition)5 IOException (java.io.IOException)4 LinkedHashMap (java.util.LinkedHashMap)4 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 CamelContext (org.apache.camel.CamelContext)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 Element (de.pdark.decentxml.Element)1 Node (de.pdark.decentxml.Node)1 StepAction (io.syndesis.common.model.action.StepAction)1 FileNotFoundException (java.io.FileNotFoundException)1 StringReader (java.io.StringReader)1 Collections.emptySet (java.util.Collections.emptySet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1