Java Code Examples for org.apache.camel.impl.DefaultCamelContext#start()

The following examples show how to use org.apache.camel.impl.DefaultCamelContext#start() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DecanterTraceEventHandlerTest.java    From karaf-decanter with Apache License 2.0 6 votes vote down vote up
private DefaultCamelContext createCamelContext(TraceEventHandler handler) throws Exception {
    RouteBuilder builder = new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").routeId("test-route").to("log:foo");
        }
    };
    DefaultCamelContext camelContext = new DefaultCamelContext();
    camelContext.setName("test-context");
    camelContext.addRoutes(builder);
    Tracer tracer = new Tracer();
    tracer.setEnabled(true);
    tracer.setTraceOutExchanges(true);
    tracer.setLogLevel(LoggingLevel.OFF);
    tracer.addTraceHandler(handler);
    camelContext.setTracing(true);
    camelContext.setDefaultTracer(tracer);
    camelContext.start();
    return camelContext;
}
 
Example 2
Source File: SimpleRegistryTest.java    From camelinaction2 with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    // create the registry to be the SimpleRegistry which is just a Map based implementation
    SimpleRegistry registry = new SimpleRegistry();
    // register our HelloBean under the name helloBean
    registry.put("helloBean", new HelloBean());

    // tell Camel to use our SimpleRegistry
    context = new DefaultCamelContext(registry);

    // create a producer template to use for testing
    template = context.createProducerTemplate();

    // add the route using an inlined RouteBuilder
    context.addRoutes(new RouteBuilder() {
        public void configure() throws Exception {
            from("direct:hello").bean("helloBean", "hello");
        }
    });
    // star Camel
    context.start();
}
 
Example 3
Source File: AbstractActivityLoggingTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws Exception {
    activityEvents = new ArrayList<>();

    activityTracker = items -> {
        try {
            String json = JsonSupport.toJsonObject(items);
            LOGGER.debug(json);
            ActivityEvent event = JsonUtils.reader().forType(ActivityEvent.class).readValue(json);

            activityEvents.add(event);
        } catch (IOException e) {
            LOGGER.warn("Errors during activity tracking", e);
        }
    };

    context = new DefaultCamelContext();
    context.setUuidGenerator(KeyGenerator::createKey);
    context.addLogListener(new IntegrationLoggingListener(activityTracker));
    context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
    context.addRoutes(createTestRoutes());

    context.start();
}
 
Example 4
Source File: IntegrationLoggingDisabledTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void testDisabledContextConfiguration() throws Exception {
    DefaultCamelContext context = new DefaultCamelContext();

    Properties properties = new Properties();

    PropertiesComponent pc = new PropertiesComponent();
    pc.setInitialProperties(properties);
    context.setPropertiesComponent(pc);

    RuntimeSupport.configureContextCustomizers(context);

    context.start();

    assertThat(context.getLogListeners()).have(new Condition<LogListener>() {
        @Override
        public boolean matches(LogListener value) {
            return !(value instanceof IntegrationLoggingListener);
        }
    });

    assertThat(context.getUuidGenerator()).isInstanceOf(DefaultUuidGenerator.class);

    context.stop();
}
 
Example 5
Source File: SyndesisContextCustomizerTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void testSyndesisHeaderStrategy() throws Exception {
    DefaultCamelContext context = new DefaultCamelContext();

    Properties properties = new Properties();
    properties.setProperty(Constants.PROPERTY_CAMEL_K_CUSTOMIZER, "syndesis");

    PropertiesComponent pc  = new PropertiesComponent();
    pc.setInitialProperties(properties);
    context.setPropertiesComponent(pc);

    RuntimeSupport.configureContextCustomizers(context);

    context.start();

    assertThat(context.getRegistry().findByType(HeaderFilterStrategy.class)).hasSize(1);
    assertThat(context.getRegistry().lookupByName("syndesisHeaderStrategy")).isInstanceOf(SyndesisHeaderStrategy.class);

    context.stop();
}
 
