Java Code Examples for org.apache.camel.component.mock.MockEndpoint#expectedHeaderReceived()

The following examples show how to use org.apache.camel.component.mock.MockEndpoint#expectedHeaderReceived() . 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: PubNubIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testPubNubPublish() throws Exception {
    CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository());
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .to("pubnub:publishChannel?pubnub=#pubnub")
            .to("mock:resultA");
        }
    });

    MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:resultA", MockEndpoint.class);
    mockEndpoint.expectedMessageCount(1);
    mockEndpoint.expectedHeaderReceived(TIMETOKEN, "14598111595318003");

    camelctx.start();
    try {
        ProducerTemplate template = camelctx.createProducerTemplate();
        template.sendBody("direct:start", "Hello Kermit");

        mockEndpoint.assertIsSatisfied();
    } finally {
        camelctx.close();
    }
}
 
Example 2
Source File: CaffeineCacheIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testCacheClear() throws Exception {

    camelctx.addRoutes(createRouteBuilder());

    camelctx.start();
    try {
        MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class);
        mock.expectedMinimumMessageCount(1);
        mock.expectedBodiesReceived((Object)null);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_HAS_RESULT, false);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_SUCCEEDED, true);

        camelctx.createFluentProducerTemplate().to("direct://start")
        .withHeader(CaffeineConstants.ACTION, CaffeineConstants.ACTION_CLEANUP)
        .send();

        mock.assertIsSatisfied();
    } finally {
        camelctx.close();
    }
}
 
Example 3
Source File: CaffeineLoadCacheIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testCacheGet() throws Exception {
    final Integer key = 1;
    final Integer val = 2;

    camelctx.addRoutes(createRouteBuilder());

    camelctx.start();
    try {
        MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class);
        mock.expectedMinimumMessageCount(1);
        mock.expectedBodiesReceived(val);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_HAS_RESULT, true);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_SUCCEEDED, true);

        camelctx.createFluentProducerTemplate().to("direct://start")
        .withHeader(CaffeineConstants.ACTION, CaffeineConstants.ACTION_GET)
        .withHeader(CaffeineConstants.KEY, key)
        .withBody(val)
        .send();

        mock.assertIsSatisfied();
    } finally {
        camelctx.close();
    }
}
 
Example 4
Source File: CaffeineCacheIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testCacheInvalidate() throws Exception {
    final String key = generateRandomString();
    final String val = generateRandomString();

    cache.put(key, val);

    camelctx.addRoutes(createRouteBuilder());

    camelctx.start();
    try {
        MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class);
        mock.expectedMinimumMessageCount(1);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_HAS_RESULT, false);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_SUCCEEDED, true);

        camelctx.createFluentProducerTemplate().to("direct://start")
        .withHeader(CaffeineConstants.ACTION, CaffeineConstants.ACTION_INVALIDATE)
        .withHeader(CaffeineConstants.KEY, key)
        .send();

        mock.assertIsSatisfied();

        Assert.assertFalse(cache.getIfPresent(key) != null);
    } finally {
        camelctx.close();
    }
}
 
Example 5
Source File: CaffeineCacheIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testCacheGet() throws Exception {
    final String key = generateRandomString();
    final String val = generateRandomString();

    cache.put(key, val);

    camelctx.addRoutes(createRouteBuilder());

    camelctx.start();
    try {
        MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class);
        mock.expectedMinimumMessageCount(1);
        mock.expectedBodiesReceived(val);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_HAS_RESULT, true);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_SUCCEEDED, true);

        camelctx.createFluentProducerTemplate().to("direct://start")
        .withHeader(CaffeineConstants.ACTION, CaffeineConstants.ACTION_GET)
        .withHeader(CaffeineConstants.KEY, key)
        .withBody(val)
        .send();

        mock.assertIsSatisfied();
    } finally {
        camelctx.close();
    }
}
 
Example 6
Source File: CaffeineCacheIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testCachePutAll() throws Exception {
    final Map<String, String> map = generateRandomMapOfString(3);
    final Set<String> keys = map.keySet().stream().limit(2).collect(Collectors.toSet());

    camelctx.addRoutes(createRouteBuilder());

    camelctx.start();
    try {
        MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class);
        mock.expectedMinimumMessageCount(1);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_HAS_RESULT, false);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_SUCCEEDED, true);

        camelctx.createFluentProducerTemplate().to("direct://start")
        .withHeader(CaffeineConstants.ACTION, CaffeineConstants.ACTION_PUT_ALL)
        .withBody(map)
        .send();

        final Map<Object, Object> elements = cache.getAllPresent(keys);
        keys.forEach(k -> {
            Assert.assertTrue(elements.containsKey(k));
            Assert.assertEquals(map.get(k), elements.get(k));
        });

        mock.assertIsSatisfied();
    } finally {
        camelctx.close();
    }
}
 
