CamelEndpoint extends AbstractEndpoint { @Override public Producer createProducer() { if (camelProducer == null) { camelProducer = new CamelProducer(getProducerName(), getEndpointConfiguration()); } return camelProducer; } CamelEndpoint();  CamelEndpoint(CamelEndpointConfiguration endpointConfiguration); @Override Producer createProducer(); @Override Consumer createConsumer(); @Override CamelEndpointConfiguration getEndpointConfiguration();  }
@Test public void testCamelEndpointProducer() { String endpointUri = "direct:news-feed"; CamelEndpointConfiguration endpointConfiguration = new CamelEndpointConfiguration(); endpointConfiguration.setCamelContext(camelContext); endpointConfiguration.setEndpointUri(endpointUri); CamelEndpoint camelEndpoint = new CamelEndpoint(endpointConfiguration); Message requestMessage = new com.consol.citrus.message.DefaultMessage("Hello from Citrus!"); reset(camelContext, producerTemplate, exchange); when(camelContext.createProducerTemplate()).thenReturn(producerTemplate); when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory()); when(producerTemplate.send(eq(endpointUri), any(Processor.class))).thenReturn(exchange); when(exchange.getException()).thenReturn(null); camelEndpoint.createProducer().send(requestMessage, context); }
@Test(expectedExceptions = CitrusRuntimeException.class) public void testCamelEndpointProducerWithInternalException() { String endpointUri = "direct:news-feed"; CamelEndpointConfiguration endpointConfiguration = new CamelEndpointConfiguration(); endpointConfiguration.setCamelContext(camelContext); endpointConfiguration.setEndpointUri(endpointUri); CamelEndpoint camelEndpoint = new CamelEndpoint(endpointConfiguration); Message requestMessage = new com.consol.citrus.message.DefaultMessage("Hello from Citrus!"); CamelExchangeException exchangeException = new CamelExchangeException("Failed", exchange); reset(camelContext, producerTemplate, exchange); when(camelContext.createProducerTemplate()).thenReturn(producerTemplate); when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory()); when(producerTemplate.send(eq(endpointUri), any(Processor.class))).thenReturn(exchange); when(exchange.getException()).thenReturn(exchangeException); camelEndpoint.createProducer().send(requestMessage, context); }