Example 6
Source File: GRPCIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testGRPCSynchronousProducer() throws Exception {

    Future<String> future = AvailablePortFinder.readServerDataAsync("grpc-port");
    int port = Integer.parseInt(future.get(10, TimeUnit.SECONDS));

    DefaultCamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .toF("grpc://localhost:%d/%s?method=pingSyncSync&synchronous=true", port, "org.wildfly.camel.test.grpc.subA.PingPong");
        }
    });

    camelctx.start();
    try {
        ProducerTemplate template = camelctx.createProducerTemplate();
        PingRequest pingRequest = PingRequest.newBuilder()
            .setPingName(GRPC_TEST_PING_VALUE)
            .setPingId(GRPC_TEST_PING_ID_1)
            .build();

        PongResponse response = template.requestBody("direct:start", pingRequest, PongResponse.class);
        Assert.assertNotNull(response);
        Assert.assertEquals(response.getPongId(), GRPC_TEST_PING_ID_1);
        Assert.assertEquals(response.getPongName(), GRPC_TEST_PING_VALUE + GRPC_TEST_PONG_VALUE);
    } finally {
        camelctx.close();
    }
}
 
Example 7
Source File: SplitStepHandlerJsonTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
/**
 * Test split to the very end of the integration - no aggregate
 * direct -> split -> mock
 */
@Test
public void testSplitToEnd() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = new IntegrationRouteBuilder(
                "classpath:/syndesis/integration/split-to-end.json",
                Resources.loadServices(IntegrationStepHandler.class)
        );

        // Set up the camel context
        context.addRoutes(routes);
        context.start();

        // Dump routes as XML for troubleshooting
        dumpRoutes(context);

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:expression", MockEndpoint.class);
        final String[] expected = { "a","b","c" };
        final List<String> body = Arrays.asList(expected);

        result.expectedMessageCount(3);
        result.expectedBodiesReceived((Object[])expected);

        template.sendBody("direct:expression", body);

        result.assertIsSatisfied();
    } finally {
        context.stop();
    }
}
 
Example 8
Source File: SplitStepHandlerJsonTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
/**
 * Test simple split/aggregate use case.
 * direct -> split -> log -> aggregate -> mock
 */
@Test
public void testSplitAggregate() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = new IntegrationRouteBuilder(
                "classpath:/syndesis/integration/split-aggregate.json",
                Resources.loadServices(IntegrationStepHandler.class)
        );

        // Set up the camel context
        context.addRoutes(routes);
        addBodyLogger(context);
        context.start();

        // Dump routes as XML for troubleshooting
        dumpRoutes(context);

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:expression", MockEndpoint.class);
        final List<String> body = Arrays.asList("a", "b", "c");

        result.expectedMessageCount(1);

        template.sendBody("direct:expression", body);

        result.assertIsSatisfied();
        List<?> bodyReceived = result.getExchanges().get(0).getIn().getBody(List.class);
        assertThat(bodyReceived).hasSize(3);
        assertThat(bodyReceived.get(0)).isEqualTo("a");
        assertThat(bodyReceived.get(1)).isEqualTo("b");
        assertThat(bodyReceived.get(2)).isEqualTo("c");
    } finally {
        context.stop();
    }
}
 
Example 9
Source File: CamelVerticle.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Future<Void> startFuture) throws Exception {

    // create camel context
    SimpleRegistry registry = new SimpleRegistry();
    camelContext = new DefaultCamelContext(registry);
    camelContext.addRoutes(new CamelRoutes());
    camelContext.start();

    bridge = CamelBridge.create(vertx, new CamelBridgeOptions(camelContext)
            .addOutboundMapping(OutboundMapping.fromVertx("greetings-counter").toCamel("seda:greetings"))
    ).start();
}
 
Example 10
Source File: HeadersStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testSetHeadersStepHandler() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(
            new Step.Builder()
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .id(KeyGenerator.createKey())
                    .descriptor(new ConnectorDescriptor.Builder()
                        .connectorId("new")
                        .componentScheme("direct")
                        .putConfiguredProperty("name", "start")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .stepKind(StepKind.headers)
                .putConfiguredProperty("action", "set")
                .putConfiguredProperty("MyHeader1", "1")
                .putConfiguredProperty("MyHeader2", "2")
                .build(),
            new Step.Builder()
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("mock")
                        .putConfiguredProperty("name", "result")
                        .build())
                    .build())
                .build()
        );

        // Set up the camel context
        context.addRoutes(routes);
        context.start();

        // Dump routes as XML for troubleshooting
        dumpRoutes(context);

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);

        result.expectedMessageCount(1);
        result.expectedHeaderReceived("MyHeader1", "1");
        result.expectedHeaderReceived("MyHeader2", "2");

        template.sendBody("direct:start", "");

        result.assertIsSatisfied();
    } finally {
        context.stop();
    }
}
 
