Search in sources :

Example 1 with Greeting

use of org.switchyard.quickstarts.camel.sql.binding.Greeting 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 2 with Greeting

use of org.switchyard.quickstarts.camel.sql.binding.Greeting in project quickstarts by jboss-switchyard.

the class CamelSqlStoreTest method shouldStoreGreet.

@Test
public void shouldStoreGreet() throws Exception {
    invoker.operation("store").sendInOnly(new Greeting(RECEIVER, SENDER));
    ResultSet result = connection.createStatement().executeQuery("SELECT * FROM greetings");
    assertTrue(result.next());
    assertEquals(RECEIVER, result.getString("receiver"));
    assertEquals(SENDER, result.getString("sender"));
    result.close();
}
Also used : Greeting(org.switchyard.quickstarts.camel.sql.binding.Greeting) ResultSet(java.sql.ResultSet) Test(org.junit.Test)

Example 3 with Greeting

use of org.switchyard.quickstarts.camel.sql.binding.Greeting 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)

Aggregations

Greeting (org.switchyard.quickstarts.camel.sql.binding.Greeting)3 Test (org.junit.Test)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 HashSet (java.util.HashSet)1 Exchange (org.switchyard.Exchange)1 ServiceInterface (org.switchyard.metadata.ServiceInterface)1 MockHandler (org.switchyard.test.MockHandler)1