Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.classpath7
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.cvsignore1
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.project28
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.settings/org.eclipse.core.resources.prefs3
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.settings/org.eclipse.jdt.core.prefs12
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.settings/org.eclipse.jdt.ui.prefs3
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/META-INF/MANIFEST.MF20
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/build.properties4
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/config.ini5
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/createDDL.jdbc28
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/dropDDL.jdbc27
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/plugin.properties15
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/osgi/Activator.java24
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/AdHocTest.java99
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/AllTests.java48
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/BasicTest.java36
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/BookCoverTest.java62
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/BookStylesTest.java74
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/BookTranslatorTest.java51
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/ContainerTest.java71
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/EContainerReferenceTest.java68
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/EListEMapTest.java70
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/EListTest.java178
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/EMapTest.java175
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/EObjectTest.java108
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/JPATest.java118
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibBookEContainerTest.java80
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibWriterEContainerTest.java78
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibraryEContainerLibraryTest.java74
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibraryEContainerTest.java76
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibraryEnvironmentTest.java86
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibraryJPATest.java231
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibraryXMIPersistenceTest.java116
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/ManagedTest.java50
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/OneToOneTest.java42
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/PublisherWriterTest.java176
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/TypeWriterTypeTest.java69
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/WriterAddressTest.java63
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/WriterPublisherTest.java73
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/WriterTypewriterTest.java80
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/AllTests.java27
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/BasicEclipseLinkTest.java55
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/CreateSampleLibrariesWithEclipseLinkResourceTest.java85
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/EclipseLinkAndXMIResourceTest.java253
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/EclipseLinkResourceTest.java130
-rw-r--r--tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/TestModelFactory.java92
46 files changed, 3271 insertions, 0 deletions
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.classpath b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.classpath
new file mode 100644
index 000000000..4fb238e40
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry excluding="org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/CRUDTest.java" kind="src" path="src"/>
+ <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 kind="output" path="bin"/>
+</classpath>
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.cvsignore b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.cvsignore
new file mode 100644
index 000000000..ba077a403
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.cvsignore
@@ -0,0 +1 @@
+bin
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.project b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.project
new file mode 100644
index 000000000..a536853b4
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.emf.teneo.eclipselink.examples.library.orm.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/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.settings/org.eclipse.core.resources.prefs b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 000000000..03710d336
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,3 @@
+#Tue Oct 12 14:12:28 CEST 2004
+eclipse.preferences.version=1
+
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..4089dc6e4
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+#Fri Feb 24 08:55:57 CET 2006
+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.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+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/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.settings/org.eclipse.jdt.ui.prefs b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.settings/org.eclipse.jdt.ui.prefs
new file mode 100644
index 000000000..412b55da4
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/.settings/org.eclipse.jdt.ui.prefs
@@ -0,0 +1,3 @@
+#Fri Feb 24 08:55:57 CET 2006
+eclipse.preferences.version=1
+internal.default.compliance=default
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..9be41f503
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/META-INF/MANIFEST.MF
@@ -0,0 +1,20 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests; singleton:=true
+Bundle-Version: 1.0.0
+Bundle-Localization: plugin
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.core.resources,
+ org.eclipse.emf.ecore,
+ org.eclipse.emf.ecore.xmi,
+ org.eclipse.emf.teneo.eclipselink,
+ org.eclipse.emf.teneo.eclipselink.examples.library,
+ org.eclipse.emf.teneo.eclipselink.examples.library.orm,
+ org.junit,
+ org.apache.derby
+Eclipse-LazyStart: true
+Bundle-Vendor: %providerName
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-Activator: org.eclipse.emf.teneo.eclipselink.examples.library.orm.osgi.Activator
+JPA-PersistenceUnits: library
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/build.properties b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/build.properties
new file mode 100644
index 000000000..34d2e4d2d
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/config.ini b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/config.ini
new file mode 100644
index 000000000..e5cc96108
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/config.ini
@@ -0,0 +1,5 @@
+osgi.bundles=javax.persistence@1:start,org.eclipse.persistence.jpa@2:start,org.eclipse.equinox.common@2:start,
+org.eclipse.update.configurator@3:start, org.eclipse.core.runtime@start
+
+# End of file marker - must be here
+eof=eof \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/createDDL.jdbc b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/createDDL.jdbc
new file mode 100644
index 000000000..028bc1eec
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/createDDL.jdbc
@@ -0,0 +1,28 @@
+CREATE TABLE EMFLIB_STYLE (ID BIGINT NOT NULL, NAME VARCHAR(255), PRIMARY KEY (ID))
+CREATE TABLE EMFLIB_PUBLISHER (ID BIGINT NOT NULL, NAME VARCHAR(255), PRIMARY KEY (ID))
+CREATE TABLE EMFLIB_PUBLISHER_WRITER (publishers_ID BIGINT NOT NULL, writers_ID BIGINT NOT NULL, PRIMARY KEY (publishers_ID, writers_ID))
+CREATE TABLE EMFLIB_COVER (ID BIGINT NOT NULL, COLORED SMALLINT DEFAULT 0, ECONT_FEAT_ID INTEGER, ECONTAINER_ID BIGINT, PRIMARY KEY (ID))
+CREATE TABLE EMFLIB_LIBRARY (ID BIGINT NOT NULL, NAME VARCHAR(255), PRIMARY KEY (ID))
+CREATE TABLE EMFLIB_TRANSLATOR (ID BIGINT NOT NULL, LOCATION VARCHAR(255), NAME VARCHAR(255), PRIMARY KEY (ID))
+CREATE TABLE EMFLIB_LIBRARY_BOOK_MAP (MAPKEY VARCHAR(255) NOT NULL, ECONT_FEAT_ID INTEGER, LIBRARY_ID BIGINT NOT NULL, BOOK_ID BIGINT, PRIMARY KEY (MAPKEY, LIBRARY_ID))
+CREATE TABLE EMFLIB_BOOK_STYLE_MAP (MAPKEY VARCHAR(255) NOT NULL, ECONT_FEAT_ID INTEGER, BOOK_ID BIGINT NOT NULL, STYLE_ID BIGINT, PRIMARY KEY (MAPKEY, BOOK_ID))
+CREATE TABLE EMFLIB_ADDRESS (ID BIGINT NOT NULL, TOWN VARCHAR(255), ECONT_FEAT_ID INTEGER, PRIMARY KEY (ID))
+CREATE TABLE EMFLIB_TYPEWRITER (ID BIGINT NOT NULL, MAKER VARCHAR(255), TYPE VARCHAR(255), PRIMARY KEY (ID))
+CREATE TABLE EMFLIB_WRITER (ID BIGINT NOT NULL, NAME VARCHAR(255), ECONT_FEAT_ID INTEGER, ECONTAINER_ID BIGINT, ADDRESS_ID BIGINT, PRIMARY KEY (ID))
+CREATE TABLE EMFLIB_BOOK (ID BIGINT NOT NULL, TITLE VARCHAR(255), PAGES INTEGER, ECONT_FEAT_ID INTEGER, AUTHOR_ID BIGINT, TRANSLATOR_ID BIGINT, PRIMARY KEY (ID))
+CREATE TABLE EMFLIB_WRITER_TYPEWRITER (Writer_ID BIGINT NOT NULL, typewriters_ID BIGINT NOT NULL, PRIMARY KEY (Writer_ID, typewriters_ID))
+ALTER TABLE EMFLIB_PUBLISHER_WRITER ADD CONSTRAINT MFLBPBLSHRWRwrtrsD FOREIGN KEY (writers_ID) REFERENCES EMFLIB_WRITER (ID)
+ALTER TABLE EMFLIB_PUBLISHER_WRITER ADD CONSTRAINT MFLBPBLSHRpblshrsD FOREIGN KEY (publishers_ID) REFERENCES EMFLIB_PUBLISHER (ID)
+ALTER TABLE EMFLIB_COVER ADD CONSTRAINT MFLBCOVERCNTINERID FOREIGN KEY (ECONTAINER_ID) REFERENCES EMFLIB_BOOK (ID)
+ALTER TABLE EMFLIB_LIBRARY_BOOK_MAP ADD CONSTRAINT MFLBLBRRYBKMLBRRYD FOREIGN KEY (LIBRARY_ID) REFERENCES EMFLIB_LIBRARY (ID)
+ALTER TABLE EMFLIB_LIBRARY_BOOK_MAP ADD CONSTRAINT MFLBLBRRYBOKMAPBKD FOREIGN KEY (BOOK_ID) REFERENCES EMFLIB_BOOK (ID)
+ALTER TABLE EMFLIB_BOOK_STYLE_MAP ADD CONSTRAINT MFLBBOKSTYLEMAPBKD FOREIGN KEY (BOOK_ID) REFERENCES EMFLIB_BOOK (ID)
+ALTER TABLE EMFLIB_BOOK_STYLE_MAP ADD CONSTRAINT MFLBBKSTYLMAPSTYLD FOREIGN KEY (STYLE_ID) REFERENCES EMFLIB_STYLE (ID)
+ALTER TABLE EMFLIB_WRITER ADD CONSTRAINT MFLBWRITERCNTNERID FOREIGN KEY (ECONTAINER_ID) REFERENCES EMFLIB_LIBRARY (ID)
+ALTER TABLE EMFLIB_WRITER ADD CONSTRAINT MFLBWRITERDDRESSID FOREIGN KEY (ADDRESS_ID) REFERENCES EMFLIB_ADDRESS (ID)
+ALTER TABLE EMFLIB_BOOK ADD CONSTRAINT EMFLIBBOOKAUTHORID FOREIGN KEY (AUTHOR_ID) REFERENCES EMFLIB_WRITER (ID)
+ALTER TABLE EMFLIB_BOOK ADD CONSTRAINT MFLBBOOKTRNSLTORID FOREIGN KEY (TRANSLATOR_ID) REFERENCES EMFLIB_TRANSLATOR (ID)
+ALTER TABLE EMFLIB_WRITER_TYPEWRITER ADD CONSTRAINT MFLBWRTRTtypwrtrsD FOREIGN KEY (typewriters_ID) REFERENCES EMFLIB_TYPEWRITER (ID)
+ALTER TABLE EMFLIB_WRITER_TYPEWRITER ADD CONSTRAINT MFLBWRTRTYPWRWrtrD FOREIGN KEY (Writer_ID) REFERENCES EMFLIB_WRITER (ID)
+CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT DECIMAL, PRIMARY KEY (SEQ_NAME))
+INSERT INTO SEQUENCE(SEQ_NAME, SEQ_COUNT) values ('SEQ_GEN', 0)
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/dropDDL.jdbc b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/dropDDL.jdbc
new file mode 100644
index 000000000..1fda3296d
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/dropDDL.jdbc
@@ -0,0 +1,27 @@
+ALTER TABLE EMFLIB_PUBLISHER_WRITER DROP CONSTRAINT MFLBPBLSHRWRwrtrsD
+ALTER TABLE EMFLIB_PUBLISHER_WRITER DROP CONSTRAINT MFLBPBLSHRpblshrsD
+ALTER TABLE EMFLIB_COVER DROP CONSTRAINT MFLBCOVERCNTINERID
+ALTER TABLE EMFLIB_LIBRARY_BOOK_MAP DROP CONSTRAINT MFLBLBRRYBKMLBRRYD
+ALTER TABLE EMFLIB_LIBRARY_BOOK_MAP DROP CONSTRAINT MFLBLBRRYBOKMAPBKD
+ALTER TABLE EMFLIB_BOOK_STYLE_MAP DROP CONSTRAINT MFLBBOKSTYLEMAPBKD
+ALTER TABLE EMFLIB_BOOK_STYLE_MAP DROP CONSTRAINT MFLBBKSTYLMAPSTYLD
+ALTER TABLE EMFLIB_WRITER DROP CONSTRAINT MFLBWRITERCNTNERID
+ALTER TABLE EMFLIB_WRITER DROP CONSTRAINT MFLBWRITERDDRESSID
+ALTER TABLE EMFLIB_BOOK DROP CONSTRAINT EMFLIBBOOKAUTHORID
+ALTER TABLE EMFLIB_BOOK DROP CONSTRAINT MFLBBOOKTRNSLTORID
+ALTER TABLE EMFLIB_WRITER_TYPEWRITER DROP CONSTRAINT MFLBWRTRTtypwrtrsD
+ALTER TABLE EMFLIB_WRITER_TYPEWRITER DROP CONSTRAINT MFLBWRTRTYPWRWrtrD
+DROP TABLE EMFLIB_STYLE
+DROP TABLE EMFLIB_PUBLISHER
+DROP TABLE EMFLIB_PUBLISHER_WRITER
+DROP TABLE EMFLIB_COVER
+DROP TABLE EMFLIB_LIBRARY
+DROP TABLE EMFLIB_TRANSLATOR
+DROP TABLE EMFLIB_LIBRARY_BOOK_MAP
+DROP TABLE EMFLIB_BOOK_STYLE_MAP
+DROP TABLE EMFLIB_ADDRESS
+DROP TABLE EMFLIB_TYPEWRITER
+DROP TABLE EMFLIB_WRITER
+DROP TABLE EMFLIB_BOOK
+DROP TABLE EMFLIB_WRITER_TYPEWRITER
+DELETE FROM SEQUENCE WHERE SEQ_NAME = 'SEQ_GEN'
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/plugin.properties b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/plugin.properties
new file mode 100644
index 000000000..f62a54671
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/plugin.properties
@@ -0,0 +1,15 @@
+# ====================================================================
+# To code developer:
+# Do NOT change the properties between this line and the
+# "%%% END OF TRANSLATED PROPERTIES %%%" line.
+# Make a new property name, append to the end of the file and change
+# the code to use the new property.
+# ====================================================================
+
+# ====================================================================
+# %%% END OF TRANSLATED PROPERTIES %%%
+# ====================================================================
+
+pluginName = Library O/R Mapping Tests
+providerName = www.example.org
+
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/osgi/Activator.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/osgi/Activator.java
new file mode 100644
index 000000000..ed16335cc
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/osgi/Activator.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.osgi;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator implements BundleActivator {
+
+ public void start(BundleContext context) throws Exception {
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ }
+
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/AdHocTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/AdHocTest.java
new file mode 100644
index 000000000..6ce452f72
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/AdHocTest.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+import org.eclipse.emf.teneo.eclipselink.examples.library.Publisher;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
+
+/**
+ *
+ * @author ebk2fe
+ * @version 1.0 (April 28th, 2006)
+ * <p>
+ * This test case creates a publisher object and assignes two writers
+ * to the publisher. The objects are committed to the data base. The publisher
+ * is fetched back from the data base.
+ */
+public class AdHocTest extends LibraryJPATest {
+
+ private Writer writer1;
+ private String writer1Name;
+ private Writer writer2;
+ private String writer2Name;
+ private Publisher publisher;
+ private String publisherName;
+
+ public AdHocTest(String name) {
+ super(name);
+ }
+
+ public void testRemovePublisherWriterWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyRemovePublisherWriter(checkCache);
+ }
+
+// public void testRemovePublisherWriterNoCache() throws Exception {
+// boolean checkCache = false;
+// verifyRemovePublisherWriter(checkCache);
+// }
+
+ private void verifyRemovePublisherWriter(boolean checkCache) {
+
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+ // dissassociate a writer from a publisher
+ beginTransaction();
+ Publisher dbPublisher = findPublisherWithName(em, publisherName);
+ Writer dbWriter1 = findWriterWithName(em, writer1Name);
+
+ dbPublisher.getWriters().remove(dbWriter1);
+ dbWriter1.getPublishers().remove(dbPublisher);
+ commitTransaction();
+
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+ // verify dissassociation
+ dbPublisher = findPublisherWithName(em, publisherName);
+ dbWriter1 = findWriterWithName(em, writer1Name);
+ Writer dbWriter2 = findWriterWithName(em, writer2Name);
+
+ assertNotNull("publisher not found", dbPublisher);
+ assertNotNull("writer1 not found", dbWriter1);
+ assertNotNull("writer2 not found", dbWriter2);
+ assertTrue("writer's publishers", dbWriter1.getPublishers().isEmpty());
+ assertEquals("num publisher's writers", 1, dbPublisher.getWriters().size());
+ assertEquals("publisher's writer", dbWriter2, dbPublisher.getWriters().get(0));
+ }
+
+ /**
+ * The test fixture consists of a single publisher
+ * with two writers.
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ beginTransaction();
+ publisher = createAnonymousPublisher(em);
+ publisherName = publisher.getName();
+ writer1 = createAnonymousWriter(em);
+ writer1Name = writer1.getName();
+ writer2 = createAnonymousWriter(em);
+ writer2Name = writer2.getName();
+ //
+ publisher.getWriters().add(writer1);
+ publisher.getWriters().add(writer2);
+ commitTransaction();
+ }
+
+
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/AllTests.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/AllTests.java
new file mode 100644
index 000000000..165794618
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/AllTests.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(
+ "ListTest for org.eclipse.emf.teneo.eclipselink.examples.library");
+ //$JUnit-BEGIN$
+ suite.addTestSuite(EObjectTest.class);
+ suite.addTestSuite(TypeWriterTypeTest.class);
+ suite.addTestSuite(LibWriterEContainerTest.class);
+ suite.addTestSuite(OneToOneTest.class);
+ suite.addTestSuite(LibBookEContainerTest.class);
+ suite.addTestSuite(WriterTypewriterTest.class);
+ suite.addTestSuite(LibraryEnvironmentTest.class);
+ suite.addTestSuite(ContainerTest.class);
+ suite.addTestSuite(BookCoverTest.class);
+ suite.addTestSuite(LibraryEContainerLibraryTest.class);
+ suite.addTestSuite(EMapTest.class);
+ suite.addTestSuite(EListEMapTest.class);
+ suite.addTestSuite(BasicTest.class);
+ suite.addTestSuite(LibraryEContainerTest.class);
+ suite.addTestSuite(BookTranslatorTest.class);
+ suite.addTestSuite(LibraryXMIPersistenceTest.class);
+ suite.addTestSuite(WriterAddressTest.class);
+ suite.addTestSuite(EListTest.class);
+ suite.addTestSuite(WriterPublisherTest.class);
+ suite.addTestSuite(PublisherWriterTest.class);
+ suite.addTestSuite(EContainerReferenceTest.class);
+ suite.addTestSuite(BookStylesTest.class);
+ //$JUnit-END$
+ return suite;
+ }
+
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/BasicTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/BasicTest.java
new file mode 100644
index 000000000..d61daa4ac
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/BasicTest.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+import org.eclipse.emf.teneo.eclipselink.examples.library.LibraryFactory;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Style;
+
+public class BasicTest extends LibraryJPATest {
+
+ public BasicTest(String name) {
+ super(name);
+ }
+
+ public void testBasicMapping() throws Exception {
+ Style style = LibraryFactory.eINSTANCE.createStyle();
+ String expectedStyle = getAnonymousString();
+ style.setName(expectedStyle);
+ em.getTransaction().begin();
+ em.persist(style);
+ em.getTransaction().commit();
+
+ Style actualStyle = (Style) em
+ .createQuery("select s from Style s where s.name = :name")
+ .setParameter("name", expectedStyle)
+ .getSingleResult();
+ assertEquals("name", expectedStyle, actualStyle.getName());
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/BookCoverTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/BookCoverTest.java
new file mode 100644
index 000000000..7b432b560
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/BookCoverTest.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+
+import org.eclipse.emf.ecore.InternalEObject;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Book;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Cover;
+
+public class BookCoverTest extends LibraryJPATest {
+
+ public BookCoverTest(String name) {
+ super(name);
+ }
+
+ public void testInsertWriterAndCoverWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyInsertWriterAddress(checkCache);
+ }
+
+ public void testInsertWriterAndCoverNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyInsertWriterAddress(checkCache);
+ }
+
+ private void verifyInsertWriterAddress(boolean checkCache) {
+
+ beginTransaction();
+
+ Book book = createAnonymousBookWithCover(em);
+ String bookTitle = book.getTitle();
+ Cover cover = book.getCover();
+
+ // put the data to the data base
+ commitTransaction();
+
+ // verify
+
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+ // Check whether the Book as been allocated at the data base.
+
+ Book dbBook = findBookWithTitle(em, bookTitle);
+ assertNotNull("Book not found", dbBook);
+ Cover dbCover = dbBook.getCover();
+
+ assertNotNull("dbCover not found", dbCover);
+ assertNotNull("eContainer not set", dbCover.eContainer());
+ int containerFeatureID = ((InternalEObject)cover).eContainerFeatureID();
+ int dbContainerFeatureID = ((InternalEObject)dbCover).eContainerFeatureID();
+ assertEquals("Containment Feature Id DB Cover", containerFeatureID, dbContainerFeatureID);
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/BookStylesTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/BookStylesTest.java
new file mode 100644
index 000000000..c16d2d020
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/BookStylesTest.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+import org.eclipse.emf.teneo.eclipselink.examples.library.Book;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Style;
+import org.eclipse.emf.teneo.eclipselink.examples.library.impl.BookStylesMapEntryImpl;
+
+public class BookStylesTest extends LibraryJPATest {
+
+ public BookStylesTest(String name) {
+ super(name);
+ }
+
+ public void testInsertBookWithStylesWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyInsertBookStyles(checkCache);
+ }
+
+ public void testInsertBookWithStylesNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyInsertBookStyles(checkCache);
+ }
+
+ private void verifyInsertBookStyles(boolean checkCache) {
+
+ beginTransaction();
+
+ Book book = createAnonymousBook(em);
+ String bookTitle = book.getTitle();
+ Style style1 = createAnonymousStyle(em);
+ String style1Name = style1.getName();
+ Style style2 = createAnonymousStyle(em);
+ String style2Name = style2.getName();
+ book.getStyles().put(style1Name, style1);
+ book.getStyles().put(style2Name, style2);
+ int eContFeatId = ((BookStylesMapEntryImpl)book.getStyles().get(0)).eContainerFeatureID();
+
+ commitTransaction();
+
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+
+ Book dbBook = findBookWithTitle(em, bookTitle);
+ assertNotNull("dbBook not found", dbBook);
+ assertEquals("dbBook nbr of styles", book.getStyles().size(), dbBook.getStyles().size());
+
+ // check the containment setting for the BookStyleMapEntry
+
+ BookStylesMapEntryImpl bookStyleMapEntry = (BookStylesMapEntryImpl)dbBook.getStyles().get(0);
+ assertEquals("eContainer of the BookStylesMapEntryImpl", dbBook, bookStyleMapEntry.eContainer());
+ assertEquals("eContainerFeatureId of the BookStylesMapEntryImpl", eContFeatId,
+ ((BookStylesMapEntryImpl)dbBook.getStyles().get(0)).eContainerFeatureID());
+
+ Style dbStyle1 = dbBook.getStyles().get(style1Name);
+ Style dbStyle2 = dbBook.getStyles().get(style2Name);
+
+ assertNotNull("First Style", dbStyle1);
+ assertNotNull("Second Style", dbStyle2);
+
+ // There is no containment relationshsip given for the Style objects
+ assertNull("no containment of the style object", dbStyle1.eContainer());
+ assertNull("no containment of the style object", dbStyle2.eContainer());
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/BookTranslatorTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/BookTranslatorTest.java
new file mode 100644
index 000000000..9e9e7837f
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/BookTranslatorTest.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+import org.eclipse.emf.teneo.eclipselink.examples.library.Book;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Translator;
+
+public class BookTranslatorTest extends LibraryJPATest {
+
+ public BookTranslatorTest(String name) {
+ super(name);
+ }
+
+ public void testInsertBookWithTranslatorWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyInsertBookTranslator(checkCache);
+ }
+
+ public void testInsertBookWithTranslatorNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyInsertBookTranslator(checkCache);
+ }
+
+ private void verifyInsertBookTranslator(boolean checkCache) {
+
+ beginTransaction();
+ Book book = createAnonymousBookWithTranslator(em);
+ String bookTitle = book.getTitle();
+ Translator translator = book.getTranslator();
+ commitTransaction();
+
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+
+ Book dbBook = findBookWithTitle(em, bookTitle);
+ assertNotNull("dbBook not found", dbBook);
+ Translator dbTranslator = dbBook.getTranslator();
+ assertNotNull("dbTranslator not found", dbTranslator);
+ assertEquals("dbTranslator.location", translator.getLocation(), dbTranslator.getLocation());
+ }
+
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/ContainerTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/ContainerTest.java
new file mode 100644
index 000000000..5ca118f57
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/ContainerTest.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Library;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
+import org.eclipse.emf.teneo.eclipselink.examples.library.impl.LibraryImpl;
+import org.eclipse.emf.teneo.eclipselink.examples.library.impl.WriterImpl;
+
+public class ContainerTest extends LibraryJPATest {
+
+ public ContainerTest(String name) {
+ super(name);
+ }
+
+ public void testMoveBetweenContainersWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyMoveBetweenContainers(checkCache);
+ }
+
+ public void testMoveBetweenContainersNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyMoveBetweenContainers(checkCache);
+ }
+
+ private void verifyMoveBetweenContainers(boolean checkCache) {
+ beginTransaction();
+ WriterImpl writer = (WriterImpl) createAnonymousWriter(em);
+ String writerName = writer.getName();
+ LibraryImpl libraryOne = (LibraryImpl) createAnonymousLibrary(em);
+ String libraryOneName = libraryOne.getName();
+ libraryOne.getWriters().add(writer);
+ commitTransaction();
+
+ // verify
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+
+ beginTransaction();
+ writer = (WriterImpl) findWriterWithName(em, writerName);
+ LibraryImpl libraryTwo = (LibraryImpl) createAnonymousLibrary(em);
+ String libraryTwoName = libraryTwo.getName();
+ libraryTwo.getWriters().add(writer);
+ commitTransaction();
+
+ // verify
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+
+ Library dbLibraryOne = findLibraryWithName(em, libraryOneName);
+ Library dbLibraryTwo = findLibraryWithName(em, libraryTwoName);
+ Writer dbWriter = findWriterWithName(em, writerName);
+ EList<Writer> dbLibOneWriters = dbLibraryOne.getWriters();
+ EList<Writer> dbLibTwoWriters = dbLibraryTwo.getWriters();
+ assertEquals("writer container", dbLibraryTwo, dbWriter.eContainer());
+ assertEquals("new library number of books", 1, dbLibTwoWriters.size());
+ assertTrue("original library has no books", dbLibOneWriters.isEmpty());
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/EContainerReferenceTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/EContainerReferenceTest.java
new file mode 100644
index 000000000..e1aeef9ef
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/EContainerReferenceTest.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Library;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
+
+public class EContainerReferenceTest extends LibraryJPATest {
+
+ public EContainerReferenceTest(String name) {
+ super(name);
+ }
+
+ public void testLibraryWriterRelationshipWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyLibaryWriterRelationship(checkCache);
+ }
+
+ public void testLibraryWriterRelationshipNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyLibaryWriterRelationship(checkCache);
+ }
+
+ /**
+ * This test creates a Library with a contained Writer and determines whether
+ * the inverse eContainer relationship is established from Writer to Library.
+ *
+ * @param checkCache
+ * @throws Exception
+ */
+ private void verifyLibaryWriterRelationship(boolean checkCache) throws Exception {
+ beginTransaction();
+ Writer writer = createAnonymousWriter(em);
+ String writerName = writer.getName();
+ Library library = createAnonymousLibrary(em);
+ String libraryName = library.getName();
+ library.getWriters().add(writer);
+ commitTransaction();
+
+ // verify
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+
+ beginTransaction();
+ Writer actualWriter = findWriterWithName(em, writerName);
+ assertNotNull("writer", actualWriter);
+
+ Library actualLibrary = findLibraryWithName(em, libraryName);
+ Writer actualLibraryWriter = actualLibrary.getWriters()
+ .get(0);
+ assertEquals("writer/library writer", actualWriter,
+ actualLibraryWriter);
+ EObject actualWriterEContainer = actualWriter.eContainer();
+ assertEquals("writer eContainer", actualLibrary, actualWriterEContainer);
+ }
+
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/EListEMapTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/EListEMapTest.java
new file mode 100644
index 000000000..48c5f5b9f
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/EListEMapTest.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+
+
+
+import org.eclipse.emf.teneo.eclipselink.examples.library.Book;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Library;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
+
+
+public class EListEMapTest extends LibraryJPATest {
+
+ public EListEMapTest(String name) {
+ super(name);
+ }
+
+ public void testInsertWriterAndBooksAndLibraryWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyInsertWriterBookLibrary(checkCache);
+ }
+
+ public void testInsertWriterAndBooksAndLibraryNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyInsertWriterBookLibrary(checkCache);
+ }
+
+ private void verifyInsertWriterBookLibrary(boolean checkCache) {
+ beginTransaction();
+ Writer writer = createAnonymousWriterWithOneBook(em);
+ String writerName = writer.getName();
+ Book book = writer.getBooks().get(0);
+ String bookTitle = book.getTitle();
+ Library library = createAnonymousLibrary(em);
+ String libraryName = library.getName();
+ library.getBooks().put(book.getTitle(), book);
+ library.getWriters().add(writer);
+ commitTransaction();
+ // verify
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+
+ Writer actualWriter = findWriterWithName(em, writerName);
+ assertNotNull("writer", actualWriter);
+ assertEquals("writer name", writerName, actualWriter.getName());
+ Book actualBook = findBookWithTitle(em, bookTitle);
+ assertNotNull("book", actualBook);
+ assertEquals("number of writer books", 1, actualWriter.getBooks().size());
+ Book actualWriterBook = actualWriter.getBooks().get(0);
+ assertEquals("book/writer book", actualBook, actualWriterBook);
+ assertEquals("writer book", actualWriter.getBooks().get(0), actualBook);
+ Library actualLibrary = findLibraryWithName(em, libraryName);
+ Book actualLibraryBook = actualLibrary.getBooks().get(bookTitle);
+ assertEquals("book/library book", actualBook, actualLibraryBook);
+ Writer actualLibraryWriter = actualLibrary.getWriters().get(0);
+ assertEquals("writer/library writer", actualWriter, actualLibraryWriter);
+ }
+
+
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/EListTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/EListTest.java
new file mode 100644
index 000000000..89573c11b
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/EListTest.java
@@ -0,0 +1,178 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+
+
+import java.util.List;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Book;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Library;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
+
+
+public class EListTest extends LibraryJPATest {
+
+
+ public EListTest(String name) {
+ super(name);
+ }
+
+
+ public void testInsertWriterAndBooksWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyInsertWriterBook(checkCache);
+ }
+
+ public void testInsertWriterAndBooksNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyInsertWriterBook(checkCache);
+ }
+
+ private void verifyInsertWriterBook(boolean checkCache) {
+ beginTransaction();
+ Writer writer = createAnonymousWriterWithOneBook(em);
+ String writerName = writer.getName();
+ Book book = writer.getBooks().get(0);
+ String bookTitle = book.getTitle();
+ commitTransaction();
+
+ // verify
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+ Writer actualWriter = findWriterWithName(em, writerName);
+ assertNotNull("writer", actualWriter);
+ EList<Book> actualBooks = actualWriter.getBooks();
+ assertEquals("number writer's books", 1, actualBooks.size());
+ Book actualBook = findBookWithTitle(em, bookTitle);
+ assertNotNull("book", actualBook);
+ assertEquals("writer book", actualBooks.get(0), actualBook);
+ assertEquals("book author", actualWriter, actualBook.getAuthor());
+ }
+
+
+ public void testAddBookToWriterWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyAddBookToWriter(checkCache);
+ }
+
+ public void testAddBookToWriterNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyAddBookToWriter(checkCache);
+ }
+
+ private void verifyAddBookToWriter(boolean checkCache) {
+ // setup fixture
+ beginTransaction();
+ Writer writer = createAnonymousWriter(em);
+ Book firstBook = createAnonymousBookForWriter(em, writer);
+ String writerName = writer.getName();
+ commitTransaction();
+
+ // exercise SUT
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+
+ beginTransaction();
+ writer = findWriterWithName(em, writerName);
+ Book secondBook = createAnonymousBookForWriter(em, writer);
+ commitTransaction();
+
+ // verify
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+ Writer actualWriter = findWriterWithName(em, writerName);
+ List<Book> actualBooks = actualWriter.getBooks();
+ assertEquals("number of books",2, actualBooks.size());
+ assertBookListContains(actualBooks, firstBook);
+ assertBookListContains(actualBooks, secondBook);
+ }
+
+ public void testRemoveBookFromWriterWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyRemoveBookFromWriter(checkCache);
+ }
+
+ public void testRemoveBookFromWriterNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyRemoveBookFromWriter(checkCache);
+ }
+
+ private void verifyRemoveBookFromWriter(boolean checkCache) {
+ beginTransaction();
+ // fixture
+ Writer writer = createAnonymousWriterWithOneBook(em);
+ String writerName = writer.getName();
+ commitTransaction();
+ // exercise SUT
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+ beginTransaction();
+ writer = findWriterWithName(em, writerName);
+ Book book = writer.getBooks().get(0);
+ writer.getBooks().remove(book);
+ em.remove(book);
+ commitTransaction();
+ // verify
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+ Writer actualWriter = findWriterWithName(em, writerName);
+ List<Book> actualBooks = actualWriter.getBooks();
+ assertEquals("number of books", 0, actualBooks.size());
+ }
+
+
+ public void testInsertLibraryWriterWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyInsertLibraryWriter(checkCache);
+ }
+
+ public void testInsertLibraryWriterNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyInsertLibraryWriter(checkCache);
+ }
+
+ private void verifyInsertLibraryWriter(boolean checkCache) {
+ beginTransaction();
+ Library library = createAnonymousLibrary(em);
+ Writer writer = createAnonymousWriter(em);
+ String libraryName = library.getName();
+ String writerName = writer.getName();
+ library.getWriters().add(writer);
+ commitTransaction();
+ // verify
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+ Writer actualWriter = findWriterWithName(em, writerName);
+ assertNotNull("writer", actualWriter);
+ Library actualLibrary = findLibraryWithName(em, libraryName);
+ assertNotNull("library", actualLibrary);
+ EList<Writer> actualLibraryWriters = actualLibrary.getWriters();
+ assertEquals("library writers", 1, actualLibraryWriters.size());
+ Writer actualLibraryWriter = actualLibraryWriters.get(0);
+ assertEquals("writer/library writer", actualWriter, actualLibraryWriter);
+
+ EObject actualWriterEContainer = actualWriter.eContainer();
+ assertEquals("library", actualLibrary, actualWriterEContainer);
+ }
+
+
+
+
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/EMapTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/EMapTest.java
new file mode 100644
index 000000000..18f6decb6
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/EMapTest.java
@@ -0,0 +1,175 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+import java.util.Map.Entry;
+
+import org.eclipse.emf.common.util.EMap;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Book;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Library;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
+
+public class EMapTest extends LibraryJPATest {
+
+ public EMapTest(String name) {
+ super(name);
+ }
+
+ public void testInsertLibraryAndBooksWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyInsertLibraryAndBooks(checkCache);
+ }
+
+ public void testInsertLibaryAndBooksNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyInsertLibraryAndBooks(checkCache);
+ }
+
+ private void verifyInsertLibraryAndBooks(boolean checkCache) {
+ beginTransaction();
+ Library library = createAnonymousLibrary(em);
+ String libraryName = library.getName();
+ Book book = createAnonymousBook(em);
+ String bookTitle = book.getTitle();
+ library.getBooks().put(bookTitle, book);
+ commitTransaction();
+ // verify
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+ Library actualLibrary = findLibraryWithName(em, libraryName);
+ assertNotNull("library", actualLibrary);
+ Book actualBook = findBookWithTitle(em, bookTitle);
+ assertNotNull("book", actualBook);
+ EMap<String, Book> actualBooks = actualLibrary.getBooks();
+ int numberActualBooks = actualBooks.size();
+ assertEquals("number of book", 1, numberActualBooks);
+ EObject actualLibraryBook = actualBooks.get(bookTitle);
+ assertEquals("library book", actualBook, actualLibraryBook);
+
+ EObject bookContainer = actualBook.eContainer();
+ EObject libraryBookContainer = actualLibraryBook.eContainer();
+ assertEquals("book container", bookContainer, libraryBookContainer);
+
+ EObject bookEntryContainer = bookContainer.eContainer();
+ EObject libraryBookEntryContainer = libraryBookContainer.eContainer();
+ assertEquals("entry container", bookEntryContainer,
+ libraryBookEntryContainer);
+ assertEquals("entry container", actualLibrary, bookEntryContainer);
+ assertEquals("entry container", actualLibrary,
+ libraryBookEntryContainer);
+ }
+
+ public void testAddBookToLibraryWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyAddBookToLibrary(checkCache);
+ }
+
+ public void testAddBookToLibraryNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyAddBookToLibrary(checkCache);
+ }
+
+ private void verifyAddBookToLibrary(boolean checkCache) {
+ beginTransaction();
+ // setup fixture
+ Library library = createAnonymousLibrary(em);
+ Writer writer = createAnonymousWriter(em);
+ Book bookOne = createAnonymousBookForWriter(em, writer);
+ String bookOneTitle = bookOne.getTitle();
+ library.getBooks().put(bookOneTitle, bookOne);
+ library.getWriters().add(writer);
+ String libraryName = library.getName();
+ String writerName = writer.getName();
+ commitTransaction();
+ // exercise SUT
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+
+ beginTransaction();
+ library = findLibraryWithName(em, libraryName);
+ writer = findWriterWithName(em, writerName);
+ Book bookTwo = createAnonymousBookForWriter(em, writer);
+ String bookTwoTitle = bookTwo.getTitle();
+ library.getBooks().put(bookTwoTitle, bookTwo);
+ commitTransaction();
+
+ // verify - cache
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+
+ Library actualLibrary = findLibraryWithName(em, libraryName);
+ Book actualBookOne = findBookWithTitle(em, bookOneTitle);
+ Book actualBookTwo = findBookWithTitle(em, bookTwoTitle);
+ EMap<String, Book> libraryBooks = actualLibrary.getBooks();
+ assertEquals("number of books", 2, libraryBooks.size());
+ assertEquals("first library book", actualBookOne, libraryBooks
+ .get(bookOneTitle));
+ assertEquals("second library book", actualBookTwo, libraryBooks
+ .get(bookTwoTitle));
+ }
+
+ public void testRemoveBookFromLibraryWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyRemoveBookFromLibrary(checkCache);
+ }
+
+ public void testRemoveBookFromLibraryNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyRemoveBookFromLibrary(checkCache);
+ }
+
+ private void verifyRemoveBookFromLibrary(boolean checkCache) {
+ beginTransaction();
+ // fixture
+ Writer writer = createAnonymousWriter(em);
+ Book bookOne = createAnonymousBookForWriter(em, writer);
+ Book bookTwo = createAnonymousBookForWriter(em, writer);
+ Library library = createAnonymousLibrary(em);
+ library.getBooks().put(bookOne.getTitle(), bookOne);
+ library.getBooks().put(bookTwo.getTitle(), bookTwo);
+ String libraryName = library.getName();
+ String bookOneTitle = bookOne.getTitle();
+ String bookTwoTitle = bookTwo.getTitle();
+ commitTransaction();
+ // exercise SUT
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+ beginTransaction();
+ library = findLibraryWithName(em, libraryName);
+ bookTwo = findBookWithTitle(em, bookTwoTitle);
+ Book bookTwoFromLibrary = library.getBooks().removeKey(bookTwoTitle);
+ assertEquals(bookTwo, bookTwoFromLibrary);
+ // TODO: ResourceImpl will get callback to delete MapEntry
+ EObject bookTwoEContainer = bookTwo.eContainer();
+ if ((bookTwoEContainer != null) && (bookTwoEContainer instanceof Entry)) {
+ em.remove(bookTwoEContainer);
+ }
+ em.remove(bookTwo);
+ commitTransaction();
+ // verify
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+
+ Library actualLibrary = findLibraryWithName(em, libraryName);
+ Book actualBookOne = findBookWithTitle(em, bookOneTitle);
+ EMap<String, Book> actualBooks = actualLibrary.getBooks();
+ assertEquals("number of books", 1, actualBooks.size());
+ Book actualLibraryBook = actualBooks.get(bookOneTitle);
+ assertEquals("book in library", actualBookOne, actualLibraryBook);
+ }
+
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/EObjectTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/EObjectTest.java
new file mode 100644
index 000000000..a40584bdf
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/EObjectTest.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+import org.eclipse.emf.teneo.eclipselink.examples.library.Book;
+import org.eclipse.emf.teneo.eclipselink.examples.library.BookCategory;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Library;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
+
+public class EObjectTest extends LibraryJPATest {
+
+ public EObjectTest(String name) {
+ super(name);
+ }
+
+ public void testInsertWriterWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyInsertWriter(checkCache);
+ }
+
+ public void testInsertWriterNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyInsertWriter(checkCache);
+ }
+
+ private void verifyInsertWriter(boolean checkCache) {
+ beginTransaction();
+ Writer writer = createAnonymousWriter(em);
+ String writerName = writer.getName();
+ commitTransaction();
+
+ // verify
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+
+ beginTransaction();
+ Writer actualWriter = findWriterWithName(em, writerName);
+ assertNotNull("writer", actualWriter);
+ rollbackTransaction();
+ }
+
+ public void testInsertBookWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyInsertBook(checkCache);
+ }
+
+ public void testInsertBookNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyInsertBook(checkCache);
+ }
+
+ private void verifyInsertBook(boolean checkCache) {
+ beginTransaction();
+ Book book = createAnonymousBook(em);
+ String title = book.getTitle();
+ BookCategory category = book.getCategory();
+ commitTransaction();
+
+ // verify
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+
+ beginTransaction();
+ Book actualBook = findBookWithTitle(em, title);
+ assertNotNull("book", actualBook);
+ assertEquals("category", category, actualBook.getCategory());
+ rollbackTransaction();
+ }
+
+ public void testInsertLibraryWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyInsertLibrary(checkCache);
+ }
+
+ public void testInsertLibraryNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyInsertLibrary(checkCache);
+ }
+
+ private void verifyInsertLibrary(boolean checkCache) {
+ beginTransaction();
+ Library library = createAnonymousLibrary(em);
+ String name = library.getName();
+ commitTransaction();
+
+ // verify
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+
+ beginTransaction();
+ Library actualLibrary = findLibraryWithName(em, name);
+ assertNotNull("library", actualLibrary);
+ rollbackTransaction();
+ }
+
+
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/JPATest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/JPATest.java
new file mode 100644
index 000000000..8fc0a0f4d
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/JPATest.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+import java.util.Calendar;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+
+import org.eclipse.persistence.jpa.osgi.PersistenceProvider;
+import org.eclipse.persistence.sessions.Session;
+import org.eclipse.persistence.sessions.factories.SessionManager;
+
+public abstract class JPATest extends ManagedTest {
+ private static EntityManagerFactory factory;
+
+ protected EntityManager em;
+
+ public JPATest(String name) {
+ super(name);
+ }
+
+ public EntityManagerFactory getEntityManagerFactory() {
+ if (factory == null) {
+ factory = new PersistenceProvider().createEntityManagerFactory(getPersistenceUnitName(), null, this.getClass().getClassLoader());
+ }
+ return factory;
+ }
+
+ protected String getPersistenceUnitName() {
+ return "default";
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ em = getEntityManagerFactory().createEntityManager();
+ cleanDatabase();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ if (em != null) {
+ try {
+ em.close();
+ } catch (RuntimeException e) {
+ System.out.println("Exception closing EntityManager: "
+ + e.getMessage());
+ e.printStackTrace();
+ // not supposed to fail in tearDown
+ } finally {
+ }
+ }
+ super.tearDown();
+ }
+ protected static long nextTitleInt = Calendar.getInstance().getTimeInMillis();
+
+ /**
+ * Subclasses should define to return all objects that should be
+ * deleted before a test is run.
+ *
+ * @param uow
+ */
+ protected abstract void cleanDatabase(EntityManager em);
+
+ /**
+ * Utility method used to generate Strings for "don't care"
+ * attribute values of test objects:
+ * DON'T HARD WIRE VALUES IN TESTS
+ *
+ * @return String
+ */
+ protected String getAnonymousString() {
+ return String.valueOf(nextTitleInt++);
+ }
+
+ /**
+ * Called when all the tests in the current suite are have
+ * been run.
+ */
+ @Override
+ protected void allTestsComplete() {
+ factory.close();
+ }
+
+ protected void cleanDatabase() {
+ em.getTransaction().begin();
+ cleanDatabase(em);
+ em.getTransaction().commit();
+ }
+
+ protected void beginTransaction() {
+ em.getTransaction().begin();
+ }
+
+ protected void commitTransaction() {
+ em.getTransaction().commit();
+ }
+
+ protected void rollbackTransaction() {
+ em.getTransaction().rollback();
+ }
+ protected void reinitializeCachesAndEntityManager() {
+ Session session = SessionManager.getManager().getSession(getPersistenceUnitName());
+ session.getIdentityMapAccessor().initializeAllIdentityMaps();
+ em.close();
+ em = getEntityManagerFactory().createEntityManager();
+ }
+
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibBookEContainerTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibBookEContainerTest.java
new file mode 100644
index 000000000..240c265cb
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibBookEContainerTest.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+
+import org.eclipse.emf.ecore.InternalEObject;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Book;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Library;
+
+public class LibBookEContainerTest extends LibraryJPATest {
+
+ public LibBookEContainerTest(String name) {
+ super(name);
+ }
+
+ public void testInsertBookAndLibraryWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyInsertBookLibrary(checkCache);
+ }
+
+ public void testInsertBookAndLibraryNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyInsertBookLibrary(checkCache);
+ }
+
+ /**
+ * Create the library and a book within the library.<br>
+ * Store the library to the data base.<br>
+ * Fetch back the library from the data base.<br>
+ * Identify the book object assigned to libray.<br>
+ * Check whether the attribute eContainer is set at the book object.
+ *
+ * @param checkCache
+ */
+ private void verifyInsertBookLibrary(boolean checkCache) {
+
+ beginTransaction();
+ Book book = createAnonymousBook(em);
+ String bookTitle = book.getTitle();
+ Library library = createAnonymousLibrary(em);
+ String libraryName = library.getName();
+ library.getBooks().put(book.getTitle(), book);
+ commitTransaction();
+
+ // verify
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+
+ // Check whether the book as been allocated at the data base.
+ Book actualBook = findBookWithTitle(em, bookTitle);
+ assertNotNull("book", actualBook);
+ assertNotNull("Field Actual/Book.eContainer not set", actualBook.eContainer());
+ int containerFeatureID = ((InternalEObject)book).eContainerFeatureID();
+ int actualContainerFeatureID = ((InternalEObject)actualBook).eContainerFeatureID();
+ assertEquals("Containment Feature Id DB Book", containerFeatureID, actualContainerFeatureID);
+
+ Library actualLibrary = findLibraryWithName(em, libraryName);
+ assertNotNull("library missing", actualLibrary);
+
+ Book actualLibraryBook = actualLibrary.getBooks().get(bookTitle);
+ assertNotNull("book missing", actualLibraryBook);
+ assertEquals("book title", bookTitle, actualLibraryBook.getTitle());
+ assertEquals("Book Check", actualBook, actualLibraryBook);
+
+ // verify whether the field eContainer is set
+ assertNotNull("Field Library/Book.eContainer not set", actualLibraryBook.eContainer());
+ assertEquals("Containment Relationship", actualLibrary, actualLibraryBook.eContainer().eContainer());
+
+ }
+
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibWriterEContainerTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibWriterEContainerTest.java
new file mode 100644
index 000000000..452baf9b2
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibWriterEContainerTest.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+
+import org.eclipse.emf.ecore.InternalEObject;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Library;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
+
+public class LibWriterEContainerTest extends LibraryJPATest {
+
+ public LibWriterEContainerTest(String name) {
+ super(name);
+ }
+
+ public void testInsertWriterAndLibraryWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyInsertWriterLibrary(checkCache);
+ }
+
+ public void testInsertWriterAndLibraryNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyInsertWriterLibrary(checkCache);
+ }
+
+ /**
+ * Create the library and a writer within the library.<br>
+ * Store the library to the data base.<br>
+ * Fetch back the library from the data base.<br>
+ * Identify the writer object assigned to libray.<br>
+ * Check whether the attribute eContainer is set at the writer object.
+ *
+ * @param checkCache
+ */
+ private void verifyInsertWriterLibrary(boolean checkCache) {
+
+ beginTransaction();
+
+ Writer writer = createAnonymousWriter(em);
+ String writerName = writer.getName();
+ Library library = createAnonymousLibrary(em);
+ String libraryName = library.getName();
+ library.getWriters().add(writer);
+ commitTransaction();
+ // verify
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+ Writer actualWriter = findWriterWithName(em, writerName);
+ assertNotNull("writer", actualWriter);
+ assertEquals("writer name", writerName, actualWriter.getName());
+ assertNotNull("Field Actual/Writer.eContainer not set", actualWriter.eContainer());
+ int containerFeatureID = ((InternalEObject)writer).eContainerFeatureID();
+ int actualContainerFeatureID = ((InternalEObject)actualWriter).eContainerFeatureID();
+ assertEquals("Containment Feature Id DB Writer", containerFeatureID, actualContainerFeatureID);
+
+ Library actualLibrary = findLibraryWithName(em, libraryName);
+ assertNotNull("library missing", actualLibrary);
+
+ Writer actualLibraryWriter = actualLibrary.getWriters().get(0);
+ assertNotNull("writer missing", actualLibraryWriter);
+ assertEquals("writer name", writerName, actualLibraryWriter.getName());
+ assertEquals("Writer Check", actualWriter, actualLibraryWriter);
+
+ // verify whether the field eContainer is set
+ assertNotNull("Field Library/Writer.eContainer not set", actualLibraryWriter.eContainer());
+ assertEquals("Containment Relationship", actualLibrary, actualLibraryWriter.eContainer());
+ }
+
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibraryEContainerLibraryTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibraryEContainerLibraryTest.java
new file mode 100644
index 000000000..f1998ac90
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibraryEContainerLibraryTest.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+import org.eclipse.emf.teneo.eclipselink.examples.library.Book;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Library;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
+
+public class LibraryEContainerLibraryTest extends LibraryJPATest {
+
+ public LibraryEContainerLibraryTest(String name) {
+ super(name);
+ }
+
+ public void testInsertWriterAndBooksAndLibraryWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyInsertWriterBookLibrary(checkCache);
+ }
+
+ public void testInsertWriterAndBooksAndLibraryNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyInsertWriterBookLibrary(checkCache);
+ }
+
+ /**
+ * Create a library object model holding a library, writer and
+ * book object.
+ * Fetches back the library object from the data base.
+ * Check whether the containment relationship is correctly set up at the
+ * field eContainer of the book and writer objects.
+ *
+ * @param checkCache
+ */
+ private void verifyInsertWriterBookLibrary(boolean checkCache) {
+
+ beginTransaction();
+ Writer writer = createAnonymousWriterWithOneBook(em);
+ String writerName = writer.getName();
+ Book book = writer.getBooks().get(0);
+ String bookTitle = book.getTitle();
+ Library library = createAnonymousLibrary(em);
+ String libraryName = library.getName();
+ library.getBooks().put(book.getTitle(), book);
+ library.getWriters().add(writer);
+
+ commitTransaction();
+
+ // verify
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+
+ Library actualLibrary = findLibraryWithName(em, libraryName);
+ Book actualLibraryBook = actualLibrary.getBooks().get(bookTitle);
+ assertNotNull("book missing", actualLibraryBook);
+
+ Writer actualLibraryWriter = actualLibrary.getWriters().get(0);
+ assertNotNull("writer missing", actualLibraryWriter);
+ assertEquals("writer name", writerName, actualLibraryWriter.getName());
+
+ // verify whether the field eContainer is set
+ assertNotNull("Field Library/Book.eContainer not set", actualLibraryBook.eContainer());
+ assertNotNull("Field Library/Writer.eContainer not set", actualLibraryWriter.eContainer());
+ }
+
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibraryEContainerTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibraryEContainerTest.java
new file mode 100644
index 000000000..324972ff0
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibraryEContainerTest.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+import org.eclipse.emf.teneo.eclipselink.examples.library.Book;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Library;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
+
+public class LibraryEContainerTest extends LibraryJPATest {
+
+ public LibraryEContainerTest(String name) {
+ super(name);
+ }
+
+ public void testInsertWriterAndBooksAndLibraryWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyInsertWriterBookLibrary(checkCache);
+ }
+
+ public void testInsertWriterAndBooksAndLibraryNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyInsertWriterBookLibrary(checkCache);
+ }
+
+ /**
+ * The test case creates a library object model holding a library, writer and
+ * book object.
+ * The writer and book objects are directly fetched back from the data base.
+ * Check whether the containment relationship is correctly set up at the
+ * field eContainer of the book and writer objects.
+ *
+ * @param checkCache
+ */
+ private void verifyInsertWriterBookLibrary(boolean checkCache) {
+
+ beginTransaction();
+ Writer writer = createAnonymousWriterWithOneBook(em);
+ String writerName = writer.getName();
+ Book book = writer.getBooks().get(0);
+ String bookTitle = book.getTitle();
+ Library library = createAnonymousLibrary(em);
+ library.getBooks().put(book.getTitle(), book);
+ library.getWriters().add(writer);
+ commitTransaction();
+
+ // verify
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+
+ Writer actualWriter = findWriterWithName(em, writerName);
+ assertNotNull("writer", actualWriter);
+ assertEquals("writer name", writerName, actualWriter.getName());
+
+ Book actualBook = findBookWithTitle(em, bookTitle);
+ assertNotNull("book", actualBook);
+ assertEquals("number of writer books", 1, actualWriter.getBooks()
+ .size());
+ Book actualWriterBook = actualWriter.getBooks().get(0);
+ assertEquals("book/writer book", actualBook, actualWriterBook);
+ assertEquals("writer book", actualWriter.getBooks().get(0),
+ actualBook);
+
+ // verify whether the field eContainer is set
+ assertNotNull("Field Actual/Writer.eContainer not set", actualWriter.eContainer());
+ assertNotNull("Field Actual/Book.eContainer not set", actualBook.eContainer());
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibraryEnvironmentTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibraryEnvironmentTest.java
new file mode 100644
index 000000000..d01123e31
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibraryEnvironmentTest.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+import org.eclipse.emf.teneo.eclipselink.examples.library.Address;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Book;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Library;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Publisher;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Style;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Translator;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
+
+
+public class LibraryEnvironmentTest extends LibraryJPATest {
+
+ public LibraryEnvironmentTest(String name) {
+
+ super(name);
+ }
+
+ public void testLibraryEnvironmentWithCache() throws Exception {
+
+ boolean checkCache = true;
+ verifyLibraryEnvironment(checkCache);
+ }
+
+ public void testLibraryEnvironmentNoCache() throws Exception {
+
+ boolean checkCache = false;
+ verifyLibraryEnvironment(checkCache);
+ }
+
+ private void verifyLibraryEnvironment(boolean checkCache) {
+
+ beginTransaction();
+
+ // Create the Test Environment
+
+ Library library = setupLibraryEnvironment(em);
+
+ String libraryName = library.getName();
+
+ // put the data to the data base
+
+ commitTransaction();
+
+ // set the cache usage
+
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+
+ // fetch back the library
+
+ Library dbLibrary = findLibraryWithName(em, libraryName);
+
+ // verify
+
+ assertNotNull("dbLibray not found", dbLibrary);
+ assertEquals("dbLibrary.name", libraryName, dbLibrary.getName());
+
+ Book dbBook = (Book) dbLibrary.getBooks().values().toArray()[0];
+ Writer dbWriter = dbLibrary.getWriters().get(0);
+
+ assertNotNull("dbBook not found", dbBook);
+ assertNotNull("dbWriter not found", dbWriter);
+
+ Translator dbTranslator = dbBook.getTranslator();
+ Address dbAddress = dbWriter.getAddress();
+ Publisher dbPublisher = dbWriter.getPublishers().get(0);
+ Style dbStyle = (Style) dbBook.getStyles().values().toArray()[0];
+
+ assertNotNull("dbTranslator not found", dbTranslator);
+ assertNotNull("dbAddress not found", dbAddress);
+ assertNotNull("dbPublisher not found", dbPublisher);
+ assertNotNull("dbStyle not found", dbStyle);
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibraryJPATest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibraryJPATest.java
new file mode 100644
index 000000000..ba97bb026
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibraryJPATest.java
@@ -0,0 +1,231 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+
+import junit.framework.AssertionFailedError;
+
+import org.eclipse.emf.teneo.eclipselink.examples.library.Address;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Book;
+import org.eclipse.emf.teneo.eclipselink.examples.library.BookCategory;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Cover;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Library;
+import org.eclipse.emf.teneo.eclipselink.examples.library.LibraryFactory;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Publisher;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Style;
+import org.eclipse.emf.teneo.eclipselink.examples.library.TWriterType;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Translator;
+import org.eclipse.emf.teneo.eclipselink.examples.library.TypeWriter;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
+import org.eclipse.emf.teneo.eclipselink.examples.library.impl.LibraryFactoryImpl;
+
+public abstract class LibraryJPATest extends JPATest {
+
+ public LibraryJPATest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected String getPersistenceUnitName() {
+ return "library";
+ }
+
+ @Override
+ protected void cleanDatabase(EntityManager em) {
+ // delete does not cascade so order is important
+ em.createQuery("delete from Publisher o").executeUpdate();
+ em.createQuery("delete from StringToBookMapEntryImpl o").executeUpdate();
+ em.createQuery("delete from BookStylesMapEntryImpl o").executeUpdate();
+ em.createQuery("delete from Cover o").executeUpdate();
+ em.createQuery("delete from Book o").executeUpdate();
+ em.createQuery("delete from Translator o").executeUpdate();
+ em.createQuery("delete from Writer o").executeUpdate();
+ em.createQuery("delete from TypeWriter o").executeUpdate();
+ em.createQuery("delete from Address o").executeUpdate();
+ em.createQuery("delete from Library o").executeUpdate();
+ em.createQuery("delete from Style o").executeUpdate();
+ }
+
+ protected static final LibraryFactory factory = LibraryFactoryImpl.eINSTANCE;
+
+ protected static void assertBookListContains(List<Book> books, Book firstBook) {
+ for (Book each : books) {
+ try {
+ assertBooksEqual(each, firstBook);
+ return; // found
+ }
+ catch (AssertionFailedError e) {
+ }
+ }
+ }
+
+ protected static void assertBooksEqual(Book expectedBook, Book actualBook) {
+ assertEquals("author", expectedBook.getAuthor(), actualBook.getAuthor());
+ assertEquals("title", expectedBook.getTitle(), actualBook.getTitle());
+ assertEquals("category", expectedBook.getCategory(), actualBook.getCategory());
+ assertEquals("pages", expectedBook.getPages(), actualBook.getPages());
+ }
+
+ protected Book createAnonymousBookForWriter(EntityManager em, Writer writer) {
+ Book book = createAnonymousBook(em);
+ book.setAuthor(writer);
+ writer.getBooks().add(book);
+ return book;
+ }
+
+ protected Book createAnonymousBook(EntityManager em) {
+ Book book = factory.createBook();
+ em.persist(book);
+ book.setCategory(BookCategory.MYSTERY);
+ book.setPages(100);
+ book.setTitle(getAnonymousString());
+ return book;
+ }
+
+ protected Book createAnonymousBookWithCover(EntityManager em) {
+ Book book = createAnonymousBook(em);
+ Cover cover = factory.createCover();
+ cover.setColored(true);
+ book.setCover(cover);
+ return book;
+ }
+
+ protected Writer createAnonymousWriter(EntityManager em) {
+ Writer writer = factory.createWriter();
+ em.persist(writer);
+ writer.setName(getAnonymousString());
+ return writer;
+ }
+
+ protected Library createAnonymousLibrary(EntityManager em) {
+ Library library = factory.createLibrary();
+ em.persist(library);
+ library.setName(getAnonymousString());
+ return library;
+ }
+
+ protected Writer createAnonymousWriterWithOneBook(EntityManager em) {
+ Writer writer = createAnonymousWriter(em);
+ createAnonymousBookForWriter(em, writer);
+ return writer;
+ }
+
+ protected Writer createAnonymousWriterWithAddress(EntityManager em) {
+ Writer writer = createAnonymousWriter(em);
+ createAnonymousAddressForWriter(em, writer);
+ return writer;
+ }
+
+ protected Address createAnonymousAddressForWriter(EntityManager em, Writer writer) {
+ Address address = factory.createAddress();
+ address.setTown(getAnonymousString());
+ em.persist(address);
+ writer.setAddress(address);
+ return address;
+ }
+
+ protected Publisher createAnonymousPublisher(EntityManager em) {
+ Publisher publisher = factory.createPublisher();
+ publisher.setName(getAnonymousString());
+ em.persist(publisher);
+ return publisher;
+ }
+
+ protected Book createAnonymousBookWithTranslator(EntityManager em) {
+ Book book = createAnonymousBook(em);
+ book.setTranslator(createAnonymousTranslator(em));
+ return book;
+ }
+
+ protected Translator createAnonymousTranslator(EntityManager em) {
+ Translator translator = factory.createTranslator();
+ translator.setName(getAnonymousString());
+ translator.setLocation("Stuttgart");
+ em.persist(translator);
+ return translator;
+ }
+
+ protected Book createAnonymousBookWithStyles(EntityManager em) {
+ Book book = createAnonymousBook(em);
+ Style style1 = createAnonymousStyle(em);
+ Style style2 = createAnonymousStyle(em);
+ book.getStyles().put(style1.getName(), style1);
+ book.getStyles().put(style2.getName(), style2);
+ return book;
+ }
+
+ protected Style createAnonymousStyle(EntityManager em) {
+ Style style = factory.createStyle();
+ style.setName(getAnonymousString());
+ em.persist(style);
+ return style;
+ }
+
+ protected TypeWriter createAnonymousTypewriter(EntityManager em) {
+ TypeWriter twriter = factory.createTypeWriter();
+ twriter.setMaker(getAnonymousString());
+ twriter.setType(TWriterType.COMPUTER);
+ em.persist(twriter);
+ return twriter;
+ }
+
+ protected Writer createAnonymousWriterWithTypeWriter(EntityManager em) {
+ Writer writer = createAnonymousWriter(em);
+ TypeWriter twriter = createAnonymousTypewriter(em);
+ writer.getTypewriters().add(twriter);
+ return writer;
+ }
+
+ protected Library setupLibraryEnvironment(EntityManager em) {
+
+ Library library = createAnonymousLibrary(em);
+
+ Book book = createAnonymousBookWithStyles(em);
+ library.getBooks().put(book.getTitle(), book);
+
+ Translator translator = createAnonymousTranslator(em);
+ book.setTranslator(translator);
+
+ Writer writer = createAnonymousWriterWithAddress(em);
+ library.getWriters().add(writer);
+
+ Publisher publisher = createAnonymousPublisher(em);
+ writer.getPublishers().add(publisher);
+ publisher.getWriters().add(writer);
+
+ return library;
+ }
+
+ protected Writer findWriterWithName(EntityManager em, String name) {
+ return (Writer) em.createQuery("select o from Writer o where o.name = :name").setParameter("name", name).getSingleResult();
+ }
+
+ protected Book findBookWithTitle(EntityManager em, String title) {
+ return (Book) em.createQuery("select o from Book o where o.title = :title").setParameter("title", title).getSingleResult();
+ }
+
+ protected Library findLibraryWithName(EntityManager em, String name) {
+ return (Library) em.createQuery("select o from Library o where o.name = :name").setParameter("name", name).getSingleResult();
+ }
+
+ protected Publisher findPublisherWithName(EntityManager em, String name) {
+ return (Publisher) em.createQuery("select o from Publisher o where o.name = :name").setParameter("name", name).getSingleResult();
+ }
+
+ protected TypeWriter findTypeWriterWithMaker(EntityManager em, String maker) {
+
+ return (TypeWriter) em.createQuery("select o from TypeWriter o where o.maker = :maker").setParameter("maker", maker).getSingleResult();
+ }
+
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibraryXMIPersistenceTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibraryXMIPersistenceTest.java
new file mode 100644
index 000000000..fbf6c24fa
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/LibraryXMIPersistenceTest.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+import java.io.IOException;
+import java.util.Collections;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Book;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Library;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
+
+public class LibraryXMIPersistenceTest extends LibraryJPATest {
+
+ public LibraryXMIPersistenceTest(String name) {
+ super(name);
+ }
+
+ public void testInsertWriterAndBooksAndLibraryWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyInsertWriterBookLibrary(checkCache);
+ }
+
+ public void testInsertWriterAndBooksAndLibraryNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyInsertWriterBookLibrary(checkCache);
+ }
+
+ /**
+ * The test case creates a library object model holding a library, writer and
+ * book object.
+ * It generates a XMI file using the build in persistency API of EMF.
+ * The first XMI file is generated directly after creation of the library
+ * object model.
+ * A second XMI file is created based on the library object model which is
+ * read back from the data base. Both files shall be identical.
+ *
+ * @param checkCache
+ */
+ private void verifyInsertWriterBookLibrary(boolean checkCache) throws Exception {
+ beginTransaction();
+ Writer writer = createAnonymousWriterWithOneBook(em);
+ String writerName = writer.getName();
+ Book book = writer.getBooks().get(0);
+ String bookTitle = book.getTitle();
+ Library library = createAnonymousLibrary(em);
+ String libraryName = library.getName();
+ library.getBooks().put(book.getTitle(), book);
+ library.getWriters().add(writer);
+
+ saveToXMIFile(library,
+ "file://c:/temp/LibraryXMIPersistenceTestBefore.library");
+
+ commitTransaction();
+ // verify
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+ Writer actualWriter = findWriterWithName(em, writerName);
+ assertNotNull("writer", actualWriter);
+ assertEquals("writer name", writerName, actualWriter.getName());
+
+ Book actualBook = findBookWithTitle(em, bookTitle);
+ assertNotNull("book", actualBook);
+ assertEquals("number of writer books", 1, actualWriter.getBooks()
+ .size());
+ Book actualWriterBook = actualWriter.getBooks().get(0);
+ assertEquals("book/writer book", actualBook, actualWriterBook);
+ assertEquals("writer book", actualWriter.getBooks().get(0),
+ actualBook);
+
+ Library actualLibrary = findLibraryWithName(em, libraryName);
+ Book actualLibraryBook = actualLibrary.getBooks().get(
+ bookTitle);
+ assertEquals("book/library book", actualBook, actualLibraryBook);
+ Writer actualLibraryWriter = actualLibrary.getWriters()
+ .get(0);
+ assertEquals("writer/library writer", actualWriter,
+ actualLibraryWriter);
+
+ // Start the writing to XMI
+
+ saveToXMIFile(actualLibrary,
+ "file://c:/temp/LibraryXMIPersistenceTestAfter.library");
+
+ }
+
+ /**
+ * The private method saveToXMIFile allocates a resource set and
+ * stores the contents of the library object model to a XMI file.
+ *
+ * @param library The root object of the library object model
+ * @param fileURI The name of the file "file://C:/<file name>"
+ * @throws IOException
+ */
+ private void saveToXMIFile(Library library, String fileURI)
+ throws IOException {
+ ResourceSet resourceSet = new ResourceSetImpl();
+ URI resURI = URI.createURI(fileURI);
+ Resource res = resourceSet.createResource(resURI);
+
+ res.getContents().add(library);
+ res.save(Collections.EMPTY_MAP);
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/ManagedTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/ManagedTest.java
new file mode 100644
index 000000000..1cf1a5a1c
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/ManagedTest.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public abstract class ManagedTest extends TestCase {
+ private static List<ManagedTest> runningTests = new ArrayList<ManagedTest>();
+
+ public ManagedTest(String sTestName) {
+ super(sTestName);
+ registerTest();
+ }
+
+ private void registerTest() {
+ runningTests.add(this);
+ }
+
+ private void unregisterTest() {
+ runningTests.remove(this);
+ if (runningTests.isEmpty()) {
+ allTestsComplete();
+ }
+ }
+
+ /**
+ * Called when all the tests in the current suite are have
+ * been run.
+ */
+ protected abstract void allTestsComplete();
+
+ @Override
+ protected void tearDown() throws Exception {
+ unregisterTest();
+ super.tearDown();
+ }
+
+
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/OneToOneTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/OneToOneTest.java
new file mode 100644
index 000000000..7985adb2e
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/OneToOneTest.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+import org.eclipse.emf.teneo.eclipselink.examples.library.Address;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
+
+public class OneToOneTest extends LibraryJPATest {
+
+ public OneToOneTest(String name) {
+ super(name);
+ }
+
+ public void testWriteRead() throws Exception {
+ em.getTransaction().begin();
+ Writer writer = createAnonymousWriter(em);
+ String writerName = writer.getName();
+ Address address = createAnonymousAddressForWriter(em, writer);
+ String addressTown = address.getTown();
+ writer.setAddress(address);
+ em.getTransaction().commit();
+
+ Writer actualWriter = (Writer) em
+ .createQuery("select o from Writer o where o.name = :name")
+ .setParameter("name", writerName)
+ .getSingleResult();
+ Address actualAddress = (Address) em
+ .createQuery("select o from Address o where o.town = :town")
+ .setParameter("town", addressTown)
+ .getSingleResult();
+
+ assertEquals("writer address", actualWriter.getAddress(), actualAddress);
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/PublisherWriterTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/PublisherWriterTest.java
new file mode 100644
index 000000000..ddccaf314
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/PublisherWriterTest.java
@@ -0,0 +1,176 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+import org.eclipse.emf.teneo.eclipselink.examples.library.Publisher;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
+
+/**
+ *
+ * @author ebk2fe
+ * @version 1.0 (April 28th, 2006)
+ * <p>
+ * This test case creates a publisher object and assignes two writers
+ * to the publisher. The objects are committed to the data base. The publisher
+ * is fetched back from the data base.
+ */
+public class PublisherWriterTest extends LibraryJPATest {
+
+ private Writer writer1;
+ private String writer1Name;
+ private Writer writer2;
+ private String writer2Name;
+ private Publisher publisher;
+ private String publisherName;
+
+ public PublisherWriterTest(String name) {
+ super(name);
+ }
+
+ public void testInsertPublisherWriterWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyInsertPublisherWriter(checkCache);
+ }
+
+ public void testInsertPublisherWriterNoCache() throws Exception {
+ boolean checkCache = true;
+ verifyInsertPublisherWriter(checkCache);
+ }
+
+ public void testRemovePublisherWriterWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyRemovePublisherWriter(checkCache);
+ }
+
+ public void testRemovePublisherWriterNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyRemovePublisherWriter(checkCache);
+ }
+
+ public void testMovePublisherWriterWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyMovePublisherWriter(checkCache);
+ }
+
+ public void testMovePublisherWriterNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyMovePublisherWriter(checkCache);
+ }
+
+ private void verifyMovePublisherWriter(boolean checkCache) {
+
+ // move a writer to a new publisher
+ beginTransaction();
+ Publisher publisher2 = createAnonymousPublisher(em);
+ String publisher2Name = publisher2.getName();
+
+ Publisher dbPublisher1 = findPublisherWithName(em, publisherName);
+ Writer dbWriter2 = findWriterWithName(em, writer2Name);
+
+ dbPublisher1.getWriters().remove(dbWriter2);
+ dbWriter2.getPublishers().remove(dbPublisher1);
+ dbWriter2.getPublishers().add(publisher2);
+ publisher2.getWriters().add(dbWriter2);
+ commitTransaction();
+
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+
+ // verify dissassociation
+ dbPublisher1 = findPublisherWithName(em, publisherName);
+ Publisher dbPublisher2 = findPublisherWithName(em, publisher2Name);
+ Writer dbWriter1 = findWriterWithName(em, writer1Name);
+ dbWriter2 = findWriterWithName(em, writer2Name);
+
+ assertNotNull("publisher1", dbPublisher1);
+ assertNotNull("publisher2", dbPublisher2);
+ assertNotNull("writer1", dbWriter1);
+ assertNotNull("writer2", dbWriter2);
+ assertEquals("writer1's publishers", 1, dbWriter1.getPublishers().size());
+ assertEquals("writer2's publishers", 1, dbWriter2.getPublishers().size());
+ assertEquals("publisher1's writers", 1, dbPublisher1.getWriters().size());
+ assertEquals("publisher2's writers", 1, dbPublisher2.getWriters().size());
+ assertEquals("publisher1's writer", dbWriter1, dbPublisher1.getWriters().get(0));
+ assertEquals("publisher2's writer", dbWriter2, dbPublisher2.getWriters().get(0));
+ assertEquals("writer1's publisher", dbPublisher1, dbWriter1.getPublishers().get(0));
+ assertEquals("writer2's publisher", dbPublisher2, dbWriter2.getPublishers().get(0));
+ }
+
+ private void verifyRemovePublisherWriter(boolean checkCache) {
+
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+ // dissassociate a writer from a publisher
+ beginTransaction();
+ Publisher dbPublisher = findPublisherWithName(em, publisherName);
+ Writer dbWriter1 = findWriterWithName(em, writer1Name);
+
+ dbPublisher.getWriters().remove(dbWriter1);
+ dbWriter1.getPublishers().remove(dbPublisher);
+ commitTransaction();
+
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+ // verify dissassociation
+ dbPublisher = findPublisherWithName(em, publisherName);
+ dbWriter1 = findWriterWithName(em, writer1Name);
+ Writer dbWriter2 = findWriterWithName(em, writer2Name);
+
+ assertNotNull("publisher not found", dbPublisher);
+ assertNotNull("writer1 not found", dbWriter1);
+ assertNotNull("writer2 not found", dbWriter2);
+ assertTrue("writer's publishers", dbWriter1.getPublishers().isEmpty());
+ assertEquals("num publisher's writers", 1, dbPublisher.getWriters().size());
+ assertEquals("publisher's writer", dbWriter2, dbPublisher.getWriters().get(0));
+ }
+
+ private void verifyInsertPublisherWriter(boolean checkCache) {
+ // the fixture setUp does the insert, now verify
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+ Publisher dbPublisher = findPublisherWithName(em, publisherName);
+
+ assertNotNull("publisher not found", dbPublisher);
+ assertEquals("publisher's writers", 2, dbPublisher
+ .getWriters().size());
+
+ Writer dbWriter = dbPublisher.getWriters().get(0);
+ assertNotNull("writer not found", dbWriter);
+ assertEquals("writer's publisher", dbPublisher, dbWriter
+ .getPublishers().get(0));
+ }
+
+ /**
+ * The test fixture consists of a single publisher
+ * with two writers.
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ beginTransaction();
+ publisher = createAnonymousPublisher(em);
+ publisherName = publisher.getName();
+ writer1 = createAnonymousWriter(em);
+ writer1Name = writer1.getName();
+ writer2 = createAnonymousWriter(em);
+ writer2Name = writer2.getName();
+ //
+ publisher.getWriters().add(writer1);
+ publisher.getWriters().add(writer2);
+ commitTransaction();
+ }
+
+
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/TypeWriterTypeTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/TypeWriterTypeTest.java
new file mode 100644
index 000000000..10b901485
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/TypeWriterTypeTest.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+import org.eclipse.emf.teneo.eclipselink.examples.library.TWriterType;
+import org.eclipse.emf.teneo.eclipselink.examples.library.TypeWriter;
+
+/**
+ * @author ebk2fe
+ * @version 1.0 (April 28th, 2006)
+ * <p>
+ * This test case create a typewriter object which holds at the attribute
+ * type an EMF enumeration type. To store the attribute EMF enumeration value
+ * at the data base the transformation mapping is used. Two java classes
+ * have been implemented: <code>TypewriterTypeAttributeTransformer</code> and
+ * <code>TypewriterTypeFieldTransformer</code>.<br>
+ * The correct EMF value for the attribute has to be fetched back from the
+ * data base.
+ *
+ */
+public class TypeWriterTypeTest extends LibraryJPATest {
+
+ public TypeWriterTypeTest(String name) {
+ super(name);
+ }
+
+ public void testInsertTypeWriterWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyInsertTypeWriter(checkCache);
+ }
+
+ public void testInsertTypeWriterNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyInsertTypeWriter(checkCache);
+ }
+
+ private void verifyInsertTypeWriter(boolean checkCache) {
+
+ beginTransaction();
+
+ TypeWriter twriter = createAnonymousTypewriter(em);
+ String twriterMaker = twriter.getMaker();
+ TWriterType twriterType = twriter.getType();
+
+ // put the data to the data base
+ commitTransaction();
+
+ // verify
+
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+ // Check whether the writer as been allocated at the data base.
+
+ TypeWriter dbTWriter = findTypeWriterWithMaker(em, twriterMaker);
+
+ assertNotNull("dbTWriter not found", dbTWriter);
+ assertEquals("dbTWriter.maker", twriterMaker, dbTWriter.getMaker());
+ assertEquals("dbTWriter.type", twriterType, dbTWriter.getType());
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/WriterAddressTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/WriterAddressTest.java
new file mode 100644
index 000000000..0b44e1261
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/WriterAddressTest.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+
+import org.eclipse.emf.ecore.InternalEObject;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Address;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
+
+public class WriterAddressTest extends LibraryJPATest {
+
+ public WriterAddressTest(String name) {
+ super(name);
+ }
+
+ public void testInsertWriterAndAddressWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyInsertWriterAddress(checkCache);
+ }
+
+ public void testInsertWriterAndAddressNoCache() throws Exception {
+ boolean checkCache = false;
+ verifyInsertWriterAddress(checkCache);
+ }
+
+ private void verifyInsertWriterAddress(boolean checkCache) {
+
+ beginTransaction();
+
+ Writer writer = createAnonymousWriterWithAddress(em);
+ String writerName = writer.getName();
+ Address address = writer.getAddress();
+
+ // put the data to the data base
+ commitTransaction();
+
+ // verify
+
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+
+ // Check whether the writer as been allocated at the data base.
+
+ Writer dbWriter = findWriterWithName(em, writerName);
+ assertNotNull("dbWriter not found", dbWriter);
+ Address dbAddress = dbWriter.getAddress();
+
+ assertNotNull("dbAddress not found", dbAddress);
+ assertNotNull("eContainer not set", dbAddress.eContainer());
+ int containerFeatureID = ((InternalEObject)address).eContainerFeatureID();
+ int dbContainerFeatureID = ((InternalEObject)dbAddress).eContainerFeatureID();
+ assertEquals("Containment Feature Id DB Address", containerFeatureID, dbContainerFeatureID);
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/WriterPublisherTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/WriterPublisherTest.java
new file mode 100644
index 000000000..5bb4e17e9
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/WriterPublisherTest.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+import org.eclipse.emf.teneo.eclipselink.examples.library.Publisher;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
+
+/**
+ *
+ * @author ebk2fe
+ * @version 1.0 (April 28th, 2006)
+ * <p>
+ * This test case creates a writer object and assignes two publishers
+ * to the writer. The objects are committed to the data base. The
+ * writer is fetched back from the data base.
+ */
+public class WriterPublisherTest extends LibraryJPATest {
+
+ public WriterPublisherTest(String name) {
+ super(name);
+ }
+
+ public void testInsertWriterPublisherWithCache() throws Exception {
+ boolean checkCache = true;
+ verifyInsertWriterPublisher(checkCache);
+ }
+
+ public void testInsertWriterPublisherNoCache() throws Exception {
+ boolean checkCache = true;
+ verifyInsertWriterPublisher(checkCache);
+ }
+
+ private void verifyInsertWriterPublisher(boolean checkCache) {
+
+ beginTransaction();
+ Writer writer = createAnonymousWriter(em);
+ String writerName = writer.getName();
+ Publisher publisher1 = createAnonymousPublisher(em);
+ Publisher publisher2 = createAnonymousPublisher(em);
+
+ publisher1.getWriters().add(writer);
+ publisher2.getWriters().add(writer);
+
+ writer.getPublishers().add(publisher1);
+ writer.getPublishers().add(publisher2);
+
+ int nbrElements = writer.getPublishers().size();
+
+ commitTransaction();
+
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+ Writer dbWriter = findWriterWithName(em, writerName);
+
+ assertNotNull("dbWriter not found", dbWriter);
+ assertEquals("nbr list elements", nbrElements, dbWriter.getPublishers().size());
+
+ Publisher dbPublisher = dbWriter.getPublishers().get(0);
+
+ assertNotNull("dbPublisher not found", dbPublisher);
+ assertEquals("reference to the writer", dbWriter, dbPublisher.getWriters().get(0));
+ }
+
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/WriterTypewriterTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/WriterTypewriterTest.java
new file mode 100644
index 000000000..bdf551c8e
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/WriterTypewriterTest.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests;
+
+import org.eclipse.emf.teneo.eclipselink.examples.library.TWriterType;
+import org.eclipse.emf.teneo.eclipselink.examples.library.TypeWriter;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
+
+/**
+ * @author ebk2fe
+ * @version 1.0.1 June 9th, 2006
+ * <p>
+ * This test case creates a writer object and assigns a typewriter to
+ * the writer. The object model uses a 1:n association based on EList
+ * to store the reference from writer to the typewriter(s). The data
+ * base model provides an associative table to cover the list of
+ * references. The or-mapping uses the many-to-many mapping to
+ * implement the 1:n relationship. The benefit would be that no
+ * explicite backward reference is required at the object model.
+ */
+public class WriterTypewriterTest extends LibraryJPATest {
+
+ public WriterTypewriterTest(String name) {
+
+ super(name);
+ }
+
+ public void testInsertWriterWithTypeWriterWithCache() throws Exception {
+
+ boolean checkCache = true;
+ verifyInsertWriterWithTypeWriter(checkCache);
+ }
+
+ public void testInsertWriterWithTypeWriterNoCache() throws Exception {
+
+ boolean checkCache = false;
+ verifyInsertWriterWithTypeWriter(checkCache);
+ }
+
+ private void verifyInsertWriterWithTypeWriter(boolean checkCache) {
+
+ beginTransaction();
+
+ Writer writer = createAnonymousWriterWithTypeWriter(em);
+ TypeWriter twriter = writer.getTypewriters().get(0);
+ String twriterMaker = twriter.getMaker();
+ TWriterType twriterType = twriter.getType();
+ String writerName = writer.getName();
+
+ // put the data to the data base
+ commitTransaction();
+
+ // verify
+ if (!checkCache) {
+ reinitializeCachesAndEntityManager();
+ }
+ // Check whether the writer as been allocated at the data base.
+
+ Writer dbWriter = findWriterWithName(em, writerName);
+
+ assertNotNull("dbWriter not found", dbWriter);
+ assertEquals("dbWriter.name", writerName, dbWriter.getName());
+
+ TypeWriter dbTWriter = dbWriter.getTypewriters().get(0);
+
+ assertNotNull("dbTWriter not found", dbTWriter);
+ assertEquals("dbTWriter.maker", twriterMaker, dbTWriter.getMaker());
+ assertEquals("dbTWriter.type", twriterType, dbTWriter.getType());
+
+ }
+
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/AllTests.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/AllTests.java
new file mode 100644
index 000000000..16f513fd4
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/AllTests.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests.resource;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+
+ public static Test suite() {
+
+ TestSuite suite = new TestSuite("TestSuite for EclipseLinkResourceImpl");
+ //$JUnit-BEGIN$
+ suite.addTestSuite(EclipseLinkResourceTest.class);
+ suite.addTestSuite(EclipseLinkAndXMIResourceTest.class);
+ //$JUnit-END$
+ return suite;
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/BasicEclipseLinkTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/BasicEclipseLinkTest.java
new file mode 100644
index 000000000..d9de5ab06
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/BasicEclipseLinkTest.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests.resource;
+
+import java.util.Collections;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+
+import junit.framework.TestCase;
+
+import org.eclipse.persistence.jpa.osgi.PersistenceProvider;
+
+
+public class BasicEclipseLinkTest extends TestCase {
+
+ protected static final String TEST_PERSISTENCE_UNIT_NAME = "library";
+
+ protected TestModelFactory testLibraryFactory = new TestModelFactory();
+
+ protected Map<? extends Object, ? extends Object> getTestDatabaseLoginProperties() {
+
+ return Collections.emptyMap();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+
+ super.tearDown();
+
+ // create entity manager factory for given persistence unit name
+ EntityManagerFactory entityManagerFactory = new PersistenceProvider().createEntityManagerFactory(TEST_PERSISTENCE_UNIT_NAME, getTestDatabaseLoginProperties(), this.getClass().getClassLoader());
+
+ // create entity manager and begin transaction
+ EntityManager entityManager = entityManagerFactory.createEntityManager();
+
+ // destroy library model in database and memory
+ testLibraryFactory.destroyLibraryModel(entityManager);
+
+ // close entity manager
+ entityManager.close();
+
+ // close entity manager factory for given persistence unit name
+ entityManagerFactory.close();
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/CreateSampleLibrariesWithEclipseLinkResourceTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/CreateSampleLibrariesWithEclipseLinkResourceTest.java
new file mode 100644
index 000000000..3f4a34090
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/CreateSampleLibrariesWithEclipseLinkResourceTest.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests.resource;
+
+import java.io.IOException;
+import java.util.Collections;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.teneo.eclipselink.resource.EclipseLinkResourceUtil;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Address;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Book;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Library;
+import org.eclipse.emf.teneo.eclipselink.examples.library.LibraryFactory;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Translator;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
+
+public class CreateSampleLibrariesWithEclipseLinkResourceTest extends BasicEclipseLinkTest {
+
+ private URI uri;
+ private Resource resource;
+ private Library library1, library2, library3;
+
+ public void testEclipseLinkResource() throws IOException {
+
+ // create and populate first library model instance
+ library1 = LibraryFactory.eINSTANCE.createLibrary();
+ library1.setName("EclipseCon Library");
+
+ Writer writer1 = LibraryFactory.eINSTANCE.createWriter();
+ writer1.setName("The True Eclipse Expert");
+ library1.getWriters().add(writer1);
+
+ Address address1 = LibraryFactory.eINSTANCE.createAddress();
+ address1.setTown("Sin City");
+ writer1.setAddress(address1);
+
+ Book book1 = LibraryFactory.eINSTANCE.createBook();
+ book1.setTitle("Eclipse Tips & Tricks");
+ library1.getBooks().put(book1.getTitle(), book1);
+
+ Translator translator1 = LibraryFactory.eINSTANCE.createTranslator();
+ translator1.setName("Mr. Babelfish");
+ book1.setTranslator(translator1);
+
+ Address address2 = LibraryFactory.eINSTANCE.createAddress();
+ address2.setTown("Foo City");
+ // TODO add this relationship to mapping
+ translator1.setAddress(address2);
+
+ // create and populate second library model instance
+ library2 = LibraryFactory.eINSTANCE.createLibrary();
+ library2.setName("IBM Library");
+
+ // create and populate third library model instance
+ library3 = LibraryFactory.eINSTANCE.createLibrary();
+ library3.setName("ORACLE Library");
+
+ // create EclipseLink URI for saving/loading all library models in/from
+ // database
+ uri = EclipseLinkResourceUtil.createEclipseLinkURI(TEST_PERSISTENCE_UNIT_NAME, Library.class.getName());
+
+ // save all library model instances in database
+ ResourceSet resourceSet = new ResourceSetImpl();
+ resourceSet.getLoadOptions().putAll(getTestDatabaseLoginProperties());
+ resource = resourceSet.createResource(uri);
+ resource.getContents().add(library1);
+ resource.getContents().add(library2);
+ resource.getContents().add(library3);
+ resource.save(Collections.EMPTY_MAP);
+
+ // unload resource of library model instances
+ resource.unload();
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/EclipseLinkAndXMIResourceTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/EclipseLinkAndXMIResourceTest.java
new file mode 100644
index 000000000..c84ae2e79
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/EclipseLinkAndXMIResourceTest.java
@@ -0,0 +1,253 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests.resource;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
+import org.eclipse.emf.teneo.eclipselink.resource.EclipseLinkResourceImpl;
+import org.eclipse.emf.teneo.eclipselink.resource.EclipseLinkResourceUtil;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Book;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Library;
+import org.eclipse.emf.teneo.eclipselink.examples.library.LibraryPackage;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
+import org.eclipse.emf.teneo.eclipselink.examples.library.forum.Forum;
+import org.eclipse.emf.teneo.eclipselink.examples.library.impl.StringToBookMapEntryImpl;
+
+public class EclipseLinkAndXMIResourceTest extends BasicEclipseLinkTest {
+
+ private IProject testProject;
+ private URI libraryURI, forumURI;
+ private Library library1;
+ private Forum forum1;
+ private Resource libraryResource1, libraryResource2, libraryResource3;
+ private Resource forumResource1, forumResource2, forumResource3;
+
+ @Override
+ protected void setUp() throws Exception {
+
+ super.setUp();
+
+ // create test project in runtime workspace
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ testProject = workspace.getRoot().getProject("Test");
+ IProjectDescription description = workspace.newProjectDescription("Test");
+ testProject.create(description, null);
+ testProject.open(null);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+
+ // delete test project including its contents from runtime workspace
+ try {
+ testProject.delete(true, true, null);
+ }
+ catch (CoreException cex) {
+ cex.printStackTrace();
+ }
+
+ super.tearDown();
+ }
+
+ public void testEclipseLinkAndXMIResource() throws IOException {
+
+ // create library model instance
+ library1 = testLibraryFactory.createLibraryModel();
+
+ // create forum model instance
+ forum1 = testLibraryFactory.createForumModel();
+
+ saveLibraryModel1AndForumModel1();
+ loadLibraryModel2FromForumModel2ViaIDBasedCrossDocumentReference();
+ loadLibraryModel3FromForumModel3ViaIndexBasedCrossDocumentReference();
+ deleteLibraryModel1();
+ unloadAllLibraryAndForumModels();
+ }
+
+ private void saveLibraryModel1AndForumModel1() throws IOException {
+
+ // create EclipseLink URI for saving/loading library model in/from database
+ String query = EclipseLinkResourceUtil.createContentsEqualQuery(LibraryPackage.eINSTANCE.getLibrary(), LibraryPackage.eINSTANCE.getLibrary_Name(), library1.getName());
+ libraryURI = EclipseLinkResourceUtil.createEclipseLinkURI(TEST_PERSISTENCE_UNIT_NAME, query);
+
+ // save library model instance in database
+ ResourceSet resourceSet1 = new ResourceSetImpl();
+ resourceSet1.getLoadOptions().putAll(getTestDatabaseLoginProperties());
+ libraryResource1 = resourceSet1.createResource(libraryURI);
+
+ assertTrue(libraryResource1 instanceof EclipseLinkResourceImpl);
+
+ libraryResource1.getContents().add(library1);
+ libraryResource1.save(Collections.EMPTY_MAP);
+
+ // create platform resource URI for saving/loading forum model in/from
+ // XMI file
+ String forumPathName = createForumModelPathName(testProject, forum1);
+ forumURI = URI.createPlatformResourceURI(forumPathName, false);
+
+ // save forum model instance in XMI resource
+ forumResource1 = resourceSet1.createResource(forumURI);
+
+ assertTrue(forumResource1 instanceof XMIResourceImpl);
+
+ forumResource1.getContents().add(forum1);
+ forumResource1.save(Collections.EMPTY_MAP);
+ }
+
+ private void loadLibraryModel2FromForumModel2ViaIDBasedCrossDocumentReference() {
+
+ // load second forum model instance from XMI resource
+ ResourceSet resourceSet2 = new ResourceSetImpl();
+ resourceSet2.getLoadOptions().putAll(getTestDatabaseLoginProperties());
+ forumResource2 = resourceSet2.getResource(forumURI, true);
+
+ assertTrue(forumResource2 instanceof XMIResourceImpl);
+
+ // analyse second forum model instance
+ List<EObject> forumContents2 = forumResource2.getContents();
+ assertNotNull(forumContents2);
+ assertEquals(1, forumContents2.size());
+ EObject forum2 = forumContents2.get(0);
+
+ EPackage forumPack = forum2.eClass().getEPackage();
+ EClass forumCls = (EClass) forumPack.getEClassifier("Forum");
+ EStructuralFeature nameFeat = forumCls.getEStructuralFeature("name");
+ EStructuralFeature ratedAuthorsFeat = forumCls.getEStructuralFeature("ratedAuthors");
+
+ assertNotNull(forum2.eGet(nameFeat));
+ assertEquals(forum1.eGet(nameFeat), forum2.eGet(nameFeat));
+ assertNotNull(forum2.eGet(ratedAuthorsFeat));
+ assertEquals(((EList<?>) forum1.eGet(ratedAuthorsFeat)).size(), ((EList<?>) forum2.eGet(ratedAuthorsFeat)).size());
+
+ // navigate from second forum to referenced rated author and thereby
+ // lazily load second library model instance from database resource
+ Writer writer2 = (Writer) ((EList<?>) forum2.eGet(ratedAuthorsFeat)).get(0);
+
+ assertNotNull(writer2);
+
+ libraryResource2 = writer2.eResource();
+
+ assertTrue(libraryResource2 instanceof EclipseLinkResourceImpl);
+ assertEquals(libraryResource2.getURI(), libraryURI);
+
+ // analyse second library model instance
+ assertTrue(writer2.eContainer() instanceof Library);
+ Library library2 = (Library) writer2.eContainer();
+
+ assertNotNull(library2.getName());
+ assertEquals(library1.getName(), library2.getName());
+ assertNotNull(library2.getWriters());
+ assertEquals(library1.getWriters().size(), library2.getWriters().size());
+ assertNotNull(library2.getBooks());
+ assertEquals(library1.getBooks().size(), library2.getBooks().size());
+ }
+
+ private void loadLibraryModel3FromForumModel3ViaIndexBasedCrossDocumentReference() {
+
+ // load third forum model instance from XMI resource
+ ResourceSet resourceSet3 = new ResourceSetImpl();
+ resourceSet3.getLoadOptions().putAll(getTestDatabaseLoginProperties());
+ forumResource3 = resourceSet3.getResource(forumURI, true);
+
+ assertTrue(forumResource3 instanceof XMIResourceImpl);
+
+ // analyse third forum model instance
+ List<EObject> forumContents3 = forumResource3.getContents();
+ assertNotNull(forumContents3);
+ assertEquals(1, forumContents3.size());
+ EObject forum3 = forumContents3.get(0);
+
+ EPackage forumPack = forum3.eClass().getEPackage();
+ EClass forumCls = (EClass) forumPack.getEClassifier("Forum");
+ EStructuralFeature nameFeat = forumCls.getEStructuralFeature("name");
+ EStructuralFeature featuredBooksFeat = forumCls.getEStructuralFeature("featuredBooks");
+
+ assertNotNull(forum3.eGet(nameFeat));
+ assertEquals(forum1.eGet(nameFeat), forum3.eGet(nameFeat));
+ assertNotNull(forum3.eGet(featuredBooksFeat));
+ assertEquals(((EList<?>) forum1.eGet(featuredBooksFeat)).size(), ((EList<?>) forum3.eGet(featuredBooksFeat)).size());
+
+ // navigate from third forum to referenced featured book and thereby
+ // lazily load third library model instance from database resource
+ Book book3 = (Book) ((EList<?>) forum3.eGet(featuredBooksFeat)).get(0);
+
+ assertNotNull(book3);
+
+ libraryResource3 = book3.eResource();
+
+ assertTrue(libraryResource3 instanceof EclipseLinkResourceImpl);
+ assertEquals(libraryResource3.getURI(), libraryURI);
+
+ // analyse third library model instance
+ assertTrue(book3.eContainer() instanceof StringToBookMapEntryImpl);
+ StringToBookMapEntryImpl bookEntry3 = (StringToBookMapEntryImpl) book3.eContainer();
+ assertTrue(bookEntry3.eContainer() instanceof Library);
+ Library library3 = (Library) bookEntry3.eContainer();
+
+ assertNotNull(library3.getName());
+ assertEquals(library1.getName(), library3.getName());
+ assertNotNull(library3.getWriters());
+ assertEquals(library1.getWriters().size(), library3.getWriters().size());
+ assertNotNull(library3.getBooks());
+ assertEquals(library1.getBooks().size(), library3.getBooks().size());
+ }
+
+ private void deleteLibraryModel1() throws IOException {
+
+ // delete first library model instance in database
+ libraryResource1.getContents().remove(library1);
+ libraryResource1.save(Collections.EMPTY_MAP);
+ }
+
+ private void unloadAllLibraryAndForumModels() {
+
+ // unload resources of first library and forum model instance
+ libraryResource1.unload();
+ forumResource1.unload();
+
+ // unload resources of second library and forum model instance
+ libraryResource2.unload();
+ forumResource2.unload();
+
+ // unload resources of third library and forum model instance
+ libraryResource3.unload();
+ forumResource3.unload();
+ }
+
+ //
+ // helper methods
+ //
+
+ private String createForumModelPathName(IProject project, Forum forum) {
+
+ IPath result = project.getFullPath().append(forum.getName() + "." + forum.eClass().getEPackage().getName());
+ return result.toString();
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/EclipseLinkResourceTest.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/EclipseLinkResourceTest.java
new file mode 100644
index 000000000..9cd02f6ee
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/EclipseLinkResourceTest.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests.resource;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Library;
+import org.eclipse.emf.teneo.eclipselink.examples.library.LibraryPackage;
+import org.eclipse.emf.teneo.eclipselink.examples.library.impl.LibraryImpl;
+import org.eclipse.emf.teneo.eclipselink.resource.EclipseLinkResourceImpl;
+import org.eclipse.emf.teneo.eclipselink.resource.EclipseLinkResourceUtil;
+
+public class EclipseLinkResourceTest extends BasicEclipseLinkTest {
+
+ private URI uri;
+ private Resource resource1, resource2;
+ private Library library1;
+
+ public void testEclipseLinkResource() throws IOException {
+
+ // create library model instance
+ library1 = testLibraryFactory.createLibraryModel();
+
+ saveLibraryModel1();
+ loadLibraryModel2();
+ deleteLibraryModel1();
+ reloadLibraryModel2();
+ unloadAllLibraryModels();
+ }
+
+ private void saveLibraryModel1() throws IOException {
+
+ // create EclipseLink URI for saving/loading library model in/from database
+ String query = EclipseLinkResourceUtil.createContentsEqualQuery(LibraryPackage.eINSTANCE.getLibrary(), LibraryPackage.eINSTANCE.getLibrary_Name(), library1.getName());
+ uri = EclipseLinkResourceUtil.createEclipseLinkURI(TEST_PERSISTENCE_UNIT_NAME, query);
+
+ // save library model instance in database
+ ResourceSet resourceSet1 = new ResourceSetImpl();
+ resourceSet1.getLoadOptions().putAll(getTestDatabaseLoginProperties());
+ resource1 = resourceSet1.createResource(uri);
+
+ assertTrue(resource1 instanceof EclipseLinkResourceImpl);
+ assertFalse(resource1.isLoaded());
+
+ resource1.getContents().add(library1);
+
+ assertTrue(resource1.isLoaded());
+
+ resource1.save(Collections.EMPTY_MAP);
+ }
+
+ private void loadLibraryModel2() {
+
+ // load second library model instance from database
+ ResourceSet resourceSet2 = new ResourceSetImpl();
+ resourceSet2.getLoadOptions().putAll(getTestDatabaseLoginProperties());
+ resource2 = resourceSet2.getResource(uri, true);
+
+ assertTrue(resource2 instanceof EclipseLinkResourceImpl);
+ assertTrue(resource2.isLoaded());
+
+ // analyse second library model instance
+ List<EObject> contents2 = resource2.getContents();
+ assertNotNull(contents2);
+ assertEquals(1, contents2.size());
+ assertTrue(contents2.get(0) instanceof LibraryImpl);
+ Library library2 = (Library) contents2.get(0);
+
+ assertNotNull(library2.getName());
+ assertEquals(library1.getName(), library2.getName());
+ assertNotNull(library2.getWriters());
+ assertEquals(library1.getWriters().size(), library2.getWriters().size());
+ assertEquals(resource2, (library2.getWriters().get(0)).eResource());
+ assertNotNull(library2.getBooks());
+ assertEquals(library1.getBooks().size(), library2.getBooks().size());
+ assertEquals(resource2, (library2.getBooks().get("myBook")).eResource());
+ }
+
+ private void deleteLibraryModel1() throws IOException {
+
+ // delete first library model instance in database
+ resource1.getContents().remove(library1);
+ resource1.save(Collections.EMPTY_MAP);
+ }
+
+ private void reloadLibraryModel2() throws IOException {
+
+ // reload second library model instance from database
+ resource2.unload();
+
+ assertFalse(resource2.isLoaded());
+
+ resource2.load(Collections.EMPTY_MAP);
+
+ assertTrue(resource2.isLoaded());
+
+ // analyse second library model instance
+ List<EObject> contents2 = resource2.getContents();
+ assertNotNull(contents2);
+ assertEquals(0, contents2.size());
+ }
+
+ private void unloadAllLibraryModels() {
+
+ // unload resource of first library model instance
+ resource1.unload();
+
+ assertFalse(resource1.isLoaded());
+
+ // unload resource of second library model instance
+ resource2.unload();
+
+ assertFalse(resource2.isLoaded());
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/TestModelFactory.java b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/TestModelFactory.java
new file mode 100644
index 000000000..9c78d23c1
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests/src/org/eclipse/emf/teneo/eclipselink/examples/library/orm/tests/resource/TestModelFactory.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Oracle and Geensys.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle and Geensys - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.teneo.eclipselink.examples.library.orm.tests.resource;
+
+import javax.persistence.EntityManager;
+
+import org.eclipse.emf.teneo.eclipselink.examples.library.Book;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Library;
+import org.eclipse.emf.teneo.eclipselink.examples.library.LibraryFactory;
+import org.eclipse.emf.teneo.eclipselink.examples.library.Writer;
+import org.eclipse.emf.teneo.eclipselink.examples.library.forum.Forum;
+import org.eclipse.emf.teneo.eclipselink.examples.library.forum.ForumFactory;
+
+
+public class TestModelFactory {
+
+ private Library library;
+
+ private Writer writer;
+
+ private Book book;
+
+ public Library createLibraryModel() {
+
+ if (library == null) {
+ // create and populate library model instance
+ library = LibraryFactory.eINSTANCE.createLibrary();
+ library.setName("myLibrary");
+ writer = LibraryFactory.eINSTANCE.createWriter();
+ writer.setName("myWriter");
+ library.getWriters().add(writer);
+ book = LibraryFactory.eINSTANCE.createBook();
+ book.setTitle("myBook");
+ library.getBooks().put(book.getTitle(), book);
+ }
+
+ return library;
+ }
+
+ public Forum createForumModel() {
+
+ // create and populate forum model instance
+ Forum forum = ForumFactory.eINSTANCE.createForum();
+ forum.setName("myForum");
+ if (writer != null) {
+ forum.getRatedAuthors().add(writer);
+ }
+ if (book != null) {
+ forum.getFeaturedBooks().add(book);
+ }
+
+ return forum;
+ }
+
+ public void destroyLibraryModel(EntityManager entityManager) {
+
+ if (library != null) {
+ // begin transaction
+ entityManager.getTransaction().begin();
+
+ // delete library model from database; delete does not cascade so order is
+ // important
+ entityManager.createQuery("delete from StringToBookMapEntryImpl o").executeUpdate();
+ entityManager.createQuery("delete from BookStylesMapEntryImpl o").executeUpdate();
+ entityManager.createQuery("delete from Cover o").executeUpdate();
+ entityManager.createQuery("delete from Book o").executeUpdate();
+ entityManager.createQuery("delete from Publisher o").executeUpdate();
+ entityManager.createQuery("delete from Translator o").executeUpdate();
+ entityManager.createQuery("delete from Writer o").executeUpdate();
+ entityManager.createQuery("delete from TypeWriter o").executeUpdate();
+ entityManager.createQuery("delete from Address o").executeUpdate();
+ entityManager.createQuery("delete from Library o").executeUpdate();
+ entityManager.createQuery("delete from Style o").executeUpdate();
+
+ // commit and end transaction
+ entityManager.getTransaction().commit();
+
+ // dispose library model
+ library = null;
+ writer = null;
+ book = null;
+ }
+ }
+}

Back to the top