Example 11
Source File: FilterStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testRuleFilterStepWithJsonComplexPath() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
            new Step.Builder()
                .id(START_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("direct")
                        .putConfiguredProperty("name", "start")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id(FILTER_STEP)
                .stepKind(StepKind.ruleFilter)
                .putConfiguredProperty("type", "rule")
                .putConfiguredProperty("predicate", "OR")
                .putConfiguredProperty("rules", "[{\"path\":\"user.name\",\"op\":\"==\",\"value\":\"James\"}, {\"path\":\"user.name\",\"op\":\"==\",\"value\":\"Roland\"}]")
                .build(),
            new Step.Builder()
                .id(MOCK_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("mock")
                        .putConfiguredProperty("name", "result")
                        .build())
                    .build())
                .build()
        );

        // Set up the camel context
        context.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);
        context.start();

        // Dump routes as XML for troubleshooting
        dumpRoutes(context);

        final List<String> matchingMessages = Arrays.asList(buildUserJson("James"), buildUserJson("Roland"));
        final List<String> notMatchingMessages = Collections.singletonList(buildUserJson("Jimmi"));
        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);

        List<String> allMessages = new ArrayList<>();
        allMessages.addAll(matchingMessages);
        allMessages.addAll(notMatchingMessages);

        result.expectedBodiesReceived(matchingMessages);

        for (Object body : allMessages) {
            template.sendBody("direct:start", body);
        }

        result.assertIsSatisfied();

        verify(activityTracker, times(allMessages.size())).startTracking(any(Exchange.class));
        verifyActivityStepTracking(MOCK_STEP, matchingMessages.size());
        verifyActivityStepTracking(FILTER_STEP, allMessages.size());
        verify(activityTracker, times(allMessages.size())).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}
 
Example 12
Source File: SplitStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testSplitBody() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
            new Step.Builder()
                .id(START_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("direct")
                        .putConfiguredProperty("name", "expression")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id(SPLIT_STEP)
                .stepKind(StepKind.split)
                .build(),
            new Step.Builder()
                .id(MOCK_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("mock")
                        .putConfiguredProperty("name", "expression")
                        .build())
                    .build())
                .build()
        );

        // Set up the camel context
        context.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);
        context.start();

        // Dump routes as XML for troubleshooting
        dumpRoutes(context);

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:expression", MockEndpoint.class);
        final List<String> body = Arrays.asList("a","b","c");

        result.expectedMessageCount(3);
        result.expectedBodiesReceived(body);

        template.sendBody("direct:expression", body);

        result.assertIsSatisfied();

        verify(activityTracker).startTracking(any(Exchange.class));
        verifyActivityStepTracking(SPLIT_STEP, 0);
        verifyActivityStepTracking(MOCK_STEP, 3);
        verify(activityTracker).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}
 
Example 13
Source File: GRPCIntegrationTest.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
@Test
public void testGRPCAsynchronousProducer() throws Exception {

    Future<String> future = AvailablePortFinder.readServerDataAsync("grpc-port");
    int port = Integer.parseInt(future.get(10, TimeUnit.SECONDS));

    DefaultCamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .toF("grpc://localhost:%d/%s?method=pingAsyncSync", port, "org.wildfly.camel.test.grpc.subA.PingPong");
        }
    });

    camelctx.start();
    try {
        final CountDownLatch latch = new CountDownLatch(1);

        PingRequest pingRequest = PingRequest.newBuilder()
            .setPingName(GRPC_TEST_PING_VALUE)
            .setPingId(GRPC_TEST_PING_ID_1)
            .build();

        ProducerTemplate template = camelctx.createProducerTemplate();
        template.asyncCallbackSendBody("direct:start", pingRequest, new SynchronizationAdapter() {
            @Override
            public void onComplete(Exchange exchange) {
                latch.countDown();

                @SuppressWarnings("unchecked")
                List<PongResponse> response = exchange.getOut().getBody(List.class);

                Assert.assertEquals(2, response.size());
                Assert.assertEquals(response.get(0).getPongId(), GRPC_TEST_PONG_ID_1);
                Assert.assertEquals(response.get(0).getPongName(), GRPC_TEST_PING_VALUE + GRPC_TEST_PONG_VALUE);
                Assert.assertEquals(response.get(1).getPongId(), GRPC_TEST_PONG_ID_2);
            }
        });

        Assert.assertTrue("Gave up waiting for latch", latch.await(5, TimeUnit.SECONDS));
    } finally {
        camelctx.close();
    }
}
 
