Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 489FB11F87 for ; Mon, 15 Sep 2014 04:31:40 +0000 (UTC) Received: (qmail 85544 invoked by uid 500); 15 Sep 2014 04:31:40 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 85471 invoked by uid 500); 15 Sep 2014 04:31:40 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 85454 invoked by uid 99); 15 Sep 2014 04:31:40 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Sep 2014 04:31:40 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id BFF5A9C5CC6; Mon, 15 Sep 2014 04:31:39 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ningjiang@apache.org To: commits@camel.apache.org Date: Mon, 15 Sep 2014 04:31:39 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/3] git commit: Fixed OSGi itest build error of JpaRouteTest with Spring4.x 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 Authored: Mon Sep 15 12:00:57 2014 +0800 Committer: Willem Jiang 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() { - public Boolean doInTransaction(TransactionStatus arg0) { - @SuppressWarnings("rawtypes") - List list = jpaTemplate.find(SELECT_ALL_STRING); + private void cleanupRepository() { + transactionTemplate.execute(new TransactionCallback() { + 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 @@ - - - -