Example 7
Source File: RxJava2IntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testOnNextHeaderForwarded() throws Exception {
    CamelContext camelctx = createCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("reactive-streams:numbers")
                .to("mock:endpoint");
        }
    });

    CamelReactiveStreamsService crs = CamelReactiveStreams.get(camelctx);
    Subscriber<Integer> numbers = crs.streamSubscriber("numbers", Integer.class);

    camelctx.start();
    try {
        Flowable.just(1).subscribe(numbers);

        MockEndpoint endpoint = camelctx.getEndpoint("mock:endpoint", MockEndpoint.class);
        endpoint.expectedHeaderReceived(ReactiveStreamsConstants.REACTIVE_STREAMS_EVENT_TYPE, "onNext");
        endpoint.expectedMessageCount(1);
        endpoint.assertIsSatisfied();

        Exchange ex = endpoint.getExchanges().get(0);
        Assert.assertEquals(1, ex.getIn().getBody());
    } finally {
        camelctx.close();
    }
}
 
Example 8
Source File: NormalizerTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testNormalizeUnknown() throws Exception {
    getMockEndpoint("mock:csv").setExpectedMessageCount(0);
    getMockEndpoint("mock:json").setExpectedMessageCount(0);
    getMockEndpoint("mock:xml").setExpectedMessageCount(0);
    getMockEndpoint("mock:normalized").setExpectedMessageCount(0);

    final MockEndpoint mockUnknown = getMockEndpoint("mock:unknown");
    mockUnknown.expectedBodiesReceived("Unknown Data");
    mockUnknown.expectedHeaderReceived(Exchange.FILE_NAME, "bookstore.unknown");

    template.sendBodyAndHeader("direct:start", "Unknown Data", Exchange.FILE_NAME, "bookstore.unknown");

    assertMockEndpointsSatisfied();
}
 
Example 9
Source File: NormalizerSpringTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testNormalizeUnknown() throws Exception {
    getMockEndpoint("mock:csv").setExpectedMessageCount(0);
    getMockEndpoint("mock:json").setExpectedMessageCount(0);
    getMockEndpoint("mock:xml").setExpectedMessageCount(0);
    getMockEndpoint("mock:normalized").setExpectedMessageCount(0);

    final MockEndpoint mockUnknown = getMockEndpoint("mock:unknown");
    mockUnknown.expectedBodiesReceived("Unknown Data");
    mockUnknown.expectedHeaderReceived(Exchange.FILE_NAME, "bookstore.unknown");

    template.sendBodyAndHeader("direct:start", "Unknown Data", Exchange.FILE_NAME, "bookstore.unknown");

    assertMockEndpointsSatisfied();
}
 
Example 10
Source File: RxJava2IntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testOnErrorHeaderForwarded() throws Exception {
    CamelContext camelctx = createCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("reactive-streams:numbers?forwardOnError=true")
                .to("mock:endpoint");
        }
    });

    CamelReactiveStreamsService crs = CamelReactiveStreams.get(camelctx);
    Subscriber<Integer> numbers = crs.streamSubscriber("numbers", Integer.class);

    camelctx.start();
    try {
        RuntimeException ex = new RuntimeException("1");

        Flowable.just(1)
            .map(n -> {
                if (n == 1) {
                    throw ex;
                }
                return n;
            })
            .subscribe(numbers);


        MockEndpoint endpoint = camelctx.getEndpoint("mock:endpoint", MockEndpoint.class);
        endpoint.expectedMessageCount(1);
        endpoint.expectedHeaderReceived(ReactiveStreamsConstants.REACTIVE_STREAMS_EVENT_TYPE, "onError");
        endpoint.assertIsSatisfied();

        Exchange exchange = endpoint.getExchanges().get(0);
        Assert.assertEquals(ex, exchange.getIn().getBody());
    } finally {
        camelctx.close();
    }
}
 