Example 14
Source File: ODataMetaDataRetrievalTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() throws Exception {
    context = new DefaultCamelContext();
    context.disableJMX();
    context.start();
}
 
Example 15
Source File: CamelCollectorTest.java    From karaf-decanter with Apache License 2.0 4 votes vote down vote up
@Test
public void testTracer() throws Exception {
    // install decanter
    System.out.println(executeCommand("feature:repo-add decanter " + System.getProperty("decanter.version")));
    System.out.println(executeCommand("feature:install decanter-collector-camel", new RolePrincipal("admin")));

    // add a event handler
    List<Event> received = new ArrayList();
    EventHandler eventHandler = new EventHandler() {
        @Override
        public void handleEvent(Event event) {
            received.add(event);
        }
    };
    Hashtable serviceProperties = new Hashtable();
    serviceProperties.put(EventConstants.EVENT_TOPIC, "decanter/collect/*");
    bundleContext.registerService(EventHandler.class, eventHandler, serviceProperties);

    // create route with tracer
    EventAdmin eventAdmin = getOsgiService(EventAdmin.class);
    DecanterTraceEventHandler handler = new DecanterTraceEventHandler();
    handler.setEventAdmin(eventAdmin);

    RouteBuilder routeBuilder = new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:test").routeId("route-test").to("log:foo");
        }
    };
    DefaultCamelContext camelContext = new DefaultCamelContext();
    camelContext.setName("context-test");
    camelContext.addRoutes(routeBuilder);
    Tracer tracer = new Tracer();
    tracer.setEnabled(true);
    tracer.setTraceOutExchanges(true);
    tracer.setLogLevel(LoggingLevel.OFF);
    tracer.addTraceHandler(handler);
    camelContext.setTracing(true);
    camelContext.setDefaultTracer(tracer);
    camelContext.start();

    // send a exchange into the route
    ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
    producerTemplate.sendBodyAndHeader("direct:test", "This is a test", "testHeader", "testValue");

    // TODO two events ?
    Assert.assertEquals(2, received.size());

    Assert.assertEquals("decanter/collect/camel/tracer", received.get(0).getTopic());
    Assert.assertEquals("context-test", received.get(0).getProperty("camelContextName"));
    Assert.assertEquals("InOnly", received.get(0).getProperty("exchangePattern"));
    Assert.assertEquals("camelTracer", received.get(0).getProperty("type"));
    Assert.assertEquals("log://foo", received.get(0).getProperty("toNode"));
    Assert.assertEquals("route-test", received.get(0).getProperty("routeId"));
    Assert.assertEquals("direct://test", received.get(0).getProperty("fromEndpointUri"));
    Assert.assertEquals("root", received.get(0).getProperty("karafName"));
    Assert.assertEquals("This is a test", received.get(0).getProperty("inBody"));
    Assert.assertEquals("String", received.get(0).getProperty("inBodyType"));
}
 
Example 16
Source File: SplitStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
@Parameters({"/person-unified-schema.json",
             "/person-unified-schema-draft-4.json",
             "/person-unified-schema-draft-6.json"})
