use of org.switchyard.Exchange in project quickstarts by jboss-switchyard.
the class CamelAmqpBindingTest method sendTextMessageToAmqpQueue.
@Test
public void sendTextMessageToAmqpQueue() throws Exception {
//replace existing implementation for testing purposes
_testKit.removeService("GreetingService");
final MockHandler greetingService = _testKit.registerInOnlyService("GreetingService");
sentTextToQueue(PAYLOAD);
greetingService.waitForOKMessage();
final LinkedBlockingQueue<Exchange> receivedMessages = greetingService.getMessages();
assertThat(receivedMessages, is(notNullValue()));
final Exchange receivedExchange = receivedMessages.iterator().next();
assertThat(receivedExchange.getMessage().getContent(String.class), is(equalTo(PAYLOAD)));
}
use of org.switchyard.Exchange in project quickstarts by jboss-switchyard.
the class CamelAtomPollTest method shouldRetrieveGreetings.
@Test
public void shouldRetrieveGreetings() throws Exception {
_testKit.removeService("PrintService");
final MockHandler printService = _testKit.registerInOnlyService("PrintService");
Thread.sleep(10001);
final LinkedBlockingQueue<Exchange> receivedMessages = printService.getMessages();
for (Exchange e : receivedMessages) {
FOMEntry entry = (FOMEntry) e.getMessage().getContent();
Assert.assertNotNull(entry);
Assert.assertTrue(entry.getTitle().equals(TITLE));
Assert.assertTrue(entry.getId().toString().equals(ID));
}
}
use of org.switchyard.Exchange in project quickstarts by jboss-switchyard.
the class CamelMQTTBindingTest method testServiceBinding.
@Test
public void testServiceBinding() throws Exception {
MockHandler mock = _testKit.replaceService("StoreReference");
MQTT mqtt = new MQTT();
BlockingConnection connection = mqtt.blockingConnection();
try {
connection.connect();
connection.publish(TOPIC_INPUT, MESSAGE_INPUT.getBytes(), QoS.AT_LEAST_ONCE, false);
Thread.sleep(1000);
LinkedBlockingQueue<Exchange> received = mock.getMessages();
Assert.assertNotNull(received);
Exchange exchange = received.iterator().next();
Assert.assertEquals(MESSAGE_OUTPUT, exchange.getMessage().getContent(String.class));
} finally {
connection.disconnect();
}
}
use of org.switchyard.Exchange in project quickstarts by jboss-switchyard.
the class CamelNettyBindingTest method sendTextMessageThroughUdp.
@Test
public void sendTextMessageThroughUdp() throws Exception {
// replace existing implementation for testing purposes
_testKit.removeService("DefaultGreetingService");
final MockHandler greetingService = _testKit.registerInOnlyService("DefaultGreetingService");
MulticastSocket clientSocket = new MulticastSocket();
InetAddress group = InetAddress.getByName("localhost");
byte[] datagramBody = PAYLOAD.getBytes(Charset.defaultCharset());
DatagramPacket packet = new DatagramPacket(datagramBody, 0, datagramBody.length, group, 3940);
clientSocket.send(packet);
// sleep a bit to receive message on camel side
clientSocket.close();
greetingService.waitForOKMessage();
final LinkedBlockingQueue<Exchange> recievedMessages = greetingService.getMessages();
assertThat(recievedMessages, is(notNullValue()));
final Exchange recievedExchange = recievedMessages.iterator().next();
String content = recievedExchange.getMessage().getContent(String.class);
// the receive content is trimmed because extra bytes appended to frame by receiver
assertThat(PAYLOAD, is(equalTo(content.trim())));
}
use of org.switchyard.Exchange in project quickstarts by jboss-switchyard.
the class CamelNettyBindingTest method sendTextMessageThroughTcp.
@Test
public void sendTextMessageThroughTcp() throws Exception {
// replace existing implementation for testing purposes
_testKit.removeService("SecuredGreetingService");
final MockHandler greetingService = _testKit.registerInOnlyService("SecuredGreetingService");
greetingService.forwardInToOut();
KeyStore keystore = KeyStore.getInstance("JKS");
keystore.load(new FileInputStream("users.jks"), "changeit".toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(keystore);
SSLContext context = SSLContext.getInstance("TLS");
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keystore, "changeit".toCharArray());
context.init(keyManagerFactory.getKeyManagers(), tmf.getTrustManagers(), null);
SSLSocketFactory sf = context.getSocketFactory();
Socket clientSocket = sf.createSocket("localhost", 3939);
DataOutputStream outputStream = new DataOutputStream(clientSocket.getOutputStream());
// lets write payload directly as bytes to avoid encoding mismatches
outputStream.write(PAYLOAD.getBytes());
outputStream.flush();
// sleep a bit to receive message on camel side
Thread.sleep(50);
clientSocket.close();
greetingService.waitForOKMessage();
final LinkedBlockingQueue<Exchange> recievedMessages = greetingService.getMessages();
assertThat(recievedMessages, is(notNullValue()));
final Exchange recievedExchange = recievedMessages.iterator().next();
assertThat(PAYLOAD, is(equalTo(recievedExchange.getMessage().getContent(String.class))));
}
Aggregations