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);
}
}
}
}
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);
}
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);
}
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);
}
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();
}
Aggregations