Example 11
Source File: CaffeineLoadCacheIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testCacheInvalidateAll() throws Exception {
    final Map<Integer, Integer> map = new HashMap<>();
    map.put(1, 1);
    map.put(2, 2);
    map.put(3, 3);
    final Set<Integer> keys = map.keySet().stream().limit(2).collect(Collectors.toSet());

    cache.putAll(map);

    camelctx.addRoutes(createRouteBuilder());

    camelctx.start();
    try {
        MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class);
        mock.expectedMinimumMessageCount(1);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_HAS_RESULT, false);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_SUCCEEDED, true);

        camelctx.createFluentProducerTemplate().to("direct://start")
        .withHeader(CaffeineConstants.ACTION, CaffeineConstants.ACTION_INVALIDATE_ALL)
        .withHeader(CaffeineConstants.KEYS, keys)
        .send();

        mock.assertIsSatisfied();

        final Map<Integer, Integer> elements = cache.getAllPresent(keys);
        keys.forEach(k -> {
            Assert.assertFalse(elements.containsKey(k));
        });
    } finally {
        camelctx.close();
    }
}
 
Example 12
Source File: CaffeineCacheIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testStats() throws Exception {
    final Map<String, String> map = generateRandomMapOfString(3);
    final Set<String> keys = map.keySet().stream().limit(2).collect(Collectors.toSet());

    camelctx.addRoutes(createRouteBuilder());

    camelctx.start();
    try {
        MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class);
        mock.expectedMinimumMessageCount(1);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_HAS_RESULT, false);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_SUCCEEDED, true);

        camelctx.createFluentProducerTemplate().to("direct://start")
        .withHeader(CaffeineConstants.ACTION, CaffeineConstants.ACTION_PUT_ALL)
        .withBody(map)
        .send();

        mock.assertIsSatisfied();

        final Map<Object, Object> elements = cache.getAllPresent(keys);
        keys.forEach(k -> {
            Assert.assertTrue(elements.containsKey(k));
            Assert.assertEquals(map.get(k), elements.get(k));
        });
    } finally {
        camelctx.close();
    }
}
 
Example 13
Source File: CaffeineCacheIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testCacheGetAll() throws Exception {
    final Map<String, String> map = generateRandomMapOfString(3);
    final Set<String> keys = map.keySet().stream().limit(2).collect(Collectors.toSet());

    cache.putAll(map);

    camelctx.addRoutes(createRouteBuilder());

    camelctx.start();
    try {
        MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class);
        mock.expectedMinimumMessageCount(1);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_HAS_RESULT, true);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_SUCCEEDED, true);

        camelctx.createFluentProducerTemplate().to("direct://start")
        .withHeader(CaffeineConstants.ACTION, CaffeineConstants.ACTION_GET_ALL)
        .withHeader(CaffeineConstants.KEYS, keys)
        .send();

        final Map<?, ?> elements = mock.getExchanges().get(0).getIn().getBody(Map.class);
        keys.forEach(k -> {
            Assert.assertTrue(elements.containsKey(k));
            Assert.assertEquals(map.get(k), elements.get(k));
        });
    } finally {
        camelctx.close();
    }
}
 
Example 14
Source File: CaffeineCacheIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testCachePut() throws Exception {
    final String key = generateRandomString();
    final String val = generateRandomString();

    camelctx.addRoutes(createRouteBuilder());

    camelctx.start();
    try {
        MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class);
        mock.expectedMinimumMessageCount(1);
        mock.expectedBodiesReceived(val);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_HAS_RESULT, false);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_SUCCEEDED, true);

        camelctx.createFluentProducerTemplate().to("direct://start")
        .withHeader(CaffeineConstants.ACTION, CaffeineConstants.ACTION_PUT)
        .withHeader(CaffeineConstants.KEY, key)
        .withBody(val)
        .send();

        Assert.assertTrue(cache.getIfPresent(key) != null);
        Assert.assertEquals(val, cache.getIfPresent(key));
    } finally {
        camelctx.close();
    }
}
 
Example 15
Source File: CaffeineLoadCacheIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testCachePutAll() throws Exception {
    final Map<Integer, Integer> map = new HashMap<>();
    map.put(1, 1);
    map.put(2, 2);
    map.put(3, 3);
    final Set<Integer> keys = map.keySet().stream().limit(2).collect(Collectors.toSet());

    camelctx.addRoutes(createRouteBuilder());

    camelctx.start();
    try {
        MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class);
        mock.expectedMinimumMessageCount(1);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_HAS_RESULT, false);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_SUCCEEDED, true);

        camelctx.createFluentProducerTemplate().to("direct://start")
        .withHeader(CaffeineConstants.ACTION, CaffeineConstants.ACTION_PUT_ALL)
        .withBody(map)
        .send();

        final Map<Integer, Integer> elements = cache.getAllPresent(keys);
        keys.forEach(k -> {
            Assert.assertTrue(elements.containsKey(k));
            Assert.assertEquals(map.get(k), elements.get(k));
        });

        mock.assertIsSatisfied();
    } finally {
        camelctx.close();
    }
}
 
