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 2010/06/17 23:24:02 UTC

svn commit: r955752 - in /camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa: JpaWithNamedQueryTest.java JpaWithNativeQueryTest.java JpaWithQueryTest.java

Author: cmueller
Date: Thu Jun 17 21:24:01 2010
New Revision: 955752

URL: http://svn.apache.org/viewvc?rev=955752&view=rev
Log:
modified the JpaWithNamedQueryTest and add the JpaWithNativeQueryTest and JpaWithQueryTest

Added:
    camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNativeQueryTest.java   (with props)
    camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithQueryTest.java   (with props)
Modified:
    camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryTest.java

Modified: camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryTest.java?rev=955752&r1=955751&r2=955752&view=diff
==============================================================================
--- camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryTest.java (original)
+++ camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryTest.java Thu Jun 17 21:24:01 2010
@@ -45,7 +45,9 @@ import org.springframework.orm.jpa.JpaTe
  * @version $Revision$
  */
 public class JpaWithNamedQueryTest extends Assert {
-    private static final transient Log LOG = LogFactory.getLog(JpaWithNamedQueryTest.class);
+    
+    protected final transient Log LOG = LogFactory.getLog(this.getClass());
+    
     protected CamelContext camelContext = new DefaultCamelContext();
     protected ProducerTemplate template;
     protected JpaEndpoint endpoint;
@@ -101,10 +103,7 @@ public class JpaWithNamedQueryTest exten
         boolean received = latch.await(50, TimeUnit.SECONDS);
         assertTrue("Did not receive the message!", received);
 
-        assertNotNull(receivedExchange);
-        MultiSteps result = receivedExchange.getIn().getBody(MultiSteps.class);
-        assertNotNull("Received a POJO", result);
-        assertEquals("address property", "foo@bar.com", result.getAddress());
+        assertReceivedResult(receivedExchange);
 
         // lets now test that the database is updated
         // we need to sleep as we will be invoked from inside the transaction!
@@ -125,7 +124,7 @@ public class JpaWithNamedQueryTest exten
                     if (row.getAddress().equals("foo@bar.com")) {
                         LOG.info("Found updated row: " + row);
 
-                        assertEquals("Updated row step for: " + row, 2, row.getStep());
+                        assertEquals("Updated row step for: " + row, getUpdatedStepValue(), row.getStep());
                     } else {
                         // dummy row
                         assertEquals("dummy row step for: " + row, 4, row.getStep());
@@ -136,6 +135,21 @@ public class JpaWithNamedQueryTest exten
         });
 
         JpaConsumer jpaConsumer = (JpaConsumer) consumer;
+        assertURIQueryOption(jpaConsumer);
+    }
+
+    protected void assertReceivedResult(Exchange exchange) {
+        assertNotNull(exchange);
+        MultiSteps result = exchange.getIn().getBody(MultiSteps.class);
+        assertNotNull("Received a POJO", result);
+        assertEquals("address property", "foo@bar.com", result.getAddress());
+    }
+    
+    protected int getUpdatedStepValue() {
+        return 2;
+    }
+    
+    protected void assertURIQueryOption(JpaConsumer jpaConsumer) {
         assertEquals("step1", jpaConsumer.getNamedQuery());
     }
 

Added: camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNativeQueryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNativeQueryTest.java?rev=955752&view=auto
==============================================================================
--- camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNativeQueryTest.java (added)
+++ camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNativeQueryTest.java Thu Jun 17 21:24:01 2010
@@ -0,0 +1,57 @@
+/**
+ * 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 org.apache.camel.Exchange;
+import org.apache.camel.examples.MultiSteps;
+
+/**
+ * @version $Revision: $
+ */
+public class JpaWithNativeQueryTest extends JpaWithNamedQueryTest {
+    
+    /**
+     * We receive an object array, because we call entityManager.createNativeQuery(nativeQuery)
+     * and not entityManager.createNativeQuery(nativeQuery, MultiSteps.class)
+     */
+    @Override
+    protected void assertReceivedResult(Exchange exchange) {
+        assertNotNull(exchange);
+        Object[] result = exchange.getIn().getBody(Object[].class);
+        assertNotNull("Received an object array", result);
+        assertEquals("address property", "foo@bar.com", result[1]);
+    }
+    
+    /**
+     * Is still 1, because we receive an object array which has no @Consumed annotation
+     * as the MultiSteps class has.
+     */
+    @Override
+    protected int getUpdatedStepValue() {
+        return 1;
+    }
+    
+    @Override
+    protected void assertURIQueryOption(JpaConsumer jpaConsumer) {
+        assertEquals("select * from MultiSteps where step = 1", jpaConsumer.getNativeQuery());
+    }
+
+    @Override
+    protected String getEndpointUri() {
+        return "jpa://" + MultiSteps.class.getName() + "?consumer.nativeQuery=select * from MultiSteps where step = 1";
+    }
+}
\ No newline at end of file

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

Propchange: camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNativeQueryTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithQueryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithQueryTest.java?rev=955752&view=auto
==============================================================================
--- camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithQueryTest.java (added)
+++ camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithQueryTest.java Thu Jun 17 21:24:01 2010
@@ -0,0 +1,35 @@
+/**
+ * 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 org.apache.camel.examples.MultiSteps;
+
+/**
+ * @version $Revision: $
+ */
+public class JpaWithQueryTest extends JpaWithNamedQueryTest {
+
+    @Override
+    protected void assertURIQueryOption(JpaConsumer jpaConsumer) {
+        assertEquals("select o from " + entityName + " o where o.step = 1", jpaConsumer.getQuery());
+    }
+
+    @Override
+    protected String getEndpointUri() {
+        return "jpa://" + MultiSteps.class.getName() + "?consumer.query=select o from " + entityName + " o where o.step = 1";
+    }
+}
\ No newline at end of file

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

Propchange: camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithQueryTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain