use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class ValidatorRouteTest method testEndpointValidator.
public void testEndpointValidator() throws Exception {
Exchange exchange = new DefaultExchange(context, ExchangePattern.InOut);
exchange.getIn().setBody("<XOrder/>");
Exchange answerEx = template.send("direct:endpoint", exchange);
if (answerEx.getException() != null) {
throw answerEx.getException();
}
assertEquals("<XOrderResponse/>", answerEx.getOut().getBody(String.class));
assertEquals(MyXmlEndpoint.class, answerEx.getProperty(VALIDATOR_INVOKED));
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class ValidatorRouteTest method testCustomValidator.
public void testCustomValidator() throws Exception {
Exchange exchange = new DefaultExchange(context, ExchangePattern.InOut);
exchange.getIn().setBody("name=XOrder");
Exchange answerEx = template.send("direct:custom", exchange);
if (answerEx.getException() != null) {
throw answerEx.getException();
}
assertEquals("name=XOrderResponse", answerEx.getOut().getBody(String.class));
assertEquals(OtherXOrderResponseValidator.class, answerEx.getProperty(VALIDATOR_INVOKED));
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class DefaultExchangeFormatterTest method setUp.
@Before
public void setUp() {
camelContext = new DefaultCamelContext();
Message message = new DefaultMessage();
message.setBody("This is the message body");
exchange = new DefaultExchange(camelContext);
exchange.setIn(message);
exchangeFormatter = new DefaultExchangeFormatter();
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class AggregateProcessorTimeoutCompletionRestartTest method testAggregateProcessorTimeoutExpressionRestart.
public void testAggregateProcessorTimeoutExpressionRestart() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("A+B");
mock.expectedPropertyReceived(Exchange.AGGREGATED_COMPLETED_BY, "timeout");
Processor done = new SendProcessor(context.getEndpoint("mock:result"));
Expression corr = header("id");
AggregationStrategy as = new BodyInAggregatingStrategy();
AggregateProcessor ap = new AggregateProcessor(context, done, corr, as, executorService, true);
// start with a high timeout so no completes before we stop
ap.setCompletionTimeoutExpression(header("myTimeout"));
ap.start();
Exchange e1 = new DefaultExchange(context);
e1.getIn().setBody("A");
e1.getIn().setHeader("id", 123);
e1.getIn().setHeader("myTimeout", 2000);
Exchange e2 = new DefaultExchange(context);
e2.getIn().setBody("B");
e2.getIn().setHeader("id", 123);
e2.getIn().setHeader("myTimeout", 2000);
ap.process(e1);
ap.process(e2);
// shutdown before the 2 sec timeout occurs
// however we use stop instead of shutdown as shutdown will clear the in memory aggregation repository,
ap.stop();
// should be no completed
assertEquals(0, mock.getReceivedCounter());
// start aggregator again
ap.start();
// the aggregator should restore the timeout condition and trigger timeout
assertMockEndpointsSatisfied();
assertEquals(1, mock.getReceivedCounter());
ap.shutdown();
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class AggregateProcessorTimeoutCompletionRestartTest method testAggregateProcessorTimeoutRestart.
public void testAggregateProcessorTimeoutRestart() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("A+B");
mock.expectedPropertyReceived(Exchange.AGGREGATED_COMPLETED_BY, "timeout");
Processor done = new SendProcessor(context.getEndpoint("mock:result"));
Expression corr = header("id");
AggregationStrategy as = new BodyInAggregatingStrategy();
AggregateProcessor ap = new AggregateProcessor(context, done, corr, as, executorService, true);
// start with a high timeout so no completes before we stop
ap.setCompletionTimeout(2000);
ap.start();
Exchange e1 = new DefaultExchange(context);
e1.getIn().setBody("A");
e1.getIn().setHeader("id", 123);
Exchange e2 = new DefaultExchange(context);
e2.getIn().setBody("B");
e2.getIn().setHeader("id", 123);
ap.process(e1);
ap.process(e2);
// shutdown before the 2 sec timeout occurs
// however we use stop instead of shutdown as shutdown will clear the in memory aggregation repository,
ap.stop();
// should be no completed
assertEquals(0, mock.getReceivedCounter());
// start aggregator again
ap.start();
// the aggregator should restore the timeout condition and trigger timeout
assertMockEndpointsSatisfied();
assertEquals(1, mock.getReceivedCounter());
ap.shutdown();
}
Aggregations