Example 16
Source File: RxJava2IntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testOnCompleteHeaderForwarded() throws Exception {
    CamelContext camelctx = createCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("reactive-streams:numbers?forwardOnComplete=true")
                .to("mock:endpoint");
        }
    });

    CamelReactiveStreamsService crs = CamelReactiveStreams.get(camelctx);
    Subscriber<Integer> numbers = crs.streamSubscriber("numbers", Integer.class);

    camelctx.start();
    try {
        Flowable.<Integer>empty().subscribe(numbers);

        MockEndpoint endpoint = camelctx.getEndpoint("mock:endpoint", MockEndpoint.class);
        endpoint.expectedMessageCount(1);
        endpoint.expectedHeaderReceived(ReactiveStreamsConstants.REACTIVE_STREAMS_EVENT_TYPE, "onComplete");
        endpoint.expectedBodiesReceived(new Object[]{null});
        endpoint.assertIsSatisfied();
    } finally {
        camelctx.close();
    }
}
 
Example 17
Source File: CaffeineLoadCacheIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testCachePut() throws Exception {
    final Integer key = 1;
    final Integer val = 3;

    camelctx.addRoutes(createRouteBuilder());

    camelctx.start();
    try {
        MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class);
        mock.expectedMinimumMessageCount(1);
        mock.expectedBodiesReceived(val);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_HAS_RESULT, false);
        mock.expectedHeaderReceived(CaffeineConstants.ACTION_SUCCEEDED, true);

        camelctx.createFluentProducerTemplate().to("direct://start")
        .withHeader(CaffeineConstants.ACTION, CaffeineConstants.ACTION_PUT)
        .withHeader(CaffeineConstants.KEY, key)
        .withBody(val)
        .send();

        Assert.assertTrue(cache.getIfPresent(key) != null);
        Assert.assertEquals(val, cache.getIfPresent(key));
    } finally {
        camelctx.close();
    }
}
 
Example 18
Source File: KnativeSourceRoutesLoaderTest.java    From camel-k-runtime with Apache License 2.0 4 votes vote down vote up
@ParameterizedTest
@MethodSource("parameters")
public void testWrapLoaderWithSyntheticServiceDefinition(String uri) throws Exception {
    LOGGER.info("uri: {}", uri);

    final String data = UUID.randomUUID().toString();
    final TestRuntime runtime = new TestRuntime();
    final String typeHeaderKey = CloudEvents.v1_0.mandatoryAttribute(CloudEvent.CAMEL_CLOUD_EVENT_TYPE).http();
    final String typeHeaderVal = UUID.randomUUID().toString();
    final String url = String.format("http://localhost:%d", runtime.port);

    KnativeComponent component = new KnativeComponent();
    component.setEnvironment(new KnativeEnvironment(Collections.emptyList()));

    Properties properties = new Properties();
    properties.put("knative.sink", "mySynk");
    properties.put("k.sink", String.format("http://localhost:%d", runtime.port));
    properties.put("k.ce.overrides", Knative.MAPPER.writeValueAsString(Map.of(typeHeaderKey, typeHeaderVal)));

    CamelContext context = runtime.getCamelContext();
    context.getPropertiesComponent().setInitialProperties(properties);
    context.addComponent(KnativeConstants.SCHEME, component);

    Source source = Sources.fromURI(uri);
    SourceLoader loader = RoutesConfigurer.load(runtime, source);

    assertThat(loader.getSupportedLanguages()).contains(source.getLanguage());
    assertThat(runtime.builders).hasSize(1);

    try {
        context.addRoutes(runtime.builders.get(0));
        context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                fromF("platform-http:/")
                    .routeId("http")
                    .to("mock:result");
            }
        });
        context.start();

        var definitions = context.adapt(ModelCamelContext.class).getRouteDefinitions();
        var services = context.getRegistry().findByType(KnativeEnvironment.KnativeServiceDefinition.class);

        assertThat(definitions).hasSize(2);
        assertThat(definitions).first().satisfies(d -> {
            assertThat(d.getOutputs()).last().hasFieldOrPropertyWithValue(
                "endpointUri",
                "knative://endpoint/mySynk"
            );
        });

        assertThat(services).hasSize(1);
        assertThat(services).first().hasFieldOrPropertyWithValue("name", "mySynk");
        assertThat(services).first().hasFieldOrPropertyWithValue("url", url);

        MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class);
        mock.expectedMessageCount(1);
        mock.expectedBodiesReceived(data);
        mock.expectedHeaderReceived(typeHeaderKey, typeHeaderVal);

        context.createFluentProducerTemplate()
            .to("direct:start")
            .withHeader("MyHeader", data)
            .send();

        mock.assertIsSatisfied();
    } finally {
        context.stop();
    }
}
 
