camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [09/12] camel git commit: CAMEL-10490 Some code cleanup
Date Wed, 30 Nov 2016 14:49:38 GMT
CAMEL-10490 Some code cleanup


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

Branch: refs/heads/camel-2.18.x
Commit: 40c6fa3cda2b19061e785fa4c247e77f7e15aac0
Parents: f504c1e
Author: Bob Gaudaen <bob.gaudaen@gmail.com>
Authored: Mon Nov 28 11:11:00 2016 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Nov 30 15:48:45 2016 +0100

----------------------------------------------------------------------
 .../camel/component/jpa/JpaPollingConsumer.java |   6 +-
 .../org/apache/camel/examples/Customer.java     |  10 +-
 .../jpa/JpaPollingConsumerLockEntityTest.java   | 106 +++++++++++++++++++
 .../processor/jpa/JpaPollingConsumerTest.java   |  46 +-------
 4 files changed, 118 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/40c6fa3c/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaPollingConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaPollingConsumer.java
b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaPollingConsumer.java
index 212ad73..f787393 100644
--- a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaPollingConsumer.java
+++ b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaPollingConsumer.java
@@ -24,7 +24,11 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
-import javax.persistence.*;
+import javax.persistence.Entity;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Query;
+import javax.persistence.LockModeType;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.impl.PollingConsumerSupport;

http://git-wip-us.apache.org/repos/asf/camel/blob/40c6fa3c/components/camel-jpa/src/test/java/org/apache/camel/examples/Customer.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/test/java/org/apache/camel/examples/Customer.java b/components/camel-jpa/src/test/java/org/apache/camel/examples/Customer.java
index efe21fa..1bf2ec6 100644
--- a/components/camel-jpa/src/test/java/org/apache/camel/examples/Customer.java
+++ b/components/camel-jpa/src/test/java/org/apache/camel/examples/Customer.java
@@ -37,7 +37,7 @@ public class Customer {
     private String name;
     @OneToOne(cascade = CascadeType.ALL)
     private Address address;
-    private int orders;
+    private int orderCount;
 
     public Long getId() {
         return id;
@@ -63,12 +63,12 @@ public class Customer {
         this.address = address;
     }
 
-    public int getOrders() {
-        return orders;
+    public int getOrderCount() {
+        return orderCount;
     }
 
-    public void setOrders(int orders) {
-        this.orders = orders;
+    public void setOrderCount(int orderCount) {
+        this.orderCount = orderCount;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/40c6fa3c/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaPollingConsumerLockEntityTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaPollingConsumerLockEntityTest.java
b/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaPollingConsumerLockEntityTest.java
new file mode 100644
index 0000000..89c95db
--- /dev/null
+++ b/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaPollingConsumerLockEntityTest.java
@@ -0,0 +1,106 @@
+/**
+ * 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 org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.examples.Customer;
+import org.apache.camel.spring.SpringRouteBuilder;
+import org.junit.Test;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.TransactionCallback;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class JpaPollingConsumerLockEntityTest extends AbstractJpaTest {
+    protected static final String SELECT_ALL_STRING = "select x from " + Customer.class.getName()
+ " x";
+
+    protected void save(final Customer customer) {
+        transactionTemplate.execute(new TransactionCallback<Object>() {
+            public Object doInTransaction(TransactionStatus status) {
+                entityManager.joinTransaction();
+                entityManager.persist(customer);
+                entityManager.flush();
+                return null;
+            }
+        });
+    }
+
+    protected void assertEntitiesInDatabase(int count, String entity) {
+        List<?> results = entityManager.createQuery("select o from " + entity + " o").getResultList();
+        assertEquals(count, results.size());
+    }
+
+    @Test
+    public void testPollingConsumerHandlesLockedEntity() throws Exception {
+        Customer customer = new Customer();
+        customer.setName("Donald Duck");
+        save(customer);
+
+        Customer customer2 = new Customer();
+        customer2.setName("Goofy");
+        save(customer2);
+
+        assertEntitiesInDatabase(2, Customer.class.getName());
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived(
+            "orders: 1",
+            "orders: 2"
+        );
+
+        Map<String, Object> headers = new HashMap<>();
+        headers.put("name", "Donald%");
+
+        template.asyncRequestBodyAndHeaders("direct:start", "message", headers);
+        template.asyncRequestBodyAndHeaders("direct:start", "message", headers);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new SpringRouteBuilder() {
+            public void configure() {
+                from("direct:start")
+                    .transacted()
+                    .pollEnrich().simple("jpa://" + Customer.class.getName() + "?joinTransaction=true&consumeLockEntity=true&query=select
c from Customer c where c.name like '${header.name}'")
+                    .aggregationStrategy((originalExchange, jpaExchange) -> {
+                        Customer customer = jpaExchange.getIn().getBody(Customer.class);
+                        customer.setOrderCount(customer.getOrderCount()+1);
+
+                        return jpaExchange;
+                    })
+                    .to("jpa://" + Customer.class.getName() + "?joinTransaction=true&usePassedInEntityManager=true")
+                    .setBody().simple("orders: ${body.orderCount}")
+                    .to("mock:result");
+            }
+        };
+    }
+
+    @Override
+    protected String routeXml() {
+        return "org/apache/camel/processor/jpa/springJpaRouteTest.xml";
+    }
+
+    @Override
+    protected String selectAllString() {
+        return SELECT_ALL_STRING;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/40c6fa3c/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaPollingConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaPollingConsumerTest.java
b/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaPollingConsumerTest.java
index c3bdc9a..5b72211 100644
--- a/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaPollingConsumerTest.java
+++ b/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaPollingConsumerTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.processor.jpa;
 
+import java.util.List;
+
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.examples.Customer;
@@ -24,10 +26,6 @@ import org.junit.Test;
 import org.springframework.transaction.TransactionStatus;
 import org.springframework.transaction.support.TransactionCallback;
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 public class JpaPollingConsumerTest extends AbstractJpaTest {
     protected static final String SELECT_ALL_STRING = "select x from " + Customer.class.getName()
+ " x";
 
@@ -66,33 +64,6 @@ public class JpaPollingConsumerTest extends AbstractJpaTest {
         assertMockEndpointsSatisfied();
     }
 
-    @Test
-    public void testPollingConsumerHandlesLockedEntity() throws Exception {
-        Customer customer = new Customer();
-        customer.setName("Donald Duck");
-        save(customer);
-
-        Customer customer2 = new Customer();
-        customer2.setName("Goofy");
-        save(customer2);
-
-        assertEntitiesInDatabase(2, Customer.class.getName());
-
-        MockEndpoint mock = getMockEndpoint("mock:result2");
-        mock.expectedBodiesReceived(
-            "orders: 1",
-            "orders: 2"
-        );
-
-        Map<String, Object> headers = new HashMap<>();
-        headers.put("name", "Donald%");
-
-        template.asyncRequestBodyAndHeaders("direct:start2", "message", headers);
-        template.asyncRequestBodyAndHeaders("direct:start2", "message", headers);
-
-        assertMockEndpointsSatisfied();
-    }
-
     @Override
     protected RouteBuilder createRouteBuilder() {
         return new SpringRouteBuilder() {
@@ -106,19 +77,6 @@ public class JpaPollingConsumerTest extends AbstractJpaTest {
                             return a;
                         })
                     .to("mock:result");
-
-                from("direct:start2")
-                    .transacted()
-                    .pollEnrich().simple("jpa://" + Customer.class.getName() + "?joinTransaction=true&consumeLockEntity=true&query=select
c from Customer c where c.name like '${header.name}'")
-                    .aggregationStrategy((originalExchange, jpaExchange) -> {
-                        Customer customer = jpaExchange.getIn().getBody(Customer.class);
-                        customer.setOrders(customer.getOrders()+1);
-
-                        return jpaExchange;
-                    })
-                    .to("jpa://" + Customer.class.getName() + "?joinTransaction=true&usePassedInEntityManager=true")
-                    .setBody().simple("orders: ${body.orders}")
-                    .to("mock:result2");
             }
         };
     }


Mime
View raw message