Author: davsclaus
Date: Mon Oct 19 11:20:26 2009
New Revision: 826641

URL: http://svn.apache.org/viewvc?rev=826641&view=rev
Log:
MR-198: Added more unit tests

Added:
    
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaComponentTest.java
   (with props)
    
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaEndpointTest.java
   (with props)
    
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaFlushOnSendTest.java
      - copied, changed from r826590, 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteTest.java
    
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteConsumeLockEntityTest.java
   (with props)
    
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteMaximumResultsTest.java
      - copied, changed from r826590, 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteTest.java
    
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRoutemaxMessagesPerPollTest.java
   (with props)
Removed:
    
camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/DefaultTransactionStrategy.java
Modified:
    
camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
    
camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaTemplateTransactionStrategy.java
    
camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/TransactionStrategy.java

Modified: 
camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java?rev=826641&r1=826640&r2=826641&view=diff
==============================================================================
--- 
camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
 (original)
+++ 
camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
 Mon Oct 19 11:20:26 2009
@@ -242,8 +242,7 @@
     }
 
     protected DeleteHandler<Object> createDeleteHandler() {
-        // TODO auto-discover an annotation in the entity bean to indicate the
-        // process completed method call?
+        // look for @Consumed to allow custom callback when the Entity has 
been consumed
         Class<?> entityType = getEndpoint().getEntityType();
         if (entityType != null) {
             List<Method> methods = 
ObjectHelper.findMethodsWithAnnotation(entityType, Consumed.class);

Modified: 
camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaTemplateTransactionStrategy.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaTemplateTransactionStrategy.java?rev=826641&r1=826640&r2=826641&view=diff
==============================================================================
--- 
camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaTemplateTransactionStrategy.java
 (original)
+++ 
camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaTemplateTransactionStrategy.java
 Mon Oct 19 11:20:26 2009
@@ -35,7 +35,7 @@
  *
  * @version $Revision$
  */
-public class JpaTemplateTransactionStrategy extends ServiceSupport implements 
TransactionStrategy {
+public class JpaTemplateTransactionStrategy implements TransactionStrategy {
     private final JpaTemplate jpaTemplate;
     private final TransactionTemplate transactionTemplate;
 
@@ -87,9 +87,4 @@
         });
     }
 
-    protected void doStart() throws Exception {
-    }
-
-    protected void doStop() throws Exception {
-    }
 }

Modified: 
camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/TransactionStrategy.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/TransactionStrategy.java?rev=826641&r1=826640&r2=826641&view=diff
==============================================================================
--- 
camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/TransactionStrategy.java
 (original)
+++ 
camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/TransactionStrategy.java
 Mon Oct 19 11:20:26 2009
@@ -16,12 +16,18 @@
  */
 package org.apache.camel.component.jpa;
 
-import org.apache.camel.Service;
 import org.springframework.orm.jpa.JpaCallback;
 
 /**
  * @version $Revision$
  */
