void advice(@Observes CamelContextStartingEvent event, @Uri("mock:messages") MockEndpoint messages, ModelCamelContext context) throws Exception { messages.expectedMessageCount(2); messages.expectedBodiesReceived("Hello", "Bye"); verifier.messages = messages; context.getRouteDefinition("route") .adviceWith(context, new AdviceWithRouteBuilder() { @Override public void configure() { weaveAddLast().to("mock:messages"); } }); }
@Test public void sendMessageToProducer(@Uri("direct:produce") ProducerTemplate producer) throws InterruptedException { long random = Math.round(Math.random() * Long.MAX_VALUE); produced.expectedMessageCount(1); produced.expectedBodiesReceived(random); produced.message(0).predicate(exchange -> { EventMetadata metadata = exchange.getIn().getHeader("metadata", EventMetadata.class); return metadata.getType().equals(Long.class) && metadata.getQualifiers().equals(new HashSet<>(Arrays.asList(new AnnotationLiteral<Any>() {}, new AnnotationLiteral<Default>() {}))); }); consumed.expectedMessageCount(1); consumed.expectedBodiesReceived(random); producer.sendBody(random); assertIsSatisfied(2L, TimeUnit.SECONDS, consumed, produced); }
void hello(@Observes CamelContextStartedEvent event, // Configuration properties can be injected with @ConfigProperty @ConfigProperty(name = "message") String message, // Property placeholders in @Uri qualifier are also resolved @Uri("{{destination}}") ProducerTemplate producer) { producer.sendBody(message); }
@Test public void testRouteMessage(@Uri("mock:outbound") MockEndpoint outbound) { assertThat("Exchange count is incorrect!", outbound.getExchanges(), hasSize(1)); assertThat("Exchange body is incorrect!", outbound.getExchanges().get(0).getIn().getBody(String.class), is(equalTo("Hello"))); }
@Test @Order(1) public void takeTheBluePill(@Uri("mock:matrix") MockEndpoint matrix) throws InterruptedException { matrix.expectedMessageCount(1); matrix.expectedBodiesReceived("Matrix » Take the blue pill!"); prompt.sendBody(neo, "Take the blue pill!"); assertIsSatisfied(2L, TimeUnit.SECONDS, matrix); }
@Test @Order(2) public void takeTheRedPill(@Uri("mock:zion") MockEndpoint zion) throws InterruptedException { zion.expectedMessageCount(1); zion.expectedHeaderReceived("location", "matrix"); prompt.sendBody(neo, "Take the red pill!"); assertIsSatisfied(2L, TimeUnit.SECONDS, zion); }
@Test public void sendMessageToInbound(@Uri("direct:start") ProducerTemplate inbound, @Uri("mock:result") MockEndpoint outbound) throws InterruptedException { outbound.expectedMessageCount(1); outbound.expectedBodiesReceived("test"); inbound.sendBody("test"); assertIsSatisfied(2L, TimeUnit.SECONDS, outbound); }
@Test @InSequence(2) public void sendMessageToInbound(@Uri("direct:inbound") ProducerTemplate inbound, @Uri("mock:outbound") MockEndpoint outbound) throws InterruptedException { outbound.expectedMessageCount(1); outbound.expectedBodiesReceived("second-first-test"); inbound.sendBody("test"); MockEndpoint.assertIsSatisfied(1L, TimeUnit.SECONDS, outbound); }
@Test @InSequence(2) public void sendMessageToInbound(@Uri("direct:in") ProducerTemplate in, @Uri("mock:out") MockEndpoint out) throws InterruptedException { out.expectedMessageCount(1); out.expectedBodiesReceived("test"); out.expectedHeaderReceived("header", "value"); in.sendBody("test"); assertIsSatisfied(2L, TimeUnit.SECONDS, out); }
@Test public void sendMessageToProducer(@Uri("direct:produce") ProducerTemplate producer) throws InterruptedException { long random = Math.round(Math.random() * Long.MAX_VALUE); produced.expectedMessageCount(1); produced.expectedBodiesReceived(random); consumed.expectedMessageCount(1); consumed.expectedBodiesReceived(random); producer.sendBody(random); assertIsSatisfied(2L, TimeUnit.SECONDS, consumed, produced); }
@Test public void camelStartedEvent(@Uri("mock:started") MockEndpoint started) { assertThat("Event fired is incorrect!", started.getExchanges(), contains( hasProperty("in", hasProperty("body", instanceOf(CamelContextStartedEvent.class))))); }
@Test public void sendMessageToInbound(@Uri("direct:inbound") ProducerTemplate inbound, @Uri("mock:outbound") MockEndpoint outbound) throws InterruptedException { outbound.expectedMessageCount(1); outbound.expectedBodiesReceived("test"); outbound.expectedHeaderReceived("context", "first"); inbound.sendBody("test"); assertIsSatisfied(2L, TimeUnit.SECONDS, outbound); }
@Test public void sendMessageToInbound(@Uri("direct:inbound") ProducerTemplate in, @Uri("mock:outbound") MockEndpoint out) throws InterruptedException { out.expectedMessageCount(1); out.expectedBodiesReceived("test-processed"); in.sendBody("test"); assertIsSatisfied(2L, TimeUnit.SECONDS, out); }
@Test public void sendMessageToFirstInbound(@Uri(value = "direct:inbound", context = "first") ProducerTemplate inbound, @Uri(value = "mock:outbound", context = "first") MockEndpoint outbound) throws InterruptedException { outbound.expectedMessageCount(1); outbound.expectedBodiesReceived("test"); outbound.expectedHeaderReceived("context", "first"); inbound.sendBody("test"); assertIsSatisfied(2L, TimeUnit.SECONDS, outbound); }
@Test public void sendMessageToSecondInbound(@Uri("direct:inbound") @ContextName("second") ProducerTemplate inbound, @Uri("mock:outbound") @ContextName("second") MockEndpoint outbound) throws InterruptedException { outbound.expectedMessageCount(1); outbound.expectedBodiesReceived("test"); outbound.expectedHeaderReceived("context", "second"); inbound.sendBody("test"); assertIsSatisfied(2L, TimeUnit.SECONDS, outbound); }
@Test public void sendMessageToInbound() throws InterruptedException { ProducerTemplate inbound = producers.select(Uri.Literal.of("direct:inbound")).get(); MockEndpoint outbound = endpoints.select(MockEndpoint.class, Uri.Literal.of("mock:outbound")).get(); outbound.expectedMessageCount(1); outbound.expectedBodiesReceived("test"); inbound.sendBody("test"); assertIsSatisfied(2L, TimeUnit.SECONDS, outbound); }
@Test public void sendMessageToInbound(@Uri("direct:inbound") ProducerTemplate inbound, @Uri("mock:outbound") MockEndpoint outbound) throws InterruptedException { outbound.expectedMessageCount(1); TypeConverterInput input = new TypeConverterInput(); input.setProperty("property value is [{{property1}}]"); inbound.sendBody(input); assertIsSatisfied(2L, TimeUnit.SECONDS, outbound); assertThat(outbound.getExchanges().get(0).getIn().getBody(TypeConverterOutput.class).getProperty(), is(equalTo("property value is [value 1]"))); }
@Test @InSequence(2) public void sendMessageToInbound(@Uri("direct:inbound") ProducerTemplate in, @Uri("mock:outbound") MockEndpoint out) throws InterruptedException { out.expectedMessageCount(1); out.expectedBodiesReceived("test-processed"); in.sendBody("test"); assertIsSatisfied(2L, TimeUnit.SECONDS, out); }
@Test @InSequence(2) public void sendMessageToInbound(@Uri("direct:inbound") FluentProducerTemplate in, @Uri("mock:outbound") MockEndpoint out) throws InterruptedException { out.expectedMessageCount(1); out.expectedBodiesReceived("test-processed"); in.withBody("test").send(); assertIsSatisfied(2L, TimeUnit.SECONDS, out); }
@Test public void sendMessageToFirstInbound(@Uri("direct:inbound") @ContextName("first") ProducerTemplate inbound, @Uri("mock:outbound") @ContextName("first") MockEndpoint outbound) throws InterruptedException { outbound.expectedMessageCount(1); outbound.expectedBodiesReceived("test"); outbound.expectedHeaderReceived("context", "first"); inbound.sendBody("test"); assertIsSatisfied(2L, TimeUnit.SECONDS, outbound); }
@Test @InSequence(1) public void takeTheBluePill(@Uri("mock:matrix") MockEndpoint matrix) throws InterruptedException { matrix.expectedMessageCount(1); matrix.expectedBodiesReceived("Matrix » Take the blue pill!"); prompt.sendBody(neo, "Take the blue pill!"); assertIsSatisfied(2L, TimeUnit.SECONDS, matrix); }
@Test @InSequence(2) public void takeTheRedPill(@Uri("mock:zion") MockEndpoint zion) throws InterruptedException { zion.expectedMessageCount(1); zion.expectedHeaderReceived("location", "matrix"); prompt.sendBody(neo, "Take the red pill!"); assertIsSatisfied(2L, TimeUnit.SECONDS, zion); }