You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2011/09/19 05:11:26 UTC

svn commit: r1172414 - in /camel/trunk: components/camel-ejb/src/test/java/org/apache/camel/component/ejb/ tests/camel-itest-osgi/ tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/ tests/camel-itest-osgi/src/test/java/org/apache/camel/i...

Author: ningjiang
Date: Mon Sep 19 03:11:26 2011
New Revision: 1172414

URL: http://svn.apache.org/viewvc?rev=1172414&view=rev
Log:
CAMEL-4463 Add OSGi integration test for camel-jpa

Added:
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/JpaBlueprintRouteTest.java   (with props)
    camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jpa/blueprintCamelContext.xml   (with props)
Modified:
    camel/trunk/components/camel-ejb/src/test/java/org/apache/camel/component/ejb/GreaterCamelEjbTest.java
    camel/trunk/tests/camel-itest-osgi/pom.xml
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OSGiIntegrationTestSupport.java
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/JpaRouteTest.java
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/SendEmail.java
    camel/trunk/tests/camel-itest-osgi/src/test/resources/META-INF/persistence.xml

Modified: camel/trunk/components/camel-ejb/src/test/java/org/apache/camel/component/ejb/GreaterCamelEjbTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ejb/src/test/java/org/apache/camel/component/ejb/GreaterCamelEjbTest.java?rev=1172414&r1=1172413&r2=1172414&view=diff
==============================================================================
--- camel/trunk/components/camel-ejb/src/test/java/org/apache/camel/component/ejb/GreaterCamelEjbTest.java (original)
+++ camel/trunk/components/camel-ejb/src/test/java/org/apache/camel/component/ejb/GreaterCamelEjbTest.java Mon Sep 19 03:11:26 2011
@@ -17,6 +17,7 @@
 package org.apache.camel.component.ejb;
 
 import java.util.Properties;
+
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
@@ -24,7 +25,6 @@ import javax.naming.NamingException;
 import org.apache.camel.CamelContext;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.impl.SimpleRegistry;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 

Modified: camel/trunk/tests/camel-itest-osgi/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/pom.xml?rev=1172414&r1=1172413&r2=1172414&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/pom.xml (original)
+++ camel/trunk/tests/camel-itest-osgi/pom.xml Mon Sep 19 03:11:26 2011
@@ -377,7 +377,61 @@
                 </execution>
             </executions>
         </plugin>
+        <!-- lets enhance the classes for OpenJPA (shame it can't do it at runtime!) -->
+        <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-antrun-plugin</artifactId>
+            <dependencies>
+                <dependency>
+                    <groupId>org.apache.openjpa</groupId>
+                    <artifactId>openjpa-persistence-jdbc</artifactId>
+                    <version>${openjpa-version}</version>
+                </dependency>
+            </dependencies>
 
+            <executions>
+                <execution>
+                    <phase>process-test-classes</phase>
+                    <configuration>
+                        <tasks>
+                            <path id="cp">
+                                <path refid="maven.test.classpath"/>
+                                <path refid="maven.compile.classpath"/>
+                                <path refid="maven.dependency.classpath"/>
+                            </path>
+                            <taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask">
+                                <classpath refid="cp"/>
+                            </taskdef>
+
+                            <mkdir dir="${basedir}/target/jpa-test-classes"/>
+
+                            <openjpac directory="${basedir}/target/jpa-test-classes">
+                                <classpath refid="cp"/>
+                                <fileset dir="${basedir}/target/classes">
+                                    <include name="org/apache/camel/itest/osgi/jpa/SendEmail.class"/>
+                                </fileset>
+                                <config propertiesFile="${basedir}/src/test/resources/META-INF/persistence.xml"/>
+                            </openjpac>
+
+                            <openjpac directory="${basedir}/target/jpa-test-classes">
+                                <classpath refid="cp"/>
+                                <fileset dir="${basedir}/target/test-classes">
+                                    <include name="org/apache/camel/examples/*.class"/>
+                                </fileset>
+                                <config propertiesFile="${basedir}/src/test/resources/META-INF/persistence.xml"/>
+                            </openjpac>
+
+                            <copy overwrite="true" todir="${basedir}/target/test-classes">
+                                <fileset dir="${basedir}/target/jpa-test-classes"/>
+                            </copy>
+                        </tasks>
+                    </configuration>
+                    <goals>
+                        <goal>run</goal>
+                    </goals>
+                </execution>
+            </executions>
+        </plugin>
     </plugins>
   </build>
    

Modified: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OSGiIntegrationTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OSGiIntegrationTestSupport.java?rev=1172414&r1=1172413&r2=1172414&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OSGiIntegrationTestSupport.java (original)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OSGiIntegrationTestSupport.java Mon Sep 19 03:11:26 2011
@@ -92,6 +92,15 @@ public class OSGiIntegrationTestSupport 
         return mavenBundle().groupId("org.apache.karaf.assemblies.features").
             artifactId("standard").version(karafVersion).type(type);
     }
+
+    public static UrlReference getKarafEnterpriseFeatureUrl() {
+        String karafVersion = System.getProperty("karafVersion");
+        System.out.println("*** The karaf version is " + karafVersion + " ***");
+
+        String type = "xml/features";
+        return mavenBundle().groupId("org.apache.karaf.assemblies.features").
+            artifactId("enterprise").version(karafVersion).type(type);
+    }
     
     private static URL getResource(String location) {
         URL url = null;

Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/JpaBlueprintRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/JpaBlueprintRouteTest.java?rev=1172414&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/JpaBlueprintRouteTest.java (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/JpaBlueprintRouteTest.java Mon Sep 19 03:11:26 2011
@@ -0,0 +1,89 @@
+/**
+ * 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.itest.osgi.jpa;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.itest.osgi.blueprint.OSGiBlueprintTestSupport;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Customizer;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Constants;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+
+import java.io.InputStream;
+
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.OptionUtils.combine;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.modifyBundle;
+
+
+@RunWith(JUnit4TestRunner.class)
+public class JpaBlueprintRouteTest extends OSGiBlueprintTestSupport {
+
+    @Test
+    public void testBlueprintRouteJpa() throws Exception {
+        getInstalledBundle("CamelBlueprintJpaTestBundle").start();
+        BlueprintContainer ctn = getOsgiService(BlueprintContainer.class, "(osgi.blueprint.container.symbolicname=CamelBlueprintJpaTestBundle)", 20000);
+        CamelContext ctx = getOsgiService(CamelContext.class, "(camel.context.symbolicname=CamelBlueprintJpaTestBundle)", 20000);
+
+        MockEndpoint mock = (MockEndpoint) ctx.getEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+
+        ProducerTemplate template = ctx.createProducerTemplate();
+        template.sendBody("direct:start", new SendEmail(1L,"someone@somewhere.org"));
+        template.sendBody("direct:start", new SendEmail(2L,"someoneelse@somewhere.org"));
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Configuration
+    public static Option[] configure() throws Exception {
+
+        Option[] options = combine(
+                getDefaultCamelKarafOptions(),
+                new Customizer() {
+                    @Override
+                    public InputStream customizeTestProbe(InputStream testProbe) {
+                        return modifyBundle(testProbe)
+                                .add(SendEmail.class)
+                                .add("META-INF/persistence.xml", JpaBlueprintRouteTest.class.getResource("/META-INF/persistence.xml"))
+                                .add("OSGI-INF/blueprint/test.xml", JpaBlueprintRouteTest.class.getResource("blueprintCamelContext.xml"))
+                                .set(Constants.BUNDLE_SYMBOLICNAME, "CamelBlueprintJpaTestBundle")
+                                .set(Constants.DYNAMICIMPORT_PACKAGE, "*")
+                                .set("Meta-Persistence", "META-INF/persistence.xml")
+                                .build();
+                    }
+                },
+                scanFeatures(getKarafFeatureUrl(), "spring"),
+                scanFeatures(getKarafEnterpriseFeatureUrl(), "jndi", "jpa", "transaction"),
+                mavenBundle("org.apache.derby", "derby", "10.4.2.0"),
+                // using the features to install the camel components
+                scanFeatures(getCamelKarafFeatureUrl(),
+                        "camel-blueprint", "camel-jpa"),
+                felix(), equinox());
+
+        return options;
+    }
+}

Propchange: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/JpaBlueprintRouteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/JpaBlueprintRouteTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/JpaRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/JpaRouteTest.java?rev=1172414&r1=1172413&r2=1172414&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/JpaRouteTest.java (original)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/JpaRouteTest.java Mon Sep 19 03:11:26 2011
@@ -16,22 +16,23 @@
  */
 package org.apache.camel.itest.osgi.jpa;
 
-import java.util.List;
-
 import org.apache.camel.CamelContext;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport;
 import org.apache.camel.spring.SpringCamelContext;
 import org.apache.karaf.testing.Helper;
 import org.junit.After;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Inject;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.ops4j.pax.exam.options.UrlProvisionOption;
+import org.ops4j.store.Store;
+import org.ops4j.store.StoreFactory;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
 import org.springframework.orm.jpa.JpaTemplate;
 import org.springframework.orm.jpa.JpaTransactionManager;
 import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext;
@@ -40,15 +41,19 @@ import org.springframework.transaction.T
 import org.springframework.transaction.support.TransactionCallback;
 import org.springframework.transaction.support.TransactionTemplate;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
 import static org.ops4j.pax.exam.CoreOptions.equinox;
 import static org.ops4j.pax.exam.CoreOptions.felix;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
 import static org.ops4j.pax.exam.OptionUtils.combine;
 import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
 import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.workingDirectory;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.newBundle;
 
 @RunWith(JUnit4TestRunner.class)
-@Ignore("TODO: fix me")
 public class JpaRouteTest extends OSGiIntegrationTestSupport {
     protected static final String SELECT_ALL_STRING = "select x from " + SendEmail.class.getName() + " x";
 
@@ -63,7 +68,7 @@ public class JpaRouteTest extends OSGiIn
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
 
-        template.sendBody("direct:start", new SendEmail("someone@somewhere.org"));
+        template.sendBody("direct:start", new SendEmail(1L,"someone@somewhere.org"));
 
         assertMockEndpointsSatisfied();
         assertEntityInDB();
@@ -86,6 +91,7 @@ public class JpaRouteTest extends OSGiIn
 
     @Override
     protected CamelContext createCamelContext() throws Exception {
+        setThreadContextClassLoader();
         applicationContext = new OsgiBundleXmlApplicationContext(
             new String[]{"org/apache/camel/itest/osgi/jpa/springJpaRouteContext.xml"});
         if (bundleContext != null) {
@@ -134,14 +140,13 @@ public class JpaRouteTest extends OSGiIn
             // this is how you set the default log level when using pax logging (logProfile)
                 Helper.setLogLevel("WARN")),
                 
-            // install the spring, http features first
-            scanFeatures(getKarafFeatureUrl(), "spring", "spring-dm", "jetty"),
+            // install the spring.
+            scanFeatures(getKarafFeatureUrl(), "spring"),
             // using the features to install the camel components             
             scanFeatures(getCamelKarafFeatureUrl(),                         
                           "camel-core", "camel-spring", "camel-test", "camel-jpa"),
             
-            mavenBundle().groupId("org.apache.derby").artifactId("derby").version("10.4.2.0"), 
-
+            mavenBundle().groupId("org.apache.derby").artifactId("derby").version("10.4.2.0"),
             workingDirectory("target/paxrunner/"),
 
             felix(), equinox());

Modified: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/SendEmail.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/SendEmail.java?rev=1172414&r1=1172413&r2=1172414&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/SendEmail.java (original)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jpa/SendEmail.java Mon Sep 19 03:11:26 2011
@@ -17,8 +17,8 @@
 package org.apache.camel.itest.osgi.jpa;
 
 import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
+import javax.persistence.Table;
 
 /**
  * Represents a task which is added to the database, then removed from the database when it is consumed
@@ -26,6 +26,7 @@ import javax.persistence.Id;
  * @version 
  */
 @Entity
+@Table(name = "SENDEMAIL")
 public class SendEmail {
     private Long id;
     private String address;
@@ -33,6 +34,11 @@ public class SendEmail {
     public SendEmail() {
     }
 
+    public SendEmail(Long id,String address) {
+        setId(id);
+        setAddress(address);
+    }
+
     public SendEmail(String address) {
         setAddress(address);
     }
@@ -43,7 +49,6 @@ public class SendEmail {
     }
 
     @Id
-    @GeneratedValue
     public Long getId() {
         return id;
     }

Modified: camel/trunk/tests/camel-itest-osgi/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/META-INF/persistence.xml?rev=1172414&r1=1172413&r2=1172414&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/resources/META-INF/persistence.xml (original)
+++ camel/trunk/tests/camel-itest-osgi/src/test/resources/META-INF/persistence.xml Mon Sep 19 03:11:26 2011
@@ -16,8 +16,8 @@
 -->
 <persistence xmlns="http://java.sun.com/xml/ns/persistence"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-             version="1.0"
-             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
+             version="2.0"
+             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
 
     <persistence-unit name="camel" transaction-type="RESOURCE_LOCAL">
     <!--
@@ -31,6 +31,7 @@
     </provider>
 
     <class>org.apache.camel.itest.osgi.jpa.SendEmail</class>
+    <exclude-unlisted-classes/>
 
     <properties>
       <property name="openjpa.ConnectionURL" value="jdbc:derby:target/derby;create=true"/>

Added: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jpa/blueprintCamelContext.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jpa/blueprintCamelContext.xml?rev=1172414&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jpa/blueprintCamelContext.xml (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jpa/blueprintCamelContext.xml Mon Sep 19 03:11:26 2011
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2006 The Apache Software Foundation.
+
+ Licensed 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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.1.0" default-activation="lazy">
+
+    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+        <route>
+          <from uri="direct:start"/>
+          <to uri="jpa://org.apache.camel.itest.osgi.jpa.SendEmail"/>
+        </route>
+        <route>
+            <from uri="jpa://org.apache.camel.itest.osgi.jpa.SendEmail?consumer.query=select s from SendEmail s where s.id=1"/>
+            <to uri="mock:result"/>
+       </route>
+    </camelContext>
+
+    <bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
+        <jpa:unit unitname="camel" property="enitityManagerFactory"/>
+    </bean>
+
+</blueprint>

Propchange: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jpa/blueprintCamelContext.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jpa/blueprintCamelContext.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jpa/blueprintCamelContext.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml