@Override public void configure() throws Exception { weaveById(processorId).replace().to("mock:"+processorId); } });
@Override public void configure() throws Exception { weaveById(id).remove(); } });
@Override public void configure() throws Exception { weaveById(processorId).replace().process(newProcessor); } });
/** * Replaces calling TO {@link AsynchConstants#URI_ASYNCH_IN_MSG} with processor that creates OK response. * <p> * Useful when you want to test input (IN) route of asynchronous process. * * @param builder the advice builder */ public static void replaceToAsynch(AdviceWithRouteBuilder builder) { // remove AsynchInMessageRoute.URI_ASYNCH_IN_MSG builder.weaveByType(ToDefinition.class).replace().process(new Processor() { @Override public void process(Exchange exchange) throws Exception { // creates OK response CallbackResponse callbackResponse = new CallbackResponse(); callbackResponse.setStatus(ConfirmationTypes.OK); exchange.getIn().setBody(callbackResponse); } }); }
@Test public void mockEndpoint_snapshotsTheExchange() throws Exception { // Given weaveRoute(GreetingRouteBuilder.ROUTE_ID, routeBuilder -> routeBuilder.weaveByToString(".*ocessor.*") .replace() .to(mockEndpoint)); // And Exchange inputExchange = new ExchangeBuilder(camelContext) .withBody("Duke") .build(); // When producerTemplate.send(inputExchange); Exchange mockEndpointExchange = mockEndpoint.getExchanges().get(0); // Then assertThat(mockEndpointExchange.getExchangeId()).isEqualTo(inputExchange.getExchangeId()); // And assertThat(mockEndpointExchange.getProperty(FIRST_PROPERTY)).isEqualTo("Hello Duke"); assertThat(mockEndpointExchange.getProperty(SECOND_PROPERTY)).isNull(); // And assertThat(inputExchange.getProperty(FIRST_PROPERTY)).isEqualTo("Hello Duke"); assertThat(inputExchange.getProperty(SECOND_PROPERTY)).isEqualTo("Goodbye Duke"); // And assertThat(mockEndpointExchange).isNotSameAs(inputExchange); }