Author: davsclaus
Date: Sat Sep 27 00:52:59 2008
New Revision: 699595
URL: http://svn.apache.org/viewvc?rev=699595&view=rev
Log:
CAMEL-940: Added ibatis scheduled polling consumer example
Added:
activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisPollingDelayRouteTest.java
(contents, props changed)
- copied, changed from r699425,
activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteTest.java
Modified:
activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteTest.java
Copied:
activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisPollingDelayRouteTest.java
(from r699425,
activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteTest.java)
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisPollingDelayRouteTest.java?p2=activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisPollingDelayRouteTest.java&p1=activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteTest.java&r1=699425&r2=699595&rev=699595&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteTest.java
(original)
+++
activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisPollingDelayRouteTest.java
Sat Sep 27 00:52:59 2008
@@ -18,7 +18,6 @@
import java.sql.Connection;
import java.sql.Statement;
-import java.util.List;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.RouteBuilder;
@@ -27,39 +26,40 @@
/**
* @version $Revision$
*/
-public class IBatisRouteTest extends ContextTestSupport {
+public class IBatisPollingDelayRouteTest extends ContextTestSupport {
+
public void testSendAccountBean() throws Exception {
- MockEndpoint endpoint = getMockEndpoint("mock:results");
- endpoint.expectedMinimumMessageCount(1);
+ createTestData();
+
+ long start = System.currentTimeMillis();
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(2);
+
+ assertMockEndpointsSatisfied();
+ long delta = System.currentTimeMillis() - start;
+ assertTrue("Should not take that long: " + delta, delta < 5000);
+ }
+
+ private void createTestData() {
+ // insert test data
Account account = new Account();
account.setId(123);
account.setFirstName("James");
account.setLastName("Strachan");
account.setEmailAddress("[EMAIL PROTECTED]");
-
template.sendBody("direct:start", account);
-
- assertMockEndpointsSatisifed();
-
- // now lets poll that the account has been inserted
- Object answer = template.sendBody("ibatis:selectAllAccounts", null);
- List body = assertIsInstanceOf(List.class, answer);
-
- assertEquals("Wrong size: " + body, 1, body.size());
- Account actual = assertIsInstanceOf(Account.class, body.get(0));
-
- assertEquals("Account.getFirstName()", "James", actual.getFirstName());
- assertEquals("Account.getLastName()", "Strachan",
actual.getLastName());
-
- log.info("Found: " + actual);
}
+
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
- from("ibatis:selectAllAccounts").to("mock:results");
+ // START SNIPPET: e1
+ // run this timer every 2nd second, that will select data from
the database and send it to the mock endpiont
+
from("timer://pollTheDatabase?delay=2000").to("ibatis:selectAllAccounts").to("mock:result");
+ // END SNIPPET: e1
from("direct:start").to("ibatis:insertAccount");
}
@@ -71,10 +71,25 @@
super.setUp();
// lets create the database...
- IBatisEndpoint endpoint = resolveMandatoryEndpoint("ibatis:Account",
IBatisEndpoint.class);
- Connection connection =
endpoint.getSqlClient().getDataSource().getConnection();
+ Connection connection = createConnection();
Statement statement = connection.createStatement();
statement.execute("create table ACCOUNT ( ACC_ID INTEGER ,
ACC_FIRST_NAME VARCHAR(255), ACC_LAST_NAME VARCHAR(255), ACC_EMAIL VARCHAR(255)
)");
connection.close();
}
-}
+
+ @Override
+ protected void tearDown() throws Exception {
+ Connection connection = createConnection();
+ Statement statement = connection.createStatement();
+ statement.execute("drop table ACCOUNT");
+ connection.close();
+
+ super.tearDown();
+ }
+
+ private Connection createConnection() throws Exception {
+ IBatisEndpoint endpoint =
resolveMandatoryEndpoint("ibatis:selectAllAccounts", IBatisEndpoint.class);
+ return endpoint.getSqlClient().getDataSource().getConnection();
+ }
+
+}
\ No newline at end of file
Propchange:
activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisPollingDelayRouteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisPollingDelayRouteTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisPollingDelayRouteTest.java
------------------------------------------------------------------------------
svn:mergeinfo =
Modified:
activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteTest.java?rev=699595&r1=699594&r2=699595&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteTest.java
(original)
+++
activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteTest.java
Sat Sep 27 00:52:59 2008
@@ -28,6 +28,7 @@
* @version $Revision$
*/
public class IBatisRouteTest extends ContextTestSupport {
+
public void testSendAccountBean() throws Exception {
MockEndpoint endpoint = getMockEndpoint("mock:results");
endpoint.expectedMinimumMessageCount(1);
@@ -40,7 +41,7 @@
template.sendBody("direct:start", account);
- assertMockEndpointsSatisifed();
+ assertMockEndpointsSatisfied();
// now lets poll that the account has been inserted
Object answer = template.sendBody("ibatis:selectAllAccounts", null);
@@ -71,10 +72,25 @@
super.setUp();
// lets create the database...
- IBatisEndpoint endpoint = resolveMandatoryEndpoint("ibatis:Account",
IBatisEndpoint.class);
- Connection connection =
endpoint.getSqlClient().getDataSource().getConnection();
+ Connection connection = createConnection();
Statement statement = connection.createStatement();
statement.execute("create table ACCOUNT ( ACC_ID INTEGER ,
ACC_FIRST_NAME VARCHAR(255), ACC_LAST_NAME VARCHAR(255), ACC_EMAIL VARCHAR(255)
)");
connection.close();
}
+
+ @Override
+ protected void tearDown() throws Exception {
+ Connection connection = createConnection();
+ Statement statement = connection.createStatement();
+ statement.execute("drop table ACCOUNT");
+ connection.close();
+
+ super.tearDown();
+ }
+
+ private Connection createConnection() throws Exception {
+ IBatisEndpoint endpoint = resolveMandatoryEndpoint("ibatis:Account",
IBatisEndpoint.class);
+ return endpoint.getSqlClient().getDataSource().getConnection();
+ }
+
}