-public interface TransactionStrategy extends Service {
+public interface TransactionStrategy {
+
+    /**
+     * Executes in a transaction.
+     *
+     * @param callback the callback
+     * @return the result
+     */
     Object execute(JpaCallback callback);
 }

Added: 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaComponentTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaComponentTest.java?rev=826641&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaComponentTest.java
 (added)
+++ 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaComponentTest.java
 Mon Oct 19 11:20:26 2009
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jpa;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+
+import org.apache.camel.examples.SendEmail;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+import org.springframework.orm.jpa.JpaTransactionManager;
+
+/**
+ * @version $Revision$
+ */
+public class JpaComponentTest extends CamelTestSupport {
+
+    @Test
+    public void testJpaComponentCtr() throws Exception {
+        JpaComponent comp = new JpaComponent();
+        comp.setCamelContext(context);
+        assertNull(comp.getEntityManagerFactory());
+        assertNull(comp.getTransactionManager());
+
+        JpaEndpoint jpa = (JpaEndpoint) comp.createEndpoint("jpa://" + 
SendEmail.class.getName());
+        assertNotNull(jpa);
+    }
+
+    @Test
+    public void testJpaComponentEMFandTM() throws Exception {
+        JpaComponent comp = new JpaComponent();
+        comp.setCamelContext(context);
+        assertNull(comp.getEntityManagerFactory());
+        assertNull(comp.getTransactionManager());
+
+        EntityManagerFactory fac = 
Persistence.createEntityManagerFactory("camel");
+        JpaTransactionManager tm = new JpaTransactionManager(fac);
+        tm.afterPropertiesSet();
+
+        comp.setEntityManagerFactory(fac);
+        comp.setTransactionManager(tm);
+
+        assertSame(fac, comp.getEntityManagerFactory());
+        assertSame(tm, comp.getTransactionManager());
+
+        JpaEndpoint jpa = (JpaEndpoint) comp.createEndpoint("jpa://" + 
SendEmail.class.getName());
+        assertNotNull(jpa);
+    }
+
+}

Propchange: 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaComponentTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaComponentTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaEndpointTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaEndpointTest.java?rev=826641&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaEndpointTest.java
 (added)
+++ 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaEndpointTest.java
 Mon Oct 19 11:20:26 2009
@@ -0,0 +1,104 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jpa;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+
+import org.apache.camel.examples.SendEmail;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+import org.springframework.orm.jpa.JpaTransactionManager;
+
+/**
+ * @version $Revision$
+ */
+public class JpaEndpointTest extends CamelTestSupport {
+
+    @Test
+    public void testJpaEndpointCtr() throws Exception {
+        JpaEndpoint jpa = new JpaEndpoint();
+        jpa.setEntityType(SendEmail.class);
+
+        assertNotNull(jpa.getEntityManagerFactory());
+        assertNotNull(jpa.getTransactionManager());
+
+        assertEquals("jpa://org.apache.camel.examples.SendEmail", 
jpa.getEndpointUri());
+        assertEquals("camel", jpa.getPersistenceUnit());
+    }
+
+    @Test
+    public void testJpaEndpointCtrUrl() throws Exception {
+        JpaEndpoint jpa = new 
JpaEndpoint("jpa://org.apache.camel.examples.SendEmail");
+        jpa.setEntityType(SendEmail.class);
+
+        assertNotNull(jpa.getEntityManagerFactory());
+        assertNotNull(jpa.getTransactionManager());
+
+        assertEquals("jpa://org.apache.camel.examples.SendEmail", 
jpa.getEndpointUri());
+        assertEquals("camel", jpa.getPersistenceUnit());
+    }
+
+    @Test
+    public void testJpaEndpointCtrUrlEMF() throws Exception {
+        EntityManagerFactory fac = 
Persistence.createEntityManagerFactory("camel");
+
+        JpaEndpoint jpa = new 
JpaEndpoint("jpa://org.apache.camel.examples.SendEmail", fac);
+        jpa.setEntityType(SendEmail.class);
+
+        assertSame(fac, jpa.getEntityManagerFactory());
+        assertNotNull(jpa.getTransactionManager());
+
+        assertEquals("jpa://org.apache.camel.examples.SendEmail", 
jpa.getEndpointUri());
+        assertEquals("camel", jpa.getPersistenceUnit());
+    }
+
+    @Test
+    public void testJpaEndpointCtrUrlEMFandTM() throws Exception {
+        EntityManagerFactory fac = 
Persistence.createEntityManagerFactory("camel");
+        JpaTransactionManager tm = new JpaTransactionManager(fac);
+        tm.afterPropertiesSet();
+
+        JpaEndpoint jpa = new 
JpaEndpoint("jpa://org.apache.camel.examples.SendEmail", fac, tm);
+        jpa.setEntityType(SendEmail.class);
+
+        assertSame(fac, jpa.getEntityManagerFactory());
+        assertSame(tm, jpa.getTransactionManager());
+
+        assertEquals("jpa://org.apache.camel.examples.SendEmail", 
jpa.getEndpointUri());
+        assertEquals("camel", jpa.getPersistenceUnit());
+    }
+
+    @Test
+    public void testJpaEndpointCustomEMFandTM() throws Exception {
+        EntityManagerFactory fac = 
Persistence.createEntityManagerFactory("camel");
+        JpaTransactionManager tm = new JpaTransactionManager(fac);
+        tm.afterPropertiesSet();
+
+        JpaEndpoint jpa = new JpaEndpoint();
+        jpa.setEntityType(SendEmail.class);
+
+        jpa.setEntityManagerFactory(fac);
+        jpa.setTransactionManager(tm);
+
+        assertSame(fac, jpa.getEntityManagerFactory());
+        assertSame(tm, jpa.getTransactionManager());
+
+        assertEquals("jpa://org.apache.camel.examples.SendEmail", 
jpa.getEndpointUri());
+        assertEquals("camel", jpa.getPersistenceUnit());
+    }
+}

Propchange: 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaEndpointTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaEndpointTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaFlushOnSendTest.java
 (from r826590, 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteTest.java)
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaFlushOnSendTest.java?p2=camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaFlushOnSendTest.java&p1=camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteTest.java&r1=826590&r2=826641&rev=826641&view=diff
==============================================================================
--- 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteTest.java
 (original)
+++ 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaFlushOnSendTest.java
 Mon Oct 19 11:20:26 2009
@@ -38,7 +38,7 @@
 /**
  * @version $Revision$
  */
-public class JpaRouteTest extends CamelTestSupport {
+public class JpaFlushOnSendTest extends CamelTestSupport {
     protected static final String SELECT_ALL_STRING = "select x from " + 
SendEmail.class.getName() + " x";
 
     protected ApplicationContext applicationContext;
@@ -66,7 +66,7 @@
     protected RouteBuilder createRouteBuilder() {
         return new SpringRouteBuilder() {
             public void configure() {
-                from("direct:start").to("jpa://" + 
SendEmail.class.getName()).to("mock:result");
+                from("direct:start").to("jpa://" + SendEmail.class.getName() + 
"?flushOnSend=true").to("mock:result");
             }
         };
     }
@@ -76,7 +76,7 @@
 
         List list = jpaTemplate.find(SELECT_ALL_STRING);
         assertEquals(1, list.size());
-        
+
         assertIsInstanceOf(SendEmail.class, list.get(0));
     }
 

Added: 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteConsumeLockEntityTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteConsumeLockEntityTest.java?rev=826641&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteConsumeLockEntityTest.java
 (added)
+++ 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteConsumeLockEntityTest.java
 Mon Oct 19 11:20:26 2009
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor.jpa;
+
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.examples.SendEmail;
+import org.apache.camel.spring.SpringCamelContext;
+import org.apache.camel.spring.SpringRouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.orm.jpa.JpaTemplate;
+import org.springframework.orm.jpa.JpaTransactionManager;
+import org.springframework.transaction.TransactionDefinition;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.TransactionCallback;
+import org.springframework.transaction.support.TransactionTemplate;
+
+/**
+ * @version $Revision$
+ */
+public class JpaRouteConsumeLockEntityTest extends CamelTestSupport {
+    protected static final String SELECT_ALL_STRING = "select x from " + 
SendEmail.class.getName() + " x";
+
+    protected ApplicationContext applicationContext;
+    protected JpaTemplate jpaTemplate;
+
+    @Test
+    public void testRouteJpa() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+
+        template.sendBody("direct:start", new SendEmail("[email protected]"));
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        applicationContext = new 
ClassPathXmlApplicationContext("org/apache/camel/processor/jpa/springJpaRouteTest.xml");
+        cleanupRepository();
+        return SpringCamelContext.springCamelContext(applicationContext);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new SpringRouteBuilder() {
+            public void configure() {
+                from("direct:start").to("jpa://" + SendEmail.class.getName());
+
+                from("jpa://" + SendEmail.class.getName() + 
"?consumeLockEntity=true").to("mock:result");
+            }
+        };
+    }
+
+    protected void cleanupRepository() {
+        jpaTemplate = (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 Object doInTransaction(TransactionStatus arg0) {
+                List list = jpaTemplate.find(SELECT_ALL_STRING);
+                for (Object item : list) {
+                    jpaTemplate.remove(item);
+                }
+                jpaTemplate.flush();
+                return Boolean.TRUE;
+            }
+        });
+    }
+}
\ No newline at end of file

