private void replaceFromEndpoints() throws Exception { for (final Map.Entry<String, String> entry : fromEndpoints.entrySet()) { context.getRouteDefinition(entry.getKey()).adviceWith(context, new AdviceWithRouteBuilder() { @Override public void configure() throws Exception { replaceFromWith(entry.getValue()); } }); } }
public static void skipProcessor(final String processorId, final String routeId, ModelCamelContext camelContext) throws Exception { getRouteDefinition(routeId, camelContext).adviceWith(camelContext, new AdviceWithRouteBuilder() { @Override public void configure() throws Exception { weaveById(processorId).replace().to("mock:"+processorId); } }); }
public static void mockEndpointAndInsertBody(final String uri, final Object body, String routeId, ModelCamelContext camelContext) throws Exception { getRouteDefinition(routeId, camelContext).adviceWith(camelContext, new AdviceWithRouteBuilder() { @Override public void configure() throws Exception { interceptSendToEndpoint(uri) .skipSendToOriginalEndpoint() .process(exchange -> exchange.getIn().setBody(body)); } }); }
public static void skipById(final String id, final String routeId, ModelCamelContext camelContext) throws Exception { getRouteDefinition(routeId, camelContext).adviceWith(camelContext, new AdviceWithRouteBuilder() { @Override public void configure() throws Exception { weaveById(id).remove(); } }); }
/** * @param endpointPattern endpoint uri or a pattern (String with '*' at the end or a regex) * @param routeId routeId * @param camelContext camelContext * * @throws Exception */ public static void skipEndpoint(final String endpointPattern, final String routeId, ModelCamelContext camelContext) throws Exception { getRouteDefinition(routeId, camelContext).adviceWith(camelContext, new AdviceWithRouteBuilder() { @Override public void configure() throws Exception { mockEndpointsAndSkip(endpointPattern); } }); }
public static void addBodyAndPropertiesBeforeStart(final Object body, final Map<String, Object> properties, String routeId, ModelCamelContext camelContext) throws Exception { getRouteDefinition(routeId, camelContext).adviceWith(camelContext, new AdviceWithRouteBuilder() { @Override public void configure() throws Exception { weaveAddFirst() .process(exchange -> { for(Map.Entry<String, Object> entry : properties.entrySet()) { exchange.setProperty(entry.getKey(), entry.getValue()); } exchange.getIn().setBody(body); }); } }); }
/** * @param processorId the id of process-xml-element e.g. <process ref="beanRef" id="myId"/> => id = myId * @param newProcessor newProcessor * @param routeId routeId * @param camelContext camelContext * * @throws Exception */ public static void replaceProcessorWithProcessor(final String processorId, final Processor newProcessor, final String routeId, ModelCamelContext camelContext) throws Exception { getRouteDefinition(routeId, camelContext).adviceWith(camelContext, new AdviceWithRouteBuilder() { @Override public void configure() throws Exception { weaveById(processorId).replace().process(newProcessor); } }); }
/** * @param endpointPattern endpoint uri or a pattern (String with '*' at the end or a regex) * @param routeId routeId * @param camelContext camelContext * * @return MockEndpoint the mocked endpoint * * @throws Exception */ public static MockEndpoint replaceEndpointWithMock(final String endpointPattern, String routeId, ModelCamelContext camelContext) throws Exception { getRouteDefinition(routeId, camelContext).adviceWith(camelContext, new AdviceWithRouteBuilder() { @Override public void configure() throws Exception { mockEndpoints(endpointPattern); } }); return camelContext.getEndpoint("mock:"+endpointPattern, MockEndpoint.class); }
/** * INFO: Currently, it does not work for routes, which ends with an choice: https://issues.apache.org/jira/browse/CAMEL-8798 * @param routeId routeId * @param camelContext camelContext * * @return MockEndpoint the mocked endpoint * * @throws Exception */ public static MockEndpoint addMockEndpointToEndOfRoute(String routeId, ModelCamelContext camelContext) throws Exception { final String mockEndpointURI = "mock:output"; getRouteDefinition(routeId, camelContext).adviceWith(camelContext, new AdviceWithRouteBuilder() { @Override public void configure() throws Exception { weaveAddLast().to(mockEndpointURI); } }); return camelContext.getEndpoint(mockEndpointURI, MockEndpoint.class); }
/** * INFO: Currently, it does not work for routes, which ends with an choice: https://issues.apache.org/jira/browse/CAMEL-8798 * @param endpointPattern endpoint uri or a pattern (String with '*' at the end or a regex) * @param routeId routeId * @param camelContext camelContext * * @return MockEndpoint the mocked endpoint * * @throws Exception */ public static MockEndpoint replaceEndpointWithMockAndSkip(final String endpointPattern, String routeId, ModelCamelContext camelContext) throws Exception { getRouteDefinition(routeId, camelContext).adviceWith(camelContext, new AdviceWithRouteBuilder() { @Override public void configure() throws Exception { mockEndpointsAndSkip(endpointPattern); } }); return camelContext.getEndpoint("mock:"+endpointPattern, MockEndpoint.class); }
private void weaveRoute(String id, Consumer<AdviceWithRouteBuilder> consumer) throws Exception { camelContext.getRouteDefinition(id) .adviceWith(camelContext, new AdviceWithRouteBuilder() { @Override public void configure() { consumer.accept(this); } }); }
@Before public void mockEndpoints() throws Exception { if (tracing) { context.setTracing(true); context.setStreamCaching(true); context.getProperties().put(Exchange.LOG_DEBUG_BODY_STREAMS, Boolean.TRUE.toString()); } context.removeComponent("petals"); context.addComponent("petals", new MockComponent()); for (final String from : routesToMock()) { RouteDefinition routeDef = context.getRouteDefinition(from); assertNotNull("You should set the routeId of one of the routes to '" + from + "' from mocking to work", routeDef); routeDef.adviceWith(context, new AdviceWithRouteBuilder() { @Override public void configure() throws Exception { replaceFromWith("direct:" + from); } }); } context.start(); }
routeDefinition.adviceWith(modelCamelContext, new AdviceWithRouteBuilder() { @Override public void configure() throws Exception {
routeDefinition.adviceWith(modelCamelContext, new AdviceWithRouteBuilder() { @Override public void configure() throws Exception {