protected <T extends Endpoint> T getMandatoryEndpoint(String uri, Class<T> type) { T endpoint = context.getEndpoint(uri, type); assertNotNull("No endpoint found for uri: " + uri, endpoint); return endpoint; }
protected Endpoint getMandatoryEndpoint(String uri) { Endpoint endpoint = context.getEndpoint(uri); assertNotNull("No endpoint found for uri: " + uri, endpoint); return endpoint; }
private OrchestratedTestSpecification.EndpointNode findEndpointNodeMatch(Collection<OrchestratedTestSpecification.EndpointNode> endpointNodes, Endpoint endpoint) { for (OrchestratedTestSpecification.EndpointNode node : endpointNodes) { if (endpoint.equals(context.getEndpoint(node.getEndpointUri()))) { logger.debug("Message arrived in the correct order to endpoint {}", node.getEndpointUri()); return node; } } //not found, which should cause an exception return null; } }
/** * 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); }
/** * @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); }
@Override public void configure() throws Exception { final JmsEndpoint endpoint = getContext().getEndpoint(String.format("queuingservice:%s?asyncConsumer=true", queueNameFactory.getName()), JmsEndpoint.class); final String selector = getJmsSelector(identity.getId()); LOG.trace("Using JMS selector: {} for module: {} on: {}", selector, module, identity); endpoint.setSelector(selector); from(endpoint).setExchangePattern(ExchangePattern.InOut) .process(new CamelRpcServerProcessor(module)) .routeId(getRouteId(module)); } }
@Override public void configure() throws Exception { final JmsEndpoint endpoint = getContext().getEndpoint(String.format("queuingservice:%s?asyncConsumer=true", queueNameFactory.getName()), JmsEndpoint.class); final String selector = getJmsSelector(identity.getId()); LOG.trace("Using JMS selector: {} for module: {} on: {}", selector, module, identity); endpoint.setSelector(selector); from(endpoint).setExchangePattern(ExchangePattern.InOut) .process(new CamelRpcServerProcessor(module)) .routeId(getRouteId(module)); } }
@Override public void configure() throws Exception { final String requestQueueName = sqsManager.getRpcRequestQueueNameAndCreateIfNecessary(module.getId(), identity.getLocation()); final JmsEndpoint endpoint = getContext().getEndpoint(String.format("jms:queue:%s?connectionFactory=#connectionFactory" + "&correlationProperty=%s" + "&asyncConsumer=true", requestQueueName, AmazonSQSRPCConstants.AWS_SQS_CORRELATION_ID_HEADER), JmsEndpoint.class); from(endpoint).setExchangePattern(ExchangePattern.InOut) .process(new SystemIdFilterProcessor(identity.getId())) .process(new AmazonSQSServerProcessor(module)) .routeId(getRouteId(module)); } }
@Override public void configure() throws Exception { final String requestQueueName = sqsManager.getRpcRequestQueueNameAndCreateIfNecessary(module.getId(), identity.getLocation()); final JmsEndpoint endpoint = getContext().getEndpoint(String.format("jms:queue:%s?connectionFactory=#connectionFactory" + "&correlationProperty=%s" + "&asyncConsumer=true", requestQueueName, AmazonSQSRPCConstants.AWS_SQS_CORRELATION_ID_HEADER), JmsEndpoint.class); from(endpoint).setExchangePattern(ExchangePattern.InOut) .process(new SystemIdFilterProcessor(identity.getId())) .process(new AmazonSQSServerProcessor(module)) .routeId(getRouteId(module)); } }
@Test public void testSessionInsertWithHeaders() throws Exception { MockEndpoint mockResult = context.getEndpoint("mock:resultWithHeader", MockEndpoint.class); Person person = new Person(); person.setName("Mauricio"); InsertObjectCommand cmd = (InsertObjectCommand) CommandFactory.newInsert(person, "salaboy"); Map<String, Object> headers = new HashMap<String, Object>(); headers.put("testHeaderName", "testHeaderValue"); template.requestBodyAndHeaders("direct:test-with-session-withHeader", cmd, headers); ExecutionResults response = mockResult.getReceivedExchanges().get(0).getIn().getBody(ExecutionResults.class); assertTrue("Expected valid ExecutionResults object", response != null); assertTrue("ExecutionResults missing expected fact", response.getFactHandle("salaboy") != null); assertTrue("ExecutionResults missing expected fact", response.getFactHandle("salaboy") instanceof FactHandle); mockResult.assertIsSatisfied(); }
@Test public void testNoSessionInsertWithHeaders() throws Exception { MockEndpoint mockResult = context.getEndpoint("mock:resultWithHeader", MockEndpoint.class); String headerName = "testHeaderName"; String headerValue = "testHeaderValue"; Person person = new Person(); person.setName("Mauricio"); InsertObjectCommand cmd = (InsertObjectCommand) CommandFactory.newInsert(person, "salaboy"); Map<String, Object> headers = new HashMap<String, Object>(); headers.put(headerName, headerValue); headers.put(KieComponent.KIE_LOOKUP, "ksession1"); // set mock expectations mockResult.expectedMessageCount(1); mockResult.expectedHeaderReceived(headerName, headerValue); template.requestBodyAndHeaders("direct:test-no-session-withHeader", cmd, headers); ExecutionResults response = mockResult.getReceivedExchanges().get(0).getIn().getBody(ExecutionResults.class); assertTrue("Expected valid ExecutionResults object", response != null); assertTrue("ExecutionResults missing expected fact", response.getFactHandle("salaboy") != null); mockResult.assertIsSatisfied(); }
@Test public void testNoSessionInsertWithHeaders() throws Exception { MockEndpoint mockResult = context.getEndpoint("mock:resultWithHeader",MockEndpoint.class);
@Test public void sqlStoredStartConnectorTest() throws Exception { MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class); mock.expectedMessageCount(1); mock.expectedBodiesReceived("{\"c\":60}"); ProducerTemplate template = context.createProducerTemplate(); template.sendBody("direct:start", null); mock.assertIsSatisfied(); } }
@Test public void testSessionBatchExecutionCommandWithHeader() throws Exception { MockEndpoint mockResult = context.getEndpoint("mock:resultWithHeader", MockEndpoint.class); String headerName = "testHeaderName"; String headerValue = "testHeaderValue"; Person john = new Person(); john.setName("John Smith"); List<Command> commands = new ArrayList<Command>(); commands.add(CommandFactory.newInsert(john, "john")); BatchExecutionCommand batchExecutionCommand = CommandFactory.newBatchExecution(commands); Map<String, Object> headers = new HashMap<String, Object>(); headers.put(headerName, headerValue); // set mock expectations mockResult.expectedMessageCount(1); mockResult.expectedHeaderReceived(headerName, headerValue); // do test template.requestBodyAndHeaders("direct:test-with-session-withHeader", batchExecutionCommand, headers); ExecutionResults response = mockResult.getReceivedExchanges().get(0).getIn().getBody(ExecutionResults.class); assertTrue("Expected valid ExecutionResults object", response != null); assertTrue("ExecutionResults missing expected fact", response.getFactHandle("john") != null); assertTrue("ExecutionResults missing expected fact", response.getFactHandle("john") instanceof FactHandle); mockResult.assertIsSatisfied(); }
@Test public void testSessionBatchExecutionCommandWithHeader() throws Exception { MockEndpoint mockResult = context.getEndpoint("mock:resultWithHeader",MockEndpoint.class);
@Test public void testSessionInsertWithHeaders() throws Exception { MockEndpoint mockResult = context.getEndpoint("mock:resultWithHeader",MockEndpoint.class);
final MockEndpoint createCtidMock = getCamelContext().getEndpoint("mock:" + uri, MockEndpoint.class);
@Test public void sqlStartConnectorTest() throws Exception { MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class); mock.expectedMessageCount(2); mock.expectedMessagesMatches( exchange -> validateProperty(exchange, "ID", "1"), exchange -> validateProperty(exchange, "ID", "2") ); ProducerTemplate template = context.createProducerTemplate(); template.sendBody("direct:start", null); mock.assertIsSatisfied(); }
@Override public void dispatch(final Exchange exchange) { // We can only send Camel exchanges through the camel bus if (!CamelExchange.class.isInstance(exchange)) { throw BusMessages.MESSAGES.onlyCamelExchanges(); } CamelExchange camelEx = (CamelExchange)exchange; // For camel exchanges, the only phase we care about is IN. The dispatch method can also // be called on the OUT path, but that should be handled by the IN_OUT filter in the Camel // bus route. if (!exchange.getPhase().equals(ExchangePhase.IN)) { return; } Throttling throttling = _reference.getServiceMetadata().getThrottling(); if (throttling != null && throttling.getMaxRequests() > 0) { exchange.getMessage().getContext().setProperty( Throttling.MAX_REQUESTS, throttling.getMaxRequests()) .addLabels(BehaviorLabel.TRANSIENT.label()); } String uri = "direct:" + exchange.getConsumer().getName(); DirectEndpoint ep = _context.getEndpoint(uri, DirectEndpoint.class); if (ep.getConsumer() == null) { throw BusMessages.MESSAGES.consumerForinternalCamelRouteNotFound(uri); } _producer.send(ep, camelEx.getExchange()); }