use of org.apache.camel.Exchange in project camel by apache.
the class Mina2ProducerShutdownMockTest method testProducerShutdownTestingWithMock.
@Test
public void testProducerShutdownTestingWithMock() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
// create our mock and record expected behavior = that worker timeout should be set to 0
SocketConnector mockConnector = createMock(SocketConnector.class);
mockConnector.dispose(true);
replay(mockConnector);
// normal camel code to get a producer
Endpoint endpoint = context.getEndpoint(String.format("mina2:tcp://localhost:%1$s?textline=true&sync=false", getPort()));
Exchange exchange = endpoint.createExchange();
Producer producer = endpoint.createProducer();
producer.start();
// set input and execute it
exchange.getIn().setBody("Hello World");
producer.process(exchange);
// insert our mock instead of real MINA IoConnector
Field field = producer.getClass().getDeclaredField("connector");
field.setAccessible(true);
field.set(producer, mockConnector);
//
// Everything is asynchronous.
// We need to wait a second to make sure we get the message.
//
Thread.sleep(1000);
// stop using our mock
producer.stop();
verify(mockConnector);
assertMockEndpointsSatisfied();
}
use of org.apache.camel.Exchange in project camel by apache.
the class Mina2ProducerShutdownTest method sendMessage.
private void sendMessage() throws Exception {
Endpoint endpoint = context.getEndpoint(URI);
Producer producer = endpoint.createProducer();
Exchange exchange = endpoint.createExchange();
exchange.getIn().setBody("Hello World");
producer.start();
producer.process(exchange);
producer.stop();
}
use of org.apache.camel.Exchange in project camel by apache.
the class Mina2TcpWithInOutTest method testMinaRouteWithInOut.
@Test
public void testMinaRouteWithInOut() throws Exception {
latch = new CountDownLatch(1);
uri = String.format("mina2:tcp://localhost:%1$s?textline=true", getPort());
Mina2ReverserServer server = new Mina2ReverserServer(getPort());
server.start();
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:x").to(uri).process(new Processor() {
public void process(Exchange e) {
receivedExchange = e;
latch.countDown();
}
});
}
});
context.start();
// now lets fire in a message
Endpoint endpoint = context.getEndpoint("direct:x");
Exchange exchange = endpoint.createExchange(ExchangePattern.InOut);
Message message = exchange.getIn();
message.setBody("Hello!");
message.setHeader("cheese", 123);
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
// now lets sleep for a while
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertNotNull(receivedExchange.getIn());
assertEquals("!olleH", receivedExchange.getIn().getBody());
producer.stop();
context.stop();
server.stop();
}
use of org.apache.camel.Exchange in project camel by apache.
the class Mina2TransferExchangeOptionTest method sendExchange.
private Exchange sendExchange(boolean setException) throws Exception {
Endpoint endpoint = context.getEndpoint(String.format("mina2:tcp://localhost:%1$s?sync=true&encoding=UTF-8&transferExchange=true", getPort()));
Producer producer = endpoint.createProducer();
Exchange exchange = endpoint.createExchange();
//Exchange exchange = endpoint.createExchange();
Message message = exchange.getIn();
message.setBody("Hello!");
message.setHeader("cheese", "feta");
exchange.setProperty("ham", "old");
exchange.setProperty("setException", setException);
producer.start();
producer.process(exchange);
return exchange;
}
use of org.apache.camel.Exchange in project camel by apache.
the class Mina2TransferExchangeOptionTest method testMinaTransferExchangeOptionWithException.
@Test
public void testMinaTransferExchangeOptionWithException() throws Exception {
Exchange exchange = sendExchange(true);
assertExchange(exchange, true);
}
Aggregations