Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Keith2011-10-11 21:29:32 +0000
committerMike Keith2011-10-11 21:29:32 +0000
commit2e70ab85a3e2dc4c465bb161eccf88afe1315994 (patch)
tree2f484e516c2ee7d696e98fc1863333d92e365665
parent1dc1493d4addb163773ae2a34331e7e9782cdb41 (diff)
downloadorg.eclipse.gemini.jpa-2e70ab85a3e2dc4c465bb161eccf88afe1315994.tar.gz
org.eclipse.gemini.jpa-2e70ab85a3e2dc4c465bb161eccf88afe1315994.tar.xz
org.eclipse.gemini.jpa-2e70ab85a3e2dc4c465bb161eccf88afe1315994.zip
made a copy1.0.0
git-svn-id: file:///svnroot/rt/org.eclipse.gemini.jpa/branches/1.0.0@194 738bc060-e27f-0410-be59-ab60bd4d2b7a
-rw-r--r--org.eclipse.gemini.jpa.tests/.classpath7
-rw-r--r--org.eclipse.gemini.jpa.tests/.project28
-rw-r--r--org.eclipse.gemini.jpa.tests/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--org.eclipse.gemini.jpa.tests/.settings/org.eclipse.pde.core.prefs5
-rw-r--r--org.eclipse.gemini.jpa.tests/META-INF/MANIFEST.MF23
-rw-r--r--org.eclipse.gemini.jpa.tests/build.properties4
-rw-r--r--org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/Activator.java211
-rw-r--r--org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/JpaTest.java182
-rw-r--r--org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEMFBuilderExternalDataSource.java96
-rw-r--r--org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEMFBuilderService.java64
-rw-r--r--org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEMFBuilderServiceProperties.java59
-rw-r--r--org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEMFService.java55
-rw-r--r--org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEmbeddedJdbc.java83
-rw-r--r--org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEmbeddedPUnit.java80
-rw-r--r--org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEmptyPersistence.java71
-rw-r--r--org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEmptyPersistenceWithProps.java71
-rw-r--r--org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestMappingFileElement.java82
-rw-r--r--org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestOrmMappingFile.java82
-rw-r--r--org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestStaticPersistence.java56
-rw-r--r--org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestWeaving.java101
20 files changed, 1368 insertions, 0 deletions
diff --git a/org.eclipse.gemini.jpa.tests/.classpath b/org.eclipse.gemini.jpa.tests/.classpath
new file mode 100644
index 0000000..335ba65
--- /dev/null
+++ b/org.eclipse.gemini.jpa.tests/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry excluding="**/.svn/*" kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.gemini.jpa.tests/.project b/org.eclipse.gemini.jpa.tests/.project
new file mode 100644
index 0000000..adca819
--- /dev/null
+++ b/org.eclipse.gemini.jpa.tests/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.gemini.jpa.tests</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.gemini.jpa.tests/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.gemini.jpa.tests/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..491a8ab
--- /dev/null
+++ b/org.eclipse.gemini.jpa.tests/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Tue Jul 06 10:16:50 EDT 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/org.eclipse.gemini.jpa.tests/.settings/org.eclipse.pde.core.prefs b/org.eclipse.gemini.jpa.tests/.settings/org.eclipse.pde.core.prefs
new file mode 100644
index 0000000..5b13dda
--- /dev/null
+++ b/org.eclipse.gemini.jpa.tests/.settings/org.eclipse.pde.core.prefs
@@ -0,0 +1,5 @@
+#Wed Aug 12 10:01:56 EDT 2009
+eclipse.preferences.version=1
+pluginProject.equinox=false
+pluginProject.extensions=false
+resolve.requirebundle=false
diff --git a/org.eclipse.gemini.jpa.tests/META-INF/MANIFEST.MF b/org.eclipse.gemini.jpa.tests/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..0a9a3f4
--- /dev/null
+++ b/org.eclipse.gemini.jpa.tests/META-INF/MANIFEST.MF
@@ -0,0 +1,23 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Gemini JPA Unit Tests
+Bundle-SymbolicName: org.eclipse.gemini.jpa.tests
+Bundle-Version: 1.0.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Import-Package: javax.persistence;jpa="2.0";version="1.1.0",
+ javax.persistence.metamodel;jpa="2.0";version="1.1.0",
+ org.junit;version="4.8.1",
+ org.junit.runner;version="4.8.1",
+ org.junit.runner.notification;version="4.5.0",
+ org.osgi.framework;version="1.3.0",
+ org.osgi.service.jpa;version="1.0.0",
+ org.osgi.util.tracker;version="1.3.1",
+ org.osgi.service.jdbc;version="[1.0,2.0)",
+ test;version="1.0.0",
+ model.account;version="1.0.0",
+ model.embeddedjdbc;version="1.0.0";resolution:=optional,
+ model.embeddedaccount;version="1.0.0";resolution:=optional,
+ model.xmlmapped;version="1.0.0";resolution:=optional,
+ model.weaved;version="1.0.0";resolution:=optional
+Require-Bundle: org.eclipse.persistence.core
+Bundle-Activator: org.eclipse.gemini.jpa.tests.Activator
diff --git a/org.eclipse.gemini.jpa.tests/build.properties b/org.eclipse.gemini.jpa.tests/build.properties
new file mode 100644
index 0000000..41eb6ad
--- /dev/null
+++ b/org.eclipse.gemini.jpa.tests/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/Activator.java b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/Activator.java
new file mode 100644
index 0000000..388e2fe
--- /dev/null
+++ b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/Activator.java
@@ -0,0 +1,211 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Apache License v2.0 which accompanies this distribution.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Apache License v2.0 is available at
+ * http://www.opensource.org/licenses/apache2.0.php.
+ * You may elect to redistribute this code under either of these licenses.
+ *
+ * Contributors:
+ * mkeith - Gemini JPA tests
+ ******************************************************************************/
+package org.eclipse.gemini.jpa.tests;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.junit.runner.JUnitCore;
+import org.junit.runner.Result;
+import org.junit.runner.notification.Failure;
+
+import test.TestState;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+import javax.persistence.EntityManagerFactory;
+
+import org.osgi.service.jdbc.DataSourceFactory;
+import org.osgi.service.jpa.EntityManagerFactoryBuilder;
+
+/**
+ * Activator to start tests when relevant service becomes available
+ *
+ * @author mkeith
+ */
+public class Activator implements BundleActivator, ServiceTrackerCustomizer {
+
+ BundleContext ctx;
+
+ ServiceTracker emfTracker;
+ ServiceTracker emfbTracker;
+ ServiceTracker dsfTracker;
+
+ // Map of test class to test instance
+ Map<Class<? extends JpaTest>,JpaTest> testClasses = new HashMap<Class<? extends JpaTest>,JpaTest>();
+// Set<JpaTest> testClassInstances = new HashSet<JpaTest>();
+
+ public void start(BundleContext context) throws Exception {
+ log("Tests active");
+
+ ctx = context;
+ JpaTest.context = context;
+
+ emfTracker = new ServiceTracker(ctx, EntityManagerFactory.class.getName(), this);
+ emfbTracker = new ServiceTracker(ctx, EntityManagerFactoryBuilder.class.getName(), this);
+ dsfTracker = new ServiceTracker(ctx, DataSourceFactory.class.getName(), this);
+
+ // Create the set of tests to run (get list from TestState)
+ try {
+ for (String clsString : TestState.getIncompletedTests()) {
+ // Load the class
+ Class<? extends JpaTest> testClass = (Class<? extends JpaTest>)
+ ctx.getBundle().loadClass("org.eclipse.gemini.jpa.tests." + clsString);
+ // Create an instance of the class
+ JpaTest test = null;
+ test = testClass.newInstance();
+ // Store the instance against the class
+ testClasses.put(testClass, test);
+ }
+ log("TestClasses: " + testClasses.keySet());
+ } catch (ClassNotFoundException cnfEx) {
+ log("***************** Failed trying to load test class: " + cnfEx);
+ }
+ // Run tests from tracker when service is online
+ emfTracker.open();
+ emfbTracker.open();
+ dsfTracker.open();
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ log("Tests stopped");
+ emfbTracker.close();
+ emfTracker.close();
+ dsfTracker.close();
+ // Clear the queue since if we are being refreshed we may have new classes on restart
+ TestState.dsfQueuedTests.clear();
+ }
+
+ private JpaTest testInstance(Class<? extends JpaTest> cls) {
+ return testClasses.get(cls);
+ }
+
+ boolean shouldRun(Class<? extends JpaTest> testClass, String unitName, boolean isEMFService) {
+ JpaTest test = testClasses.get(testClass);
+ return !TestState.isTested(testClass.getSimpleName())
+ && test.getTestPersistenceUnitName().equals(unitName)
+ && (!(test.needsEmfService() ^ isEMFService));
+ }
+
+ void runTest(Class<? extends JpaTest> testClass) {
+ String testName = testClass.getSimpleName();
+ TestState.startTest(testName);
+ log("Running " + testName + ": ");
+ Result r = JUnitCore.runClasses(testClass);
+
+ log(testName + " results: ");
+ logResultStats(r);
+ TestState.completedTest(testName,r);
+
+ log("Done " + testName);
+
+ Set<String> incompleteTests = TestState.getIncompletedTests();
+ if (!incompleteTests.isEmpty()) {
+ System.out.println("------------------- Tests not run yet: " + incompleteTests);
+ } else {
+ // If no more tests to run, print out a summary
+ System.out.println("-----------------------------------------------------");
+ System.out.println("------------------- Test Summary --------------------");
+ System.out.println("-----------------------------------------------------");
+ Set<Map.Entry<String,Result>> results = TestState.getAllTestResults().entrySet();
+ for (Map.Entry<String,Result> entry : results) {
+ System.out.println("Test: " + entry.getKey());
+ logResultStats(entry.getValue());
+ }
+ }
+ }
+
+ /*========================*/
+ /* ServiceTracker methods */
+ /*========================*/
+
+ public Object addingService(ServiceReference ref) {
+ Object service = ref.getBundle().getBundleContext().getService(ref);
+
+ // Check to see if it is a DSF (and the Client driver)
+ String driverClassName = (String) ref.getProperty(DataSourceFactory.OSGI_JDBC_DRIVER_CLASS);
+ if ((driverClassName != null) && (driverClassName.equals(JpaTest.JDBC_TEST_DRIVER))) {
+ // Record in the TestState (does not risk getting refreshed) that the DSF is online
+ TestState.isDsfOnline = true;
+ log("Service added **** DataSourceFactory for " + driverClassName);
+ // Now go through the pending dsf queue and run the tests
+ log("**** Running queued tests");
+ for (Class cls : TestState.dsfQueuedTests) {
+ runTest((Class<? extends JpaTest>)cls);
+ }
+ log("**** Finished running queued tests");
+ TestState.dsfQueuedTests.clear();
+ } else {
+ // Check if it is JPA service (EMF or EMFB)
+ String unitName = (String)ref.getProperty(EntityManagerFactoryBuilder.JPA_UNIT_NAME);
+ if (unitName != null) {
+ // We have a JPA service. Is it an EMF or an EMFBuilder?
+ boolean isEmfService = EntityManagerFactory.class.isInstance(service);
+ log("Service added **** name=" + unitName + " EMF" + (isEmfService ? "" : "Builder"));
+
+ // Now ask each test if it should run based on the punit name and whether
+ // the service is an EMF or an EMFBuilder. Note that more than one test
+ // may run on the same EMF/B service.
+ for (Class<? extends JpaTest> cls : testClasses.keySet()) {
+
+ // See if the test would run (ignoring whether DSF is online)
+ if (shouldRun(cls, unitName, isEmfService)) {
+
+ // If the test needs the DSF service but the service is not online
+ // then put the test in the pending DSF queue.
+ if (testInstance(cls).needsDsfService() && !TestState.isDsfOnline) {
+ TestState.dsfQueuedTests.add(cls);
+ } else {
+ // We are good to go
+ runTest(cls);
+ }
+ }
+ }
+ }
+ }
+ return service;
+ }
+
+ public void modifiedService(ServiceReference ref, Object service) {}
+
+ public void removedService(ServiceReference ref, Object service) {}
+
+ /*================*/
+ /* Helper methods */
+ /*================*/
+
+ void logResultStats(Result r) {
+ log("Result: " +
+ " runs=" + r.getRunCount() +
+ " failures=" + r.getFailureCount() +
+ " ignore=" + r.getIgnoreCount());
+ log("Failures: " + r.getFailures());
+ for (Failure f : r.getFailures())
+ log("--- Failure: \n" + f.getTrace());
+ }
+
+ static void log(String msg) {
+ System.out.println("===== " + msg);
+ }
+}
diff --git a/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/JpaTest.java b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/JpaTest.java
new file mode 100644
index 0000000..65d3af1
--- /dev/null
+++ b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/JpaTest.java
@@ -0,0 +1,182 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Apache License v2.0 which accompanies this distribution.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Apache License v2.0 is available at
+ * http://www.opensource.org/licenses/apache2.0.php.
+ * You may elect to redistribute this code under either of these licenses.
+ *
+ * Contributors:
+ * mkeith - Gemini JPA tests
+ ******************************************************************************/
+package org.eclipse.gemini.jpa.tests;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.persistence.*;
+import javax.persistence.metamodel.EntityType;
+
+import org.junit.*;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.jpa.EntityManagerFactoryBuilder;
+
+import model.account.*;
+
+/**
+ * Test class to test EMF Service from a client
+ *
+ * @author mkeith
+ */
+public abstract class JpaTest {
+
+ public static BundleContext context;
+
+ // Define the JDBC access details. At some point we should probably externalize this...
+ public static final String JDBC_TEST_DRIVER = "org.apache.derby.jdbc.ClientDriver";
+ public static final String JDBC_TEST_URL = "jdbc:derby://localhost:1527/accountDB;create=true";
+ public static final String JDBC_TEST_USER = "app";
+ public static final String JDBC_TEST_PASSWORD = "app";
+
+ // Put the JDBC access config in the default props
+ public static Map<String,Object> defaultProps() {
+ Map<String,Object> props = new HashMap<String,Object>();
+ props.put("javax.persistence.jdbc.driver", JDBC_TEST_DRIVER);
+ props.put("javax.persistence.jdbc.url", JDBC_TEST_URL);
+ props.put("javax.persistence.jdbc.user", JDBC_TEST_USER);
+ props.put("javax.persistence.jdbc.password", JDBC_TEST_URL);
+ return props;
+ }
+
+ /* === Methods that *must* be subclassed === */
+
+ public abstract EntityManagerFactory getEmf();
+
+ public abstract String getTestPersistenceUnitName();
+
+ /* === Methods that *may* be subclassed === */
+
+ public boolean needsEmfService() { return true; }
+
+ public boolean needsDsfService() { return true; }
+
+ public String testName() {
+ return this.getClass().getSimpleName();
+ }
+
+ public Object newObject() {
+ Account a = new Account();
+ a.setBalance(100.0);
+ return a;
+ }
+
+ public Object findObject() {
+ EntityManager em = getEmf().createEntityManager();
+ Object obj = em.find(Account.class, 1);
+ em.close();
+ return obj;
+ }
+
+ public Object queryObjects() {
+ EntityManager em = getEmf().createEntityManager();
+ List<?> result = em.createQuery("SELECT a FROM Account a").getResultList();
+ em.close();
+ return result;
+ }
+
+ /* === Test Methods === */
+
+ @Test
+ public void testGettingEntityManager() {
+ log("testGettingEntityManager");
+ EntityManager em = getEmf().createEntityManager();
+ log("Got EM - " + em);
+ }
+
+ @Test
+ public void testPersisting() {
+ log("testPersisting");
+ EntityManager em = getEmf().createEntityManager();
+ Object obj = newObject();
+ em.getTransaction().begin();
+ log("testPersisting - tx begun");
+ try {
+ em.persist(obj);
+ } catch (Exception e) {
+ log("Error calling persist(): ");
+ e.printStackTrace(System.out);
+ }
+ log("testPersisting - tx committing");
+ em.getTransaction().commit();
+ em.close();
+ log("Persisted " + obj);
+ }
+
+ @Test
+ public void testFinding() {
+ log("testFinding");
+ log("Find returned - " + findObject());
+ }
+
+ @Test
+ public void testQuerying() {
+ log("testQuerying");
+ log("Query returned - " + queryObjects());
+ }
+
+ @Test
+ public void testGettingMetamodel() {
+ log("testGettingMetamodel");
+ EntityManager em = getEmf().createEntityManager();
+ Set<EntityType<?>> s = em.getMetamodel().getEntities();
+ for (EntityType<?> et : s) {
+ log("Managed Entity name: " + et.getName());
+ log("Managed Entity class: " + et.getJavaType());
+ log("Classloader: " + et.getJavaType().getClassLoader());
+ }
+ }
+
+ /* === Helper methods === */
+
+ public static EntityManagerFactory lookupEntityManagerFactory(String testName, String puName) {
+ String filter = "(osgi.unit.name="+puName+")";
+ ServiceReference[] refs = null;
+ try {
+ refs = context.getServiceReferences(EntityManagerFactory.class.getName(), filter);
+ } catch (InvalidSyntaxException isEx) {
+ new RuntimeException("Bad filter", isEx);
+ }
+ slog(testName, "EMF Service refs looked up from registry: " + refs);
+ return (refs == null)
+ ? null
+ : (EntityManagerFactory) context.getService(refs[0]);
+ }
+
+ public static EntityManagerFactoryBuilder lookupEntityManagerFactoryBuilder(String testName, String puName) {
+ String filter = "(osgi.unit.name="+puName+")";
+ ServiceReference[] refs = null;
+ try {
+ refs = context.getServiceReferences(EntityManagerFactoryBuilder.class.getName(), filter);
+ } catch (InvalidSyntaxException isEx) {
+ new RuntimeException("Bad filter", isEx);
+ }
+ slog(testName, "EMF Builder Service refs looked up from registry: " + refs);
+ return (refs == null)
+ ? null
+ : (EntityManagerFactoryBuilder) context.getService(refs[0]);
+ }
+
+ public static void slog(String testName, String msg) {
+ System.out.println("***** " + testName + " - " + msg);
+ }
+ public void log(String msg) {
+ System.out.println("***** " + this.getClass().getSimpleName() + " - " + msg);
+ }
+}
diff --git a/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEMFBuilderExternalDataSource.java b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEMFBuilderExternalDataSource.java
new file mode 100644
index 0000000..5e38d21
--- /dev/null
+++ b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEMFBuilderExternalDataSource.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Apache License v2.0 which accompanies this distribution.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Apache License v2.0 is available at
+ * http://www.opensource.org/licenses/apache2.0.php.
+ * You may elect to redistribute this code under either of these licenses.
+ *
+ * Contributors:
+ * mkeith - Gemini JPA tests
+ ******************************************************************************/
+package org.eclipse.gemini.jpa.tests;
+
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.persistence.EntityManagerFactory;
+import javax.sql.DataSource;
+
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.jdbc.DataSourceFactory;
+import org.osgi.service.jpa.EntityManagerFactoryBuilder;
+
+import org.junit.*;
+
+/**
+ * Test class to test looking up EMF Builder Service from a client
+ * for a punit that does not a have data source props specified
+ *
+ * @author mkeith
+ */
+public class TestEMFBuilderExternalDataSource extends JpaTest {
+
+ public static final String TEST_NAME = "TestEMFBuilderExternalDataSource";
+ public static final String PERSISTENCE_UNIT_UNDER_TEST = "AccountsNoDataSource";
+
+ public static EntityManagerFactory emf;
+
+ @BeforeClass
+ public static void classSetUp() {
+ slog(TEST_NAME, "In setup");
+ EntityManagerFactoryBuilder emfb = lookupEntityManagerFactoryBuilder(TEST_NAME, PERSISTENCE_UNIT_UNDER_TEST);
+ DataSource ds = null;
+ try {
+ ServiceReference[] refs = context.getServiceReferences(
+ DataSourceFactory.class.getName(), "(osgi.jdbc.driver.class=" + JDBC_TEST_DRIVER + ")");
+ if (refs == null) {
+ throw new RuntimeException("Failed looking up driver in registry");
+ }
+
+ DataSourceFactory dsf = (DataSourceFactory)context.getService(refs[0]);
+ if (dsf == null) {
+ throw new RuntimeException("Failed getting svc from DSF svc ref");
+ }
+ Properties props = new Properties();
+ props.put(DataSourceFactory.JDBC_URL, JDBC_TEST_URL);
+ props.put(DataSourceFactory.JDBC_USER, JDBC_TEST_USER);
+ props.put(DataSourceFactory.JDBC_PASSWORD, JDBC_TEST_PASSWORD);
+
+ ds = dsf.createDataSource(props);
+
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+
+ Map<String,Object> props = new HashMap<String,Object>();
+ props.put("javax.persistence.nonJtaDataSource", ds);
+
+ emf = emfb.createEntityManagerFactory(props);
+ slog(TEST_NAME, "Got EMF - " + emf);
+ }
+
+ @AfterClass
+ public static void classCleanUp() {
+ if (emf != null) {
+ emf.close();
+ emf = null;
+ }
+ }
+
+ /* === Subclassed methods === */
+
+ public EntityManagerFactory getEmf() { return emf; }
+
+ public String getTestPersistenceUnitName() { return PERSISTENCE_UNIT_UNDER_TEST; }
+
+ public boolean needsEmfService() { return false; }
+}
diff --git a/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEMFBuilderService.java b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEMFBuilderService.java
new file mode 100644
index 0000000..12add83
--- /dev/null
+++ b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEMFBuilderService.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Apache License v2.0 which accompanies this distribution.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Apache License v2.0 is available at
+ * http://www.opensource.org/licenses/apache2.0.php.
+ * You may elect to redistribute this code under either of these licenses.
+ *
+ * Contributors:
+ * mkeith - Gemini JPA tests
+ ******************************************************************************/
+package org.eclipse.gemini.jpa.tests;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.persistence.EntityManagerFactory;
+
+import org.osgi.service.jpa.EntityManagerFactoryBuilder;
+
+import org.junit.*;
+
+/**
+ * Test class to test looking up EMF Builder Service from a client
+ *
+ * @author mkeith
+ */
+public class TestEMFBuilderService extends JpaTest {
+
+ public static final String TEST_NAME = "TestEMFBuilderService";
+ public static final String PERSISTENCE_UNIT_UNDER_TEST = "Accounts";
+
+ protected static EntityManagerFactory emf;
+
+ /* === Test Methods === */
+
+ @BeforeClass
+ public static void classSetUp() {
+ slog(TEST_NAME, "In setup");
+ EntityManagerFactoryBuilder emfb = lookupEntityManagerFactoryBuilder(TEST_NAME, PERSISTENCE_UNIT_UNDER_TEST);
+ Map<String,Object> props = new HashMap<String,Object>();
+ emf = emfb.createEntityManagerFactory(props);
+ slog(TEST_NAME, "Got EMF - " + emf);
+ }
+
+ @AfterClass
+ public static void classCleanUp() {
+ if (emf != null) {
+ emf.close();
+ emf = null;
+ }
+ }
+
+ /* === Subclassed methods === */
+
+ public EntityManagerFactory getEmf() { return emf; }
+
+ public String getTestPersistenceUnitName() { return PERSISTENCE_UNIT_UNDER_TEST; }
+
+ public boolean needsEmfService() { return false; }
+}
diff --git a/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEMFBuilderServiceProperties.java b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEMFBuilderServiceProperties.java
new file mode 100644
index 0000000..3419a4e
--- /dev/null
+++ b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEMFBuilderServiceProperties.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Apache License v2.0 which accompanies this distribution.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Apache License v2.0 is available at
+ * http://www.opensource.org/licenses/apache2.0.php.
+ * You may elect to redistribute this code under either of these licenses.
+ *
+ * Contributors:
+ * mkeith - Gemini JPA tests
+ ******************************************************************************/
+package org.eclipse.gemini.jpa.tests;
+
+import javax.persistence.EntityManagerFactory;
+
+import org.osgi.service.jpa.EntityManagerFactoryBuilder;
+
+import org.junit.*;
+
+/**
+ * Test class to test looking up EMF Builder Service from a client
+ * for a punit that does not have data source props specified
+ *
+ * @author mkeith
+ */
+public class TestEMFBuilderServiceProperties extends JpaTest {
+
+ public static final String TEST_NAME = "TestEMFBuilderServiceProperties";
+ public static final String PERSISTENCE_UNIT_UNDER_TEST = "AccountsNoDataSource";
+
+ public static EntityManagerFactory emf;
+
+ @BeforeClass
+ public static void classSetUp() {
+ slog(TEST_NAME, "In setup");
+ EntityManagerFactoryBuilder emfb = lookupEntityManagerFactoryBuilder(TEST_NAME, PERSISTENCE_UNIT_UNDER_TEST);
+ emf = emfb.createEntityManagerFactory(JpaTest.defaultProps());
+ slog(TEST_NAME, "Got EMF - " + emf);
+ }
+
+ @AfterClass
+ public static void classCleanUp() {
+ if (emf != null) {
+ emf.close();
+ emf = null;
+ }
+ }
+
+ /* === Subclassed methods === */
+
+ public EntityManagerFactory getEmf() { return emf; }
+
+ public String getTestPersistenceUnitName() { return PERSISTENCE_UNIT_UNDER_TEST; }
+
+ public boolean needsEmfService() { return false; }
+}
diff --git a/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEMFService.java b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEMFService.java
new file mode 100644
index 0000000..0a889f0
--- /dev/null
+++ b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEMFService.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Apache License v2.0 which accompanies this distribution.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Apache License v2.0 is available at
+ * http://www.opensource.org/licenses/apache2.0.php.
+ * You may elect to redistribute this code under either of these licenses.
+ *
+ * Contributors:
+ * mkeith - Gemini JPA tests
+ ******************************************************************************/
+package org.eclipse.gemini.jpa.tests;
+
+import javax.persistence.EntityManagerFactory;
+
+import org.junit.*;
+
+/**
+ * Test class to test looking up EMF Service from a client
+ *
+ * @author mkeith
+ */
+public class TestEMFService extends JpaTest {
+
+ public static final String TEST_NAME = "TestEMFService";
+ public static final String PERSISTENCE_UNIT_UNDER_TEST = "Accounts";
+
+ protected static EntityManagerFactory emf;
+
+ /* === Test Methods === */
+
+ @BeforeClass
+ public static void classSetUp() {
+ slog(TEST_NAME, "In setup");
+ emf = lookupEntityManagerFactory(TEST_NAME, PERSISTENCE_UNIT_UNDER_TEST);
+ slog(TEST_NAME, "Got EMF - " + emf);
+ }
+
+ @AfterClass
+ public static void classCleanUp() {
+ if (emf != null) {
+ emf.close();
+ emf = null;
+ }
+ }
+
+ /* === Subclassed methods === */
+
+ public EntityManagerFactory getEmf() { return emf; }
+
+ public String getTestPersistenceUnitName() { return PERSISTENCE_UNIT_UNDER_TEST; }
+}
diff --git a/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEmbeddedJdbc.java b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEmbeddedJdbc.java
new file mode 100644
index 0000000..bf810e3
--- /dev/null
+++ b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEmbeddedJdbc.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Apache License v2.0 which accompanies this distribution.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Apache License v2.0 is available at
+ * http://www.opensource.org/licenses/apache2.0.php.
+ * You may elect to redistribute this code under either of these licenses.
+ *
+ * Contributors:
+ * mkeith - Gemini JPA tests
+ ******************************************************************************/
+package org.eclipse.gemini.jpa.tests;
+
+import java.util.List;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityManager;
+
+import model.embeddedjdbc.EmptyEntity;
+
+import org.junit.*;
+
+/**
+ * Test class to test persistence without using DBAccess
+ *
+ * @author mkeith
+ */
+public class TestEmbeddedJdbc extends JpaTest {
+
+ public static final String TEST_NAME = "TestEmbeddedJdbc";
+ public static final String PERSISTENCE_UNIT_UNDER_TEST = "EmbeddedJDBC";
+
+ protected static EntityManagerFactory emf;
+
+ /* === Test Methods === */
+
+ @BeforeClass
+ public static void classSetUp() {
+ slog(TEST_NAME, "In setup");
+ emf = lookupEntityManagerFactory(TEST_NAME, PERSISTENCE_UNIT_UNDER_TEST);
+ slog(TEST_NAME, "Got EMF - " + emf);
+ }
+
+ @AfterClass
+ public static void classCleanUp() {
+ if (emf != null) {
+ emf.close();
+ emf = null;
+ }
+ }
+
+ /* === Subclassed methods === */
+
+ public boolean needsDsfService() { return false; }
+
+ public EntityManagerFactory getEmf() { return emf; }
+
+ public String getTestPersistenceUnitName() { return PERSISTENCE_UNIT_UNDER_TEST; }
+
+ public Object newObject() {
+ EmptyEntity a = new EmptyEntity();
+ a.setId(1);
+ a.setData("data");
+ return a;
+ }
+
+ public Object findObject() {
+ EntityManager em = emf.createEntityManager();
+ Object obj = em.find(EmptyEntity.class, 1);
+ em.close();
+ return obj;
+ }
+
+ public Object queryObjects() {
+ EntityManager em = emf.createEntityManager();
+ List<?> result = em.createQuery("SELECT a FROM EmptyEntity a").getResultList();
+ em.close();
+ return result;
+ }
+}
diff --git a/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEmbeddedPUnit.java b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEmbeddedPUnit.java
new file mode 100644
index 0000000..86d61b1
--- /dev/null
+++ b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEmbeddedPUnit.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Apache License v2.0 which accompanies this distribution.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Apache License v2.0 is available at
+ * http://www.opensource.org/licenses/apache2.0.php.
+ * You may elect to redistribute this code under either of these licenses.
+ *
+ * Contributors:
+ * mkeith - Gemini JPA tests
+ ******************************************************************************/
+package org.eclipse.gemini.jpa.tests;
+
+import java.util.List;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityManager;
+
+import model.embeddedaccount.EmbAccount;
+
+import org.junit.*;
+
+/**
+ * Test class to test looking up EMF Service of an embedded persistence unit
+ *
+ * @author mkeith
+ */
+public class TestEmbeddedPUnit extends JpaTest {
+
+ public static final String TEST_NAME = "TestEmbeddedPUnit";
+ public static final String PERSISTENCE_UNIT_UNDER_TEST = "EmbeddedAccounts";
+
+ protected static EntityManagerFactory emf;
+
+ /* === Test Methods === */
+
+ @BeforeClass
+ public static void classSetUp() {
+ slog(TEST_NAME, "In setup");
+ emf = lookupEntityManagerFactory(TEST_NAME, PERSISTENCE_UNIT_UNDER_TEST);
+ slog(TEST_NAME, "Got EMF - " + emf);
+ }
+
+ @AfterClass
+ public static void classCleanUp() {
+ if (emf != null) {
+ emf.close();
+ emf = null;
+ }
+ }
+
+ /* === Subclassed methods === */
+
+ public EntityManagerFactory getEmf() { return emf; }
+
+ public String getTestPersistenceUnitName() { return PERSISTENCE_UNIT_UNDER_TEST; }
+
+ public Object newObject() {
+ EmbAccount a = new EmbAccount();
+ a.setBalance(100.0);
+ return a;
+ }
+
+ public Object findObject() {
+ EntityManager em = emf.createEntityManager();
+ Object obj = em.find(EmbAccount.class, 1);
+ em.close();
+ return obj;
+ }
+
+ public Object queryObjects() {
+ EntityManager em = emf.createEntityManager();
+ List<?> result = em.createQuery("SELECT a FROM EmbAccount a").getResultList();
+ em.close();
+ return result;
+ }
+}
diff --git a/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEmptyPersistence.java b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEmptyPersistence.java
new file mode 100644
index 0000000..f3c0e66
--- /dev/null
+++ b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEmptyPersistence.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Apache License v2.0 which accompanies this distribution.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Apache License v2.0 is available at
+ * http://www.opensource.org/licenses/apache2.0.php.
+ * You may elect to redistribute this code under either of these licenses.
+ *
+ * Contributors:
+ * mkeith - Gemini JPA tests
+ ******************************************************************************/
+package org.eclipse.gemini.jpa.tests;
+
+import javax.persistence.EntityManagerFactory;
+
+import org.junit.*;
+import org.osgi.service.jpa.EntityManagerFactoryBuilder;
+
+/**
+ * Test class to test empty persistence unit using OSGi JPA services
+ *
+ * @author mkeith
+ */
+public class TestEmptyPersistence extends JpaTest {
+
+ public static final String TEST_NAME = "TestEmptyPersistenceUnit";
+ public static final String PERSISTENCE_UNIT_UNDER_TEST = "Empty1";
+
+ public static EntityManagerFactory emf;
+
+ public static boolean shouldRun(String unitName, boolean isEMF) {
+ return PERSISTENCE_UNIT_UNDER_TEST.equals(unitName) && !isEMF;
+ }
+
+ /* === Test Methods === */
+
+ @BeforeClass
+ public static void classSetUp() {
+ slog(TEST_NAME, "In setup");
+ EntityManagerFactoryBuilder emfb = lookupEntityManagerFactoryBuilder(TEST_NAME, PERSISTENCE_UNIT_UNDER_TEST);
+ emf = emfb.createEntityManagerFactory(JpaTest.defaultProps());
+ slog(TEST_NAME, "Got EMF - " + emf);
+ }
+
+ @AfterClass
+ public static void classCleanUp() {
+ if (emf != null) {
+ emf.close();
+ emf = null;
+ }
+ }
+
+ public void testPersisting() {
+ log("overridden testPersisting");
+ }
+
+ /* === Subclassed methods === */
+
+ public EntityManagerFactory getEmf() { return emf; }
+
+ public String getTestPersistenceUnitName() { return PERSISTENCE_UNIT_UNDER_TEST; }
+
+ public boolean needsEmfService() { return false; }
+
+ public Object newObject() { return null; }
+ public Object findObject() { return null; }
+ public Object queryObjects() { return null; }
+}
diff --git a/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEmptyPersistenceWithProps.java b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEmptyPersistenceWithProps.java
new file mode 100644
index 0000000..4e0f32e
--- /dev/null
+++ b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestEmptyPersistenceWithProps.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Apache License v2.0 which accompanies this distribution.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Apache License v2.0 is available at
+ * http://www.opensource.org/licenses/apache2.0.php.
+ * You may elect to redistribute this code under either of these licenses.
+ *
+ * Contributors:
+ * mkeith - Gemini JPA tests
+ ******************************************************************************/
+package org.eclipse.gemini.jpa.tests;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.persistence.EntityManagerFactory;
+
+import org.junit.*;
+import org.osgi.service.jpa.EntityManagerFactoryBuilder;
+
+/**
+ * Test class to test empty persistence unit using OSGi JPA services
+ *
+ * @author mkeith
+ */
+public class TestEmptyPersistenceWithProps extends JpaTest {
+
+ public static final String TEST_NAME = "TestEmptyPersistenceUnitWithProps";
+ public static final String PERSISTENCE_UNIT_UNDER_TEST = "Empty2";
+
+ public static EntityManagerFactory emf;
+
+ /* === Test Methods === */
+
+ @BeforeClass
+ public static void classSetUp() {
+ slog(TEST_NAME, "In setup");
+ EntityManagerFactoryBuilder emfb = lookupEntityManagerFactoryBuilder(TEST_NAME, PERSISTENCE_UNIT_UNDER_TEST);
+ Map<String,Object> props = new HashMap<String,Object>();
+ emf = emfb.createEntityManagerFactory(props);
+ slog(TEST_NAME, "Got EMF - " + emf);
+ }
+
+ @AfterClass
+ public static void classCleanUp() {
+ if (emf != null) {
+ emf.close();
+ emf = null;
+ }
+ }
+
+ public void testPersisting() {
+ log("overridden testPersisting");
+ }
+
+ /* === Subclassed methods === */
+
+ public EntityManagerFactory getEmf() { return emf; }
+
+ public String getTestPersistenceUnitName() { return PERSISTENCE_UNIT_UNDER_TEST; }
+
+ public boolean needsEmfService() { return false; }
+
+ public Object newObject() { return null; }
+ public Object findObject() { return null; }
+ public Object queryObjects() { return null; }
+}
diff --git a/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestMappingFileElement.java b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestMappingFileElement.java
new file mode 100644
index 0000000..d8d06f5
--- /dev/null
+++ b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestMappingFileElement.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Apache License v2.0 which accompanies this distribution.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Apache License v2.0 is available at
+ * http://www.opensource.org/licenses/apache2.0.php.
+ * You may elect to redistribute this code under either of these licenses.
+ *
+ * Contributors:
+ * mkeith - Gemini JPA tests
+ ******************************************************************************/
+package org.eclipse.gemini.jpa.tests;
+
+import java.util.List;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityManager;
+
+import model.xmlmapped.SimpleEntity2;
+
+import org.junit.*;
+
+/**
+ * Test class for an entity mapped in orm.xml
+ *
+ * @author mkeith
+ */
+public class TestMappingFileElement extends JpaTest {
+
+ public static final String TEST_NAME = "TestMappingFileElement";
+ public static final String PERSISTENCE_UNIT_UNDER_TEST = "XmlMapped";
+
+ protected static EntityManagerFactory emf;
+
+ /* === Test Methods === */
+
+ @BeforeClass
+ public static void classSetUp() {
+ slog(TEST_NAME, "In setup");
+ emf = lookupEntityManagerFactory(TEST_NAME, PERSISTENCE_UNIT_UNDER_TEST);
+ slog(TEST_NAME, "Got EMF - " + emf);
+ }
+
+ @AfterClass
+ public static void classCleanUp() {
+ if (emf != null) {
+ emf.close();
+ emf = null;
+ }
+ }
+
+ /* === Subclassed methods === */
+
+ public EntityManagerFactory getEmf() { return emf; }
+
+ public String getTestPersistenceUnitName() { return PERSISTENCE_UNIT_UNDER_TEST; }
+
+ public Object newObject() {
+ SimpleEntity2 a = new SimpleEntity2();
+ a.setId(20);
+ a.setSimpleInt(21);
+ return a;
+ }
+
+ public Object findObject() {
+ EntityManager em = emf.createEntityManager();
+ Object obj = em.find(SimpleEntity2.class, 1);
+ em.close();
+ return obj;
+ }
+
+ public Object queryObjects() {
+ EntityManager em = emf.createEntityManager();
+ List<?> result = em.createQuery("SELECT a FROM SimpleEntity2 a").getResultList();
+ assert(result.size() == 1);
+ em.close();
+ return result;
+ }
+}
diff --git a/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestOrmMappingFile.java b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestOrmMappingFile.java
new file mode 100644
index 0000000..659ee00
--- /dev/null
+++ b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestOrmMappingFile.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Apache License v2.0 which accompanies this distribution.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Apache License v2.0 is available at
+ * http://www.opensource.org/licenses/apache2.0.php.
+ * You may elect to redistribute this code under either of these licenses.
+ *
+ * Contributors:
+ * mkeith - Gemini JPA tests
+ ******************************************************************************/
+package org.eclipse.gemini.jpa.tests;
+
+import java.util.List;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityManager;
+
+import model.xmlmapped.SimpleEntity;
+
+import org.junit.*;
+
+/**
+ * Test class for an entity mapped in orm.xml
+ *
+ * @author mkeith
+ */
+public class TestOrmMappingFile extends JpaTest {
+
+ public static final String TEST_NAME = "TestOrmMappingFile";
+ public static final String PERSISTENCE_UNIT_UNDER_TEST = "XmlMapped";
+
+ protected static EntityManagerFactory emf;
+
+ /* === Test Methods === */
+
+ @BeforeClass
+ public static void classSetUp() {
+ slog(TEST_NAME, "In setup");
+ emf = lookupEntityManagerFactory(TEST_NAME, PERSISTENCE_UNIT_UNDER_TEST);
+ slog(TEST_NAME, "Got EMF - " + emf);
+ }
+
+ @AfterClass
+ public static void classCleanUp() {
+ if (emf != null) {
+ emf.close();
+ emf = null;
+ }
+ }
+
+ /* === Subclassed methods === */
+
+ public EntityManagerFactory getEmf() { return emf; }
+
+ public String getTestPersistenceUnitName() { return PERSISTENCE_UNIT_UNDER_TEST; }
+
+ public Object newObject() {
+ SimpleEntity a = new SimpleEntity();
+ a.setId(10);
+ a.setSimpleString("11");
+ return a;
+ }
+
+ public Object findObject() {
+ EntityManager em = emf.createEntityManager();
+ Object obj = em.find(SimpleEntity.class, 1);
+ em.close();
+ return obj;
+ }
+
+ public Object queryObjects() {
+ EntityManager em = emf.createEntityManager();
+ List<?> result = em.createQuery("SELECT a FROM SimpleEntity a").getResultList();
+ assert(result.size() == 1);
+ em.close();
+ return result;
+ }
+}
diff --git a/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestStaticPersistence.java b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestStaticPersistence.java
new file mode 100644
index 0000000..5e2ae2d
--- /dev/null
+++ b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestStaticPersistence.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Apache License v2.0 which accompanies this distribution.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Apache License v2.0 is available at
+ * http://www.opensource.org/licenses/apache2.0.php.
+ * You may elect to redistribute this code under either of these licenses.
+ *
+ * Contributors:
+ * mkeith - Gemini JPA tests
+ ******************************************************************************/
+package org.eclipse.gemini.jpa.tests;
+
+import javax.persistence.Persistence;
+import javax.persistence.EntityManagerFactory;
+
+import org.junit.*;
+
+/**
+ * Test class to test static Persistence class using OSGi JPA services
+ *
+ * @author mkeith
+ */
+public class TestStaticPersistence extends JpaTest {
+
+ public static final String TEST_NAME = "TestStaticPersistence";
+ public static final String PERSISTENCE_UNIT_UNDER_TEST = "Accounts";
+
+ public static EntityManagerFactory emf;
+
+ /* === Test Methods === */
+
+ @BeforeClass
+ public static void classSetUp() {
+ slog(TEST_NAME, "In setup");
+ emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_UNDER_TEST);
+ slog(TEST_NAME, "Got EMF - " + emf);
+ }
+
+ @AfterClass
+ public static void classCleanUp() throws Exception {
+ if (emf != null) {
+ emf.close();
+ emf = null;
+ }
+ }
+
+ /* === Subclassed methods === */
+
+ public EntityManagerFactory getEmf() { return emf; }
+
+ public String getTestPersistenceUnitName() { return PERSISTENCE_UNIT_UNDER_TEST; }
+}
diff --git a/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestWeaving.java b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestWeaving.java
new file mode 100644
index 0000000..88948c7
--- /dev/null
+++ b/org.eclipse.gemini.jpa.tests/src/org/eclipse/gemini/jpa/tests/TestWeaving.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Apache License v2.0 which accompanies this distribution.
+ * The Eclipse Public License is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * and the Apache License v2.0 is available at
+ * http://www.opensource.org/licenses/apache2.0.php.
+ * You may elect to redistribute this code under either of these licenses.
+ *
+ * Contributors:
+ * mkeith - Gemini JPA tests
+ ******************************************************************************/
+package org.eclipse.gemini.jpa.tests;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+
+import model.weaved.WeavedEntity;
+
+import org.junit.*;
+
+/**
+ * Test class to test weaving of JPA provider
+ *
+ * @author mkeith
+ */
+public class TestWeaving extends JpaTest {
+
+ public static final String TEST_NAME = "TestWeaving";
+ public static final String PERSISTENCE_UNIT_UNDER_TEST = "Weaved";
+
+ public static EntityManagerFactory emf;
+
+ /* === Test Methods === */
+
+ @BeforeClass
+ public static void classSetUp() {
+ slog(TEST_NAME, "In setup");
+ emf = lookupEntityManagerFactory(TEST_NAME, PERSISTENCE_UNIT_UNDER_TEST);
+ slog(TEST_NAME, "Got EMF - " + emf);
+ }
+
+ @AfterClass
+ public static void classCleanUp() throws Exception {
+ if (emf != null) {
+ emf.close();
+ emf = null;
+ }
+ }
+
+ /* === Additional test methods === */
+ @Test
+ public void testWovenClass() {
+ log("testWovenClass");
+ WeavedEntity entity = new WeavedEntity();
+ boolean weaved = false;
+
+ Class<?>[] clsArray = entity.getClass().getInterfaces();
+ for ( Class<?> cls : clsArray) {
+ if (cls.toString().equals("org.eclipse.persistence.internal.weaving.PersistenceWeaved")) {
+ weaved = true;
+ break;
+ }
+ }
+ assert(weaved) ;
+ }
+
+ /* === Subclassed methods === */
+
+ // Dues to Lazy EMF creation, and the fact that we are never actually invoking
+ // methods on the EMF, the real underlying provider EMF is never really created
+ public boolean needsDsfService() { return false; }
+
+ public EntityManagerFactory getEmf() { return emf; }
+
+ public String getTestPersistenceUnitName() { return PERSISTENCE_UNIT_UNDER_TEST; }
+
+ public Object newObject() {
+ WeavedEntity a = new WeavedEntity();
+ a.setId(100);
+ return a;
+ }
+
+ public Object findObject() {
+ EntityManager em = getEmf().createEntityManager();
+ Object obj = em.find(WeavedEntity.class, 100);
+ em.close();
+ return obj;
+ }
+
+ public Object queryObjects() {
+ EntityManager em = getEmf().createEntityManager();
+ List<?> result = em.createQuery("SELECT a FROM WeavedEntity a").getResultList();
+ em.close();
+ return result;
+ }
+}

Back to the top