Propchange: 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteConsumeLockEntityTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteConsumeLockEntityTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteMaximumResultsTest.java
 (from r826590, 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteTest.java)
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteMaximumResultsTest.java?p2=camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteMaximumResultsTest.java&p1=camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteTest.java&r1=826590&r2=826641&rev=826641&view=diff
==============================================================================
--- 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteTest.java
 (original)
+++ 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRouteMaximumResultsTest.java
 Mon Oct 19 11:20:26 2009
@@ -38,7 +38,7 @@
 /**
  * @version $Revision$
  */
-public class JpaRouteTest extends CamelTestSupport {
+public class JpaRouteMaximumResultsTest extends CamelTestSupport {
     protected static final String SELECT_ALL_STRING = "select x from " + 
SendEmail.class.getName() + " x";
 
     protected ApplicationContext applicationContext;
@@ -47,12 +47,17 @@
     @Test
     public void testRouteJpa() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedMessageCount(1);
+        mock.expectedMinimumMessageCount(1);
 
-        template.sendBody("direct:start", new 
SendEmail("[email protected]"));
+        template.sendBody("direct:start", new SendEmail("[email protected]"));
+        template.sendBody("direct:start", new SendEmail("[email protected]"));
+        template.sendBody("direct:start", new 
SendEmail("[email protected]"));
 
         assertMockEndpointsSatisfied();
         assertEntityInDB();
+
+        // should not consume 3 at once
+        assertTrue("Should not consume all 3 at once", 
mock.getReceivedCounter() < 3);
     }
 
     @Override
@@ -66,7 +71,9 @@
     protected RouteBuilder createRouteBuilder() {
         return new SpringRouteBuilder() {
             public void configure() {
-                from("direct:start").to("jpa://" + 
SendEmail.class.getName()).to("mock:result");
+                from("direct:start").to("jpa://" + SendEmail.class.getName());
+
+                from("jpa://" + SendEmail.class.getName() + 
"?maximumResults=1&consumeDelete=false&delay=5000").to("mock:result");
             }
         };
     }
@@ -75,8 +82,8 @@
         jpaTemplate = (JpaTemplate)applicationContext.getBean("jpaTemplate", 
JpaTemplate.class);
 
         List list = jpaTemplate.find(SELECT_ALL_STRING);
-        assertEquals(1, list.size());
-        
+        assertEquals(3, list.size());
+
         assertIsInstanceOf(SendEmail.class, list.get(0));
     }
 

Added: 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRoutemaxMessagesPerPollTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRoutemaxMessagesPerPollTest.java?rev=826641&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRoutemaxMessagesPerPollTest.java
 (added)
+++ 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRoutemaxMessagesPerPollTest.java
 Mon Oct 19 11:20:26 2009
@@ -0,0 +1,105 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor.jpa;
+
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.examples.SendEmail;
+import org.apache.camel.spring.SpringCamelContext;
+import org.apache.camel.spring.SpringRouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.orm.jpa.JpaTemplate;
+import org.springframework.orm.jpa.JpaTransactionManager;
+import org.springframework.transaction.TransactionDefinition;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.TransactionCallback;
+import org.springframework.transaction.support.TransactionTemplate;
+
+/**
+ * @version $Revision$
+ */
+public class JpaRoutemaxMessagesPerPollTest extends CamelTestSupport {
+    protected static final String SELECT_ALL_STRING = "select x from " + 
SendEmail.class.getName() + " x";
+
+    protected ApplicationContext applicationContext;
+    protected JpaTemplate jpaTemplate;
+
+    @Test
+    public void testRouteJpa() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(2);
+
+        template.sendBody("direct:start", new SendEmail("[email protected]"));
+        template.sendBody("direct:start", new SendEmail("[email protected]"));
+        template.sendBody("direct:start", new 
SendEmail("[email protected]"));
+
+        assertMockEndpointsSatisfied();
+        assertEntityInDB();
+    }
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        applicationContext = new 
ClassPathXmlApplicationContext("org/apache/camel/processor/jpa/springJpaRouteTest.xml");
+        cleanupRepository();
+        return SpringCamelContext.springCamelContext(applicationContext);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new SpringRouteBuilder() {
+            public void configure() {
+                from("direct:start").to("jpa://" + SendEmail.class.getName());
+
+                from("jpa://" + SendEmail.class.getName() + 
"?maxMessagesPerPoll=2&consumeDelete=false&delay=5000").to("mock:result");
+            }
+        };
+    }
+
+    private void assertEntityInDB() throws Exception {
+        jpaTemplate = (JpaTemplate)applicationContext.getBean("jpaTemplate", 
JpaTemplate.class);
+
+        List list = jpaTemplate.find(SELECT_ALL_STRING);
+        assertEquals(3, list.size());
+
+        assertIsInstanceOf(SendEmail.class, list.get(0));
+    }
+
+    protected void cleanupRepository() {
+        jpaTemplate = (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 Object doInTransaction(TransactionStatus arg0) {
+                List list = jpaTemplate.find(SELECT_ALL_STRING);
+                for (Object item : list) {
+                    jpaTemplate.remove(item);
+                }
+                jpaTemplate.flush();
+                return Boolean.TRUE;
+            }
+        });
+    }
+}
\ No newline at end of file

Propchange: 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRoutemaxMessagesPerPollTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaRoutemaxMessagesPerPollTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date


Reply via email to