public void testSplitUnifiedJsonStep(final String schemaPath) throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
                new Step.Builder()
                        .id(START_STEP)
                        .stepKind(StepKind.endpoint)
                        .action(new ConnectorAction.Builder()
                                .descriptor(new ConnectorDescriptor.Builder()
                                        .componentScheme("direct")
                                        .putConfiguredProperty("name", "expression")
                                        .build())
                                .build())
                        .build(),
                new Step.Builder()
                        .id(SPLIT_STEP)
                        .stepKind(StepKind.split)
                        .action(new StepAction.Builder()
                                .descriptor(new StepDescriptor.Builder()
                                        .outputDataShape(new DataShape.Builder()
                                                .kind(DataShapeKinds.JSON_SCHEMA)
                                                .putMetadata(DataShapeMetaData.UNIFIED, "true")
                                                .specification(IOStreams.readText(getPersonUnifiedSchema(schemaPath)))
                                                .build())
                                        .build())
                                .build())
                        .build(),
                new Step.Builder()
                        .id(MOCK_STEP)
                        .stepKind(StepKind.endpoint)
                        .action(new ConnectorAction.Builder()
                                .descriptor(new ConnectorDescriptor.Builder()
                                        .componentScheme("mock")
                                        .putConfiguredProperty("name", "expression")
                                        .build())
                                .build())
                        .build()
        );

        // Set up the camel context
        context.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);

        context.start();

        // Dump routes as XML for troubleshooting
        dumpRoutes(context);

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:expression", MockEndpoint.class);
        final String body = "{" +
                    "\"parameters\": {" +
                        "\"a\": \"value\"," +
                        "\"b\": \"other value\"" +
                    "}," +
                    "\"body\": [" +
                        "{\"id\":1,\"name\":\"a\"}," +
                        "{\"id\":2,\"name\":\"b\"}," +
                        "{\"id\":3,\"name\":\"c\"}" +
                    "]" +
                "}";

        result.expectedMessageCount(3);
        result.expectedBodiesReceived("{\"id\":1,\"name\":\"a\"}", "{\"id\":2,\"name\":\"b\"}", "{\"id\":3,\"name\":\"c\"}");

        template.sendBody("direct:expression", body);

        result.assertIsSatisfied();

        verify(activityTracker).startTracking(any(Exchange.class));
        verifyActivityStepTracking(SPLIT_STEP, 0);
        verifyActivityStepTracking(MOCK_STEP, 3);
        verify(activityTracker).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}
 
Example 17
Source File: SplitAggregateStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testSplitAggregate() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
            new Step.Builder()
                .id(START_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("direct")
                        .putConfiguredProperty("name", "expression")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id(SPLIT_STEP)
                .stepKind(StepKind.split)
                .build(),
            new Step.Builder()
                .id(MOCK_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("mock")
                        .putConfiguredProperty("name", "split")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id(AGGREGATE_STEP)
                .stepKind(StepKind.aggregate)
                .build()

        );

        // Set up the camel context
        context.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);
        context.start();

        // Dump routes as XML for troubleshooting
        dumpRoutes(context);

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:split", MockEndpoint.class);
        final List<String> body = Arrays.asList("a","b","c");

        result.expectedBodiesReceived("a", "b", "c");

        List<?> response = template.requestBody("direct:expression", body, List.class);

        result.assertIsSatisfied();
        Assert.assertEquals(body, response);

        verify(activityTracker).startTracking(any(Exchange.class));
        verifyActivityStepTracking(START_STEP, 1);
        verifyActivityStepTracking(SPLIT_STEP, 0);
        verifyActivityStepTracking(MOCK_STEP, 3);
        verifyActivityStepTracking(AGGREGATE_STEP, 0);
        verify(activityTracker, times(4)).track(eq("exchange"), anyString(), eq("step"), anyString(), eq("id"), anyString(), eq("duration"), anyLong(), eq("failure"), isNull());
        verify(activityTracker).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}
 
Example 18
Source File: SplitAggregateStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testSplitAggregateTokenize() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
            new Step.Builder()
                .id(START_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("direct")
                        .putConfiguredProperty("name", "expression")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id(SPLIT_STEP)
                .stepKind(StepKind.split)
                .putConfiguredProperty("language", "tokenize")
                .putConfiguredProperty("expression", "|")
                .build(),
            new Step.Builder()
                .id(MOCK_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("mock")
                        .putConfiguredProperty("name", "split")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id(AGGREGATE_STEP)
                .stepKind(StepKind.aggregate)
                .build()
        );

        // Set up the camel context
        context.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);
        context.start();

        // Dump routes as XML for troubleshooting
        dumpRoutes(context);

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:split", MockEndpoint.class);
        final String body = "a|b|c";

        result.expectedBodiesReceived((Object[])body.split("|"));

        List<?> response = template.requestBody("direct:expression", body, List.class);

        result.assertIsSatisfied();
        Assert.assertEquals(5, response.size());
        Assert.assertEquals(body, response.stream().map(Object::toString).collect(Collectors.joining()));

        verify(activityTracker).startTracking(any(Exchange.class));
        verifyActivityStepTracking(START_STEP, 1);
        verifyActivityStepTracking(SPLIT_STEP, 0);
        verifyActivityStepTracking(MOCK_STEP, 5);
        verifyActivityStepTracking(AGGREGATE_STEP, 0);
        verify(activityTracker, times(6)).track(eq("exchange"), anyString(), eq("step"), anyString(), eq("id"), anyString(), eq("duration"), anyLong(), eq("failure"), isNull());
        verify(activityTracker).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}
 
