@Override protected void setUp() throws Exception { super.setUp(); validEndpoint = resolveMandatoryEndpoint("mock:valid", MockEndpoint.class); invalidEndpoint = resolveMandatoryEndpoint("mock:invalid", MockEndpoint.class); validEndpoint.whenAnyExchangeReceived(ProcessorBuilder.setBody(Builder.constant("validResult"))); invalidEndpoint.whenAnyExchangeReceived(ProcessorBuilder.setBody(Builder.constant("invalidResult"))); }
@Override public void setUp() throws Exception { super.setUp(); validEndpoint = getMockEndpoint("mock:valid"); invalidEndpoint = getMockEndpoint("mock:invalid"); validEndpoint.whenAnyExchangeReceived(ProcessorBuilder.setOutBody(Builder.constant("validResult"))); invalidEndpoint.whenAnyExchangeReceived(ProcessorBuilder.setOutBody(Builder.constant("invalidResult"))); }
private Predicate buildPredicate(String header, List<String> values) { if (values.isEmpty()) { return BooleanPredicate.TRUE; } else { return Builder.header(header).in(values.toArray()); } }
@Test public void testInputCommand() throws Exception { context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() { @Override public void configure() throws Exception { replaceFromWith("direct:test"); mockEndpoints("direct:execute-command"); } } ); context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:NOME_COMMAND") .to("mock:results"); } }); String input = "{\n" + " \"command\": \"NOME_COMMAND\",\n" + " \"params\": [\n" + " {\n" + " \"key\": \"NOME_CHIAVE1\",\n" + " \"value\": \"VALORE1\"\n" + " },\n" + " {\n" + " \"key\": \"NOME_CHIAVE2\",\n" + " \"value\": \"VALORE2\"\n" + " }\n" + " ]\n" + "}\n"; context.start(); getMockEndpoint("mock:direct:execute-command", false).expectedMessageCount(1); getMockEndpoint("mock:direct:execute-command", false) .message(0) .predicate(isInstanceOf(body(), Command.class)) .predicate(isEqualTo(Builder.simple("${body.command}"), Builder.constant("NOME_COMMAND"))) .predicate(isEqualTo(Builder.simple("${body.params?.size}"), Builder.constant(2))) .predicate(isInstanceOf(Builder.simple("${body.params[0]}"), KeyValueParam.class)) .predicate(isEqualTo(Builder.simple("${body.params[0].key}"), Builder.constant("NOME_CHIAVE1"))) .predicate(isEqualTo(Builder.simple("${body.params[0].value}"), Builder.constant("VALORE1"))) .predicate(isInstanceOf(Builder.simple("${body.params[1]}"), KeyValueParam.class)) .predicate(isEqualTo(Builder.simple("${body.params[1].key}"), Builder.constant("NOME_CHIAVE2"))) .predicate(isEqualTo(Builder.simple("${body.params[1].value}"), Builder.constant("VALORE2"))); getMockEndpoint("mock:results", false).expectedMessageCount(1); sendBody("direct:test", input); assertMockEndpointsSatisfied(1, TimeUnit.MINUTES); }
/** * Returns a value builder for the given header */ public static ValueBuilder header(String name) { return Builder.header(name); }
/** * Returns a value builder for the given exchange property */ public static ValueBuilder exchangeProperty(String name) { return Builder.exchangeProperty(name); }
/** * Returns a predicate and value builder for the inbound body on an exchange */ public static ValueBuilder body() { return Builder.body(); }
/** * Returns a value builder for the given system property */ public static ValueBuilder systemProperty(String name) { return Builder.systemProperty(name); }
/** * Returns a value builder for the given system property */ public static ValueBuilder systemProperty(String name, String defaultValue) { return Builder.systemProperty(name, defaultValue); }
/** * Returns a value builder for the given property */ public static ValueBuilder property(String name) { return Builder.exchangeProperty(name); }
/** * Returns a value builder for the given exchange property * * @deprecated use {@link #exchangeProperty(String)} */ @Deprecated public static ValueBuilder property(String name) { return Builder.exchangeProperty(name); }
/** * Returns a predicate and value builder for the inbound message body as a * specific type */ public static <T> ValueBuilder bodyAs(Class<T> type) { return Builder.bodyAs(type); }
/** * Returns a predicate and value builder for the outbound body on an * exchange * * @deprecated use {@link #body()} */ @Deprecated public static ValueBuilder outBody() { return Builder.outBody(); }
/** * Returns a predicate and value builder for the outbound message body as a * specific type * * @deprecated use {@link #bodyAs(Class)} */ @Deprecated public static <T> ValueBuilder outBodyAs(Class<T> type) { return Builder.outBodyAs(type); }
/** * Returns a predicate and value builder for the fault body on an * exchange */ public static ValueBuilder faultBody() { return Builder.faultBody(); }
/** * Returns a predicate and value builder for the fault message body as a * specific type * * @deprecated use {@link #bodyAs(Class)} */ @Deprecated public static <T> ValueBuilder faultBodyAs(Class<T> type) { return Builder.faultBodyAs(type); }
/** * Returns a value builder for the given property * * @deprecated use {@link #exchangeProperty(String)} */ @Deprecated public static ValueBuilder property(String name) { return Builder.exchangeProperty(name); }
/** * Returns a predicate and value builder for the outbound body on an * exchange */ public static ValueBuilder outBody() { return Builder.outBody(); }
/** * Returns a predicate and value builder for the outbound message body as a * specific type */ public static <T> ValueBuilder outBodyAs(Class<T> type) { return Builder.outBodyAs(type); }