You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by cm...@apache.org on 2011/12/11 22:07:30 UTC

svn commit: r1213069 - in /camel/branches/camel-2.8.x/components/camel-ibatis: ./ src/test/java/org/apache/camel/component/ibatis/ src/test/resources/

Author: cmueller
Date: Sun Dec 11 21:07:30 2011
New Revision: 1213069

URL: http://svn.apache.org/viewvc?rev=1213069&view=rev
Log:
CAMEL-4734: Consolidate the database vendors in our unit tests - work in progress

Modified:
    camel/branches/camel-2.8.x/components/camel-ibatis/pom.xml
    camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListTest.java
    camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueueTest.java
    camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteEmptyResultSetTest.java
    camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteTest.java
    camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisTestSupport.java
    camel/branches/camel-2.8.x/components/camel-ibatis/src/test/resources/SqlMapConfig.xml

Modified: camel/branches/camel-2.8.x/components/camel-ibatis/pom.xml
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-ibatis/pom.xml?rev=1213069&r1=1213068&r2=1213069&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-ibatis/pom.xml (original)
+++ camel/branches/camel-2.8.x/components/camel-ibatis/pom.xml Sun Dec 11 21:07:30 2011
@@ -62,8 +62,8 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.hsqldb</groupId>
-      <artifactId>hsqldb</artifactId>
+      <groupId>org.apache.derby</groupId>
+      <artifactId>derby</artifactId>
       <scope>test</scope>
     </dependency>
 

Modified: camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListTest.java?rev=1213069&r1=1213068&r2=1213069&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListTest.java (original)
+++ camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueryForListTest.java Sun Dec 11 21:07:30 2011
@@ -36,7 +36,7 @@ public class IBatisQueryForListTest exte
 
         assertMockEndpointsSatisfied();
 
-        List list = mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
+        List<?> list = mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
         Account james = (Account) list.get(0);
         Account claus = (Account) list.get(1);
         assertEquals("James", james.getFirstName());
@@ -56,5 +56,4 @@ public class IBatisQueryForListTest exte
             }
         };
     }
-
 }
\ No newline at end of file

Modified: camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueueTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueueTest.java?rev=1213069&r1=1213068&r2=1213069&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueueTest.java (original)
+++ camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisQueueTest.java Sun Dec 11 21:07:30 2011
@@ -16,22 +16,25 @@
  */
 package org.apache.camel.component.ibatis;
 
-import java.sql.Connection;
-import java.sql.Statement;
 import java.util.List;
 
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 
-public class IBatisQueueTest extends CamelTestSupport {
+public class IBatisQueueTest extends IBatisTestSupport {
+
+    protected boolean createTestData() {
+        return false;
+    }
+
+    @Override
+    protected String getStatement() {
+        return "create table ACCOUNT ( ACC_ID INTEGER , ACC_FIRST_NAME VARCHAR(255), ACC_LAST_NAME VARCHAR(255), ACC_EMAIL VARCHAR(255), PROCESSED BOOLEAN DEFAULT false)";
+    }
 
     @Test
     public void testConsume() throws Exception {
-
         MockEndpoint endpoint = getMockEndpoint("mock:results");
         endpoint.expectedMinimumMessageCount(2);
         
@@ -57,7 +60,7 @@ public class IBatisQueueTest extends Cam
         Thread.sleep(1000);
         
         // now lets poll that the account has been inserted
-        List body = template.requestBody("ibatis:selectProcessedAccounts?statementType=QueryForList", null, List.class);
+        List<?> body = template.requestBody("ibatis:selectProcessedAccounts?statementType=QueryForList", null, List.class);
 
         assertEquals("Wrong size: " + body, 2, body.size());
         Account actual = assertIsInstanceOf(Account.class, body.get(0));
@@ -81,29 +84,4 @@ public class IBatisQueueTest extends Cam
             }
         };
     }
-
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        super.setUp();
-
-        // lets create the database...
-        IBatisEndpoint endpoint = resolveMandatoryEndpoint("ibatis:Account", IBatisEndpoint.class);
-        Connection connection = endpoint.getSqlMapClient().getDataSource().getConnection();
-        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), PROCESSED BOOLEAN DEFAULT false)");
-        connection.close();
-    }
-    
-    @Override
-    @After
-    public void tearDown() throws Exception {
-        IBatisEndpoint endpoint = resolveMandatoryEndpoint("ibatis:Account", IBatisEndpoint.class);
-        Connection connection = endpoint.getSqlMapClient().getDataSource().getConnection();
-        Statement statement = connection.createStatement();
-        statement.execute("drop table ACCOUNT");
-        connection.close();
-
-        super.tearDown();
-    }
-}
+}
\ No newline at end of file