Example 19
Source File: KnativeHttpTest.java    From camel-k-runtime with Apache License 2.0 4 votes vote down vote up
@ParameterizedTest
@EnumSource(CloudEvents.class)
void testEventsWithTypeAndVersion(CloudEvent ce) throws Exception {
    configureKnativeComponent(
        context,
        ce,
        event(
            Knative.EndpointKind.sink,
            "default",
            "localhost",
            platformHttpPort,
            mapOf(
                Knative.KNATIVE_EVENT_TYPE, "org.apache.camel.event",
                Knative.CONTENT_TYPE, "text/plain",
                Knative.KNATIVE_KIND, "MyObject",
                Knative.KNATIVE_API_VERSION, "v1"
            )),
        sourceEvent(
            "default",
            mapOf(
                Knative.KNATIVE_EVENT_TYPE, "org.apache.camel.event",
                Knative.CONTENT_TYPE, "text/plain",
                Knative.KNATIVE_KIND, "MyOtherObject",
                Knative.KNATIVE_API_VERSION, "v2"
            ))
    );

    RouteBuilder.addRoutes(context, b -> {
        b.from("direct:source")
            .to("knative:event/myEvent?kind=MyObject&apiVersion=v1");
        b.from("knative:event/myEvent?kind=MyOtherObject&apiVersion=v2")
            .to("mock:ce");
    });

    context.start();

    MockEndpoint mock = context.getEndpoint("mock:ce", MockEndpoint.class);
    mock.expectedHeaderReceived(CloudEvent.CAMEL_CLOUD_EVENT_VERSION, ce.version());
    mock.expectedHeaderReceived(CloudEvent.CAMEL_CLOUD_EVENT_TYPE, "myEvent");
    mock.expectedHeaderReceived(Exchange.CONTENT_TYPE, "text/plain");
    mock.expectedMessagesMatches(e -> e.getMessage().getHeaders().containsKey(CloudEvent.CAMEL_CLOUD_EVENT_TIME));
    mock.expectedMessagesMatches(e -> e.getMessage().getHeaders().containsKey(CloudEvent.CAMEL_CLOUD_EVENT_ID));
    mock.expectedBodiesReceived("test");
    mock.expectedMessageCount(1);

    template.sendBody("direct:source", "test");

    mock.assertIsSatisfied();
}
 
Example 20
Source File: KnativeHttpTest.java    From camel-k-runtime with Apache License 2.0 4 votes vote down vote up
@ParameterizedTest
@EnumSource(CloudEvents.class)
void testReplyCloudEventHeaders(CloudEvent ce) throws Exception {
    configureKnativeComponent(
        context,
        ce,
        sourceEndpoint(
            "from",
            mapOf(
                Knative.KNATIVE_EVENT_TYPE, "org.apache.camel.event",
                Knative.CONTENT_TYPE, "text/plain"
            )),
        endpoint(
            Knative.EndpointKind.sink,
            "to",
            "localhost",
            platformHttpPort,
            mapOf(
                Knative.KNATIVE_EVENT_TYPE, "org.apache.camel.event",
                Knative.CONTENT_TYPE, "text/plain"
            ))
    );

    RouteBuilder.addRoutes(context, b -> {
        b.from("knative:endpoint/from?replyWithCloudEvent=true")
            .convertBodyTo(String.class)
            .setBody()
            .constant("consumer")
            .setHeader(CloudEvent.CAMEL_CLOUD_EVENT_TYPE)
            .constant("custom");
        b.from("direct:source")
            .to("knative://endpoint/to")
            .log("${body}")
            .to("mock:to");
    });

    MockEndpoint mock = context.getEndpoint("mock:to", MockEndpoint.class);
    mock.expectedBodiesReceived("consumer");
    mock.expectedHeaderReceived(ce.mandatoryAttribute(CloudEvent.CAMEL_CLOUD_EVENT_TYPE).http(), "custom");
    mock.expectedMessageCount(1);

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

    mock.assertIsSatisfied();
}