Search in sources :

Example 1 with Exchange

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)));
}
Also used : Exchange(org.switchyard.Exchange) MockHandler(org.switchyard.test.MockHandler) Test(org.junit.Test)

Example 2 with Exchange

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));
    }
}
Also used : Exchange(org.switchyard.Exchange) MockHandler(org.switchyard.test.MockHandler) FOMEntry(org.apache.abdera.parser.stax.FOMEntry) Test(org.junit.Test)

Example 3 with Exchange

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();
    }
}
Also used : MQTT(org.fusesource.mqtt.client.MQTT) Exchange(org.switchyard.Exchange) MockHandler(org.switchyard.test.MockHandler) BlockingConnection(org.fusesource.mqtt.client.BlockingConnection) Test(org.junit.Test)

Example 4 with Exchange

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())));
}
Also used : Exchange(org.switchyard.Exchange) MulticastSocket(java.net.MulticastSocket) DatagramPacket(java.net.DatagramPacket) MockHandler(org.switchyard.test.MockHandler) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 5 with Exchange

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))));
}
Also used : Exchange(org.switchyard.Exchange) DataOutputStream(java.io.DataOutputStream) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) MockHandler(org.switchyard.test.MockHandler) SSLContext(javax.net.ssl.SSLContext) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) Socket(java.net.Socket) MulticastSocket(java.net.MulticastSocket) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) Test(org.junit.Test)

Aggregations

Exchange (org.switchyard.Exchange)11 Test (org.junit.Test)10 MockHandler (org.switchyard.test.MockHandler)9 MulticastSocket (java.net.MulticastSocket)2 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)1 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)1 DataOutputStream (java.io.DataOutputStream)1 FileInputStream (java.io.FileInputStream)1 DatagramPacket (java.net.DatagramPacket)1 InetAddress (java.net.InetAddress)1 Socket (java.net.Socket)1 KeyStore (java.security.KeyStore)1 PreparedStatement (java.sql.PreparedStatement)1 HashSet (java.util.HashSet)1 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)1 SSLContext (javax.net.ssl.SSLContext)1 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)1 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)1 FOMEntry (org.apache.abdera.parser.stax.FOMEntry)1 BlockingConnection (org.fusesource.mqtt.client.BlockingConnection)1