Search in sources :

Example 6 with MockHandler

use of org.switchyard.test.MockHandler 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 MockHandler

use of org.switchyard.test.MockHandler 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 MockHandler

use of org.switchyard.test.MockHandler in project quickstarts by jboss-switchyard.

the class DealerTest method acceptValidOffer.

@Test
public void acceptValidOffer() throws Exception {
    Car car = new Car();
    car.setPrice(500.00);
    Application app = new Application();
    app.setCreditScore(650);
    Offer offer = new Offer();
    offer.setCar(car);
    offer.setApplication(app);
    offer.setAmount(450.00);
    // configure our proxy for the service reference
    MockHandler creditService = testKit.replaceService("CreditCheck");
    Application reply = new Application();
    reply.setApproved(true);
    creditService.replyWithOut(reply);
    // Invoke the service
    Deal deal = service.operation("offer").sendInOut(offer).getContent(Deal.class);
    // verify the deal is rejected
    Assert.assertTrue(deal.isAccepted());
}
Also used : MockHandler(org.switchyard.test.MockHandler) Test(org.junit.Test)

Example 9 with MockHandler

use of org.switchyard.test.MockHandler in project quickstarts by jboss-switchyard.

the class CamelSqlRetrieveTest method shouldRetrieveGreetings.

@Test
public void shouldRetrieveGreetings() throws Exception {
    _testKit.removeService("GreetingService");
    MockHandler handler = new MockHandler();
    ServiceInterface metadata = JavaService.fromClass(GreetingService.class);
    _testKit.getServiceDomain().registerService(_testKit.createQName("GreetingService"), metadata, handler);
    PreparedStatement statement = connection.prepareStatement("INSERT INTO greetings (receiver, sender) VALUES (?,?)");
    statement.setString(1, RECEIVER);
    statement.setString(2, SENDER);
    assertEquals(1, statement.executeUpdate());
    PreparedStatement statement2 = connection.prepareStatement("INSERT INTO greetings (receiver, sender) VALUES (?,?)");
    statement2.setString(1, RECEIVER_2);
    statement2.setString(2, SENDER_2);
    assertEquals(1, statement2.executeUpdate());
    Set<Greeting> greetings = getContents(handler);
    assertEquals(2, greetings.size());
    assertEquals(true, checkGreeting(RECEIVER, SENDER, greetings));
    assertEquals(true, checkGreeting(RECEIVER_2, SENDER_2, greetings));
}
Also used : Greeting(org.switchyard.quickstarts.camel.sql.binding.Greeting) ServiceInterface(org.switchyard.metadata.ServiceInterface) MockHandler(org.switchyard.test.MockHandler) PreparedStatement(java.sql.PreparedStatement) Test(org.junit.Test)

Example 10 with MockHandler

use of org.switchyard.test.MockHandler in project quickstarts by jboss-switchyard.

the class DealerTest method acceptValidOffer.

@Test
public void acceptValidOffer() throws Exception {
    Car car = new Car();
    car.setPrice(500.00);
    Application app = new Application();
    app.setCreditScore(650);
    Offer offer = new Offer();
    offer.setCar(car);
    offer.setApplication(app);
    offer.setAmount(450.00);
    // configure our proxy for the service reference
    testKit.replaceService("DealLogger");
    MockHandler creditService = testKit.replaceService("CreditCheckService");
    Application reply = new Application();
    reply.setApproved(true);
    creditService.replyWithOut(reply);
    // Invoke the service
    Deal deal = service.operation("offer").sendInOut(offer).getContent(Deal.class);
    // verify the deal is rejected
    Assert.assertTrue(deal.isAccepted());
}
Also used : Car(org.switchyard.quickstarts.demo.txpropagation.Car) Offer(org.switchyard.quickstarts.demo.txpropagation.Offer) MockHandler(org.switchyard.test.MockHandler) Deal(org.switchyard.quickstarts.demo.txpropagation.Deal) Application(org.switchyard.quickstarts.demo.txpropagation.Application) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 MockHandler (org.switchyard.test.MockHandler)12 Exchange (org.switchyard.Exchange)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 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 MQTT (org.fusesource.mqtt.client.MQTT)1