Return-Path: Delivered-To: apmail-incubator-aries-commits-archive@minotaur.apache.org Received: (qmail 9840 invoked from network); 22 Jan 2010 14:33:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 22 Jan 2010 14:33:11 -0000 Received: (qmail 68647 invoked by uid 500); 22 Jan 2010 14:33:11 -0000 Delivered-To: apmail-incubator-aries-commits-archive@incubator.apache.org Received: (qmail 68552 invoked by uid 500); 22 Jan 2010 14:33:11 -0000 Mailing-List: contact aries-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: aries-dev@incubator.apache.org Delivered-To: mailing list aries-commits@incubator.apache.org Received: (qmail 68542 invoked by uid 99); 22 Jan 2010 14:33:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jan 2010 14:33:11 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jan 2010 14:33:03 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 55E7023888BD; Fri, 22 Jan 2010 14:32:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r902098 - in /incubator/aries/trunk/jpa: ./ jpa-container-itest/ jpa-container-itest/src/ jpa-container-itest/src/test/ jpa-container-itest/src/test/java/ jpa-container-itest/src/test/java/org/ jpa-container-itest/src/test/java/org/apache/ ... Date: Fri, 22 Jan 2010 14:32:43 -0000 To: aries-commits@incubator.apache.org From: timothyjward@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100122143243.55E7023888BD@eris.apache.org> Author: timothyjward Date: Fri Jan 22 14:32:42 2010 New Revision: 902098 URL: http://svn.apache.org/viewvc?rev=902098&view=rev Log: ARIES-79: Create and manage EntityManagerFactory services for persistence units Added: incubator/aries/trunk/jpa/jpa-container-itest/ incubator/aries/trunk/jpa/jpa-container-itest/pom.xml incubator/aries/trunk/jpa/jpa-container-itest/src/ incubator/aries/trunk/jpa/jpa-container-itest/src/test/ incubator/aries/trunk/jpa/jpa-container-itest/src/test/java/ incubator/aries/trunk/jpa/jpa-container-itest/src/test/java/org/ incubator/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/ incubator/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/ incubator/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/ incubator/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/ incubator/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/ incubator/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerTest.java incubator/aries/trunk/jpa/jpa-container-testbundle/ incubator/aries/trunk/jpa/jpa-container-testbundle/pom.xml incubator/aries/trunk/jpa/jpa-container-testbundle/src/ incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/ incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/java/ incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/java/org/ incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/java/org/apache/ incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/java/org/apache/aries/ incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/ incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/ incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/ incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/ incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/Car.java incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/resources/ incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/resources/OSGI-INF/ incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/resources/OSGI-INF/persistence/ incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/resources/OSGI-INF/persistence/persistence.xml Modified: incubator/aries/trunk/jpa/pom.xml Added: incubator/aries/trunk/jpa/jpa-container-itest/pom.xml URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container-itest/pom.xml?rev=902098&view=auto ============================================================================== --- incubator/aries/trunk/jpa/jpa-container-itest/pom.xml (added) +++ incubator/aries/trunk/jpa/jpa-container-itest/pom.xml Fri Jan 22 14:32:42 2010 @@ -0,0 +1,203 @@ + + + jpa + org.apache.aries.jpa + 1.0.0-incubating-SNAPSHOT + + 4.0.0 + org.apache.aries.jpa + jpa-container-itest + 1.0.0-incubating-SNAPSHOT + + + + + org.osgi + org.osgi.core + provided + + + org.osgi + org.osgi.compendium + provided + + + junit + junit + provided + + + org.ops4j.pax.logging + pax-logging-api + test + + + org.ops4j.pax.logging + pax-logging-service + test + + + org.ops4j.pax.exam + pax-exam-container-default + 1.1.0 + test + + + org.ops4j.pax.exam + pax-exam-junit + 1.1.0 + test + + + org.apache.aries + org.apache.aries.util + ${version} + test + + + org.apache.aries.blueprint + org.apache.aries.blueprint + ${version} + test + + + org.ops4j.pax.url + pax-url-mvn + 1.0.0 + test + + + org.apache.felix + org.apache.felix.configadmin + 1.2.4 + test + + + org.apache.aries.application.api + org.apache.aries.application + 1.0.0-incubating-SNAPSHOT + + + org.apache.aries.application.utils + org.apache.aries.application + 1.0.0-incubating-SNAPSHOT + + + org.apache.geronimo.specs + geronimo-jpa_2.0_spec + + + org.apache.aries.jpa + jpa-container + 1.0.0-incubating-SNAPSHOT + test + + + + org.apache.openjpa + openjpa + 2.0.0-M3 + test + + + commons-lang + commons-lang + 2.4 + + + commons-collections + commons-collections + 3.2.1 + test + + + commons-pool + commons-pool + 1.5.3 + test + + + org.apache.aries.jpa + jpa-container-testbundle + 1.0.0-incubating-SNAPSHOT + test + + + + + + + org.apache.servicemix.tooling + depends-maven-plugin + 1.1 + + + generate-depends-file + + generate-depends-file + + + + + + + + + + ci-build-profile + + + maven.repo.local + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + -Dorg.ops4j.pax.url.mvn.localRepository=${maven.repo.local} + + + + + + + + \ No newline at end of file Added: incubator/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerTest.java URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerTest.java?rev=902098&view=auto ============================================================================== --- incubator/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerTest.java (added) +++ incubator/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerTest.java Fri Jan 22 14:32:42 2010 @@ -0,0 +1,215 @@ +/* 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.aries.jpa.container.itest; + +import static org.ops4j.pax.exam.CoreOptions.equinox; +import static org.ops4j.pax.exam.CoreOptions.options; +import static org.ops4j.pax.exam.CoreOptions.systemProperty; +import static org.ops4j.pax.exam.CoreOptions.wrappedBundle; +import static org.ops4j.pax.exam.OptionUtils.combine; + +import java.util.Hashtable; + +import javax.persistence.EntityManagerFactory; +import javax.persistence.spi.PersistenceProvider; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.CoreOptions; +import org.ops4j.pax.exam.Inject; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.JUnit4TestRunner; +import org.ops4j.pax.exam.options.BootDelegationOption; +import org.ops4j.pax.exam.options.MavenArtifactProvisionOption; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; +import org.osgi.framework.Filter; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.Version; +import org.osgi.service.packageadmin.PackageAdmin; +import org.osgi.util.tracker.ServiceTracker; + +@RunWith(JUnit4TestRunner.class) +public class JPAContainerTest { + public static final long DEFAULT_TIMEOUT = 30000; + + @Inject + protected BundleContext bundleContext; + + @Before + public void setupApplication() throws Exception + { + Bundle openJPA = getBundle("org.apache.openjpa.openjpa"); + + Class clz = openJPA.loadClass("org.apache.openjpa.persistence.PersistenceProviderImpl"); + + PersistenceProvider provider = clz.newInstance(); + + Hashtable props = new Hashtable(); + + props.put("javax.persistence.provider", "org.apache.openjpa.persistence.PersistenceProviderImpl"); + + openJPA.getBundleContext().registerService(PersistenceProvider.class.getName(), provider, props); + + //Wait for everything to be started then refresh the app + Thread.sleep(3000); + + Bundle app = getBundle("org.apache.aries.jpa.jpa-container-testbundle"); + + PackageAdmin pa = getOsgiService(PackageAdmin.class); + pa.refreshPackages(new Bundle[] {app}); + } + + //This test will run once there is an updated OpenJPA bundle that uses the latest JPA API + @Ignore + @Test + public void findEntityManagerFactory() throws Exception { + EntityManagerFactory emf = getOsgiService(EntityManagerFactory.class, "(osgi.unit.name=test-unit)", DEFAULT_TIMEOUT); + } + + @org.ops4j.pax.exam.junit.Configuration + public static Option[] configuration() { + Option[] options = options( + bootDelegation(), + + // Log + mavenBundle("org.ops4j.pax.logging", "pax-logging-api"), + mavenBundle("org.ops4j.pax.logging", "pax-logging-service"), + // Felix Config Admin + mavenBundle("org.apache.felix", "org.apache.felix.configadmin"), + // Felix mvn url handler + mavenBundle("org.ops4j.pax.url", "pax-url-mvn"), + + // this is how you set the default log level when using pax + // logging (logProfile) + systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"), + + // Bundles + mavenBundle("org.apache.aries.application", "org.apache.aries.application.utils"), + mavenBundle("org.apache.aries.application", "org.apache.aries.application.api"), + mavenBundle("org.osgi", "org.osgi.compendium"), + mavenBundle("org.apache.aries", "org.apache.aries.util"), + mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint"), + mavenBundle("org.apache.geronimo.specs", "geronimo-jpa_2.0_spec"), + mavenBundle("org.apache.aries.jpa", "jpa-container"), + mavenBundle("commons-lang", "commons-lang"), + mavenBundle("commons-collections", "commons-collections"), + mavenBundle("commons-pool", "commons-pool"), + mavenBundle("org.apache.openjpa", "openjpa"), + +// mavenBundle("org.eclipse.persistence", "org.eclipse.persistence.jpa"), +// mavenBundle("org.eclipse.persistence", "org.eclipse.persistence.core"), +// mavenBundle("org.eclipse.persistence", "org.eclipse.persistence.asm"), + + mavenBundle("org.apache.aries.jpa", "jpa-container-testbundle"), + + equinox().version("3.5.0")); + options = updateOptions(options); + return options; + } + + + protected Bundle getBundle(String symbolicName) { + return getBundle(symbolicName, null); + } + + protected Bundle getBundle(String bundleSymbolicName, String version) { + Bundle result = null; + for (Bundle b : bundleContext.getBundles()) { + if (b.getSymbolicName().equals(bundleSymbolicName)) { + if (version == null + || b.getVersion().equals(Version.parseVersion(version))) { + result = b; + break; + } + } + } + return result; + } + + public static BootDelegationOption bootDelegation() { + return new BootDelegationOption("org.apache.aries.unittest.fixture"); + } + + public static MavenArtifactProvisionOption mavenBundle(String groupId, + String artifactId) { + return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId) + .versionAsInProject(); + } + + protected static Option[] updateOptions(Option[] options) { + // We need to add pax-exam-junit here when running with the ibm + // jdk to avoid the following exception during the test run: + // ClassNotFoundException: org.ops4j.pax.exam.junit.Configuration + if ("IBM Corporation".equals(System.getProperty("java.vendor"))) { + Option[] ibmOptions = options(wrappedBundle(mavenBundle( + "org.ops4j.pax.exam", "pax-exam-junit"))); + options = combine(ibmOptions, options); + } + + return options; + } + + protected T getOsgiService(Class type, long timeout) { + return getOsgiService(type, null, timeout); + } + + protected T getOsgiService(Class type) { + return getOsgiService(type, null, DEFAULT_TIMEOUT); + } + + protected T getOsgiService(Class type, String filter, long timeout) { + return getOsgiService(null, type, filter, timeout); + } + + protected T getOsgiService(BundleContext bc, Class type, + String filter, long timeout) { + ServiceTracker tracker = null; + try { + String flt; + if (filter != null) { + if (filter.startsWith("(")) { + flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")" + + filter + ")"; + } else { + flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")(" + + filter + "))"; + } + } else { + flt = "(" + Constants.OBJECTCLASS + "=" + type.getName() + ")"; + } + Filter osgiFilter = FrameworkUtil.createFilter(flt); + tracker = new ServiceTracker(bc == null ? bundleContext : bc, osgiFilter, + null); + tracker.open(); + // Note that the tracker is not closed to keep the reference + // This is buggy, has the service reference may change i think + Object svc = type.cast(tracker.waitForService(timeout)); + if (svc == null) { + throw new RuntimeException("Gave up waiting for service " + flt); + } + return type.cast(svc); + } catch (InvalidSyntaxException e) { + throw new IllegalArgumentException("Invalid filter", e); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } +} Added: incubator/aries/trunk/jpa/jpa-container-testbundle/pom.xml URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container-testbundle/pom.xml?rev=902098&view=auto ============================================================================== --- incubator/aries/trunk/jpa/jpa-container-testbundle/pom.xml (added) +++ incubator/aries/trunk/jpa/jpa-container-testbundle/pom.xml Fri Jan 22 14:32:42 2010 @@ -0,0 +1,54 @@ + + + jpa + org.apache.aries.jpa + 1.0.0-incubating-SNAPSHOT + + 4.0.0 + org.apache.aries.jpa + jpa-container-testbundle + bundle + 1.0.0-incubating-SNAPSHOT + + + org.apache.geronimo.specs + geronimo-jpa_2.0_spec + + + + + + + OSGI-INF/persistence + false + ${basedir}/src/main/resources/OSGI-INF/persistence + + *.xml + + + + + + org.apache.felix + maven-bundle-plugin + true + + + ${pom.groupId}.${pom.artifactId} + + javax.persistence;version="[1.0.0,3.0.0)", + javax.persistence.spi;version="[1.0.0,3.0.0)", + * + + + org.apache.aries.jpa.container.itest.entities;version="${pom.version}", + + <_versionpolicy>[$(version;==;$(@)),$(version;+;$(@))) + <_removeheaders>Ignore-Package,Include-Resource,Private-Package,Bundle-DocURL + OSGI-INF/persistence/persistence.xml + + + + + + \ No newline at end of file Added: incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/Car.java URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/Car.java?rev=902098&view=auto ============================================================================== --- incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/Car.java (added) +++ incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/Car.java Fri Jan 22 14:32:42 2010 @@ -0,0 +1,50 @@ +package org.apache.aries.jpa.container.itest.entities; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +public class Car { + @Id + private String numberPlate; + + private String colour; + + private int engineSize; + + private int numberOfSeats; + + public String getNumberPlate() { + return numberPlate; + } + + public void setNumberPlate(String numberPlate) { + this.numberPlate = numberPlate; + } + + public String getColour() { + return colour; + } + + public void setColour(String colour) { + this.colour = colour; + } + + public int getEngineSize() { + return engineSize; + } + + public void setEngineSize(int engineSize) { + this.engineSize = engineSize; + } + + public int getNumberOfSeats() { + return numberOfSeats; + } + + public void setNumberOfSeats(int numberOfSeats) { + this.numberOfSeats = numberOfSeats; + } + + +} Added: incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/resources/OSGI-INF/persistence/persistence.xml URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/resources/OSGI-INF/persistence/persistence.xml?rev=902098&view=auto ============================================================================== --- incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/resources/OSGI-INF/persistence/persistence.xml (added) +++ incubator/aries/trunk/jpa/jpa-container-testbundle/src/main/resources/OSGI-INF/persistence/persistence.xml Fri Jan 22 14:32:42 2010 @@ -0,0 +1,15 @@ + + + + + Test persistence unit for the JPA Container iTest + org.apache.aries.jpa.container.itest.entities.Car + + + + + + \ No newline at end of file Modified: incubator/aries/trunk/jpa/pom.xml URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/pom.xml?rev=902098&r1=902097&r2=902098&view=diff ============================================================================== --- incubator/aries/trunk/jpa/pom.xml (original) +++ incubator/aries/trunk/jpa/pom.xml Fri Jan 22 14:32:42 2010 @@ -32,6 +32,8 @@ jpa-container jpa-container-context + jpa-container-itest + jpa-container-testbundle