Search in sources :

Example 1 with Greet

use of org.switchyard.quickstarts.camel.jpa.binding.domain.Greet in project quickstarts by jboss-switchyard.

the class PeriodicServiceImpl method execute.

@Override
public void execute() {
    Greet greet = createRandomGreet();
    _logger.info("Sending " + greet + " to JPA store");
    _store.storeGreeting(greet);
}
Also used : Greet(org.switchyard.quickstarts.camel.jpa.binding.domain.Greet)

Example 2 with Greet

use of org.switchyard.quickstarts.camel.jpa.binding.domain.Greet in project quickstarts by jboss-switchyard.

the class PeriodicServiceImpl method createRandomGreet.

private Greet createRandomGreet() {
    Random random = new Random(System.currentTimeMillis());
    Greet event = new Greet();
    event.setReceiver(NAMES[random.nextInt(NAMES.length)]);
    event.setSender(NAMES[random.nextInt(NAMES.length)]);
    event.setCreatedAt(Calendar.getInstance());
    return event;
}
Also used : Random(java.util.Random) Greet(org.switchyard.quickstarts.camel.jpa.binding.domain.Greet)

Example 3 with Greet

use of org.switchyard.quickstarts.camel.jpa.binding.domain.Greet in project quickstarts by jboss-switchyard.

the class CamelJpaBindingStoreTest method storeEntity.

@Test
public void storeEntity() throws Exception {
    Calendar createdAt = Calendar.getInstance();
    Greet event = new Greet();
    event.setReceiver(RECEIVER);
    event.setSender(SENDER);
    event.setCreatedAt(createdAt);
    _testKit.newInvoker("StoreReference").sendInOnly(event);
    PreparedStatement statement = connection.prepareStatement("select createdAt, sender, receiver from events");
    ResultSet resultSet = statement.executeQuery();
    assertTrue(resultSet.next());
    assertEquals(SENDER, resultSet.getString("sender"));
    assertEquals(RECEIVER, resultSet.getString("receiver"));
    assertEquals(createdAt.getTimeInMillis(), resultSet.getTimestamp("createdAt").getTime());
}
Also used : Greet(org.switchyard.quickstarts.camel.jpa.binding.domain.Greet) Calendar(java.util.Calendar) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Test(org.junit.Test)

Example 4 with Greet

use of org.switchyard.quickstarts.camel.jpa.binding.domain.Greet in project quickstarts by jboss-switchyard.

the class CamelJpaBindingReceiveTest method receiveEntity.

@Test
public void receiveEntity() throws Exception {
    _testKit.removeService("GreetingService");
    _testKit.removeService("StoreReference");
    service = _testKit.registerInOnlyService("GreetingService");
    PreparedStatement statement = connection.prepareStatement("insert into events (createdAt,sender,receiver) values(now(), ?, ?)");
    statement.setString(1, SENDER);
    statement.setString(2, RECEIVER);
    statement.execute();
    service.waitForOKMessage();
    final LinkedBlockingQueue<Exchange> receivedMessages = service.getMessages();
    assertNotNull(receivedMessages);
    final Exchange recievedExchange = receivedMessages.iterator().next();
    Greet receiver = recievedExchange.getMessage().getContent(Greet.class);
    assertEquals(SENDER, receiver.getSender());
    assertEquals(RECEIVER, receiver.getReceiver());
}
Also used : Exchange(org.switchyard.Exchange) Greet(org.switchyard.quickstarts.camel.jpa.binding.domain.Greet) PreparedStatement(java.sql.PreparedStatement) Test(org.junit.Test)

Aggregations

Greet (org.switchyard.quickstarts.camel.jpa.binding.domain.Greet)4 PreparedStatement (java.sql.PreparedStatement)2 Test (org.junit.Test)2 ResultSet (java.sql.ResultSet)1 Calendar (java.util.Calendar)1 Random (java.util.Random)1 Exchange (org.switchyard.Exchange)1