camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [1/3] git commit: Fixed OSGi itest build error of JpaRouteTest with Spring4.x
Date Mon, 15 Sep 2014 04:31:39 GMT
Repository: camel
Updated Branches:
  refs/heads/master c6a1e4c5e -> 89b397ab5


Fixed OSGi itest build error of JpaRouteTest with Spring4.x


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/20001fd8
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/20001fd8
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/20001fd8

Branch: refs/heads/master
Commit: 20001fd809046cfe7d58f93f7bb306d1f30abcb5
Parents: c6a1e4c
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Mon Sep 15 12:00:57 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Mon Sep 15 12:31:08 2014 +0800

----------------------------------------------------------------------
 .../camel/itest/osgi/jpa/JpaRouteTest.java      | 56 +++++++++++---------
 .../itest/osgi/jpa/springJpaRouteContext.xml    |  4 --
 2 files changed, 30 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/20001fd8/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/JpaRouteTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/JpaRouteTest.java
b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/JpaRouteTest.java
index 74ea5f3..b3ee2fb 100644
--- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/JpaRouteTest.java
+++ b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/JpaRouteTest.java
@@ -19,6 +19,8 @@ package org.apache.camel.itest.osgi.jpa;
 import java.util.List;
 
 import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.component.mock.MockEndpoint;
@@ -26,16 +28,16 @@ import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport;
 import org.apache.camel.spring.SpringCamelContext;
 import org.apache.camel.util.IOHelper;
 import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.PaxExam;
 import org.osgi.framework.BundleContext;
-import org.springframework.orm.jpa.JpaTemplate;
-import org.springframework.orm.jpa.JpaTransactionManager;
+
+
 import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext;
-import org.springframework.transaction.TransactionDefinition;
 import org.springframework.transaction.TransactionStatus;
 import org.springframework.transaction.support.TransactionCallback;
 import org.springframework.transaction.support.TransactionTemplate;
@@ -48,10 +50,23 @@ public class JpaRouteTest extends OSGiIntegrationTestSupport {
     protected static final String SELECT_ALL_STRING = "select x from " + SendEmail.class.getName()
+ " x";
 
     protected OsgiBundleXmlApplicationContext applicationContext;
+
+    protected TransactionTemplate transactionTemplate;
+    protected EntityManager entityManager;
     
     @Inject
     protected BundleContext bundleContext;
-    protected JpaTemplate jpaTemplate;
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        EntityManagerFactory entityManagerFactory = applicationContext.getBean("entityManagerFactory",
+                EntityManagerFactory.class);
+        transactionTemplate = applicationContext.getBean("transactionTemplate", TransactionTemplate.class);
+        entityManager = entityManagerFactory.createEntityManager();
+        cleanupRepository();
+    }
+
 
     @Test
     public void testRouteJpa() throws Exception {
@@ -61,7 +76,7 @@ public class JpaRouteTest extends OSGiIntegrationTestSupport {
         template.sendBody("direct:start", new SendEmail(1L, "someone@somewhere.org"));
 
         assertMockEndpointsSatisfied();
-        assertEntityInDB();
+        assertEntityInDB(1);
     }
     
     @After
@@ -92,33 +107,22 @@ public class JpaRouteTest extends OSGiIntegrationTestSupport {
         return SpringCamelContext.springCamelContext(applicationContext);
     }
 
-    private void assertEntityInDB() throws Exception {
-        // must type cast with Spring 2.x
-        jpaTemplate = applicationContext.getBean("jpaTemplate", JpaTemplate.class);
+    private void assertEntityInDB(int size) throws Exception {
+        List<?> list = entityManager.createQuery(SELECT_ALL_STRING).getResultList();
+        assertEquals(size, list.size());
 
-        @SuppressWarnings("rawtypes")
-        List list = jpaTemplate.find(SELECT_ALL_STRING);
-        assertEquals(1, list.size());
-        
         assertIsInstanceOf(SendEmail.class, list.get(0));
     }
 
-    protected void cleanupRepository() {
-        // must type cast with Spring 2.x
-        jpaTemplate = applicationContext.getBean("jpaTemplate", JpaTemplate.class);
-
-        TransactionTemplate transactionTemplate = new TransactionTemplate();
-        transactionTemplate.setTransactionManager(new JpaTransactionManager(jpaTemplate.getEntityManagerFactory()));
-        transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
-
-        transactionTemplate.execute(new TransactionCallback<Boolean>() {
-            public Boolean doInTransaction(TransactionStatus arg0) {
-                @SuppressWarnings("rawtypes")
-                List list = jpaTemplate.find(SELECT_ALL_STRING);
+    private void cleanupRepository() {
+        transactionTemplate.execute(new TransactionCallback<Object>() {
+            public Object doInTransaction(TransactionStatus arg0) {
+                entityManager.joinTransaction();
+                List<?> list = entityManager.createQuery(SELECT_ALL_STRING).getResultList();
                 for (Object item : list) {
-                    jpaTemplate.remove(item);
+                    entityManager.remove(item);
                 }
-                jpaTemplate.flush();
+                entityManager.flush();
                 return Boolean.TRUE;
             }
         });

http://git-wip-us.apache.org/repos/asf/camel/blob/20001fd8/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jpa/springJpaRouteContext.xml
----------------------------------------------------------------------
diff --git a/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jpa/springJpaRouteContext.xml
b/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jpa/springJpaRouteContext.xml
index aaca4fc..68ee080 100644
--- a/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jpa/springJpaRouteContext.xml
+++ b/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jpa/springJpaRouteContext.xml
@@ -30,10 +30,6 @@
         </property>
     </bean>
 
-    <bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate">
-        <property name="entityManagerFactory" ref="entityManagerFactory"/>
-    </bean>
-
     <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
         <property name="persistenceUnitName" value="camel"/>
     </bean>


Mime
View raw message