Search in sources :

Example 6 with Exchange

use of org.switchyard.Exchange in project quickstarts by jboss-switchyard.

the class CamelJMSBindingTest method sendTextMessageToJMSQueue.

@Test
public void sendTextMessageToJMSQueue() throws Exception {
    final String payload = "dummy payload";
    // replace existing implementation for testing purposes
    _testKit.removeService("GreetingService");
    final MockHandler greetingService = _testKit.registerInOnlyService("GreetingService");
    sendTextToQueue(payload, QUEUE_NAME);
    // Allow for the JMS Message to be processed.
    Thread.sleep(3000);
    final LinkedBlockingQueue<Exchange> recievedMessages = greetingService.getMessages();
    assertThat(recievedMessages, is(notNullValue()));
    final Exchange recievedExchange = recievedMessages.iterator().next();
    assertThat(recievedExchange.getMessage().getContent(String.class), is(equalTo(payload)));
}
Also used : Exchange(org.switchyard.Exchange) MockHandler(org.switchyard.test.MockHandler) Test(org.junit.Test)

Example 7 with Exchange

use of org.switchyard.Exchange in project quickstarts by jboss-switchyard.

the class CamelServiceTest method testXQueryRouting.

@Test
public void testXQueryRouting() throws Exception {
    _testKit.removeService("HelloService");
    _testKit.removeService("GoodbyeService");
    MockHandler helloService = _testKit.registerInOnlyService("HelloService");
    MockHandler goodbyeService = _testKit.registerInOnlyService("GoodbyeService");
    greet.sendInOnly(REQUEST_HELLO);
    greet.sendInOnly(REQUEST_GOODBYE);
    Thread.sleep(1000);
    LinkedBlockingQueue<Exchange> helloReceived = helloService.getMessages();
    Assert.assertNotNull(helloReceived);
    Exchange helloExchange = helloReceived.iterator().next();
    Assert.assertTrue(helloExchange.getMessage().getContent(String.class).matches(".*Douglas.*"));
    LinkedBlockingQueue<Exchange> goodbyeReceived = goodbyeService.getMessages();
    Assert.assertNotNull(goodbyeReceived);
    Exchange goodbyeExchange = goodbyeReceived.iterator().next();
    Assert.assertTrue(goodbyeExchange.getMessage().getContent(String.class).matches(".*Garfield.*"));
}
Also used : Exchange(org.switchyard.Exchange) MockHandler(org.switchyard.test.MockHandler) Test(org.junit.Test)

Example 8 with Exchange

use of org.switchyard.Exchange in project quickstarts by jboss-switchyard.

the class CamelSqlRetrieveTest method getContents.

// method which is capable to hold execution of test until some records pulled from database
private Set<Greeting> getContents(MockHandler handler) {
    // first execution of poll done
    handler.waitForOKMessage();
    long stop = System.nanoTime() + TimeUnit.SECONDS.toNanos(REPLY_TIMEOUT_SECONDS);
    Set<Greeting> greetings = new HashSet<Greeting>();
    while (System.nanoTime() < stop) {
        for (Exchange exchange : handler.getMessages()) {
            Greeting greeting = exchange.getMessage().getContent(Greeting.class);
            if (greeting != null && !greetings.contains(greeting)) {
                greetings.add(greeting);
            }
        }
    }
    return greetings;
}
Also used : Exchange(org.switchyard.Exchange) Greeting(org.switchyard.quickstarts.camel.sql.binding.Greeting) HashSet(java.util.HashSet)

Example 9 with Exchange

use of org.switchyard.Exchange in project quickstarts by jboss-switchyard.

the class CamelQuartzBindingTest method shouldExecuteService.

@Test
public void shouldExecuteService() throws Exception {
    // replace existing implementation for testing purposes
    _testKit.removeService("GreetingService");
    final MockHandler greetingService = _testKit.registerInOnlyService("GreetingService");
    // Number of executions can vary, depends on moment when sleep will be executed
    // eg. 10:50:999, 10:51:003, 10:52:000 - we'll get three executions
    // or  10:50:000, 10:51:001 - we'll get two executions
    // however we never should get more than three triggers and less than two
    Thread.sleep(1001);
    final LinkedBlockingQueue<Exchange> recievedMessages = greetingService.getMessages();
    assertThat(recievedMessages, is(notNullValue()));
    assertThat(recievedMessages.size(), is(greaterThanOrEqualTo(1)));
}
Also used : Exchange(org.switchyard.Exchange) MockHandler(org.switchyard.test.MockHandler) Test(org.junit.Test)

Example 10 with Exchange

use of org.switchyard.Exchange in project quickstarts by jboss-switchyard.

the class CamelRSSPollTest 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) {
        SyndFeed feed = (SyndFeed) e.getMessage().getContent();
        @SuppressWarnings("unchecked") List<SyndEntry> entries = feed.getEntries();
        Assert.assertEquals(feed.getEntries().size(), 1);
        Iterator<SyndEntry> itEntries = entries.iterator();
        while (itEntries.hasNext()) {
            SyndEntry entry = (SyndEntry) itEntries.next();
            Assert.assertTrue(entry.getTitle().equals(SONG_TITLE));
            Assert.assertTrue(entry.getLink().equals(SONG_URL));
            Assert.assertTrue(entry.getDescription().getValue().equals(SONG_DESCRIPTION));
        }
    }
}
Also used : Exchange(org.switchyard.Exchange) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) MockHandler(org.switchyard.test.MockHandler) 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