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/06 09:16:09 UTC

svn commit: r1210819 - in /camel/branches/camel-2.7.x/components/camel-mybatis: ./ src/test/java/org/apache/camel/component/mybatis/ src/test/resources/

Author: cmueller
Date: Tue Dec  6 08:16:08 2011
New Revision: 1210819

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

Modified:
    camel/branches/camel-2.7.x/components/camel-mybatis/pom.xml
    camel/branches/camel-2.7.x/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisQueueTest.java
    camel/branches/camel-2.7.x/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisSelectListTest.java
    camel/branches/camel-2.7.x/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisTestSupport.java
    camel/branches/camel-2.7.x/components/camel-mybatis/src/test/resources/SqlMapConfig.xml

Modified: camel/branches/camel-2.7.x/components/camel-mybatis/pom.xml
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/components/camel-mybatis/pom.xml?rev=1210819&r1=1210818&r2=1210819&view=diff
==============================================================================
--- camel/branches/camel-2.7.x/components/camel-mybatis/pom.xml (original)
+++ camel/branches/camel-2.7.x/components/camel-mybatis/pom.xml Tue Dec  6 08:16:08 2011
@@ -54,8 +54,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>
     <dependency>

Modified: camel/branches/camel-2.7.x/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisQueueTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisQueueTest.java?rev=1210819&r1=1210818&r2=1210819&view=diff
==============================================================================
--- camel/branches/camel-2.7.x/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisQueueTest.java (original)
+++ camel/branches/camel-2.7.x/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisQueueTest.java Tue Dec  6 08:16:08 2011
@@ -16,21 +16,24 @@
  */
 package org.apache.camel.component.mybatis;
 
-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 MyBatisQueueTest extends CamelTestSupport {
+public class MyBatisQueueTest extends MyBatisTestSupport {
+    
+    protected boolean createTestData() {
+        return false;
+    }
+    
+    protected String createStatement() {
+        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 {
@@ -60,7 +63,7 @@ public class MyBatisQueueTest extends Ca
         Thread.sleep(1000);
 
         // now lets poll that the account has been inserted
-        List body = template.requestBody("mybatis:selectProcessedAccounts?statementType=SelectList", null, List.class);
+        List<?> body = template.requestBody("mybatis:selectProcessedAccounts?statementType=SelectList", null, List.class);
 
         assertEquals("Wrong size: " + body, 2, body.size());
         Account actual = assertIsInstanceOf(Account.class, body.get(0));
@@ -84,33 +87,4 @@ public class MyBatisQueueTest extends Ca
             }
         };
     }
-
-    @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), PROCESSED BOOLEAN DEFAULT false)");
-        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 {
-        MyBatisEndpoint endpoint = resolveMandatoryEndpoint("mybatis:Account", MyBatisEndpoint.class);
-        return endpoint.getSqlSessionFactory().getConfiguration().getEnvironment().getDataSource().getConnection();
-    }
-
 }

Modified: camel/branches/camel-2.7.x/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisSelectListTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisSelectListTest.java?rev=1210819&r1=1210818&r2=1210819&view=diff
==============================================================================
--- camel/branches/camel-2.7.x/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisSelectListTest.java (original)
+++ camel/branches/camel-2.7.x/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisSelectListTest.java Tue Dec  6 08:16:08 2011
@@ -36,7 +36,7 @@ public class MyBatisSelectListTest exten
 
         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());

Modified: camel/branches/camel-2.7.x/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisTestSupport.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisTestSupport.java?rev=1210819&r1=1210818&r2=1210819&view=diff
==============================================================================
--- camel/branches/camel-2.7.x/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisTestSupport.java (original)
+++ camel/branches/camel-2.7.x/components/camel-mybatis/src/test/java/org/apache/camel/component/mybatis/MyBatisTestSupport.java Tue Dec  6 08:16:08 2011
@@ -17,9 +17,12 @@
 package org.apache.camel.component.mybatis;
 
 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;
 
@@ -31,6 +34,10 @@ public abstract class MyBatisTestSupport
     protected boolean createTestData() {
         return true;
     }
+    
+    protected String createStatement() {
+        return "create table ACCOUNT ( ACC_ID INTEGER , ACC_FIRST_NAME VARCHAR(255), ACC_LAST_NAME VARCHAR(255), ACC_EMAIL VARCHAR(255)  )";
+    }
 
     @Override
     @Before
@@ -40,7 +47,8 @@ public abstract class MyBatisTestSupport
         // 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(createStatement());
+        connection.commit();
         connection.close();
 
         if (createTestData()) {
@@ -63,12 +71,15 @@ public abstract class MyBatisTestSupport
     @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:mybatis;drop=true", new Properties());
+        } catch (SQLException ex) {
+            if (!"08006".equals(ex.getSQLState())) {
+                throw ex;
+            }
+        }
     }
 
     private Connection createConnection() throws Exception {

Modified: camel/branches/camel-2.7.x/components/camel-mybatis/src/test/resources/SqlMapConfig.xml
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/components/camel-mybatis/src/test/resources/SqlMapConfig.xml?rev=1210819&r1=1210818&r2=1210819&view=diff
==============================================================================
--- camel/branches/camel-2.7.x/components/camel-mybatis/src/test/resources/SqlMapConfig.xml (original)
+++ camel/branches/camel-2.7.x/components/camel-mybatis/src/test/resources/SqlMapConfig.xml Tue Dec  6 08:16:08 2011
@@ -36,8 +36,8 @@
         <environment id="development">
             <transactionManager type="JDBC"/>
             <dataSource type="POOLED">
-                <property name="driver" value="org.hsqldb.jdbcDriver"/>
-                <property name="url" value="jdbc:hsqldb:mem:camel_ibatis"/>
+                <property name="driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
+                <property name="url" value="jdbc:derby:memory:mybatis;create=true"/>
                 <property name="username" value="sa"/>
                 <property name="password" value=""/>
             </dataSource>