Modified: camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteEmptyResultSetTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteEmptyResultSetTest.java?rev=1213069&r1=1213068&r2=1213069&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteEmptyResultSetTest.java (original)
+++ camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteEmptyResultSetTest.java Sun Dec 11 21:07:30 2011
@@ -27,6 +27,11 @@ import org.junit.Test;
  */
 public class IBatisRouteEmptyResultSetTest extends IBatisTestSupport {
 
+    @Override
+    protected boolean createTestData() {
+        return false;
+    }
+
     @Test
     public void testRouteEmptyResultSet() throws Exception {
         MockEndpoint endpoint = getMockEndpoint("mock:results");
@@ -46,10 +51,4 @@ public class IBatisRouteEmptyResultSetTe
             }
         };
     }
-
-    @Override
-    protected boolean createTestData() {
-        // no test data so an empty resultset
-        return false;
-    }
 }
\ No newline at end of file

Modified: camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteTest.java?rev=1213069&r1=1213068&r2=1213069&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteTest.java (original)
+++ camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteTest.java Sun Dec 11 21:07:30 2011
@@ -16,21 +16,21 @@
  */
 package org.apache.camel.component.ibatis;
 
-import java.sql.Connection;
-import java.sql.Statement;
 import java.util.List;
 
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 
 /**
  * @version 
  */
-public class IBatisRouteTest extends CamelTestSupport {
+public class IBatisRouteTest extends IBatisTestSupport {
+    
+    @Override
+    protected boolean createTestData() {
+        return false;
+    }
 
     @Test
     public void testSendAccountBean() throws Exception {
@@ -48,7 +48,7 @@ public class IBatisRouteTest extends Cam
         assertMockEndpointsSatisfied();
 
         // now lets poll that the account has been inserted
-        List body = template.requestBody("ibatis:selectAllAccounts?statementType=QueryForList", null, List.class);
+        List<?> body = template.requestBody("ibatis:selectAllAccounts?statementType=QueryForList", null, List.class);
 
         assertEquals("Wrong size: " + body, 1, body.size());
         Account actual = assertIsInstanceOf(Account.class, body.get(0));
@@ -70,32 +70,4 @@ public class IBatisRouteTest extends Cam
             }
         };
     }
-
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        super.setUp();
-
-        // lets create the database...
-        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
-    @After
-    public 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.getSqlMapClient().getDataSource().getConnection();
-    }
 }

Modified: camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisTestSupport.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisTestSupport.java?rev=1213069&r1=1213068&r2=1213069&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisTestSupport.java (original)
+++ camel/branches/camel-2.8.x/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisTestSupport.java Sun Dec 11 21:07:30 2011
@@ -17,9 +17,12 @@
 package org.apache.camel.component.ibatis;
 
 import java.sql.Connection;
+import java.sql.SQLException;
 import java.sql.Statement;
+import java.util.Properties;
 
 import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.derby.jdbc.EmbeddedDriver;
 import org.junit.After;
 import org.junit.Before;
 
@@ -30,6 +33,10 @@ public class IBatisTestSupport extends C
         return true;
     }
 
+    protected String getStatement() {
+        return "create table ACCOUNT ( ACC_ID INTEGER , ACC_FIRST_NAME VARCHAR(255), ACC_LAST_NAME VARCHAR(255), ACC_EMAIL VARCHAR(255)  )";
+    }
+
     @Override
     @Before
     public void setUp() throws Exception {
@@ -38,7 +45,8 @@ public class IBatisTestSupport extends C
         // lets create the database...
         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)  )");
+        statement.execute(getStatement());
+        connection.commit();
         connection.close();
 
         if (createTestData()) {
@@ -62,12 +70,15 @@ public class IBatisTestSupport extends C
     @Override
     @After
     public void tearDown() throws Exception {
-        Connection connection = createConnection();
-        Statement statement = connection.createStatement();
-        statement.execute("drop table ACCOUNT");
-        connection.close();
-
         super.tearDown();
+        
+        try {
+            new EmbeddedDriver().connect("jdbc:derby:memory:ibatis;drop=true", new Properties());
+        } catch (SQLException ex) {
+            if (!"08006".equals(ex.getSQLState())) {
+                throw ex;
+            }
+        }
     }
 
     private Connection createConnection() throws Exception {

Modified: camel/branches/camel-2.8.x/components/camel-ibatis/src/test/resources/SqlMapConfig.xml
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-ibatis/src/test/resources/SqlMapConfig.xml?rev=1213069&r1=1213068&r2=1213069&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-ibatis/src/test/resources/SqlMapConfig.xml (original)
+++ camel/branches/camel-2.8.x/components/camel-ibatis/src/test/resources/SqlMapConfig.xml Sun Dec 11 21:07:30 2011
@@ -26,8 +26,8 @@
        and a managed datasource -->
   <transactionManager type="JDBC" commitRequired="false">
     <dataSource type="SIMPLE">
-      <property name="JDBC.Driver" value="org.hsqldb.jdbcDriver"/>
-      <property name="JDBC.ConnectionURL" value="jdbc:hsqldb:mem:camel_ibatis"/>
+      <property name="JDBC.Driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
+      <property name="JDBC.ConnectionURL" value="jdbc:derby:memory:ibatis;create=true"/>
       <property name="JDBC.Username" value="sa"/>
       <property name="JDBC.Password" value=""/>
     </dataSource>