Example 19
Source File: SplitAggregateStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testSplitAggregateWithOriginalAggregationStrategy() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
            new Step.Builder()
                .id(START_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("direct")
                        .putConfiguredProperty("name", "expression")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id(SPLIT_STEP)
                .stepKind(StepKind.split)
                .putConfiguredProperty("language", "tokenize")
                .putConfiguredProperty("expression", "|")
                .putConfiguredProperty("aggregationStrategy", "original")
                .build(),
            new Step.Builder()
                .id(MOCK_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("mock")
                        .putConfiguredProperty("name", "split")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id(AGGREGATE_STEP)
                .stepKind(StepKind.aggregate)
                .build()
        );

        // Set up the camel context
        context.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);
        context.start();

        // Dump routes as XML for troubleshooting
        dumpRoutes(context);

        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:split", MockEndpoint.class);
        final String body = "a|b|c";

        result.expectedBodiesReceived((Object[])body.split("|"));

        String response = template.requestBody("direct:expression", body, String.class);

        result.assertIsSatisfied();
        Assert.assertEquals(body, response);

        verify(activityTracker).startTracking(any(Exchange.class));
        verifyActivityStepTracking(START_STEP, 1);
        verifyActivityStepTracking(SPLIT_STEP, 0);
        verifyActivityStepTracking(MOCK_STEP, 5);
        verifyActivityStepTracking(AGGREGATE_STEP, 0);
        verify(activityTracker, times(6)).track(eq("exchange"), anyString(), eq("step"), anyString(), eq("id"), anyString(), eq("duration"), anyLong(), eq("failure"), isNull());
        verify(activityTracker).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}
 
Example 20
Source File: FilterStepHandlerTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testPlaintextFilterStep() throws Exception {
    final DefaultCamelContext context = new DefaultCamelContext();

    try {
        final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker,
            new Step.Builder()
                .id(START_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("direct")
                        .putConfiguredProperty("name", "start")
                        .build())
                    .build())
                .build(),
            new Step.Builder()
                .id(FILTER_STEP)
                .stepKind(StepKind.expressionFilter)
                .putConfiguredProperty("filter", "${body} contains 'number'")
                .build(),
            new Step.Builder()
                .id(MOCK_STEP)
                .stepKind(StepKind.endpoint)
                .action(new ConnectorAction.Builder()
                    .descriptor(new ConnectorDescriptor.Builder()
                        .componentScheme("mock")
                        .putConfiguredProperty("name", "result")
                        .build())
                    .build())
                .build()
        );

        // Set up the camel context
        context.setUuidGenerator(KeyGenerator::createKey);
        context.addLogListener(new IntegrationLoggingListener(activityTracker));
        context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker));
        context.addRoutes(routes);
        context.start();

        // Dump routes as XML for troubleshooting
        dumpRoutes(context);

        final List<String> matchingMessages = Collections.singletonList("Body: [number:9436] Log zo syndesisu");
        final List<String> notMatchingMessages = Collections.singletonList("something else");
        final ProducerTemplate template = context.createProducerTemplate();
        final MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);

        List<String> allMessages = new ArrayList<>();
        allMessages.addAll(matchingMessages);
        allMessages.addAll(notMatchingMessages);

        result.expectedBodiesReceived(matchingMessages);

        for (Object body : allMessages) {
            template.sendBody("direct:start", body);
        }

        result.assertIsSatisfied();

        verify(activityTracker, times(allMessages.size())).startTracking(any(Exchange.class));
        verifyActivityStepTracking(MOCK_STEP, matchingMessages.size());
        verifyActivityStepTracking(FILTER_STEP, allMessages.size());
        verify(activityTracker, times(allMessages.size())).finishTracking(any(Exchange.class));
    } finally {
        context.stop();
    }
}