diff options
author | Martin Taal | 2011-11-01 18:12:35 +0000 |
---|---|---|
committer | Martin Taal | 2011-11-01 18:12:35 +0000 |
commit | 97842a213a338601aa158b3d9f995f464bb25681 (patch) | |
tree | 5b9a657ccdce9960b252f3bc8dcc09a2626bd711 /tests/org.eclipse.emf.teneo.commontest/src | |
parent | 709ec105b89258b5e6b27e57cb3deb177529c54c (diff) | |
download | org.eclipse.emf.teneo-97842a213a338601aa158b3d9f995f464bb25681.tar.gz org.eclipse.emf.teneo-97842a213a338601aa158b3d9f995f464bb25681.tar.xz org.eclipse.emf.teneo-97842a213a338601aa158b3d9f995f464bb25681.zip |
New structure
Diffstat (limited to 'tests/org.eclipse.emf.teneo.commontest/src')
187 files changed, 23441 insertions, 0 deletions
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/extlibrary/ExtLibraryAction.java b/tests/org.eclipse.emf.teneo.commontest/src/extlibrary/ExtLibraryAction.java new file mode 100755 index 000000000..bca7c2d7f --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/extlibrary/ExtLibraryAction.java @@ -0,0 +1,100 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: ExtLibraryAction.java,v 1.8 2008/02/28 07:08:17 mtaal Exp $ + */ + +package extlibrary; + +import java.util.Date; + +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests the extlibrary + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.8 $ + */ +public class ExtLibraryAction extends AbstractTestAction { + + /** + * Constructor + */ + public ExtLibraryAction() { + super(ExtlibraryPackage.eINSTANCE); + } + + /** Test */ + @Override + public void doAction(TestStore store) { + + final ExtlibraryFactory factory = ExtlibraryFactory.eINSTANCE; + store.beginTransaction(); + final Writer wr = factory.createWriter(); + wr.setAddress("authorstreet"); + wr.setFirstName("John"); + wr.setLastName("Smith"); + wr.setName("Smith, John"); + final Book bk = factory.createBook(); + bk.setAuthor(wr); + bk.setCategory(BookCategory.BIOGRAPHY_LITERAL); + bk.setCopies(4); + bk.setPages(100); + bk.setPublicationDate(new Date()); + bk.setTitle("title"); + store.store(bk); + + final Library lb2 = factory.createLibrary(); + lb2.setAddress("main street"); + lb2.setName("parent"); + + final Library lb = factory.createLibrary(); + lb.setAddress("street"); + lb.setName("myname"); + lb.getBooks().add(bk); + lb.getWriters().add(wr); + lb.setParentBranch(lb2); + + final Employee em = factory.createEmployee(); + em.setAddress("employee street 4"); + em.setFirstName("martin"); + em.setLastName("taal"); + + final Employee manager = factory.createEmployee(); + manager.setAddress("manager street 2"); + manager.setFirstName("John"); + manager.setLastName("the Boss"); + + em.setManager(manager); + + lb.getEmployees().add(em); + lb.getEmployees().add(manager); + + final Borrower bw = factory.createBorrower(); + bw.setAddress("borrowstreet"); + bw.setFirstName("Jane"); + bw.setLastName("Smith"); + bw.getBorrowed().add(bk); + lb.getBorrowers().add(bw); + store.store(lb); + store.commitTransaction(); + + /* + * //Polymorphic queries are not supported store.beginTransaction(); Lendable lendable = + * (Lendable)store.query("select from extlibrary.Lendable").get(0); assertTrue(lendable != + * null); store.commitTransaction(); + */ + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/log4j.properties b/tests/org.eclipse.emf.teneo.commontest/src/log4j.properties new file mode 100755 index 000000000..18049bec2 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/log4j.properties @@ -0,0 +1,47 @@ +# Set root logger level to error and its only appender to A1. +log4j.rootCategory=error, A1 + +# A1 is set to be a ConsoleAppender. +log4j.appender.A1=org.apache.log4j.ConsoleAppender + +# A1 uses PatternLayout. +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n + +#log4j.logger.org.hibernate=error +log4j.logger.org.hibernate=error +#org.hibernate.pretty + +### log HQL query parser activity +log4j.logger.org.hibernate.hql.ast.AST=error + +### log just the SQL +log4j.logger.org.hibernate.SQL=error + +### log JDBC bind parameters ### +log4j.logger.org.hibernate.type=error +#log4j.logger.org.hibernate.type=error + +### log schema export/update ### +log4j.logger.org.hibernate.tool.hbm2ddl=error + +### log HQL parse trees +log4j.logger.org.hibernate.hql=error + +### log cache activity ### +log4j.logger.org.hibernate.cache=error + +### log transaction activity +log4j.logger.org.hibernate.transaction=error + +### log JDBC resource acquisition +log4j.logger.org.hibernate.jdbc=error + +### enable the following line if you want to track down connection ### +### leakages when using DriverManagerConnectionProvider ### +log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=error + + +### log Teneo +log4j.logger.org.eclipse.emf.teneo=error + diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/AbstractActionTest.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/AbstractActionTest.java new file mode 100755 index 000000000..90ae9c790 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/AbstractActionTest.java @@ -0,0 +1,138 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: AbstractActionTest.java,v 1.8 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test; + +import java.util.Properties; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.extension.ExtensionManager; + +/** + * Hibernate test based on abstract action. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.8 $ + */ +public class AbstractActionTest extends AbstractTest { + /** The action contains the real test */ + protected AbstractTestAction itsTestAction; + + private Properties properties; + + /** Constructor */ + public AbstractActionTest(Class<?> testActionClass) { + super("testAction"); + try { + itsTestAction = (AbstractTestAction) testActionClass.newInstance(); + } catch (Exception e) { + throw new StoreTestException("Exception while instantiating " + testActionClass.getName(), e); + } + } + + /** Constructor */ + public AbstractActionTest(AbstractTestAction itsTestAction) { + this(itsTestAction, null); + } + + /** + * Constructs an instance with additional OR-mapping properties. + * + * @param itsTestAction + * @param properties + */ + public AbstractActionTest(AbstractTestAction itsTestAction, Properties properties) { + super("testAction"); + this.itsTestAction = itsTestAction; + this.properties = properties; + } + + /** returns the underlying test action */ + public AbstractTestAction getTestAction() { + return itsTestAction; + } + + /** The actual test run */ + public void testAction() { + getTestAction().doAction(getStore()); + } + + /** Return the epackages for which this test is done */ + @Override + public EPackage[] getEPackages() { + return getTestAction().getEPackages(); + } + + /** Return the test package name */ + @Override + public String getTestPackageName() { + return getTestAction().getTestPackageName(); + } + + public Properties getProperties() { + return properties; + } + + public void setProperties(Properties props) { + properties = props; + } + + /** Return the test package name */ + @Override + public Package getTestPackage() { + return getTestAction().getClass().getPackage(); + } + + /** Returns extra properties which are passed to the or layer for additional configuration */ + @Override + public Properties getExtraConfigurationProperties() { + Properties allProperties = getTestAction().getExtraConfigurationProperties(); + + // override some defaults + if (allProperties.get(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT) == null) { + allProperties.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true"); + } + + if (allProperties.get(PersistenceOptions.JOIN_TABLE_NAMING_STRATEGY) == null) { + allProperties.setProperty(PersistenceOptions.JOIN_TABLE_NAMING_STRATEGY, "ejb3"); + } + + if (this.properties != null) { + allProperties.putAll(this.properties); + } + return allProperties; + } + + /** Add extensions if you want */ + @Override + public void setExtensions(ExtensionManager extensionManager) { + getTestAction().setExtensions(extensionManager); + } + + /** Returns a unique name based on the class name of the testAction class */ + @Override + public String getName() { + return itsTestAction.getClass().getName(); + } + + /** Returns a simple name based on the class name of the testAction class. */ + @Override + public String getSimpleName() { + final String name = getName(); + return name.substring(name.lastIndexOf(".") + 1); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/AbstractTest.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/AbstractTest.java new file mode 100755 index 000000000..6b76aa125 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/AbstractTest.java @@ -0,0 +1,125 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: AbstractTest.java,v 1.5 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test; + +import java.util.Properties; + +import junit.framework.TestCase; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.extension.ExtensionManager; +import org.eclipse.emf.teneo.test.conf.Testbed; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Base class for hibernate store based tests. The tests inheriting from this class will get a + * dedicated store to be used in order to perform the test. + * + * <p> + * The standard test suite will run such tests once for each configured test setting (see + * test.properties). + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.5 $ + */ +public abstract class AbstractTest extends TestCase { + // very strange but there was a compile (or runtime) error in one of the ecore packages, had to + // set this + static { + System.setProperty("org.eclipse.emf.ecore.EPackage.Registry.INSTANCE", + "org.eclipse.emf.ecore.impl.EPackageRegistryImpl"); + } + + /** The test store is the connection to the database and specific datalayer actions */ + private TestStore itsStore; + + /** Keep track if the run failed (exception occured) */ + private boolean lastRunFailed; + + /** + * @return Returrns true if last run failed. Meaningless if invoked before the test method + * completes, reports correct value if invoked in tearDown. + */ + public final boolean lastRunFailed() { + return lastRunFailed; + } + + /** Set of epackages for which this test runs */ + public abstract EPackage[] getEPackages(); + + /** Return the test package name */ + public abstract String getTestPackageName(); + + /** The test method (testAction) */ + AbstractTest(String testMethod) { + super(testMethod); + } + + /** Return the store used */ + protected TestStore getStore() { + return itsStore; + } + + /** Setup the store */ + @Override + public void setUp() throws Exception { + itsStore = Testbed.instance().createStore(this); + } + + /** Run the test */ + @Override + protected void runTest() throws Throwable { + try { + lastRunFailed = false; + super.runTest(); + } catch (Throwable t) { + lastRunFailed = true; + throw t; + } + } + + /** Tear down after the test */ + @Override + public void tearDown() { + getStore().tearDown(!lastRunFailed); + } + + /** Returns extra properties which are passed to the or layer for additional configuration */ + public Properties getExtraConfigurationProperties() { + return new Properties(); + } + + /** Add extensions if you want */ + public void setExtensions(ExtensionManager extensionManager) { + + } + + /** Returns a name based on the class name of the testAction class. */ + @Override + public String getName() { + return this.getClass().getName(); + } + + /** Returns a simple name based on the class name of the testAction class. */ + public String getSimpleName() { + return this.getClass().getSimpleName(); + } + + /** Return the test package name */ + public abstract Package getTestPackage(); + +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/AbstractTestAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/AbstractTestAction.java new file mode 100755 index 000000000..01d8191c4 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/AbstractTestAction.java @@ -0,0 +1,120 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: AbstractTestAction.java,v 1.9 2009/12/16 16:14:53 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test; + +import java.net.URL; +import java.util.Properties; + +import junit.framework.TestCase; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.extension.ExtensionManager; +import org.eclipse.emf.teneo.test.conf.ConfigurableTestSuite; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Abstract TestAction used in backend specific test cases. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.9 $ + */ +public abstract class AbstractTestAction extends TestCase { + // very strange but there was a compile (or runtime) error in one of the ecore packages, had to + // set this + static { + System.setProperty("org.eclipse.emf.ecore.EPackage.Registry.INSTANCE", + "org.eclipse.emf.ecore.impl.EPackageRegistryImpl"); + } + + /** The epackage */ + private EPackage[] epackages = null; + + /** + * Constructor for test without epackages + */ + public AbstractTestAction() { + this((EPackage[]) null); + } + + /** + * Constructor + * + * @param the + * epackage for which this test is run + */ + public AbstractTestAction(EPackage epackage) { + this(new EPackage[] { epackage }); + } + + /** + * Constructor for array of epackages + * + * @param epackages + */ + public AbstractTestAction(EPackage[] epackages) { + this.epackages = epackages; + } + + public EPackage[] getEPackages() { + return epackages; + } + + /** Return the packagename of the test sample, Is needed in case of non emf test cases */ + public String getTestPackageName() { + throw new UnsupportedOperationException("Not supported"); + } + + /** Performs the actual test action */ + public abstract void doAction(TestStore store); + + /** + * Can be overridden by subclass returns properties which control the or layer. Such as setting of eager loading. + */ + public Properties getExtraConfigurationProperties() { + return new Properties(); + } + + /** Add extensions if you want */ + public void setExtensions(ExtensionManager extensionManager) { + + } + + /** + * Returns the path of the XML persistence mapping file on the classpath or null if none is available. + * <p> + * Returning non-null will cause the TestAction to be run twice: first for a PAnnotatedModel populated from + * EAnnotations and then for a PAnnotatedModel populated from the XML persistence mapping. + * <p> + * This implementation looks for a mapping file on the classpath named <class name>.persistence.xml, returning + * its path if it exists or null if it does not. + * + * @see ConfigurableTestSuite + */ + public String getPersistenceXmlPath() { + final String path = getClass().getName().replace('.', '/') + ".persistence.xml"; + // Note: use ClassLoader.getResource() instead of Class.getResource(). + final URL resource = getClass().getClassLoader().getResource(path); + if (resource == null) { + return null; + } + return path; + } + + protected boolean isEAVTest() { + return this.getClass().getName().contains("EAV"); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/StoreTestException.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/StoreTestException.java new file mode 100755 index 000000000..26052164a --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/StoreTestException.java @@ -0,0 +1,43 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * StoreTestException.java,v 1.4 2007/02/01 12:35:37 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test; + +import org.eclipse.emf.teneo.TeneoException; + +/** + * This exception is the base class of all exceptions which occur in the generation process. This + * class offers automatic logging to commons logging. Note that this class extends RuntimeException, + * so no forced throws and catch statements. Although there are very differing views on this topic + * but it is our experience that to many checked exceptions only distract the programmer and have no + * added value. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.6 $ $Date: 2008/02/28 07:08:16 $ + */ + +public class StoreTestException extends TeneoException { + /** + * A serialized version id + */ + private static final long serialVersionUID = -6313295414030858545L; + + /** + * The constructor, logs the exception also + */ + public StoreTestException(String msg, Throwable cause) { + super(msg, cause); + } + + /** + * The constructor, logs the exception also + */ + public StoreTestException(String msg) { + super(msg); + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/Utils.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/Utils.java new file mode 100755 index 000000000..a0fbf94cf --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/Utils.java @@ -0,0 +1,173 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: Utils.java,v 1.4 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URL; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; + +import org.eclipse.emf.teneo.samples.SamplesSource; + +/** + * Contains utility methods for testing. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.4 $ $Date: 2008/02/28 07:08:16 $ + */ + +public class Utils { + /** The propertyname used to specify which database to use */ + public static String DATABASE_PROP_NAME = "database"; + + /** + * Returns test properties. + */ + public static Properties getTestProperties() { + // set the log4j properties + // PropertyConfigurator.configure(Utils.class.getResource("log4j.properties")); + + final Properties props = new Properties(); + try { + final InputStream is = Utils.class.getResourceAsStream("test.properties"); + props.load(is); + is.close(); + } catch (Exception e) { + throw new StoreTestException("Exception when loading properties file test.properties", e); + } + return props; + } + + // /** + // * Returns an array of test properties for one or more databases. + // */ + // public static Properties[] getAllTestProperties() + // { + // // read all the testproperties + // final Properties props = new Properties(); + // try + // { + // final InputStream is = Utils.class.getResourceAsStream("/test.properties"); + // props.load(is); + // is.close(); + // } + // catch (Exception e) + // { + // throw new StoreTestException("Exception when loading properties file test.properties", e); + // } + // + // return hiearchizeProps(props); + // } + + public static Map hiearchizeProps(final Properties props) { + Map hProps = new HashMap(); + for (Iterator i = props.keySet().iterator(); i.hasNext();) { + String propName = (String) i.next(); + int delimitAt = propName.indexOf('.'); + String propPrefix = (delimitAt < 0) ? propName : propName.substring(0, delimitAt); + String propSuffix = (delimitAt < 0) ? "." : propName.substring(delimitAt + 1); + + Properties subProps = (Properties) hProps.get(propPrefix); + if (subProps == null) { + subProps = new Properties(); + hProps.put(propPrefix, subProps); + } + subProps.put(propSuffix, props.getProperty(propName)); + } + return hProps; + } + + /** + * Returns the directory which contains the sources which are to be parsed. + */ + public static String getStartSource(String packageName) { + try { + return SamplesSource.getSourceDirectory(packageName).getAbsolutePath(); + } catch (FileNotFoundException e) { + throw new StoreTestException("Cannot find source folder for package " + packageName, e); + } + } + + /** + * Returns the outputdirectory + */ + public static String getOutputDirectory() { + // this file is now in test/src/org/elver/store/test/Utils.class + File file = new File(Utils.class.getResource('/' + Utils.class.getName().replace('.', '/') + ".class").getFile()); + + // now go up 5 directories: + // Utils test store elver org bin + return file.getParentFile().getParentFile().getParentFile().getParentFile().getParentFile().getAbsolutePath(); + } + + /** + * Returns the outputlocation of the package of the passed class + */ + public static String getOutputDirectory(String className) { + // this file is now in test/src/org/elver/store/test/Utils.class + File file = new File(Utils.class.getResource('/' + Utils.class.getName().replace('.', '/') + ".class").getFile()); + + // now go up 5 directories: + // Utils test store elver org bin + file = file.getParentFile().getParentFile().getParentFile().getParentFile().getParentFile(); + + // now go down again to the package + String path = className.replace('.', File.separatorChar); + path = path.substring(0, path.lastIndexOf(File.separatorChar)); + + file = new File(file, path); + + if (!file.exists()) { + throw new StoreTestException("Directory " + file.getAbsolutePath() + " within test directory does not exist. Tried path: " + + file.getAbsolutePath()); + } + return file.getAbsolutePath(); + } + + /** Copies a file */ + public static void copyFile(File src, File dst) throws IOException { + InputStream in = new FileInputStream(src); + OutputStream out = new FileOutputStream(dst); + + // Transfer bytes from in to out + byte[] buf = new byte[1024]; + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + in.close(); + out.close(); + } + + /** Returns the output location of the passed class, only supports directories (no jars!) */ + public static File getClassParentDirectory(Class cls) { + final ClassLoader clsl = cls.getClassLoader(); + final String clsFile = cls.getName ().replace ('.', '/').concat (".class"); + final URL url = clsl != null ? clsl.getResource(clsFile) : + ClassLoader.getSystemResource(clsFile); + final File file = new File(url.getFile()); + return file.getParentFile(); + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/ConfigurableTestSuite.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/ConfigurableTestSuite.java new file mode 100755 index 000000000..a811b0ed1 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/ConfigurableTestSuite.java @@ -0,0 +1,107 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * Davide Marchignoli + * </copyright> + * + * $Id: ConfigurableTestSuite.java,v 1.5 2008/05/27 07:42:12 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.conf; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestResult; +import junit.framework.TestSuite; + +import org.eclipse.emf.teneo.test.AbstractActionTest; +import org.eclipse.emf.teneo.test.AbstractTestAction; + +/** + * The configurable test suite takes care of setting the active configuration before starting the + * test. + * + * @author Davide Marchignoli + * @author Martin Taal + * @version $Revision: 1.5 $ + */ +public class ConfigurableTestSuite extends TestSuite { + + /** the configuration that will be used to rn the tests */ + final TestConfiguration runConfiguration; + + /** + * Constructs a TestSuite whose tests will be run in the given configuration. + */ + public ConfigurableTestSuite(TestConfiguration cfg, String name) { + super(name); + this.runConfiguration = cfg; + } + + /** + * Constructs a TestSuite whose tests will be run in the given configuration. + */ + public ConfigurableTestSuite(TestConfiguration cfg) { + this(cfg, cfg == null ? "Null configuration" : cfg.getName()); + } + + /** Gets the configuration of this run */ + public TestConfiguration getRunConfiguration() { + return runConfiguration; + } + + /** Run the test using the specified configuration */ + @Override + public void runTest(Test test, TestResult result) { + if (Testbed.instance().getActiveConfiguration() != runConfiguration) { + Testbed.instance().setActiveConfiguration(getRunConfiguration()); + } + super.runTest(test, result); + } + + /** + * Returns a test which will fail and log a warning message. + */ + public static Test warning(final String message) { + return new TestCase("warning") { + @Override + protected void runTest() { + fail(message); + } + }; + } + + /** Encapsulates an action object in a test */ + protected TestSuite createTestForAction(Class actionClass) { + TestSuite componentSuite = new TestSuite(actionClass.getName()); + Test componentTest; + try { + componentTest = new AbstractActionTest((AbstractTestAction) actionClass.newInstance()); + } catch (Throwable e) { + componentTest = warning("Cannot istantiate " + actionClass.getName() + " due to\n" + e.getMessage()); + } + componentSuite.addTest(componentTest); + return componentSuite; + } + + /** + * Handles specially testClass derived from AbstractTestAction. For this class a suite is + * created acting as a corresponding subclass of AbstractHibernateActionTest + */ + @Override + public void addTestSuite(Class testClass) { + if (AbstractTestAction.class.isAssignableFrom(testClass)) { + super.addTest(createTestForAction(testClass)); + } else { + super.addTestSuite(testClass); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/MultiCfgTestSuite.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/MultiCfgTestSuite.java new file mode 100755 index 000000000..c6bd7f0fc --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/MultiCfgTestSuite.java @@ -0,0 +1,151 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * Davide Marchignoli + * </copyright> + * + * $Id: MultiCfgTestSuite.java,v 1.5 2008/02/28 07:08:17 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.conf; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.test.AbstractActionTest; +import org.eclipse.emf.teneo.test.AbstractTest; +import org.eclipse.emf.teneo.test.AbstractTestAction; + +/** + * Test suite containing a subsuite for each configuration. + * + * @author Davide Marchignoli + * @author Martin Taal + * @version $Revision: 1.5 $ + */ +public class MultiCfgTestSuite extends TestSuite { + + /** map indexed by available configurations with values on ConfigurableTestSuite */ + private Map suitesByCfg = new HashMap(); + + /** Constructor */ + public MultiCfgTestSuite(String name, TestConfigurations availableCfgs) { + this(availableCfgs); + setName(name); + } + + /** Constructor with the available configs */ + public MultiCfgTestSuite(TestConfigurations availableCfgs) { + super(); + for (Iterator i = availableCfgs.getConfigurations().iterator(); i.hasNext();) { + TestConfiguration cfg = (TestConfiguration) i.next(); + ConfigurableTestSuite innerSuite = new ConfigurableTestSuite(cfg); + addTest(innerSuite); + suitesByCfg.put(cfg, innerSuite); + } + } + + /** Add one test suite for a specific config */ + protected void addTestSuite(Class testSuite, TestConfiguration cfg) { + ((ConfigurableTestSuite) suitesByCfg.get(cfg)).addTestSuite(testSuite); + } + + /** + * Adds a persistence XML test suite if the TestAction has an associated "<ActionClass>.persistence.xml" file. + * + * @param testActionClass + * @param testConfiguration + */ + private void addPersistenceXmlTestSuite(Class testActionClass, TestConfiguration testConfiguration) { + final AbstractTestAction testAction; + try { + testAction = (AbstractTestAction) testActionClass.newInstance(); + } catch (Exception e) { + throw new AssertionError(e); + } + + final String xmlPersistenceMappingPath = testAction.getPersistenceXmlPath(); + if (xmlPersistenceMappingPath != null) { + // Run this TestAction with XML persistence mapping. + final Properties properties = new Properties(); + properties.setProperty(PersistenceOptions.PERSISTENCE_XML, xmlPersistenceMappingPath); + // Ignore the existing EAnnotations, since we want to test only the XML mapping. + properties.setProperty(PersistenceOptions.IGNORE_EANNOTATIONS, "true"); + + TestSuite testSuite = new TestSuite(testActionClass.getName() + " (persistence.xml)"); + testSuite.addTest(new AbstractActionTest(testAction, properties)); + ((TestSuite) suitesByCfg.get(testConfiguration)).addTest(testSuite); + } + } + + /** Add one test suite for a specific config */ + protected void addTest(AbstractActionTest test, TestConfiguration cfg) { + ((ConfigurableTestSuite) suitesByCfg.get(cfg)).addTest(test); + } + + /** Add a test class */ + @Override + public void addTestSuite(Class testClass) { + if (AbstractTest.class.isAssignableFrom(testClass) || AbstractTestAction.class.isAssignableFrom(testClass)) { + for (Iterator i = suitesByCfg.keySet().iterator(); i.hasNext();) { + final TestConfiguration testConfiguration = (TestConfiguration) i.next(); + if (!testConfiguration.isXml()) { + addTestSuite(testClass, testConfiguration); + } else if (AbstractTestAction.class.isAssignableFrom(testClass)) { + addPersistenceXmlTestSuite(testClass, testConfiguration); + } + } + } else { + super.addTestSuite(testClass); + } + } + + /** Add a test action */ + public void addTest(AbstractActionTest test) { + for (Iterator i = suitesByCfg.keySet().iterator(); i.hasNext();) { + final TestConfiguration tc = (TestConfiguration) i.next(); + if (tc.isXml()) { + if (test.getTestAction().getPersistenceXmlPath() != null) { + if (test.getProperties() == null) { + test.setProperties(new Properties()); + } + final Properties properties = test.getProperties(); + properties.setProperty(PersistenceOptions.PERSISTENCE_XML, test.getTestAction() + .getPersistenceXmlPath()); + properties.setProperty(PersistenceOptions.IGNORE_EANNOTATIONS, "true"); + addTest(test, tc); + } + } else { + addTest(test, tc); + } + } + } + + /* + * (non-Javadoc) + * + * @see junit.framework.TestSuite#addTest(junit.framework.Test) + */ + @Override + public void addTest(Test test) { + if (test instanceof AbstractActionTest) { + addTest((AbstractActionTest) test); + } else { + super.addTest(test); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/TestConfiguration.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/TestConfiguration.java new file mode 100755 index 000000000..25a7b1d82 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/TestConfiguration.java @@ -0,0 +1,118 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * Davide Marchignoli + * </copyright> + * + * $Id: TestConfiguration.java,v 1.5 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.conf; + +import org.eclipse.emf.teneo.annotations.pannotation.InheritanceType; +import org.eclipse.emf.teneo.test.stores.TestDatabaseAdapter; + +/** + * Contains the parameters which define how the test should be run, for example inheritance mapping. + * + * @author Davide Marchignoli + * @author Martin Taal + * @version $Revision: 1.5 $ + */ +public class TestConfiguration { + + private final String name; + + private final TestDatabaseAdapter dbAdapter; + + private final InheritanceType mappingStrategy; + + private final boolean optimistic; + + private final boolean ejb3; + + private final boolean xml; + + /** Constructor */ + public TestConfiguration(String name, TestDatabaseAdapter dbAdapter, InheritanceType mappingStrategy, + boolean optimistic, boolean ejb3, boolean xml) { + this.name = name; + this.dbAdapter = dbAdapter; + this.mappingStrategy = mappingStrategy; + this.optimistic = optimistic; + this.ejb3 = ejb3; + this.xml = xml; + } + + /** ToString for logging */ + @Override + public String toString() { + StringBuffer s = new StringBuffer(); + s.append("HibernateTestConfiguration(name=").append(getName()).append(", dbAdapter=").append(getDbAdapter()) + .append(", ").append("mappingStrategy= ").append(getMappingStrategy().toString()).append(", ").append( + "optimistic= ").append(isOptimistic()); + return s.toString(); + } + + /** Hashcode computed on the basis of the contents of the configuration */ + @Override + public int hashCode() { + return getDbAdapter().hashCode() + getMappingStrategy().hashCode() + (isOptimistic() ? 1 : 0); + } + + /** Equal configuration */ + @Override + public boolean equals(Object other) { + if (other instanceof TestConfiguration) { + TestConfiguration otherCfg = (TestConfiguration) other; + return otherCfg.getDbAdapter() == getDbAdapter() && otherCfg.getMappingStrategy() == getMappingStrategy() && + otherCfg.isOptimistic() == isOptimistic() && otherCfg.isEjb3() == isEjb3() && + otherCfg.isXml() == isXml(); + } + ; + return false; + } + + /** The configuration name */ + public String getName() { + return name; + } + + /** Returns the test databaseadapter */ + public TestDatabaseAdapter getDbAdapter() { + return dbAdapter; + } + + /** Returns the current inheritance mapping */ + public InheritanceType getMappingStrategy() { + return mappingStrategy; + } + + /** Test optimistic locking */ + public boolean isOptimistic() { + return optimistic; + } + + /** + * @return the ejb3 + */ + public boolean isEjb3() { + return ejb3; + } + + /** + * @return the xml + */ + public boolean isXml() { + return xml; + } + +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/TestConfigurations.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/TestConfigurations.java new file mode 100755 index 000000000..7e994d75f --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/TestConfigurations.java @@ -0,0 +1,124 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * Davide Marchignoli + * </copyright> + * + * $Id: TestConfigurations.java,v 1.5 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.conf; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import org.eclipse.emf.teneo.annotations.pannotation.InheritanceType; +import org.eclipse.emf.teneo.test.Utils; +import org.eclipse.emf.teneo.test.stores.TestDBAdapters; +import org.eclipse.emf.teneo.test.stores.TestDatabaseAdapter; + +/** + * Manages multiple configurations + * + * @author Davide Marchignoli + * @author Martin Taal + * @version $Revision: 1.5 $ + */ +public class TestConfigurations { + + /** Map with configs */ + private Map cfgs = new LinkedHashMap(); + + /** The list of read database adapters */ + private final TestDBAdapters dbAdapters; + + /** Constructor */ + public TestConfigurations(TestDBAdapters dbAdapters) { + this.dbAdapters = dbAdapters; + } + + /** + * Add the given configuration. + * + * @throws NullPointerException + * if the argument is null + * @throws IllegalArgumentException + * if a configuration with the same name is already present + */ + public void addConfiguration(TestConfiguration cfg) { + if (cfgs.containsKey(cfg.getName())) { + throw new IllegalArgumentException("Duplicate configuration " + cfg.getName()); + } + cfgs.put(cfg.getName(), cfg); + } + + /** + * Add the configurations defined in a set of properties + * + * @param props + */ + public void addConfigurations(Properties props) { + Map hProps = Utils.hiearchizeProps(props); + + for (Iterator pNames = hProps.keySet().iterator(); pNames.hasNext();) { + String cfgName = (String) pNames.next(); + Properties cfgValues = (Properties) hProps.get(cfgName); + + TestDatabaseAdapter dbAdapter = dbAdapters.get(((String) cfgValues.get("dbadapter")).trim()); + InheritanceType mapStrategy = parseStrategy((String) cfgValues.get("mapstrategy")); + boolean optimistic = Boolean.valueOf((String) cfgValues.get("optimistic")).booleanValue(); + boolean ejb3 = + cfgValues.get("ejb3") != null ? Boolean.valueOf((String) cfgValues.get("ejb3")).booleanValue() + : false; + boolean xml = + cfgValues.get("xml") != null ? Boolean.valueOf((String) cfgValues.get("xml")).booleanValue() + : false; + addConfiguration(new TestConfiguration(cfgName, dbAdapter, mapStrategy, optimistic, ejb3, xml)); + } + } + + /** Add configuration */ + public void addConfigurations(InputStream propertiesStream) throws IOException { + Properties props = new Properties(); + props.load(propertiesStream); + addConfigurations(props); + } + + /** Determines the strategy */ + private InheritanceType parseStrategy(String s) { + InheritanceType inheritanceType = InheritanceType.get(s); + if (inheritanceType == null) { + throw new IllegalArgumentException("Unknown mapping strategy " + s); + } + return inheritanceType; + } + + /** Returns all configurations */ + public Collection getConfigurations() { + return cfgs.values(); + } + + /** Returns the names of the configurations */ + public Set getConfigurationNames() { + return cfgs.keySet(); + } + + /** Returns a specific configuration */ + public TestConfiguration getConfiguration(String name) { + return (TestConfiguration) cfgs.get(name); + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/Testbed.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/Testbed.java new file mode 100755 index 000000000..dd445f688 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/Testbed.java @@ -0,0 +1,168 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * Davide Marchignoli + * </copyright> + * + * $Id: Testbed.java,v 1.9 2010/02/06 20:50:51 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.conf; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.samples.SamplesSource; +import org.eclipse.emf.teneo.test.AbstractTest; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestDBAdapters; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * The test bed encapsulates the environment of a test action. It has 2 functions: 1) to encapsulate the possible + * configurations/dbadapters, and 2) to keep the current running configuration. + * + * @author Davide Marchignoli + * @author Martin Taal + * @version $Revision: 1.9 $ + */ +public abstract class Testbed { + /** The logger */ +// private static Log log = LogFactory.getLog(Testbed.class); + + /** The testbed instance */ + private static Testbed testBed = null; + + /** Return an instance of the testbed */ + public static Testbed instance() { + return testBed; + } + + /** Set the testbed */ + public static void setTestBed(Testbed setTestBed) { + testBed = setTestBed; + } + + /** Default naming of the current properties */ + public static final String DBADAPTERS_PROP_RESOURCE = "/dbadapters.properties"; + + public static final String TEST_CFG_PROP_RESOURCE = "/test.properties"; + + /** loaded dbAdapters and test configs */ + private TestDBAdapters dbAdapters; + + /** The list of configs (different test settings) which will be run */ + private TestConfigurations testConfigs; + + /** current configuration */ + private TestConfiguration currentCfg; + + /** + * Constructor, the constructor assumes that the test and db properties are located in the same location as the + * non-abstract subclass + */ + protected Testbed() { + dbAdapters = new TestDBAdapters(); + try { + dbAdapters.addDBAdapters(this.getClass().getResourceAsStream(DBADAPTERS_PROP_RESOURCE)); + testConfigs = new TestConfigurations(dbAdapters); + testConfigs.addConfigurations(getClass().getResourceAsStream(TEST_CFG_PROP_RESOURCE)); + currentCfg = (TestConfiguration) testConfigs.getConfigurations().iterator().next(); + } catch (IOException e) { + throw new StoreTestException("Unable to initialize TestSetting", e); + } + } + + /** + * Constructor, the constructor assumes that the test and db properties are located in the same location as the + * non-abstract subclass + */ + protected Testbed(String configPropertiesFile) { + dbAdapters = new TestDBAdapters(); + try { + dbAdapters.addDBAdapters(this.getClass().getResourceAsStream(DBADAPTERS_PROP_RESOURCE)); + testConfigs = new TestConfigurations(dbAdapters); + testConfigs.addConfigurations(getClass().getResourceAsStream(configPropertiesFile)); + currentCfg = (TestConfiguration) testConfigs.getConfigurations().iterator().next(); + } catch (IOException e) { + throw new StoreTestException("Unable to initialize TestSetting", e); + } + } + + /** + * Request a store for the given configuration. No other store can be requested until this one is tear down. + */ + public abstract TestStore createStore(AbstractTest testCase); + + /** Returns the database name */ + protected String getDbName(AbstractTest testCase, TestConfiguration cfg) { + // TODO maybe should shorten the name? + // first try in that direction, the testname is a classname + final String className = testCase.getName(); + return className.substring(className.lastIndexOf('.') + 1) + "_" + cfg.getName(); + } + + /** Returns the sourcelocations for the given epackages */ + protected String[] getSourceLocations(EPackage[] usedEPackages) throws FileNotFoundException { + String[] sourceLocations; + sourceLocations = new String[usedEPackages.length]; + for (int i = 0; i < usedEPackages.length; i++) + sourceLocations[i] = SamplesSource.getSourceDirectory(usedEPackages[i]).getAbsolutePath(); + return sourceLocations; + } + + /** Collects source files from a certain sourcedirectory and further */ + private void collectSourceFiles(ArrayList sourceFiles, File file) { + if (file.isDirectory()) { + collectSourceFiles(sourceFiles, file.listFiles()); + } + if (file.getName().endsWith(".java")) { + sourceFiles.add(file.getAbsolutePath()); + } + } + + /** Collects source files from the given sourcedirectories and further */ + private void collectSourceFiles(ArrayList sourceFiles, File[] dirs) { + for (int i = 0; i < dirs.length; i++) + collectSourceFiles(sourceFiles, dirs[i]); + } + + /** + * Deletes the current binary files private void deleteFiles(File directory) { File[] files = directory.listFiles(); + * for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { deleteFiles(files[i]); } if + * (files[i].getName().endsWith(".class") || files[i].getName().endsWith(".jdo")) files[i].delete(); } } + */ + + /** Get the current configuration, for which the current test is run */ + public TestConfiguration getActiveConfiguration() { + return currentCfg; + } + + /** And set the current configuration */ + public void setActiveConfiguration(TestConfiguration newConfiguration) { + if (!testConfigs.getConfigurations().contains(newConfiguration)) + throw new IllegalArgumentException("Cannot to switch to not configuration " + newConfiguration); + this.currentCfg = newConfiguration; + } + + /** Return the test configurations */ + public TestConfigurations getConfigurations() { + return testConfigs; + } + + /** Get the db Adapters */ + public TestDBAdapters getDBAdapters() { + return dbAdapters; + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/AssociationOverrideAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/AssociationOverrideAction.java new file mode 100755 index 000000000..cbb1911cb --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/AssociationOverrideAction.java @@ -0,0 +1,162 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal</copyright> + * $Id: AssociationOverrideAction.java,v 1.11 2010/02/06 18:25:53 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.List; +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.annotations.associationoverride.Address; +import org.eclipse.emf.teneo.samples.emf.annotations.associationoverride.AssociationoverrideFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.associationoverride.AssociationoverridePackage; +import org.eclipse.emf.teneo.samples.emf.annotations.associationoverride.Employee; +import org.eclipse.emf.teneo.samples.emf.annotations.associationoverride.Student; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Simple test for AssociationOverride. + */ +public class AssociationOverrideAction extends AbstractTestAction { + private static final String EMPLOYEE_DEPARTMENT = "R&D"; + + private static final String EMPLOYEE_NAME = "Piet Pietersen"; + + private static final String EMPLOYEE_VERIFICATION_QUERY = + "SELECT COUNT(*) FROM EMPLOYEE A INNER JOIN ADDRESS B ON A.EMPLOYEE_ADDRESS_ID = B.MYID".toLowerCase(); + + private static final AssociationoverrideFactory FACTORY = AssociationoverrideFactory.eINSTANCE; + + private static final Address DEFAULT_ADDRESS = FACTORY.createAddress(); + + private static final String STUDENT_FACULTY = "Biology"; + private static final String STUDENT_NAME = "Jan Janssen"; + + private static final String STUDENT_VERIFICATION_QUERY = + "SELECT COUNT(*) FROM STUDENT A INNER JOIN ADDRESS B ON A.ADDRESS_ADDRESS_E_ID = B.MYID".toLowerCase(); + + static { + DEFAULT_ADDRESS.setStreet("Amsterdamseweg 123"); + DEFAULT_ADDRESS.setPostalCode("1234 AZ"); + } + + public AssociationOverrideAction() { + super(AssociationoverridePackage.eINSTANCE); + } + + @Override + public void doAction(TestStore store) { + storeStudent(store); + storeEmployee(store); + testStudent(store); + testEmployee(store); + testTables(store); + } + + private Address getAddress() { + final Address address = FACTORY.createAddress(); + address.setStreet(DEFAULT_ADDRESS.getStreet()); + address.setPostalCode(DEFAULT_ADDRESS.getPostalCode()); + return address; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties() + */ + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.put(PersistenceOptions.ID_COLUMN_NAME, "myid"); + return props; + } + + private void storeEmployee(TestStore store) { + store.beginTransaction(); + final Employee employee = FACTORY.createEmployee(); + employee.setName(EMPLOYEE_NAME); + employee.setDepartment(EMPLOYEE_DEPARTMENT); + employee.setAddress(getAddress()); + store.store(employee); + store.commitTransaction(); + } + + private void storeStudent(TestStore store) { + store.beginTransaction(); + final Student student = FACTORY.createStudent(); + student.setName(STUDENT_NAME); + student.setAddress(getAddress()); + student.setFaculty(STUDENT_FACULTY); + store.store(student); + store.commitTransaction(); + } + + private void testAddress(Address address) { + assertEquals(DEFAULT_ADDRESS.getStreet(), address.getStreet()); + assertEquals(DEFAULT_ADDRESS.getPostalCode(), address.getPostalCode()); + } + + private void testEmployee(TestStore store) { + store.beginTransaction(); + final List<?> results = store.query("select e from Employee e"); + assertEquals(1, results.size()); + final Employee employee = (Employee) results.get(0); + assertEquals(EMPLOYEE_NAME, employee.getName()); + assertEquals(EMPLOYEE_DEPARTMENT, employee.getDepartment()); + testAddress(employee.getAddress()); + store.commitTransaction(); + } + + private void testStudent(TestStore store) { + store.beginTransaction(); + final List<?> results = store.query("select s from Student s"); + assertEquals(1, results.size()); + final Student student = (Student) results.get(0); + assertEquals(STUDENT_NAME, student.getName()); + assertEquals(STUDENT_FACULTY, student.getFaculty()); + testAddress(student.getAddress()); + store.commitTransaction(); + } + + private void testTables(TestStore store) { + final Connection conn = store.getConnection(); + Statement stmt = null; + ResultSet rs = null; + try { + stmt = conn.createStatement(); + rs = stmt.executeQuery(STUDENT_VERIFICATION_QUERY); + rs.next(); + assertEquals(1, rs.getInt(1)); + rs.close(); + rs = stmt.executeQuery(EMPLOYEE_VERIFICATION_QUERY); + rs.next(); + assertEquals(1, rs.getInt(1)); + } catch (final SQLException e) { + assertTrue(e.getMessage(), false); + } finally { + try { + if (stmt != null) { + stmt.close(); + } + } catch (final SQLException e) { + } + try { + if (rs != null) { + rs.close(); + } + } catch (final SQLException e) { + } + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/AssociationOverrideAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/AssociationOverrideAction.persistence.xml new file mode 100755 index 000000000..ffe805777 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/AssociationOverrideAction.persistence.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/associationoverride"> + + <eclass name="Person"> + <mapped-superclass /> + <property name="id"> + <id /> + </property> + <property name="address"> + <many-to-one /> + </property> + </eclass> + + <eclass name="Employee"> + <association-override name="address"> + <join-column name="employee_address_id"/> + </association-override> + </eclass> + + </epackage> + +</persistence-mapping>
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/AttributeOverridesAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/AttributeOverridesAction.java new file mode 100755 index 000000000..9526931db --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/AttributeOverridesAction.java @@ -0,0 +1,60 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: AttributeOverridesAction.java,v 1.5 2008/05/27 07:42:12 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import org.eclipse.emf.teneo.samples.emf.annotations.attributeoverrides.AttributeoverridesFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.attributeoverrides.AttributeoverridesPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.attributeoverrides.City; +import org.eclipse.emf.teneo.samples.emf.annotations.attributeoverrides.Person; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.5 $ + */ +public class AttributeOverridesAction extends AbstractTestAction { + /** + * Constructor + */ + public AttributeOverridesAction() { + super(AttributeoverridesPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final AttributeoverridesFactory factory = AttributeoverridesFactory.eINSTANCE; + { + store.beginTransaction(); + final City bornIn = factory.createCity(); + bornIn.setCountry("Singapore"); + bornIn.setName("Singapore"); + final City livesIn = factory.createCity(); + livesIn.setCountry("Netherlands"); + livesIn.setName("Doorn"); + final Person person = factory.createPerson(); + person.setName("Martin"); + person.setBornIn(bornIn); + person.setLivesIn(livesIn); + store.store(person); + store.commitTransaction(); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/BasicAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/BasicAction.java new file mode 100755 index 000000000..ed08c8a39 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/BasicAction.java @@ -0,0 +1,63 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: BasicAction.java,v 1.4 2008/02/28 07:08:14 mtaal Exp $ + */ +package org.eclipse.emf.teneo.test.emf.annotations; + +import org.eclipse.emf.teneo.samples.emf.annotations.basic.Basic; +import org.eclipse.emf.teneo.samples.emf.annotations.basic.BasicFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.basic.BasicPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.4 $ + */ +public class BasicAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * @param arg0 + */ + public BasicAction() { + super(BasicPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final BasicFactory factory = BasicFactory.eINSTANCE; + { + store.beginTransaction(); + + final Basic basic = factory.createBasic(); + // do not set optional as it is optional + // basic.setMyOptionalBasic("optional"); + basic.setMyTransient("transient"); + basic.setMyVersion(100); + store.store(basic); + store.commitTransaction(); + } + + // read back and check it + { + store.beginTransaction(); + final Basic basic = (Basic) store.getObject(Basic.class); + assertTrue("Transient field should not be set", basic.getMyTransient() == null); + store.commitTransaction(); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/BookAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/BookAction.java new file mode 100755 index 000000000..61c0bddc2 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/BookAction.java @@ -0,0 +1,136 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: BookAction.java,v 1.12 2008/05/27 07:42:12 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.math.BigDecimal; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import org.eclipse.emf.teneo.samples.emf.annotations.column.Book; +import org.eclipse.emf.teneo.samples.emf.annotations.column.ColumnFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.column.ColumnPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.HsqldbTestDatabaseAdapter; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.12 $ + */ +public class BookAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public BookAction() { + super(ColumnPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final BigDecimal testDbl = new BigDecimal("12456677.90123"); + final ColumnFactory factory = ColumnFactory.eINSTANCE; + try { + store.beginTransaction(); + final Book book = factory.createBook(); + book.setAuthor("martin"); + book.setTitle("012345678901234567890123456789"); + book.setPages(1000); + book.setWeight(new BigDecimal("12456677.90123")); + store.store(book); + store.commitTransaction(); + } catch (final Exception e) { + // in this case the constraint checking fails directly stop with this + return; + } + + // check unique constraint on title column + { + try { + store.beginTransaction(); + final Book book = factory.createBook(); + book.setAuthor("martin"); + book.setTitle("012345678901234567890123456789"); + book.setPages(1000); + book.setWeight(new BigDecimal("12456677.90123")); + store.store(book); + store.commitTransaction(); + fail("The unique constraint on title is violated"); + } catch (final Exception e) { + // no fail, this good + store.rollbackTransaction(); + } + } + + // read back and check it + { + store.beginTransaction(); + final Book book = store.getObject(Book.class); + // hsqldb does not support column length, at least not in in-mem mode + if (!(store.getDatabaseAdapter() instanceof HsqldbTestDatabaseAdapter)) { + assertTrue("The length of the booktitle should not be more than 25: " + book.getTitle().length(), book + .getTitle().length() <= 25); + assertTrue("Only a precision of 5 is defined, so weight is not correctly stored as it has more digits", + Math.abs(testDbl.subtract(book.getWeight()).doubleValue()) > 1.0); + } + book.setWeight(new BigDecimal("25.5")); + store.store(book); + store.commitTransaction(); + } + + // check if the column names have landed + { + Connection conn = null; + Statement stmt = null; + try { + conn = store.getConnection(); + stmt = conn.createStatement(); + final ResultSet rs = stmt.executeQuery("SELECT * FROM mybooktable WHERE titel='' AND gewicht IS NULL"); + assertTrue(rs != null); // dummy to get rid of warning + } catch (final SQLException s) { + throw new StoreTestException("SQL Exception", s); + } finally { + try { + if (stmt != null) { + stmt.close(); + } + if (conn != null) { + conn.close(); + } + } catch (final SQLException s) { + throw new StoreTestException("SQL Exception", s); + } + } + } + + // read back and check it + { + store.beginTransaction(); + final Book book = store.getObject(Book.class); + assertTrue(255 == (int) (book.getWeight().doubleValue() * 10)); + store.store(book); + store.commitTransaction(); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/CascadeNotallAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/CascadeNotallAction.java new file mode 100755 index 000000000..5cb13975f --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/CascadeNotallAction.java @@ -0,0 +1,231 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: CascadeNotallAction.java,v 1.11 2008/02/28 07:08:14 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.io.IOException; +import java.util.Properties; + +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.samples.emf.annotations.cascadenotall.Book; +import org.eclipse.emf.teneo.samples.emf.annotations.cascadenotall.BookCategory; +import org.eclipse.emf.teneo.samples.emf.annotations.cascadenotall.CascadenotallFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.cascadenotall.CascadenotallPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.cascadenotall.Library; +import org.eclipse.emf.teneo.samples.emf.annotations.cascadenotall.Writer; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests the library example without orphan delete or dependent element + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.11 $ + */ +public class CascadeNotallAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public CascadeNotallAction() { + super(CascadenotallPackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty("org.jpox.deletionPolicy", "JDO2"); + return props; + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final CascadenotallFactory factory = CascadenotallFactory.eINSTANCE; + + // create a book, writer and library + try { + { + final Resource res = store.getResource(); + res.load(null); + + final Writer writer = factory.createWriter(); + writer.setName("JRR Tolkien"); + + final Book book = factory.createBook(); + book.setAuthor(writer); + book.setPages(510); + book.setTitle("Fellowship of the Ring"); + book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Book book2 = factory.createBook(); + book2.setAuthor(writer); + book2.setPages(500); + book2.setTitle("The Hobbit"); + book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + // sorry george making a mistake here, will correct this below + final Book book3 = factory.createBook(); + book3.setAuthor(writer); + book3.setPages(500); + book3.setTitle("1984"); + book3.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Library library = factory.createLibrary(); + library.setName("Science Fiction"); + library.getBooks().add(book); + library.getBooks().add(book2); + library.getBooks().add(book3); + library.getWriters().add(writer); + + res.getContents().add(library); + res.save(null); + res.save(null); + res.unload(); + } + + // walk through the structure starting from the library + { + final Resource res = store.getResource(); + res.load(null); + + final Library lib = (Library) res.getContents().get(0); + + final Writer tolkien = lib.getWriters().get(0); + + /* + * final Object[] obj = ((StoreResource)res).getCrossReferencers(tolkien); for (int + * i = 0; i < obj.length; i++) { + */ + + /* + * assertEquals(3, tolkien.getBooks().size()); + * + * assertEquals(0 , tolkien.getName().compareTo("JRR Tolkien")); Book wBook = + * (Book)tolkien.getBooks().get(0); Book lBook = (Book)lib.getBooks().get(0); + * assertTrue("Book is contained in the library", wBook.eContainer() == lib); + * assertTrue("Book is contained in the library", lBook.eContainer() == lib); + * + * assertTrue(lBook.getAuthor() == tolkien); + * assertTrue(tolkien.getBooks().contains(lBook)); + * assertTrue(tolkien.getBooks().contains(wBook)); // ordering is the same + * assertTrue(wBook.getTitle().compareTo(lBook.getTitle()) == 0); + * assertTrue(wBook.getPages() == lBook.getPages()); assertTrue(wBook.getCategory() + * instanceof BookCategory); assertTrue(wBook.getCategory() == + * BookCategory.SCIENCE_FICTION_LITERAL); + */ + // correct the mistake we made + final Book orwellsBook = tolkien.getBooks().get(2); + assertTrue(orwellsBook.getTitle().compareTo("1984") == 0); + + // add orwell as a writer + final Writer george = factory.createWriter(); + george.setName("George Orwell"); + orwellsBook.setAuthor(george); + + // and put george in our library + lib.getWriters().add(george); + + assertEquals(2, tolkien.getBooks().size()); + + // and save it all + res.save(null); + res.save(null); + + george.setName("G. Orwell"); // there was a bug in which this failed, reported by + // Georgi Manev + res.save(null); + res.save(null); + res.unload(); + } + + // TODO put in JPOX specific test code + // // now retrieve the writer using a simple query + // if (store instanceof JPOXTestStore) + // { + // store.beginTransaction(); + // Writer george = (Writer)store.query("SELECT FROM " + + // JPOXHelper.INSTANCE.getInstanceClassName(Writer.class) + + // " WHERE name == \"G. Orwell\"", 1).get(0); + // assertTrue(george.getBooks().size() == 1); + // Book georgesBook = (Book)george.getBooks().get(0); + // assertTrue(georgesBook.getAuthor() == george); + // store.commitTransaction(); + // } + } catch (final IOException e) { + throw new StoreTestException("IOException during save", e); + } + + try { + final Resource res = store.getResource(); + res.load(null); + + final Library lib = (Library) res.getContents().get(0); + + final Writer writer = lib.getWriters().get(0); + + final Library newLib = factory.createLibrary(); + newLib.setName("tstlib"); + res.getContents().add(newLib); + + // this save was required to get the entitymanager working + // because if not there then newLib would not have been saved and + // the persistent writer would through its econtainer relation point + // to a non-saved newLib resulting in transient errors. + res.save(null); + assertTrue(lib.getBooks().size() > 0); // force load of books to prevent dangling error + // in jpox + lib.getWriters().remove(writer); + newLib.getWriters().add(writer); + res.save(null); + res.unload(); + + } catch (final IOException e) { + throw new StoreTestException("IOException during save", e); + } + + // and check if cascade delete works! + + try { + final Resource res = store.getResource(); + res.load(null); + + final Library lib = (Library) res.getContents().get(0); + + assertTrue(lib.getName() != null); // get rid of warning + + // delete both libraries + res.getContents().remove(0); + res.getContents().remove(0); + res.save(null); + res.unload(); + } catch (final IOException e) { + throw new StoreTestException("IOException during save", e); + } + + store.beginTransaction(); + store.checkNumber(Writer.class, 0); + store.checkNumber(Book.class, 0); + store.checkNumber(Library.class, 0); + store.commitTransaction(); + } + + protected boolean hibernateEnabled() { + return true; + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/CascadeNotallAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/CascadeNotallAction.persistence.xml new file mode 100755 index 000000000..6f6d3153c --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/CascadeNotallAction.persistence.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="utf-8"?> +<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <!-- Template for TestAction persistence mapping. --> + + <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/cascadenotall"> + + <eclass name="Writer"> + <property name="books"> + <one-to-many target-entity="Book" mapped-by="author"> + <cascade>MERGE</cascade> + <cascade>PERSIST</cascade> + </one-to-many> + </property> + </eclass> + + <eclass name="Library"> + <property name="writers"> + <one-to-many> + <cascade>MERGE</cascade> + <cascade>PERSIST</cascade> + <cascade>REFRESH</cascade> + <cascade>REMOVE</cascade> + </one-to-many> + </property> + <property name="books"> + <one-to-many> + <cascade>MERGE</cascade> + <cascade>PERSIST</cascade> + <cascade>REFRESH</cascade> + <cascade>REMOVE</cascade> + </one-to-many> + </property> + </eclass> + + </epackage> + +</persistence-mapping>
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/CompositeIdAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/CompositeIdAction.java new file mode 100755 index 000000000..cd2b8fdba --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/CompositeIdAction.java @@ -0,0 +1,64 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * CompositeIdAction.java,v 1.2 2007/02/01 12:35:36 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import org.eclipse.emf.teneo.samples.emf.annotations.compositeid.Child; +import org.eclipse.emf.teneo.samples.emf.annotations.compositeid.CompositeidFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.compositeid.CompositeidPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.compositeid.Parent; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.5 $ + */ +public class CompositeIdAction extends AbstractTestAction { + /** + * Constructor + */ + public CompositeIdAction() { + super(CompositeidPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final CompositeidFactory factory = CompositeidFactory.eINSTANCE; + { + store.beginTransaction(); + final Parent parent = factory.createParent(); + parent.setFirstName("John"); + parent.setLastName("Smith"); + final Child child1 = factory.createChild(); + child1.setFirstName("Johnny"); + child1.setLastName("Smith"); + parent.getChildren().add(child1); + final Child child2 = factory.createChild(); + child2.setFirstName("Jane"); + child2.setLastName("Smith"); + parent.getChildren().add(child2); + store.store(parent.getChildren()); + store.store(parent); + store.commitTransaction(); + } + + // read again + { + store.beginTransaction(); + final Parent parent = (Parent) store.getObject(Parent.class); + assertEquals(2, parent.getChildren().size()); + assertEquals("Johnny", parent.getChildren().get(0).getFirstName()); + assertEquals("Jane", parent.getChildren().get(1).getFirstName()); + store.commitTransaction(); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/DuplicatesAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/DuplicatesAction.java new file mode 100755 index 000000000..2e82d6123 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/DuplicatesAction.java @@ -0,0 +1,66 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * DuplicatesAction.java,v 1.3 2007/02/05 15:35:34 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import org.eclipse.emf.teneo.samples.emf.annotations.duplicates.ChildItem; +import org.eclipse.emf.teneo.samples.emf.annotations.duplicates.DuplicatesFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.duplicates.DuplicatesPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.duplicates.Item; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.5 $ + */ +public class DuplicatesAction extends AbstractTestAction { + /** No of childitems */ + private static final int NO_CHILDS = 5; + + /** + * Constructor + */ + public DuplicatesAction() { + super(DuplicatesPackage.eINSTANCE); + } + + /** Test */ + @Override + public void doAction(TestStore store) { + final DuplicatesFactory factory = DuplicatesFactory.eINSTANCE; + // create a book, writer and library + { + store.beginTransaction(); + + final Item item = factory.createItem(); + final ChildItem ci = factory.createChildItem(); + ci.setName("mychild"); + for (int i = 0; i < NO_CHILDS; i++) { + item.getChildItem().add(ci); + } + + item.setName("myitem"); + store.store(item); + store.commitTransaction(); + } + + // read back and check it + { + store.beginTransaction(); + final Item item = (Item) store.getObject(Item.class); + // assertEquals(NO_CHILDS, item.getChildItem().size()); + for (int i = 0; i < item.getChildItem().size(); i++) { + assertTrue(item.getChildItem().get(i) == item.getChildItem().get(0)); + } + store.commitTransaction(); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EDataTypeAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EDataTypeAction.java new file mode 100755 index 000000000..cede45ad8 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EDataTypeAction.java @@ -0,0 +1,136 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: EDataTypeAction.java,v 1.9 2008/07/13 13:13:39 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.math.BigDecimal; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import org.eclipse.emf.teneo.samples.emf.annotations.edatatypeColumn.Book; +import org.eclipse.emf.teneo.samples.emf.annotations.edatatypeColumn.EdatatypeColumnFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.edatatypeColumn.EdatatypeColumnPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.HsqldbTestDatabaseAdapter; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.9 $ + */ +public class EDataTypeAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public EDataTypeAction() { + super(EdatatypeColumnPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final BigDecimal testDbl = new BigDecimal("12456677.90123"); + final EdatatypeColumnFactory factory = EdatatypeColumnFactory.eINSTANCE; + try { + store.beginTransaction(); + final Book book = factory.createBook(); + book.setAuthor("martin"); + book.setTitle("012345678901234567890123456789"); + book.setPages(1000); + book.setWeight(new BigDecimal("12456677.90123")); + store.store(book); + store.commitTransaction(); + } catch (final Exception e) { + // in this case the constraint checking fails directly stop with this + return; + } + + // check unique constraint on title column + { + try { + store.beginTransaction(); + final Book book = factory.createBook(); + book.setAuthor("martin"); + book.setTitle("012345678901234567890123456789"); + book.setPages(1000); + book.setWeight(new BigDecimal("12456677.90123")); + store.store(book); + store.commitTransaction(); + fail("The unique constraint on title is violated"); + } catch (final Exception e) { + // no fail, this good + store.rollbackTransaction(); + } + } + + // read back and check it + { + store.beginTransaction(); + final Book book = store.getObject(Book.class); + // hsqldb does not support column length, at least not in in-mem mode + if (!(store.getDatabaseAdapter() instanceof HsqldbTestDatabaseAdapter)) { + assertTrue("The length of the booktitle should not be more than 25: " + book.getTitle().length(), book + .getTitle().length() <= 25); + assertTrue("Only a precision of 5 is defined, so weight is not correctly stored as it has more digits", + Math.abs(testDbl.subtract(book.getWeight()).doubleValue()) > 1.0); + } + book.setWeight(new BigDecimal("25.5")); + store.store(book); + store.commitTransaction(); + } + + // check if the column names have landed + { + Connection conn = null; + Statement stmt = null; + try { + conn = store.getConnection(); + stmt = conn.createStatement(); + final ResultSet rs = stmt.executeQuery("SELECT * FROM mybooktable WHERE titel='' AND gewicht IS NULL"); + assertTrue(rs != null); // dummy to get rid of warning + } catch (final SQLException s) { + throw new StoreTestException("SQL Exception", s); + } finally { + try { + if (stmt != null) { + stmt.close(); + } + if (conn != null) { + conn.close(); + } + } catch (final SQLException s) { + throw new StoreTestException("SQL Exception", s); + } + } + } + + // read back and check it + { + store.beginTransaction(); + final Book book = store.getObject(Book.class); + assertTrue(255 == (int) (book.getWeight().doubleValue() * 10)); + store.store(book); + store.commitTransaction(); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EDataTypeAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EDataTypeAction.persistence.xml new file mode 100755 index 000000000..9f25cf029 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EDataTypeAction.persistence.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/edatatype_column"> + + <eclass name="Book"> + <table name="mybooktable"/> + <property name="title"> + <column name="titel" unique="true" length="25"/> + </property> + </eclass> + + <edatatype name="TitleType"> + <column name="mytitle" unique="false" length="50"/> + </edatatype> + <edatatype name="PagesType"> + <column updatable="false" insertable="false"/> + </edatatype> + <edatatype name="WeightType"> + <column name="gewicht" nullable="true" precision="5" scale="2"/> + </edatatype> + + </epackage> +</persistence-mapping> diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EmbeddedAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EmbeddedAction.java new file mode 100755 index 000000000..10d18e99d --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EmbeddedAction.java @@ -0,0 +1,156 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: EmbeddedAction.java,v 1.8 2010/04/23 08:52:55 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.annotations.embedded.AOneToMany; +import org.eclipse.emf.teneo.samples.emf.annotations.embedded.AlsoEmbeddable; +import org.eclipse.emf.teneo.samples.emf.annotations.embedded.AnotherEmbeddable; +import org.eclipse.emf.teneo.samples.emf.annotations.embedded.Embeddable; +import org.eclipse.emf.teneo.samples.emf.annotations.embedded.EmbeddedFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.embedded.EmbeddedPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.embedded.Embedder; +import org.eclipse.emf.teneo.samples.emf.annotations.embedded.NestedEmbeddable; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.8 $ + */ +public class EmbeddedAction extends AbstractTestAction { + /** + * Constructor + * + * @param arg0 + */ + public EmbeddedAction() { + super(EmbeddedPackage.eINSTANCE); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties() + */ + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.MAP_EMBEDDABLE_AS_EMBEDDED, "true"); + return props; + } + + /** Just create and store an embedded and see if it all worked without column name clashes */ + @Override + public void doAction(TestStore store) { + final EmbeddedFactory factory = EmbeddedFactory.eINSTANCE; + { + store.beginTransaction(); + final Embedder embedder = factory.createEmbedder(); + { + final Embeddable ea = factory.createEmbeddable(); + ea.setMyInteger(1); + ea.setMyString("string"); + embedder.setFirstEmbedded(ea); + } + + { + final Embeddable ea = factory.createEmbeddable(); + ea.setMyInteger(2); + ea.setMyString("string"); + embedder.setSecondEmbedded(ea); + } + + { + final Embeddable ea = factory.createEmbeddable(); + ea.setMyInteger(3); + ea.setMyString("string"); + embedder.setThirdEmbedded(ea); + } + + { + final Embeddable ea = factory.createEmbeddable(); + ea.setMyInteger(4); + ea.setMyString("string"); + embedder.getFourthEmbedded().add(ea); + + final Embeddable ea2 = factory.createEmbeddable(); + ea2.setMyInteger(5); + ea2.setMyString("string5"); + embedder.getFourthEmbedded().add(ea2); + } + + { + final Embeddable ea = factory.createEmbeddable(); + ea.setMyInteger(6); + ea.setMyString("fifthstring"); + embedder.setFifthEmbedded(ea); + } + + final AnotherEmbeddable anotherEmbeddable = factory.createAnotherEmbeddable(); + anotherEmbeddable.setName("name"); + anotherEmbeddable.setAnotherName("anotherName"); + + final AOneToMany aOneToMany1 = factory.createAOneToMany(); + aOneToMany1.setName("1"); + anotherEmbeddable.getAOneToMany().add(aOneToMany1); + + final AOneToMany aOneToMany2 = factory.createAOneToMany(); + aOneToMany2.setName("2"); + anotherEmbeddable.getAOneToMany().add(aOneToMany2); + + final NestedEmbeddable nestedEmbeddable = factory.createNestedEmbeddable(); + nestedEmbeddable.setNestedName("nestName"); + anotherEmbeddable.setNestedEmbedded(nestedEmbeddable); + + embedder.setAnotherEmbedded(anotherEmbeddable); + + final AlsoEmbeddable ae = factory.createAlsoEmbeddable(); + ae.setName("me"); + embedder.setAlsoEmbeddable(ae); + + store.store(embedder); + store.commitTransaction(); + } + { + store.beginTransaction(); + final Embedder embedder = store.getObject(Embedder.class); + assertEquals(1, embedder.getFirstEmbedded().getMyInteger()); + assertEquals(2, embedder.getSecondEmbedded().getMyInteger()); + assertEquals(3, embedder.getThirdEmbedded().getMyInteger()); + assertEquals(4, (embedder.getFourthEmbedded().get(0)).getMyInteger()); + assertEquals(5, (embedder.getFourthEmbedded().get(1)).getMyInteger()); + assertEquals(6, embedder.getFifthEmbedded().getMyInteger()); + assertEquals("me", embedder.getAlsoEmbeddable().getName()); + + final AnotherEmbeddable ae = embedder.getAnotherEmbedded(); + assertEquals("anotherName", ae.getAnotherName()); + assertEquals("name", ae.getName()); + assertEquals(2, ae.getAOneToMany().size()); + assertEquals("1", ae.getAOneToMany().get(0).getName()); + assertEquals("2", ae.getAOneToMany().get(1).getName()); + assertNotNull(ae.getNestedEmbedded()); + assertEquals("nestName", ae.getNestedEmbedded().getNestedName()); + + store.commitTransaction(); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EmbeddedIdAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EmbeddedIdAction.java new file mode 100755 index 000000000..650b9f614 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EmbeddedIdAction.java @@ -0,0 +1,59 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * EmbeddedIdAction.java,v 1.3 2007/03/20 23:33:38 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.util.List; + +import org.eclipse.emf.teneo.samples.emf.annotations.embeddedid.EmbeddedidFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.embeddedid.EmbeddedidPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.embeddedid.Name; +import org.eclipse.emf.teneo.samples.emf.annotations.embeddedid.Person; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +public class EmbeddedIdAction extends AbstractTestAction { + + private static final String ADDRESS = "Amsterdamseweg 123, 4567AZ Amsterdam"; + private static final String FIRST_NAME = "Jan"; + private static final String LAST_NAME = "Janssen"; + + public EmbeddedIdAction() { + super(EmbeddedidPackage.eINSTANCE); + } + + @Override + public void doAction(TestStore store) { + storePerson(store); + testPerson(store); + } + + private void storePerson(TestStore store) { + final Person person = EmbeddedidFactory.eINSTANCE.createPerson(); + final Name name = EmbeddedidFactory.eINSTANCE.createName(); + name.setFirstName(FIRST_NAME); + name.setLastName(LAST_NAME); + person.setName(name); + person.setAddress(ADDRESS); + store.beginTransaction(); + store.store(person); + store.commitTransaction(); + } + + private void testPerson(TestStore store) { + store.beginTransaction(); + final List<?> persons = store.query("select p from Person p"); + assertEquals(1, persons.size()); + final Person person = (Person) persons.get(0); + assertEquals(FIRST_NAME, person.getName().getFirstName()); + assertEquals(LAST_NAME, person.getName().getLastName()); + assertEquals(ADDRESS, person.getAddress()); + store.commitTransaction(); + } + +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EmbeddedIdAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EmbeddedIdAction.persistence.xml new file mode 100755 index 000000000..c27dbc6dd --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EmbeddedIdAction.persistence.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/embeddedid"> + + <eclass name="Person"> + <property name="name"> + <embedded-id /> + </property> + <property name="address"> + <lob /> + </property> + </eclass> + + <eclass name="Name"> + <embeddable /> + </eclass> + + </epackage> + +</persistence-mapping>
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EntityAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EntityAction.java new file mode 100755 index 000000000..53d3f724a --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EntityAction.java @@ -0,0 +1,112 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * LazyLibraryAction.java,v 1.9 2007/03/29 15:00:32 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.List; + +import org.eclipse.emf.teneo.samples.emf.annotations.entity.Book; +import org.eclipse.emf.teneo.samples.emf.annotations.entity.EntityFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.entity.EntityPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.entity.Writer; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests extra lazy fetch strategy. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.2 $ + */ +public class EntityAction extends AbstractTestAction { + + private static final String CHECK_QUERY = "SELECT COUNT(*) FROM BOEK".toLowerCase(); + + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public EntityAction() { + super(EntityPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final EntityFactory factory = EntityFactory.eINSTANCE; + { + Book b1 = factory.createBook(); + b1.setTitle("b1"); + Book b2 = factory.createBook(); + b2.setTitle("b2"); + Writer w1 = factory.createWriter(); + w1.setName("w1"); + Writer w2 = factory.createWriter(); + w2.setName("w2"); + store.beginTransaction(); + store.store(b1); + store.store(b2); + store.store(w1); + store.store(w2); + store.commitTransaction(); + } + { + store.beginTransaction(); + List<?> l = store.query("select b from Boek as b order by b.title"); + int i = 1; + for (Object o : l) { + Book b = (Book) o; + assertEquals(b.getTitle(), "b" + i++); + } + + l = store.query("select w from Schrijver as w order by w.name"); + i = 1; + for (Object o : l) { + Writer w = (Writer) o; + assertEquals(w.getName(), "w" + i++); + } + store.deleteObject(l.get(0)); + store.commitTransaction(); + } + testTable(store); + } + + private void testTable(TestStore store) { + final Connection conn = store.getConnection(); + Statement stmt = null; + ResultSet rs = null; + try { + stmt = conn.createStatement(); + rs = stmt.executeQuery(CHECK_QUERY); + rs.next(); + assertEquals(2, rs.getInt(1)); + rs.close(); + } catch (final SQLException e) { + assertTrue(e.getMessage(), false); + } finally { + try { + if (stmt != null) { + stmt.close(); + } + } catch (final SQLException e) { + } + try { + if (rs != null) { + rs.close(); + } + } catch (final SQLException e) { + } + } + } + +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ExternalAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ExternalAction.java new file mode 100755 index 000000000..a246f2f74 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ExternalAction.java @@ -0,0 +1,137 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: ExternalAction.java,v 1.2 2011/02/27 20:10:33 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.util.Collections; + +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.ecore.util.EcoreUtil; +import org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl; +import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; +import org.eclipse.emf.teneo.TeneoException; +import org.eclipse.emf.teneo.samples.emf.annotations.external.ExternalFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.external.ExternalPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.external.ExternalTest; +import org.eclipse.emf.teneo.samples.emf.sample.play.ActType; +import org.eclipse.emf.teneo.samples.emf.sample.play.FmType; +import org.eclipse.emf.teneo.samples.emf.sample.play.PersonaeType; +import org.eclipse.emf.teneo.samples.emf.sample.play.PlayPackage; +import org.eclipse.emf.teneo.samples.emf.sample.play.PlayType; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.2 $ + */ +public class ExternalAction extends AbstractTestAction { + public ExternalAction() { + // touch the play package + super(ExternalPackage.eINSTANCE); + if (PlayPackage.eINSTANCE != null) { + // initialized + } + + } + + @Override + public void doAction(TestStore store) { + final ExternalFactory factory = ExternalFactory.eINSTANCE; + + EObject o1; + EObject o2; + EObject o3; + try { + // a file handle to the current class + // the play.xml is in the model directory + final URI uri = URI.createURI(this.getClass() + .getResource("small_play.xml").toString()); + final Resource resource = new XMLResourceImpl(uri); + resource.load(Collections.EMPTY_MAP); + PlayType play = (PlayType) resource.getContents().get(0); + o1 = play.getAct().get(0); + o2 = play.getPersonae(); + o3 = play.getFm(); + + // resource.unload(); + } catch (Exception e) { + throw new TeneoException(e.getMessage(), e); + } + + { + store.beginTransaction(); + final ExternalTest et1 = factory.createExternalTest(); + et1.setName("et1"); + et1.setEObject(o1); + et1.getEObjects().add(o3); + et1.getEObjects().add(o1); + et1.getEObjects().add(o2); + et1.setEClass(ExternalPackage.eINSTANCE.getExternalTest()); + store.store(et1); + final ExternalTest et2 = factory.createExternalTest(); + et2.setName("et2"); + et2.setEObject(o2); + et2.setEClass(ExternalPackage.eINSTANCE.getExternalTest()); + store.store(et2); + store.commitTransaction(); + + EcoreUtil.resolveAll(et2); + } + + try { + final Resource res = store.getResource(); + final ResourceSet rs = new ResourceSetImpl(); + rs.getResourceFactoryRegistry().getExtensionToFactoryMap() + .put("xml", new XMLResourceFactoryImpl()); + rs.getResources().add(res); + res.load(Collections.EMPTY_MAP); + + for (EObject eobj : res.getContents()) { + final ExternalTest et = (ExternalTest) eobj; + if (et.getName().equals("et1")) { + assertTrue(et.getEObject() instanceof ActType); + int cnt = 0; + assertEquals(3, et.getEObjects().size()); + for (EObject eo : et.getEObjects()) { + if (cnt == 0) { + assertTrue(eo instanceof FmType); + } + if (cnt == 1) { + assertTrue(eo instanceof ActType); + } + if (cnt == 2) { + assertTrue(eo instanceof PersonaeType); + } + cnt++; + } + } else { + assertTrue(et.getEObject() instanceof PersonaeType); + } + assertEquals(et.getEClass(), + ExternalPackage.eINSTANCE.getExternalTest()); + } + } catch (Exception e) { + throw new TeneoException(e.getMessage(), e); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ForcedIdBagAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ForcedIdBagAction.java new file mode 100755 index 000000000..c75e8201c --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ForcedIdBagAction.java @@ -0,0 +1,114 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * ForcedIdBagAction.java,v 1.1 2007/03/21 15:45:24 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.annotations.forcedidbag.ForcedidbagFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.forcedidbag.ForcedidbagPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.forcedidbag.Role; +import org.eclipse.emf.teneo.samples.emf.annotations.forcedidbag.User; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.HsqldbTestDatabaseAdapter; +import org.eclipse.emf.teneo.test.stores.TestStore; + +public class ForcedIdBagAction extends AbstractTestAction { + + private static final String NAME = "Loeki"; + + private static final String ROLE1 = "admin"; + + private static final String ROLE2 = "developer"; + + public ForcedIdBagAction() { + super(ForcedidbagPackage.eINSTANCE); + } + + @Override + public void doAction(TestStore store) { + storeUser(store); + testUser(store); + testPrimaryKey(store); + } + + /** Add an option to force to use an idbag */ + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.MAP_ALL_LISTS_AS_IDBAG, "true"); + props.setProperty(PersistenceOptions.IDBAG_ID_COLUMN_NAME, "idbag_id"); + props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS, "true"); + return props; + } + + private void storeUser(TestStore store) { + store.beginTransaction(); + final User user = ForcedidbagFactory.eINSTANCE.createUser(); + user.setName(NAME); + final Role role1 = ForcedidbagFactory.eINSTANCE.createRole(); + role1.setName(ROLE1); + final Role role2 = ForcedidbagFactory.eINSTANCE.createRole(); + role2.setName(ROLE2); + user.getRoles().add(role1); + user.getRoles().add(role2); + store.store(user.getRoles()); + store.store(user); + store.commitTransaction(); + } + + private void testPrimaryKey(TestStore store) { + // apparently not enough metadata can be read for hsqldb + if (store.getDatabaseAdapter() instanceof HsqldbTestDatabaseAdapter) { + return; + } + + // Verify that we have a primary key "ID" in the "roles" table. + ResultSet resultSet = null; + ResultSet resultSet2 = null; + try { + final DatabaseMetaData metaData = store.getConnection().getMetaData(); + + // apparently hibernate core creates different tables than running with + // hibernate entitymanager, need to check! + resultSet = metaData.getPrimaryKeys(null, null, "myjoin"); + resultSet.next(); + assertTrue("Primary key column should be named \"idbag_id\"", "idbag_id".equalsIgnoreCase(resultSet + .getString("COLUMN_NAME"))); + assertFalse("Found more than one primary key.", resultSet.next()); + } catch (final SQLException e) { + assertFalse(e.getMessage(), true); + } finally { + try { + if (resultSet != null) { + resultSet.close(); + if (resultSet2 != null) { + resultSet2.close(); + } + } + } catch (final SQLException e) { + } + } + } + + private void testUser(TestStore store) { + final List<?> results = store.query("select u from User u"); + assertEquals(1, results.size()); + final User user = (User) results.get(0); + assertEquals(NAME, user.getName()); + assertEquals(2, user.getRoles().size()); + assertTrue(user.getRoles().get(0).getName().equals(ROLE1)); + assertTrue(user.getRoles().get(1).getName().equals(ROLE2)); + } + +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/HbMapKeysAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/HbMapKeysAction.java new file mode 100755 index 000000000..fb760de62 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/HbMapKeysAction.java @@ -0,0 +1,110 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: HbMapKeysAction.java,v 1.2 2010/04/03 12:55:13 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.util.List; +import java.util.Properties; + +import org.eclipse.emf.teneo.samples.emf.annotations.hbmapkeys.Book; +import org.eclipse.emf.teneo.samples.emf.annotations.hbmapkeys.City; +import org.eclipse.emf.teneo.samples.emf.annotations.hbmapkeys.HbmapkeysFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.hbmapkeys.HbmapkeysPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.hbmapkeys.Writer; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests HbMapKey and MapKeyManyToMany annotations + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.2 $ + */ +public class HbMapKeysAction extends AbstractTestAction { + public HbMapKeysAction() { + super(HbmapkeysPackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); +// props.put(PersistenceOptions.EMAP_AS_TRUE_MAP, "true"); + return props; + } + + /** + * Check test set, note a where clause has been set on the relation Only writers with name + * martin are returned + */ + private void checkTestSet(Book bk) { + // final String prefix = bk.getTitle(); + for (final Object element : bk.getWritersByName().keySet()) { + final String key = (String) element; + final Writer w = bk.getWritersByName().get(key); + assertEquals(key, w.getName()); + assertTrue(key.startsWith(bk.getTitle())); + } + for (final Object element : bk.getCityByWriter().keySet()) { + final Writer key = (Writer) element; + final City c = bk.getCityByWriter().get(key); + assertEquals(key, c.getCityWriter()); + } + } + + /** Create test set */ + private Book createTestSet(String prefix) { + final HbmapkeysFactory factory = HbmapkeysFactory.eINSTANCE; + final Writer w1 = factory.createWriter(); + w1.setName(prefix + "martin"); + final Writer w2 = factory.createWriter(); + w2.setName(prefix + "martin2"); + final Book bk = factory.createBook(); + bk.setTitle(prefix); + bk.getWritersByName().put(w1.getName(), w1); + bk.getWritersByName().put(w2.getName(), w2); + final City ct1 = factory.createCity(); + ct1.setName(prefix + "CityOne"); + ct1.setCityWriter(w1); + bk.getCityByWriter().put(w1, ct1); + final City ct2 = factory.createCity(); + ct2.setName(prefix + "CityTwo"); + ct2.setCityWriter(w2); + bk.getCityByWriter().put(w2, ct2); + return bk; + } + + @Override + public void doAction(TestStore store) { + { + store.beginTransaction(); + store.store(createTestSet("")); + store.store(createTestSet("prefix2")); + store.commitTransaction(); + } + + try { + store.beginTransaction(); + final List<?> lst = store.getObjects(Book.class); + for (Object name : lst) { + checkTestSet((Book) name); + } + store.commitTransaction(); + } catch (final Exception e) { + throw new StoreTestException("Exception when testing with resource", e); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IdAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IdAction.java new file mode 100755 index 000000000..3b1ff14a5 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IdAction.java @@ -0,0 +1,111 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * IdAction.java,v 1.4 2007/03/20 23:33:38 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.util.HashMap; +import java.util.List; + +import org.eclipse.emf.teneo.samples.emf.annotations.id.AutoID; +import org.eclipse.emf.teneo.samples.emf.annotations.id.IdFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.id.IdPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.id.IdentityID; +import org.eclipse.emf.teneo.samples.emf.annotations.id.SimpleID; +import org.eclipse.emf.teneo.samples.emf.annotations.id.TableGeneratorID; +import org.eclipse.emf.teneo.samples.emf.annotations.id.TableID; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.8 $ + */ +public class IdAction extends AbstractTestAction { + /** How many test objects are created */ + private static final int NO_TEST_OBJECTS = 10; + + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public IdAction() { + super(IdPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final IdFactory factory = IdFactory.eINSTANCE; + { + store.beginTransaction(); + for (int i = 0; i < NO_TEST_OBJECTS; i++) { + store.store(factory.createIdentityID()); + store.store(factory.createTableID()); + store.store(factory.createSimpleID()); + store.store(factory.createTableGeneratorID()); + + final AutoID aid = factory.createAutoID(); + aid.setName("autoid" + i); + store.store(aid); + + } + store.commitTransaction(); + } + + // read back and check it + { + store.beginTransaction(); + // test if we saved them all + List<?> list = store.getObjects(IdentityID.class); + HashMap<Long, Object> testMap = new HashMap<Long, Object>(); + for (final Object element : list) { + final IdentityID iid = (IdentityID) element; + testMap.put(new Long(iid.getMyid()), iid); + } + assertEquals(NO_TEST_OBJECTS, testMap.size()); + + list = store.getObjects(TableID.class); + testMap = new HashMap<Long, Object>(); + for (final Object element : list) { + final TableID sid = (TableID) element; + testMap.put(new Long(sid.getMyid()), sid); + } + assertEquals(NO_TEST_OBJECTS, testMap.size()); + + list = store.getObjects(SimpleID.class); + testMap = new HashMap<Long, Object>(); + for (final Object element : list) { + final SimpleID sid = (SimpleID) element; + testMap.put(new Long(sid.getAutoID()), sid); + } + assertEquals(NO_TEST_OBJECTS, testMap.size()); + + list = store.getObjects(TableGeneratorID.class); + testMap = new HashMap<Long, Object>(); + for (final Object element : list) { + final TableGeneratorID sid = (TableGeneratorID) element; + testMap.put(new Long(sid.getMyid()), sid); + } + assertEquals(NO_TEST_OBJECTS, testMap.size()); + + list = store.getObjects(AutoID.class); + testMap = new HashMap<Long, Object>(); + int i = 0; + for (final Object element : list) { + final AutoID aid = (AutoID) element; + assertEquals("autoid" + (i++), aid.getName()); + testMap.put(new Long(aid.getAutoID()), aid); + } + assertEquals(NO_TEST_OBJECTS, testMap.size()); + store.commitTransaction(); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IdBagAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IdBagAction.java new file mode 100755 index 000000000..a4ed93b8c --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IdBagAction.java @@ -0,0 +1,116 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * IdBagAction.java,v 1.5 2007/03/20 23:33:38 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +import org.eclipse.emf.teneo.samples.emf.annotations.idbag.IdbagFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.idbag.IdbagPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.idbag.User; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.HsqldbTestDatabaseAdapter; +import org.eclipse.emf.teneo.test.stores.TestStore; + +public class IdBagAction extends AbstractTestAction { + + private static final String NAME = "Loeki"; + + private static final String ROLE1 = "admin"; + + private static final String ROLE2 = "developer"; + + public IdBagAction() { + super(IdbagPackage.eINSTANCE); + } + + @Override + public void doAction(TestStore store) { + storeUser(store); + testUser(store); + testPrimaryKey(store); + } + + private void storeUser(TestStore store) { + store.beginTransaction(); + final User user = IdbagFactory.eINSTANCE.createUser(); + user.setName(NAME); + user.getRoles().add(ROLE1); + user.getRoles().add(ROLE2); + store.store(user); + store.commitTransaction(); + } + + private void testPrimaryKey(TestStore store) { + // apparently not enough metadata can be read for hsqldb + if (store.getDatabaseAdapter() instanceof HsqldbTestDatabaseAdapter) { + return; + } + + // Verify that we have a primary key "ID" in the "roles" table. + ResultSet resultSet = null; + ResultSet resultSet2 = null; + try { + final DatabaseMetaData metaData = store.getConnection().getMetaData(); + + // apparently hibernate core creates different tables than running with + // hibernate entitymanager, need to check! + boolean rsTrue = false; + try { + resultSet = metaData.getPrimaryKeys(null, null, "user_roles"); + rsTrue = resultSet.next(); + } catch (final SQLException e) { + // ignore, hope for the next one + } + boolean rs2True = false; + try { + resultSet2 = metaData.getPrimaryKeys(null, null, "roles"); + rs2True = resultSet2.next(); + } catch (final SQLException e) { + assertTrue(rsTrue); + // ignore hope for the first one + } + assertTrue("No primary key found for \"roles\" table.", rsTrue || rs2True); + if (rsTrue) { + assertTrue("Primary key column should be named \"ID\"", "ID".equalsIgnoreCase(resultSet + .getString("COLUMN_NAME"))); + assertFalse("Found more than one primary key.", resultSet.next()); + } else { + assertTrue("Primary key column should be named \"ID\"", "ID".equalsIgnoreCase(resultSet2 + .getString("COLUMN_NAME"))); + assertFalse("Found more than one primary key.", resultSet2.next()); + } + } catch (final SQLException e) { + assertFalse(e.getMessage(), true); + } finally { + try { + if (resultSet != null) { + resultSet.close(); + if (resultSet2 != null) { + resultSet2.close(); + } + } + } catch (final SQLException e) { + } + } + } + + private void testUser(TestStore store) { + final List<?> results = store.query("select u from User u"); + assertEquals(1, results.size()); + final User user = (User) results.get(0); + assertEquals(NAME, user.getName()); + assertEquals(2, user.getRoles().size()); + assertTrue(user.getRoles().contains(ROLE1)); + assertTrue(user.getRoles().contains(ROLE2)); + } + +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IdBagAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IdBagAction.persistence.xml new file mode 100755 index 000000000..d8abe2794 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IdBagAction.persistence.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="utf-8"?> +<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <!-- Template for TestAction persistence mapping. --> + + <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/idbag"> + + <eclass name="User"> + <property name="roles"> + <!-- IdBag not yet supported. --> + <id-bag /> + </property> + </eclass> + + </epackage> + +</persistence-mapping>
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationAction.java new file mode 100755 index 000000000..ca2977364 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationAction.java @@ -0,0 +1,207 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * InheritanceAnnotationAction.java,v 1.6 2007/03/20 23:33:38 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Iterator; + +import org.eclipse.emf.teneo.annotations.pannotation.InheritanceType; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.Address; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.ContentList; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.DistrictUKAddress; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.InheritancemappingFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.InheritancemappingPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.InternationalPrice; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.Price; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.UKAddress; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.USAddress; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.USState; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.impl.DistrictUKAddressImpl; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.impl.InternationalPriceImpl; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.impl.UKAddressImpl; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.impl.USAddressImpl; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests annotations to direct the inheritance mapping. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.14 $ + */ +public class InheritanceAnnotationAction extends AbstractTestAction { + + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public InheritanceAnnotationAction() { + super(InheritancemappingPackage.eINSTANCE); + } + + /** Checks that the address types occur in the passed list */ + private void checkAddressList(Iterator<?> it) { + int cntus = 0; + int cntuk = 0; + int cntdistrict = 0; + while (it.hasNext()) { + final Address address = (Address) it.next(); + if (address instanceof DistrictUKAddress) { + cntdistrict++; + } else if (address instanceof UKAddress) { + cntuk++; + if (address.getName().compareTo("Primeminister") == 0) { + assertTrue(address instanceof UKAddress); + } + } else if (address instanceof USAddress) { + cntus++; + + if (address.getName().compareTo("empty") == 0) { + // assertFalse(((USAddress) address).isSetState()); + } else { + assertTrue(((USAddress) address).isSetState()); + } + } + } + assertTrue(cntus == 2); + assertTrue(cntuk == 1); + assertTrue(cntdistrict == 1); + } + + /** Creates simple types and tests against */ + @Override + public void doAction(TestStore store) { + // test a simple type + final InheritancemappingFactory factory = InheritancemappingFactory.eINSTANCE; + { + store.beginTransaction(); + + final USAddress usaddress = factory.createUSAddress(); + usaddress.setName("Montgomery"); + usaddress.setCity("Montgomery"); + usaddress.setState(USState.AL_LITERAL); + usaddress.setZip(new BigInteger("36101")); + usaddress.setStreet("Montgomery street"); + store.store(usaddress); + + // test nullable fields + final USAddress emptyaddress = factory.createUSAddress(); + emptyaddress.setName("empty"); + emptyaddress.setCity("empty"); + emptyaddress.setStreet("empty"); + emptyaddress.setState(USState.AK_LITERAL); + emptyaddress.setZip(new BigInteger("1231")); + + store.store(usaddress); + store.store(emptyaddress); + + // create a uk address and a uk district address + final UKAddress ukaddress = factory.createUKAddress(); + ukaddress.setCity("London"); + ukaddress.setStreet("Downingstreet 10"); + ukaddress.setName("Primeminister"); + ukaddress.setPostcode("0000"); + store.store(ukaddress); + + final DistrictUKAddress districtaddress = factory.createDistrictUKAddress(); + districtaddress.setCity("district"); + districtaddress.setDistrict("district1"); + districtaddress.setName("My districtaddress"); + districtaddress.setPostcode("postcode1"); + districtaddress.setStreet("street1"); + store.store(districtaddress); + + final ContentList contentlist = factory.createContentList(); + contentlist.setName("testme"); + contentlist.getAddress().add(usaddress); + contentlist.getAddress().add(emptyaddress); + contentlist.getAddress().add(ukaddress); + contentlist.getAddress().add(districtaddress); + store.store(contentlist); + + final InternationalPrice intprice = factory.createInternationalPrice(); + intprice.setName("euro"); + intprice.setCurrency("EUR"); + intprice.setValue(new BigDecimal("100.50")); + contentlist.getPrice().add(intprice); + + final Price price = factory.createPrice(); + price.setName("mycurrency"); + price.setValue(new BigDecimal("99.30")); + contentlist.getPrice().add(price); + + contentlist.getPrice().add(intprice); + + store.store(contentlist.getAddress()); + store.store(contentlist.getPrice()); + store.commitTransaction(); + } + + { + store.beginTransaction(); + final ContentList contentList = store.getObject(ContentList.class); + checkAddressList(contentList.getAddress().iterator()); + + assertTrue(contentList.getPrice().get(0) instanceof InternationalPrice); + assertTrue(((InternationalPrice) contentList.getPrice().get(0)).getName().compareTo("euro") == 0); + assertTrue(contentList.getPrice().get(1) instanceof Price); + assertTrue(contentList.getPrice().get(1).getName().compareTo("mycurrency") == 0); + + store.commitTransaction(); + } + + // eventhough at global level one inheritance strategy is used this should differ for + // individual + // class hierarchies as enforced by the annotations + assertTrue(store.isInheritanceStrategy(InternationalPriceImpl.class, InheritanceType.SINGLE_TABLE)); + assertTrue(store.isInheritanceStrategy(UKAddressImpl.class, InheritanceType.JOINED)); + assertTrue(store.isInheritanceStrategy(USAddressImpl.class, InheritanceType.JOINED)); + assertTrue(store.isInheritanceStrategy(DistrictUKAddressImpl.class, InheritanceType.JOINED)); + + // do some sql queries to check if the discriminator has landed + Connection conn = null; + Statement stmt = null; + try { + try { + conn = store.getConnection(); + stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery("select * from myprice where discriminator='myPrice'"); + int cnt = 0; + while (rs.next()) { + cnt++; + } + rs.close(); + assertEquals(1, cnt); + + rs = stmt.executeQuery("select * from myprice where discriminator='myInternationalPrice'"); + cnt = 0; + while (rs.next()) { + cnt++; + } + assertEquals(1, cnt); + } finally { + if (stmt != null) { + stmt.close(); + } + if (conn != null) { + conn.close(); + } + } + } catch (final SQLException e) { + throw new StoreTestException("Sql exception when retrieving objects based on discriminator values", e); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationAction.persistence.xml new file mode 100755 index 000000000..bf95c48c7 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationAction.persistence.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="utf-8"?> +<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <!-- Template for TestAction persistence mapping. --> + + <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/inheritancemapping"> + + <eclass name="ContentList"> + <property name="name"> + <id /> + </property> + </eclass> + + <eclass name="ChildOne"> + <entity extends="ParentTwo"/> + </eclass> + + <eclass name="Price"> + <table name="myprice" /> + <inheritance>SINGLE_TABLE</inheritance> + <discriminator-column name="DISCRIMINATOR" discriminator-type="STRING" /> + <discriminator-value>myPrice</discriminator-value> + </eclass> + + <eclass name="InternationalPrice"> + <discriminator-value>myInternationalPrice</discriminator-value> + </eclass> + + <eclass name="Address"> + <inheritance>JOINED</inheritance> + <property name="name"> + <id /> + </property> + </eclass> + + <eclass name="USAddress"> + <table name="UNITEDSTATESADDRESS"/> + </eclass> + + </epackage> + +</persistence-mapping>
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.java new file mode 100755 index 000000000..4115068ef --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.java @@ -0,0 +1,224 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * InheritanceAnnotationTablePerClassAction.java,v 1.3 2007/03/20 23:33:38 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.emf.teneo.annotations.pannotation.InheritanceType; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.Address; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.ContentList; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.DistrictUKAddress; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.InheritancemappingFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.InheritancemappingPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.InternationalPrice; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.Price; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.UKAddress; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.USAddress; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.USState; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.impl.DistrictUKAddressImpl; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.impl.InternationalPriceImpl; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.impl.UKAddressImpl; +import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.impl.USAddressImpl; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests annotations to direct the inheritance mapping. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.9 $ + */ +public class InheritanceAnnotationTablePerClassAction extends AbstractTestAction { + + /** UGLY, at least ensure that at least one of the three tests is run */ + private static int ignored_tests = 0; + + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public InheritanceAnnotationTablePerClassAction() { + super(InheritancemappingPackage.eINSTANCE); + } + + /** Checks that the address types occur in the passed list */ + private void checkAddressList(Iterator<?> it) { + int cntus = 0; + int cntuk = 0; + int cntdistrict = 0; + while (it.hasNext()) { + final Address address = (Address) it.next(); + if (address instanceof DistrictUKAddress) { + cntdistrict++; + } else if (address instanceof UKAddress) { + cntuk++; + if (address.getName().compareTo("Primeminister") == 0) { + assertTrue(address instanceof UKAddress); + } + } else if (address instanceof USAddress) { + cntus++; + + if (address.getName().compareTo("empty") == 0) { + assertFalse(((USAddress) address).isSetState()); + } else { + assertTrue(((USAddress) address).isSetState()); + assertTrue(((USAddress) address).isSetZip()); + } + } + } + assertTrue(cntus == 2); + assertTrue(cntuk == 1); + assertTrue(cntdistrict == 1); + } + + /** Creates simple types and tests against */ + @Override + public void doAction(TestStore store) { + if (store.isInheritanceStrategy(InternationalPriceImpl.class, InheritanceType.SINGLE_TABLE)) { + ignored_tests++; + assertTrue(ignored_tests < 5); + return; // not the correct test, should only run xml tests, need to change the whole + // test framework to do this + } + + // test a simple type + final InheritancemappingFactory factory = InheritancemappingFactory.eINSTANCE; + { + store.beginTransaction(); + final USAddress usaddress = factory.createUSAddress(); + usaddress.setName("Montgomery"); + usaddress.setCity("Montgomery"); + usaddress.setState(USState.AL_LITERAL); + usaddress.setZip(new BigInteger("36101")); + usaddress.setStreet("Montgomery street"); + store.store(usaddress); + + // test nullable fields + final USAddress emptyaddress = factory.createUSAddress(); + emptyaddress.setName("empty"); + emptyaddress.setCity("empty"); + emptyaddress.setStreet("empty"); + emptyaddress.setZip(new BigInteger("123")); + emptyaddress.setState(USState.AK_LITERAL); + + store.store(usaddress); + store.store(emptyaddress); + + // create a uk address and a uk district address + final UKAddress ukaddress = factory.createUKAddress(); + ukaddress.setCity("London"); + ukaddress.setStreet("Downingstreet 10"); + ukaddress.setName("Primeminister"); + ukaddress.setPostcode("0000"); + store.store(ukaddress); + + final DistrictUKAddress districtaddress = factory.createDistrictUKAddress(); + districtaddress.setCity("district"); + districtaddress.setDistrict("district1"); + districtaddress.setName("My districtaddress"); + districtaddress.setPostcode("postcode1"); + districtaddress.setStreet("street1"); + store.store(districtaddress); + final ContentList contentlist = factory.createContentList(); + contentlist.setName("testme"); + contentlist.getAddress().add(usaddress); + contentlist.getAddress().add(emptyaddress); + contentlist.getAddress().add(ukaddress); + contentlist.getAddress().add(districtaddress); + store.store(contentlist); + + final InternationalPrice intprice = factory.createInternationalPrice(); + intprice.setName("euro"); + intprice.setCurrency("EUR"); + intprice.setValue(new BigDecimal("100.50")); + + final Price price = factory.createPrice(); + price.setName("mycurrency"); + price.setValue(new BigDecimal("99.30")); + store.store(price); + store.store(intprice); + + store.store(contentlist); + store.commitTransaction(); + } + + { + store.beginTransaction(); + final ContentList contentList = store.getObject(ContentList.class); + checkAddressList(contentList.getAddress().iterator()); + + final List<?> prices = store.getObjects(Price.class); + assertEquals(2, prices.size()); + InternationalPrice ip; + Price p; + if (prices.get(0) instanceof InternationalPrice) { + ip = (InternationalPrice) prices.get(0); + p = (Price) prices.get(1); + } else { + ip = (InternationalPrice) prices.get(1); + p = (Price) prices.get(0); + } + assertTrue(ip.getName().compareTo("euro") == 0); + assertTrue(p.getName().compareTo("mycurrency") == 0); + + store.commitTransaction(); + } + + // eventhough at global level one inheritance strategy is used this should differ for + // individual + // class hierarchies as enforced by the annotations + assertTrue(store.isInheritanceStrategy(InternationalPriceImpl.class, InheritanceType.TABLE_PER_CLASS)); + assertTrue(store.isInheritanceStrategy(UKAddressImpl.class, InheritanceType.JOINED)); + assertTrue(store.isInheritanceStrategy(USAddressImpl.class, InheritanceType.JOINED)); + assertTrue(store.isInheritanceStrategy(DistrictUKAddressImpl.class, InheritanceType.JOINED)); + + // do some sql queries to check if the name column is present in the subclass + Connection conn = null; + Statement stmt = null; + try { + try { + conn = store.getConnection(); + stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery("select * from internationalprice where name='euro'"); + int cnt = 0; + while (rs.next()) { + cnt++; + } + rs.close(); + + assertEquals(1, cnt); + rs = stmt.executeQuery("select * from myprice where name='mycurrency'"); + cnt = 0; + while (rs.next()) { + cnt++; + } + rs.close(); + assertEquals(1, cnt); + } finally { + if (stmt != null) { + stmt.close(); + } + if (conn != null) { + conn.close(); + } + } + } catch (final SQLException e) { + throw new StoreTestException("Sql exception when retrieving objects based on discriminator values", e); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.persistence.xml new file mode 100755 index 000000000..01451cbe4 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.persistence.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <!-- Template for TestAction persistence mapping. --> + + <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/inheritancemapping"> + + <eclass name="ContentList"> + <property name="name"> + <id /> + </property> + </eclass> + + <eclass name="Price"> + <table name="myprice" /> + <inheritance>TABLE_PER_CLASS</inheritance> + <property name="name"> + <id /> + </property> + </eclass> + + <eclass name="Address"> + <inheritance>JOINED</inheritance> + <property name="name"> + <id /> + </property> + </eclass> + + </epackage> + +</persistence-mapping>
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IntegerDiscriminatorAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IntegerDiscriminatorAction.java new file mode 100755 index 000000000..67472eab9 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IntegerDiscriminatorAction.java @@ -0,0 +1,100 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: IntegerDiscriminatorAction.java,v 1.3 2008/06/10 09:41:19 mtaal Exp $ + */ +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.util.List; + +import org.eclipse.emf.teneo.samples.emf.annotations.integerdiscriminator.IntegerdiscriminatorFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.integerdiscriminator.IntegerdiscriminatorPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.integerdiscriminator.OtherSub; +import org.eclipse.emf.teneo.samples.emf.annotations.integerdiscriminator.Sub; +import org.eclipse.emf.teneo.samples.emf.annotations.integerdiscriminator.SubFormula; +import org.eclipse.emf.teneo.samples.emf.annotations.integerdiscriminator.Super; +import org.eclipse.emf.teneo.samples.emf.annotations.integerdiscriminator.SuperFormula; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase for integer discriminator, see bugzilla: + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=235945 + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ + */ +public class IntegerDiscriminatorAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public IntegerDiscriminatorAction() { + super(IntegerdiscriminatorPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final IntegerdiscriminatorFactory factory = IntegerdiscriminatorFactory.eINSTANCE; + { + store.beginTransaction(); + + final Super sup1 = factory.createSuper(); + sup1.setName("test1"); + final Super sup2 = factory.createSuper(); + sup2.setName("test2"); + final Sub sub = factory.createSub(); + sub.setName("sub"); + final OtherSub oSub = factory.createOtherSub(); + oSub.setName("osub"); + store.store(sup1); + store.store(sup2); + store.store(sub); + store.store(oSub); + + final SuperFormula superFormula = factory.createSuperFormula(); + superFormula.setName("GTEST"); + store.store(superFormula); + + final SubFormula subFormula = factory.createSubFormula(); + subFormula.setName("RTEST"); + store.store(subFormula); + + store.commitTransaction(); + } + + // read back and check it + { + store.beginTransaction(); + // note 4 because polymorphic so the Sub and OtherSub count as a Sup + store.checkNumber(Super.class, 4); + store.checkNumber(Sub.class, 1); + store.checkNumber(OtherSub.class, 1); + + final List<?> l = store.getObjects(SuperFormula.class); + assertEquals(2, l.size()); + for (Object o : l) { + if (o instanceof SubFormula) { + assertEquals("RTEST", ((SuperFormula) o).getName()); + } else if (o instanceof SuperFormula) { + assertEquals("GTEST", ((SuperFormula) o).getName()); + } else { + fail("Unknown class " + o.getClass().getName()); + } + } + store.commitTransaction(); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/JoinColumnsAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/JoinColumnsAction.java new file mode 100755 index 000000000..264e428ae --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/JoinColumnsAction.java @@ -0,0 +1,163 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * JoinColumnsAction.java,v 1.4 2007/02/01 12:35:36 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.annotations.pannotation.InheritanceType; +import org.eclipse.emf.teneo.samples.emf.annotations.joincolumns.Child; +import org.eclipse.emf.teneo.samples.emf.annotations.joincolumns.House; +import org.eclipse.emf.teneo.samples.emf.annotations.joincolumns.JoincolumnsFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.joincolumns.JoincolumnsPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.joincolumns.Parent; +import org.eclipse.emf.teneo.samples.emf.annotations.joincolumns.Person; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.11 $ + */ +public class JoinColumnsAction extends AbstractTestAction { + /** + * Constructor + */ + public JoinColumnsAction() { + super(JoincolumnsPackage.eINSTANCE); + } + + /** Checks the version column */ + protected void checkVersion(TestStore store) { + } + + /** + * Can be overridden by subclass returns properties which control the or layer. Such as setting + * of eager loading. + */ + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.VERSION_COLUMN_NAME, "myversion"); + props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS, "true"); + return props; + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final JoincolumnsFactory factory = JoincolumnsFactory.eINSTANCE; + { + store.beginTransaction(); + final Parent parent = factory.createParent(); + parent.setFirstName("John"); + parent.setLastName("Smith"); + final Child child1 = factory.createChild(); + child1.setFirstName("Johnny"); + child1.setLastName("Smith"); + parent.getChildren().add(child1); + final Child child2 = factory.createChild(); + child2.setFirstName("Jane"); + child2.setLastName("Smith"); + parent.getChildren().add(child2); + store.store(parent.getChildren()); + store.store(parent); + + House h = factory.createHouse(); + h.setOwner(parent); + h.getVisitors().add(parent); + h.getVisitors().add(child2); + store.store(h); + + // now create some friends + Person f1 = factory.createPerson(); + f1.setFirstName("friend"); + f1.setLastName("one"); + Person f2 = factory.createPerson(); + f2.setFirstName("friend"); + f2.setLastName("two"); + Person f3 = factory.createPerson(); + f3.setFirstName("friend"); + f3.setLastName("three"); + Person f4 = factory.createPerson(); + f4.setFirstName("friend"); + f4.setLastName("four"); + + f1.getFriends().add(f2); + f1.getFriends().add(f3); + f1.getFriends().add(f4); + + f2.getFriends().add(f3); + f2.getFriends().add(f4); + + f4.getFriends().add(f1); + f4.getFriends().add(f2); + f4.getFriends().add(f3); + + f3.getFriends().add(f2); + f3.getFriends().add(f4); + + store.store(f1); + store.commitTransaction(); + } + + // read again + { + store.beginTransaction(); + final Parent parent = store.getObject(Parent.class); + assertEquals(2, parent.getChildren().size()); + assertEquals("Johnny", parent.getChildren().get(0).getFirstName()); + assertEquals("Jane", parent.getChildren().get(1).getFirstName()); + final House h = store.getObject(House.class); + assertEquals(parent, h.getOwner()); + assertTrue(h.getVisitors().contains(parent)); + assertEquals(2, h.getVisitors().size()); + assertTrue(h.getVisitors().contains(parent.getChildren().get(1))); + store.commitTransaction(); + } + + // check version column and foreign keys + Connection conn = null; + Statement stmt = null; + try { + try { + conn = store.getConnection(); + stmt = conn.createStatement(); + + checkVersion(store); + + // depending on the inheritance strategy the foreign key is stored in different + // table + if (store.getInheritanceType() == InheritanceType.SINGLE_TABLE) { + final ResultSet rs = stmt.executeQuery("select myParentFirstName from person"); + assertTrue(rs.next()); + } else { + final ResultSet rs = stmt.executeQuery("select myParentFirstName from child"); + assertTrue(rs.next()); + } + } finally { + if (stmt != null) { + stmt.close(); + } + if (conn != null) { + conn.close(); + } + } + } catch (final SQLException e) { + throw new StoreTestException("Sql exception when checking db schema", e); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/LazyLibraryAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/LazyLibraryAction.java new file mode 100755 index 000000000..450312935 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/LazyLibraryAction.java @@ -0,0 +1,224 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * LazyLibraryAction.java,v 1.9 2007/03/29 15:00:32 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.io.IOException; +import java.util.Properties; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.impl.AdapterImpl; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.mapping.elist.PersistableEList; +import org.eclipse.emf.teneo.resource.StoreResource; +import org.eclipse.emf.teneo.samples.emf.annotations.lazy.Book; +import org.eclipse.emf.teneo.samples.emf.annotations.lazy.BookCategory; +import org.eclipse.emf.teneo.samples.emf.annotations.lazy.LazyFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.lazy.LazyPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.lazy.Library; +import org.eclipse.emf.teneo.samples.emf.annotations.lazy.Writer; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests non-resolving behavior of containment references. Main test is that setTrackingModification + * does not result in loaded containment elists. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.14 $ + */ +public class LazyLibraryAction extends AbstractTestAction { + /** Small adapter test */ + private class LibraryAdapter extends AdapterImpl { + /** Counts the number of changes */ + private int countNotifications = 0; + + /** Returns the number of notifications */ + public int getCountNotifications() { + return countNotifications; + } + + /** + * Returns <code>false</code> + * + * @param type + * the type. + * @return <code>false</code> + */ + @Override + public boolean isAdapterForType(Object type) { + return type instanceof Writer; + } + + /** + * Does nothing; clients may override so that it does something. + */ + @Override + public void notifyChanged(Notification msg) { + countNotifications++; + } + } + + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public LazyLibraryAction() { + super(LazyPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final LazyFactory factory = LazyFactory.eINSTANCE; + + // create a book, writer and library + try { + { + final Resource res = store.getResource(); + res.load(null); + + final Writer writer = factory.createWriter(); + writer.setName("JRR Tolkien"); + + final Book book = factory.createBook(); + book.setAuthor(writer); + book.setPages(510); + book.setTitle("Fellowship of the Ring"); + book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Book book2 = factory.createBook(); + book2.setAuthor(writer); + book2.setPages(500); + book2.setTitle("The Hobbit"); + book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + // sorry george making a mistake here, will correct this below + final Book book3 = factory.createBook(); + book3.setAuthor(writer); + book3.setPages(500); + book3.setTitle("1984"); + book3.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Library library = factory.createLibrary(); + library.setName("Science Fiction"); + library.getBooks().add(book); + library.getBooks().add(book2); + library.getBooks().add(book3); + library.getWriters().add(writer); + + res.getContents().add(library); + res.save(null); + res.unload(); + } + + // test settrackingmodification before load + { + final Resource res = store.getResource(); + // default is false + // ((StoreResource)res).setAutoResolve(false); + res.setTrackingModification(true); + res.load(null); + testResolving(res); + } + + // test settrackingmodification after load + { + final Resource res = store.getResource(); + // default is false + // ((StoreResource)res).setAutoResolve(false); + res.load(null); + res.setTrackingModification(true); + testResolving(res); + } + + // test with resolving + { + final Resource res = store.getResource(); + // default is false + res.load(null); + res.setTrackingModification(true); + testResolving(res); + } + + // simple test without setTrackingModification + { + final Resource res = store.getResource(); + res.load(null); + + final Library lib = (Library) res.getContents().get(0); + final PersistableEList<?> writers = (PersistableEList<?>) lib.getWriters(); + assertTrue("Elist should be loaded", writers.isLoaded()); + assertTrue(lib.getWriters().get(0).eContainer() == lib); + assertTrue(lib.getBooks().get(0).eContainer() == lib); + res.unload(); + } + + { + store.beginTransaction(); + final Library lib = store.getObject(Library.class); + assertTrue(lib.getWriters().get(0).eContainer() == lib); + assertTrue(lib.getBooks().get(0).eContainer() == lib); + store.commitTransaction(); + } + } catch (final IOException e) { + throw new StoreTestException("IOException during save", e); + } + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPPING, "true"); + return props; + } + + /** Check adapters and lazy loading of nonresolving */ + private void testResolving(Resource res) { + final LibraryAdapter libraryAdapter = new LibraryAdapter(); + res.eAdapters().add(libraryAdapter); + + final Library lib = (Library) res.getContents().get(0); + final PersistableEList<?> books = (PersistableEList<?>) lib.getBooks(); + final PersistableEList<?> writers = (PersistableEList<?>) lib.getWriters(); + assertTrue("Elist is not loaded while the fetch is eager", writers.isLoaded()); + assertTrue("Elist is not loaded while the fetch is eager", books.isLoaded()); + assertTrue("BasicIterator should have next true", books.basicIterator().hasNext()); + assertTrue("BasicListIterator should have next true", books.basicListIterator().hasNext()); + assertTrue("BasicIterator should have next true", writers.basicIterator().hasNext()); + assertTrue("BasicListIterator should have next true", writers.basicListIterator().hasNext()); + final Book book = (Book) books.get(0); + assertTrue(book.getAuthor().getName() != null); + + final Writer writer = (Writer) writers.get(0); + final PersistableEList<?> writerBooks = (PersistableEList<?>) writer.getBooks(); + assertTrue("Books of writers should not be loaded is lazy, but it seems to be eager", !writerBooks.isLoaded()); + + lib.setName("test" + lib.getName()); + + // change the first book + book.setTitle("test" + book.getTitle()); + + assertEquals(2, libraryAdapter.getCountNotifications()); + + boolean fndLibrary = false; + boolean fndBook = false; + for (final EObject element : ((StoreResource) res).getModifiedEObjects()) { + fndLibrary = fndLibrary || element == lib; + fndBook = fndBook || element == book; + } + assertTrue("Library should be a modified object", fndLibrary); + assertTrue("Book should be a modified object", fndBook); + assertEquals(2, ((StoreResource) res).getModifiedEObjects().size()); + res.unload(); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/LobAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/LobAction.java new file mode 100755 index 000000000..f97173d6d --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/LobAction.java @@ -0,0 +1,81 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: LobAction.java,v 1.8 2009/05/06 16:01:34 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.util.Random; + +import org.eclipse.emf.teneo.samples.emf.annotations.lob.LobFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.lob.LobPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.lob.Person; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Simple test for Lob. + */ +public class LobAction extends AbstractTestAction { + private static final String ADDRESS = "Amsterdamseweg 123, 4567AZ Amsterdam"; + + private static final long ID = 1; + + private static final String NAME = "Jan Janssen"; + + private static final byte[] PHOTO = new byte[64 * 1024]; + + static { + // Populate PHOTO with random bytes. + new Random().nextBytes(PHOTO); + } + + public LobAction() { + super(LobPackage.eINSTANCE); + } + + @Override + public void doAction(TestStore store) { + storePerson(store); + testPerson(store); + } + + private void storePerson(TestStore store) { + store.beginTransaction(); + + final Person person = LobFactory.eINSTANCE.createPerson(); + person.setId(ID); + person.setName(NAME); + person.setAddress(ADDRESS); + person.setPhoto(PHOTO); + store.store(person); + store.commitTransaction(); + } + + private void testPerson(TestStore store) { + store.beginTransaction(); + + final Person person = store.getObject(Person.class); + assertEquals(ID, person.getId()); + assertEquals(NAME, person.getName()); + assertEquals(ADDRESS, person.getAddress()); + final byte[] photo = person.getPhoto(); + assertEquals(PHOTO.length, photo.length); + for (int i = 0; i < photo.length; i++) { + assertEquals(PHOTO[i], photo[i]); + } + + store.commitTransaction(); + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/LobAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/LobAction.persistence.xml new file mode 100755 index 000000000..733fcf705 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/LobAction.persistence.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="utf-8"?> +<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/lob"> + + <eclass name="Person"> + <property name="address"> + <lob /> + </property> + <property name="photo"> + <lob /> + <column length="1000000" /> + </property> + </eclass> + </epackage> + +</persistence-mapping>
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ManyToManyAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ManyToManyAction.java new file mode 100755 index 000000000..5af0dc15e --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ManyToManyAction.java @@ -0,0 +1,149 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: ManyToManyAction.java,v 1.6 2008/02/28 07:08:14 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.emf.teneo.mapping.elist.PersistableEList; +import org.eclipse.emf.teneo.samples.emf.annotations.manytomany.Cntr; +import org.eclipse.emf.teneo.samples.emf.annotations.manytomany.Lft; +import org.eclipse.emf.teneo.samples.emf.annotations.manytomany.ManytomanyFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.manytomany.ManytomanyPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.manytomany.Rght; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.6 $ + */ +public class ManyToManyAction extends AbstractTestAction { + /** How many test objects are created */ + private static final int NO_TEST_OBJECTS = 10; + + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public ManyToManyAction() { + super(ManytomanyPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final ManytomanyFactory factory = ManytomanyFactory.eINSTANCE; + { + store.beginTransaction(); + final ArrayList<Cntr> centers = new ArrayList<Cntr>(); + final ArrayList<Lft> lefts = new ArrayList<Lft>(); + final ArrayList<Rght> rights = new ArrayList<Rght>(); + for (int i = 0; i < NO_TEST_OBJECTS; i++) { + centers.add(factory.createCntr()); + lefts.add(factory.createLft()); + rights.add(factory.createRght()); + } + for (int i = 0; i < NO_TEST_OBJECTS; i++) { + final Cntr c = centers.get(i); + c.getLft().addAll(lefts); + c.getRght().addAll(rights); + store.store(c); + } + store.commitTransaction(); + } + + // do some counts + store.checkNumber(Cntr.class, NO_TEST_OBJECTS); + store.checkNumber(Lft.class, NO_TEST_OBJECTS); + store.checkNumber(Rght.class, NO_TEST_OBJECTS); + + // check lazy versus eager loading + { + store.beginTransaction(); + final List<?> lefts = store.getObjects(Lft.class); + assertEquals(NO_TEST_OBJECTS, lefts.size()); + for (int i = 0; i < lefts.size(); i++) { + final Lft left = (Lft) lefts.get(i); + final PersistableEList<?> elist = (PersistableEList<?>) left.getCntr(); + assertTrue("Lft's center elist should be lazy loaded", !elist.isLoaded()); + assertEquals(NO_TEST_OBJECTS, left.getCntr().size()); + } + + // take one left and check the centers + final List<?> centers = ((Lft) lefts.get(0)).getCntr(); + for (int i = 0; i < centers.size(); i++) { + final Cntr c = (Cntr) centers.get(i); + final PersistableEList<?> elist = (PersistableEList<?>) c.getRght(); + assertTrue("Cntr's right elist should be eager loaded", elist.isLoaded()); + assertEquals(NO_TEST_OBJECTS, c.getRght().size()); + } + + store.commitTransaction(); + } + + // now test noncascading delete + { + store.beginTransaction(); + final List<?> rights = store.getObjects(Rght.class); + assertEquals(NO_TEST_OBJECTS, rights.size()); + for (int i = 0; i < rights.size(); i++) { + final Rght right = (Rght) rights.get(i); + right.getCntr().clear(); + store.store(right); + } + store.commitTransaction(); + } + + // check lazy versus eager loading + { + store.beginTransaction(); + final List<?> lefts = store.getObjects(Lft.class); + assertEquals(NO_TEST_OBJECTS, lefts.size()); + for (int i = 0; i < lefts.size(); i++) { + final Lft left = (Lft) lefts.get(i); + left.getCntr().clear(); + store.store(left); + } + store.commitTransaction(); + } + + // do some counts + store.checkNumber(Cntr.class, NO_TEST_OBJECTS); + store.checkNumber(Lft.class, NO_TEST_OBJECTS); + store.checkNumber(Rght.class, NO_TEST_OBJECTS); + + // now delete some + { + store.beginTransaction(); + final List<?> lefts = store.getObjects(Lft.class); + assertEquals(NO_TEST_OBJECTS, lefts.size()); + for (int i = 0; i < lefts.size(); i++) { + final Lft left = (Lft) lefts.get(i); + store.deleteObject(left); + } + store.commitTransaction(); + } + + store.checkNumber(Cntr.class, NO_TEST_OBJECTS); + store.checkNumber(Lft.class, 0); + store.checkNumber(Rght.class, NO_TEST_OBJECTS); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/MapKeyAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/MapKeyAction.java new file mode 100755 index 000000000..7deb48f62 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/MapKeyAction.java @@ -0,0 +1,199 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: MapKeyAction.java,v 1.7 2009/03/15 08:09:27 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.eclipse.emf.common.util.EMap; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.mapping.elist.PersistableDelegateList; +import org.eclipse.emf.teneo.samples.emf.annotations.mapkey.Book; +import org.eclipse.emf.teneo.samples.emf.annotations.mapkey.MapkeyFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.mapkey.MapkeyPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.mapkey.Writer; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; +import org.eclipse.emf.teneo.type.PersistentStoreAdapter; +import org.eclipse.emf.teneo.util.StoreUtil; + +/** + * Tests support for emaps. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.7 $ + */ +public class MapKeyAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public MapKeyAction() { + super(MapkeyPackage.eINSTANCE); + } + + // set the table/column names to uppercase otherwise this testcase will fail + // with hsqldb because hibernate does not escape the order by clause in a + // query. + // Caused by: java.sql.SQLException: Column not found: ITEM0_.NAME in + // statement [select item0_."item_itemlist_e_id" as item4_1_, + // item0_.e_id as e1_1_, item0_.e_id as e1_575_0_, item0_.e_version as + // e2_575_0_, item0_."name" as name3_575_0_, item0_."item_itemlist_e_id" + // as item4_575_0_ from "testset_item" item0_ where + // item0_."item_itemlist_e_id"=? + // order by item0_.name desc] + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.SQL_CASE_STRATEGY, "uppercase"); + props.put(PersistenceOptions.EMAP_AS_TRUE_MAP, "true"); + return props; + } + + /** + * Check test set, note a where clause has been set on the relation Only + * writers with name martin are returned + */ + private void checkTestSet(Book bk) { + // final String prefix = bk.getTitle(); + final ArrayList<Writer> writers = new ArrayList<Writer>(); + for (final Object element : bk.getWriters().keySet()) { + final String key = (String) element; + final Writer w = bk.getWriters().get(key); + assertEquals(key, w.getName()); + assertTrue(key.startsWith(bk.getTitle())); + writers.add(w); + } + if (bk.getTitle().length() == 0) { + assertEquals(1, writers.size()); + final Writer writerOne = writers.get(0); + assertEquals(writerOne.getName(), "martin"); + } else { + assertEquals(0, writers.size()); + } + } + + /** Create test set */ + private Book createTestSet(String prefix) { + final MapkeyFactory factory = MapkeyFactory.eINSTANCE; + final Writer w1 = factory.createWriter(); + w1.setName(prefix + "martin"); + final Writer w2 = factory.createWriter(); + w2.setName(prefix + "martin2"); + final Book bk = factory.createBook(); + bk.setTitle(prefix); + bk.getWriters().put(w1.getName(), w1); + bk.getWriters().put(w2.getName(), w2); + return bk; + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + { + store.beginTransaction(); + store.store(createTestSet("")); + store.store(createTestSet("prefix2")); + store.commitTransaction(); + } + + { + store.beginTransaction(); + final List<?> lst = store.getObjects(Book.class); + for (Object name : lst) { + checkTestSet((Book) name); + } + store.commitTransaction(); + } + + try { + final Resource res = store.getResource(); + res.load(null); + final ArrayList<Book> bks = new ArrayList<Book>(); + final ArrayList<Object> ws = new ArrayList<Object>(); + for (final Object obj : res.getContents()) { + if (obj instanceof Book) { + final Book bk = (Book) obj; + if (bk.getWriters() instanceof PersistableDelegateList) { + // check lazy load + // assertTrue(!((PersistableDelegateList)bk.getWriters()).isLoaded()); + // now load + if (bk.getTitle().length() == 0) { + assertEquals(1, bk.getWriters().size()); + } else { + assertEquals(0, bk.getWriters().size()); + } + + // disabled as hibernate and jpox differ here + assertTrue(!((PersistableDelegateList<?>) bk + .getWriters()).isLoaded()); + } else { + fail("Type not supported " + + bk.getWriters().getClass().getName()); + } + bks.add(bk); + } else { + ws.add(obj); + } + } + assertTrue(bks.size() == 2); + assertTrue(ws.size() == 4); + res.save(Collections.EMPTY_MAP); + res.save(Collections.EMPTY_MAP); + res.unload(); + } catch (final Exception e) { + throw new StoreTestException( + "Exception when testing with resource", e); + } + + // test PersistentStoreAdapter + { + store.beginTransaction(); + final Book bk = createTestSet("PSA"); + store.store(bk); + store.commitTransaction(); + final Writer w = MapkeyFactory.eINSTANCE.createWriter(); + w.setName("PSAmartin2"); + bk.getWriters().put(w.getName(), w); + + PersistentStoreAdapter adapter = StoreUtil + .getPersistentStoreAdapter(bk); + final Object value = adapter + .getStoreCollection(MapkeyPackage.eINSTANCE + .getBook_Writers()); + compareMaps((Map<?, ?>) value, bk.getWriters()); + } + } + + // compare maps + private void compareMaps(Map<?, ?> m1, EMap<?, ?> m2) { + assertTrue(m1 != m2); + assertEquals(m1.size(), m2.size()); + for (Object key1 : m1.keySet()) { + final Object v2 = m2.get(key1); + final Object v1 = m1.get(key1); + assertTrue(v1 == v2); + } + } + +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/MappedSuperClassAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/MappedSuperClassAction.java new file mode 100755 index 000000000..4c6f4a9c5 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/MappedSuperClassAction.java @@ -0,0 +1,149 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: MappedSuperClassAction.java,v 1.8 2008/04/06 13:44:01 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.annotations.mappedsuperclass.MappedsuperclassFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.mappedsuperclass.MappedsuperclassPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.mappedsuperclass.SpecificDocument; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.8 $ + */ +public class MappedSuperClassAction extends AbstractTestAction { + /** + * Constructor + */ + public MappedSuperClassAction() { + super(MappedsuperclassPackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY, "READ_WRITE"); + props.setProperty(PersistenceOptions.SET_ENTITY_AUTOMATICALLY, "false"); + return props; + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final MappedsuperclassFactory factory = MappedsuperclassFactory.eINSTANCE; + { + store.beginTransaction(); + final SpecificDocument sd = factory.createSpecificDocument(); + sd.setMyName("TEST IT"); + sd.setMyGenericInfo("GENERIC INFO"); + sd.setMySpecificInfo("SPECIFIC INFO"); + store.store(sd); + store.commitTransaction(); + } + + // query for the specific table + { + Connection conn = null; + try { + conn = store.getConnection(); + final Statement stmt = conn.createStatement(); + // the following should not fail for all inheritance strategies + final ResultSet rs = stmt.executeQuery("SELECT * FROM specificdocument"); + assertTrue(rs.next()); + } catch (final SQLException s) { + throw new StoreTestException("SQLException while checking existence of table", s); + } finally { + try { + if (conn != null) { + conn.close(); + } + } catch (final SQLException s) { + throw new StoreTestException("SQLException while checking existence of table", s); + } + } + } + + // query for the mapped superclass table, should always fail! + { + Connection conn = null; + try { + conn = store.getConnection(); + final Statement stmt = conn.createStatement(); + // the following should not fail for all inheritance strategies + final ResultSet rs = stmt.executeQuery("SELECT * FROM document"); + assertTrue(rs != null); // dummy test to get rid of warning + fail("The DOCUMENT table should not exist as it is a mapped superclass"); + } catch (final SQLException s) { + // this is correct + } catch (final Exception e) { + throw new StoreTestException("Exception while checking existence of table", e); + } finally { + try { + if (conn != null) { + conn.close(); + } + } catch (final SQLException s) { + throw new StoreTestException("SQLException while checking existence of table", s); + } + } + } + + { + Connection conn = null; + try { + conn = store.getConnection(); + final Statement stmt = conn.createStatement(); + // the following should not fail for all inheritance strategies + final ResultSet rs = stmt.executeQuery("SELECT * FROM parentdocument"); + assertTrue(rs != null); // dummy to get rid of warning + fail("The PARENTDOCUMENT table should not exist as it is a mapped superclass"); + } catch (final SQLException s) { + // this is correct + } catch (final Exception e) { + throw new StoreTestException("Exception while checking existence of table", e); + } finally { + try { + if (conn != null) { + conn.close(); + } + } catch (final SQLException s) { + throw new StoreTestException("SQLException while checking existence of table", s); + } + } + } + { + store.beginTransaction(); + final SpecificDocument sd = store.getObject(SpecificDocument.class); + assertEquals(sd.getMyName(), "TEST IT"); + assertEquals(sd.getMyGenericInfo(), "GENERIC INFO"); + assertEquals(sd.getMySpecificInfo(), "SPECIFIC INFO"); + store.commitTransaction(); + } + + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/NaturalIdAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/NaturalIdAction.java new file mode 100755 index 000000000..c663dae66 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/NaturalIdAction.java @@ -0,0 +1,168 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: NaturalIdAction.java,v 1.2 2008/06/29 20:08:59 mtaal Exp $ + */ +package org.eclipse.emf.teneo.test.emf.annotations; + +import org.eclipse.emf.teneo.samples.emf.annotations.naturalId.Family; +import org.eclipse.emf.teneo.samples.emf.annotations.naturalId.NaturalIdFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.naturalId.NaturalIdPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.naturalId.Person; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase for naturalid + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.2 $ + */ +public class NaturalIdAction extends AbstractTestAction { + public NaturalIdAction() { + super(NaturalIdPackage.eINSTANCE); + } + + @Override + public void doAction(TestStore store) { + final NaturalIdFactory factory = NaturalIdFactory.eINSTANCE; + { + store.beginTransaction(); + { + final Family fam = factory.createFamily(); + fam.setName("Jansen"); + fam.setAge(100); + store.store(fam); + final Person p1 = factory.createPerson(); + p1.setFirstName("Jan"); + p1.setLastName("Jansen"); + p1.setAge(35); + p1.setCallName("Jan"); + p1.setFamily(fam); + store.store(p1); + final Person p2 = factory.createPerson(); + p2.setFirstName("Piet"); + p2.setLastName("Jansen"); + p2.setAge(35); + p2.setCallName("Piet"); + p2.setFamily(fam); + store.store(p2); + } + { + final Family fam = factory.createFamily(); + fam.setName("Smit"); + fam.setAge(100); + store.store(fam); + final Person p1 = factory.createPerson(); + p1.setFirstName("Jan"); + p1.setLastName("Smit"); + p1.setAge(35); + p1.setCallName("Jan"); + p1.setFamily(fam); + store.store(p1); + final Person p2 = factory.createPerson(); + p2.setFirstName("Piet"); + p2.setLastName("Smit"); + p2.setAge(35); + p2.setCallName("Piet"); + p2.setFamily(fam); + store.store(p2); + } + store.commitTransaction(); + } + + // now create the Jansen family again, this should fail + { + store.beginTransaction(); + final Family fam = factory.createFamily(); + fam.setName("Jansen"); + fam.setAge(100); + try { + store.store(fam); + store.commitTransaction(); + fail(); + } catch (Exception e) { + // successfull unique key constraint check + store.rollbackTransaction(); + } + } + + { + store.beginTransaction(); + Person p = null; + for (Object o : store.getObjects(Family.class)) { + final Family f = (Family) o; + if (f.getName().compareTo("Jansen") == 0) { + p = factory.createPerson(); + p.setFirstName("Jan"); + p.setLastName("Jansen"); + p.setAge(35); + p.setCallName("Jan"); + p.setFamily(f); + break; + } + } + try { + store.store(p); + store.commitTransaction(); + fail(); + } catch (Exception e) { + // successfull unique key constraint check + store.rollbackTransaction(); + } + } + + // create a new person with a different firstname, should work + { + store.beginTransaction(); + Person p = null; + for (Object o : store.getObjects(Family.class)) { + final Family f = (Family) o; + if (f.getName().compareTo("Jansen") == 0) { + p = factory.createPerson(); + p.setFirstName("Jannetje"); + p.setLastName("Jansen"); + p.setAge(35); + p.setCallName("Jan"); + p.setFamily(f); + break; + } + } + store.store(p); + store.commitTransaction(); + } + + // create a new family and a person with the same name but a different + // family this should work + { + // now create the Jansen family again, this should fail + { + store.beginTransaction(); + final Family fam = factory.createFamily(); + fam.setName("Timmermans"); + fam.setAge(100); + store.store(fam); + Person p = factory.createPerson(); + p.setFirstName("Jan"); + p.setLastName("Jansen"); + p.setAge(35); + p.setCallName("Jan"); + p.setFamily(fam); + store.store(p); + store.commitTransaction(); + } + + } + } + +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/OnetoonePKAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/OnetoonePKAction.java new file mode 100755 index 000000000..96ec4a616 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/OnetoonePKAction.java @@ -0,0 +1,66 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: OnetoonePKAction.java,v 1.1 2008/06/29 20:08:59 mtaal Exp $ + */ +package org.eclipse.emf.teneo.test.emf.annotations; + +import org.eclipse.emf.teneo.samples.emf.annotations.otopk.Employee; +import org.eclipse.emf.teneo.samples.emf.annotations.otopk.EmployeeInfo; +import org.eclipse.emf.teneo.samples.emf.annotations.otopk.OtopkFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.otopk.OtopkPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase for a one-to-one with a pk + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.1 $ + */ +public class OnetoonePKAction extends AbstractTestAction { + public OnetoonePKAction() { + super(OtopkPackage.eINSTANCE); + } + + @Override + public void doAction(TestStore store) { + final OtopkFactory factory = OtopkFactory.eINSTANCE; + { + store.beginTransaction(); + final EmployeeInfo ei = factory.createEmployeeInfo(); + final Employee e = factory.createEmployee(); + e.setEmployeeInfo(ei); + store.store(ei); + store.store(e); + store.commitTransaction(); + } + { + store.beginTransaction(); + final EmployeeInfo ei = factory.createEmployeeInfo(); + final Employee e = factory.createEmployee(); + e.setEmployeeInfo(ei); + store.store(ei); + store.store(e); + store.commitTransaction(); + } + { + store.beginTransaction(); + for (Object o : store.getObjects(Employee.class)) { + final Employee e = (Employee) o; + assertEquals(e.getId(), e.getEmployeeInfo().getId()); + } + store.commitTransaction(); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/OverrideSecondaryAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/OverrideSecondaryAction.java new file mode 100755 index 000000000..1e69befc7 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/OverrideSecondaryAction.java @@ -0,0 +1,116 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal</copyright> + * $Id: OverrideSecondaryAction.java,v 1.2 2010/02/06 18:25:53 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import org.eclipse.emf.teneo.samples.emf.annotations.attroverridesecondarytable.Address; +import org.eclipse.emf.teneo.samples.emf.annotations.attroverridesecondarytable.AttroverridesecondarytableFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.attroverridesecondarytable.AttroverridesecondarytablePackage; +import org.eclipse.emf.teneo.samples.emf.annotations.attroverridesecondarytable.Country; +import org.eclipse.emf.teneo.samples.emf.annotations.attroverridesecondarytable.Employee; +import org.eclipse.emf.teneo.samples.emf.annotations.attroverridesecondarytable.NonEmployee; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * See bugzilla 239800 + * + * @author mtaal@elver.org + */ +public class OverrideSecondaryAction extends AbstractTestAction { + + private static final String VERIFICATION_QUERY1 = "select count(*) from secondary_table where emp_num is not null"; + private static final String VERIFICATION_QUERY2 = + "select count(*) from secondary_table where other_name is not null"; + + public OverrideSecondaryAction() { + super(AttroverridesecondarytablePackage.eINSTANCE); + } + + @Override + public void doAction(TestStore store) { + { + store.beginTransaction(); + final AttroverridesecondarytableFactory factory = AttroverridesecondarytableFactory.eINSTANCE; + final Employee e = factory.createEmployee(); + String prefix = "abc"; + e.setName(prefix + "_name"); + e.setAddress(createAddress(prefix)); + e.setEmployeeNumber(prefix); + store.store(e); + final NonEmployee ne = factory.createNonEmployee(); + prefix = "def"; + ne.setName(prefix + "_name"); + ne.setAddress(createAddress(prefix)); + store.store(ne); + store.commitTransaction(); + } + + { + store.beginTransaction(); + final Employee e = store.getObject(Employee.class); + assertTrue(e.getName().startsWith("abc")); + assertTrue(e.getAddress().getCity().startsWith("abc")); + final NonEmployee ne = store.getObject(NonEmployee.class); + assertTrue(ne.getName().startsWith("def")); + assertTrue(ne.getAddress().getStreet().startsWith("def")); + store.commitTransaction(); + } + + testTable(store); + } + + private Address createAddress(String prefix) { + final AttroverridesecondarytableFactory factory = AttroverridesecondarytableFactory.eINSTANCE; + final Address address = factory.createAddress(); + address.setName(prefix + "_name"); + address.setStreet(prefix + "_street"); + address.setCity(prefix + "_city"); + final Country c = factory.createCountry(); + c.setName(prefix); + address.setCountry(c); + return address; + } + + private void testTable(TestStore store) { + final Connection conn = store.getConnection(); + Statement stmt = null; + ResultSet rs = null; + try { + stmt = conn.createStatement(); + rs = stmt.executeQuery(VERIFICATION_QUERY1); + rs.next(); + assertEquals(1, rs.getInt(1)); + rs.close(); + rs = stmt.executeQuery(VERIFICATION_QUERY2); + rs.next(); + assertEquals(1, rs.getInt(1)); + rs.close(); + } catch (final SQLException e) { + assertTrue(e.getMessage(), false); + } finally { + try { + if (stmt != null) { + stmt.close(); + } + } catch (final SQLException e) { + } + try { + if (rs != null) { + rs.close(); + } + } catch (final SQLException e) { + } + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/PKeyJoinAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/PKeyJoinAction.java new file mode 100755 index 000000000..60e6fcc59 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/PKeyJoinAction.java @@ -0,0 +1,89 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: PKeyJoinAction.java,v 1.6 2008/07/06 16:23:25 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.util.List; + +import org.eclipse.emf.teneo.samples.emf.annotations.primarykeyjoin.Body; +import org.eclipse.emf.teneo.samples.emf.annotations.primarykeyjoin.Head; +import org.eclipse.emf.teneo.samples.emf.annotations.primarykeyjoin.PrimarykeyjoinFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.primarykeyjoin.PrimarykeyjoinPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.6 $ + */ +public class PKeyJoinAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public PKeyJoinAction() { + super(PrimarykeyjoinPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final PrimarykeyjoinFactory factory = PrimarykeyjoinFactory.eINSTANCE; + { + store.beginTransaction(); + final Body bd = factory.createBody(); + bd.setTheID(5); + final Head hd = factory.createHead(); + hd.setMyID(5); + bd.setHead(hd); + store.store(bd); + store.store(hd); + store.commitTransaction(); + } + { + store.beginTransaction(); + final Body bd = store.getObject(Body.class); + assertEquals(5, bd.getHead().getMyID()); + assertEquals(5, bd.getTheID()); + store.commitTransaction(); + } + + { + store.beginTransaction(); + final Body bd = factory.createBody(); + bd.setTheID(6); + final Head hd = factory.createHead(); + hd.setMyID(7); + bd.setHead(hd); + store.store(bd); + store.store(hd); + store.commitTransaction(); + } + { + store.beginTransaction(); + final List<?> bds = store.getObjects(Body.class); + for (Object o : bds) { + final Body b = (Body) o; + assertTrue(b.getTheID() == 5 || b.getTheID() == 7); + } + store.commitTransaction(); + } + + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SecondaryTableActionJDO.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SecondaryTableActionJDO.java new file mode 100755 index 000000000..52d77b6dd --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SecondaryTableActionJDO.java @@ -0,0 +1,98 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: SecondaryTableActionJDO.java,v 1.5 2008/02/28 07:08:14 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import org.eclipse.emf.teneo.samples.emf.annotations.secondarytable.Printer; +import org.eclipse.emf.teneo.samples.emf.annotations.secondarytable.SecondarytableFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.secondarytable.SecondarytablePackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests annotations for SecondaryTable + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.5 $ + */ +public class SecondaryTableActionJDO extends AbstractTestAction { + + /** + * Constructor for ClassHierarchyParsing. + * @param arg0 + */ + public SecondaryTableActionJDO() { + super(SecondarytablePackage.eINSTANCE); + } + + /** Creates simple types and tests against */ + @Override + public void doAction(TestStore store) { + // test a simple type + final SecondarytableFactory factory = SecondarytableFactory.eINSTANCE; + { + store.beginTransaction(); + final Printer p = factory.createPrinter(); + p.setMake("HP"); + p.setModel("officejet 2500"); + p.setTonerMake("hp"); + p.setTonerModel("56"); + store.store(p); + store.commitTransaction(); + } + + { + store.beginTransaction(); + final Printer p = (Printer) store.getObject(Printer.class); + assertTrue(p.getMake().compareTo("HP") == 0); + assertTrue(p.getModel().compareTo("officejet 2500") == 0); + assertTrue(p.getTonerMake().compareTo("hp") == 0); + store.commitTransaction(); + } + + // do a sql query to detect that the second table was created + Connection conn = null; + Statement stmt = null; + try { + try { + conn = store.getConnection(); + stmt = conn.createStatement(); + final ResultSet rs = stmt.executeQuery("select * from thetoner"); + int cnt = 0; + while (rs.next()) { + cnt++; + } + rs.close(); + assertEquals(1, cnt); + } finally { + if (stmt != null) { + stmt.close(); + } + if (conn != null) { + conn.close(); + } + } + } catch (final SQLException e) { + throw new StoreTestException("Sql exception when retrieving objects", e); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SecondarytableHibernateAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SecondarytableHibernateAction.java new file mode 100755 index 000000000..32857e26f --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SecondarytableHibernateAction.java @@ -0,0 +1,140 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: SecondarytableHibernateAction.java,v 1.10 2010/02/06 18:25:53 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.List; +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.annotations.secondarytablehibernate.Person; +import org.eclipse.emf.teneo.samples.emf.annotations.secondarytablehibernate.SecondarytablehibernateFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.secondarytablehibernate.SecondarytablehibernatePackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Simple test for Secondary table. + */ +public class SecondarytableHibernateAction extends AbstractTestAction { + + private static final String ADDRESS = "Amsterdamseweg 123, 4567AZ Amsterdam"; + + private static final long ID = 1; + + private static final String NAME = "Jan Janssen"; + + private static final byte[] PHOTO = new byte[64 * 1024]; + + private static final String VERIFICATION_QUERY = + "SELECT * FROM PERSON as A INNER JOIN PERSON_ADDRESS as B ON A.ID = B.ID " + + "INNER JOIN PERSON_PHOTO as C ON A.ID = C.ID"; + + public SecondarytableHibernateAction() { + super(SecondarytablehibernatePackage.eINSTANCE); + } + + @Override + public void doAction(TestStore store) { + storePerson(store); + testPerson(store); + testSecondaryTables(store); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties() + */ + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.SQL_CASE_STRATEGY, "uppercase"); + return props; + } + + /** + * Stores a Person in the database. + */ + private void storePerson(TestStore store) { + store.beginTransaction(); + + final Person person = SecondarytablehibernateFactory.eINSTANCE.createPerson(); + person.setId(ID); + person.setName(NAME); + person.setAddress(ADDRESS); + person.setPhoto(PHOTO); + store.store(person); + + store.commitTransaction(); + } + + /** + * Retrieves the previously stored Person from the database and checks its attributes. + */ + private void testPerson(TestStore store) { + store.beginTransaction(); + + final List<?> results = store.query(Person.class, "id", String.valueOf(ID), 1); + assertEquals(1, results.size()); + final Person person = (Person) results.get(0); + assertEquals(ID, person.getId()); + assertEquals(NAME, person.getName()); + assertEquals(ADDRESS, person.getAddress()); + final byte[] photo = person.getPhoto(); + assertEquals(PHOTO.length, photo.length); + for (int i = 0; i < photo.length; i++) { + assertEquals(PHOTO[i], photo[i]); + } + + store.commitTransaction(); + } + + /** + * Executes a query to verify the existence of the secondary tables. + */ + private void testSecondaryTables(TestStore store) { + final Connection conn = store.getConnection(); + Statement statement = null; + ResultSet resultSet = null; + try { + statement = conn.createStatement(); + resultSet = statement.executeQuery(VERIFICATION_QUERY); + } catch (final SQLException e) { + throw new StoreTestException(e.getMessage(), e); + } finally { + try { + if (resultSet != null) { + resultSet.close(); + } + } catch (final SQLException e) { + } + try { + if (statement != null) { + statement.close(); + } + } catch (final SQLException e) { + } + } + + } + +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SecondarytableHibernateAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SecondarytableHibernateAction.persistence.xml new file mode 100755 index 000000000..34911d945 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SecondarytableHibernateAction.persistence.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/secondarytablehibernate"> + + <eclass name="Person"> + <secondary-table name="person_address"/> + <secondary-table name="person_photo"/> + <property name="id"> + <id/> + </property> + <property name="address"> + <lob /> + <column table="person_address"/> + </property> + <property name="photo"> + <lob /> + <column table="person_photo" length="1000000"/> + </property> + </eclass> + + </epackage> + +</persistence-mapping>
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SetNMAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SetNMAction.java new file mode 100755 index 000000000..7511ec47e --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SetNMAction.java @@ -0,0 +1,95 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: SetNMAction.java,v 1.4 2008/02/28 07:08:14 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.emf.teneo.samples.emf.annotations.nmset.MyItem; +import org.eclipse.emf.teneo.samples.emf.annotations.nmset.NmsetFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.nmset.NmsetPackage; +import org.eclipse.emf.teneo.samples.emf.annotations.nmset.YourItem; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests an nm relation using sets on both sides. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.4 $ + */ +public class SetNMAction extends AbstractTestAction { + /** The number of testitems created */ + private static int NO_ITEMS = 10; + + /** + * Constructor for ClassHierarchyParsing. + * @param arg0 + */ + public SetNMAction() { + super(NmsetPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final NmsetFactory factory = NmsetFactory.eINSTANCE; + // create a book, writer and library + { + store.beginTransaction(); + + final ArrayList<MyItem> myItems = new ArrayList<MyItem>(); + for (int i = 0; i < NO_ITEMS; i++) { + final MyItem myitem = factory.createMyItem(); + myitem.setName("myname_" + i); + myItems.add(myitem); + store.store(myitem); + } + for (int i = 0; i < NO_ITEMS; i++) { + final YourItem youritem = factory.createYourItem(); + youritem.setName("yourname_" + i); + youritem.getMyItem().addAll(myItems); + store.store(youritem); + } + store.commitTransaction(); + } + + { + store.beginTransaction(); + final List<?> list = store.getObjects(MyItem.class); + assertTrue(list.size() == NO_ITEMS); + for (int i = 0; i < list.size(); i++) { + assertEquals(NO_ITEMS, ((MyItem) list.get(i)).getYourItem().size()); + ((MyItem) list.get(i)).getYourItem().remove(i); + } + store.commitTransaction(); + } + + { + store.beginTransaction(); + final List<?> list = store.getObjects(MyItem.class); + assertTrue(list.size() == NO_ITEMS); + for (int i = 0; i < list.size(); i++) { + assertEquals(NO_ITEMS - 1, ((MyItem) list.get(i)).getYourItem().size()); + if (i < list.size() - 1) { + assertEquals("yourname_" + (i + 1), (((MyItem) list.get(i)).getYourItem().get(i)).getName()); + } + } + store.commitTransaction(); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SetResourceAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SetResourceAction.java new file mode 100755 index 000000000..739a1ea8a --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SetResourceAction.java @@ -0,0 +1,199 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * SetResourceAction.java,v 1.4 2007/02/08 23:11:22 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Properties; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.InternalEObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.annotations.set.ContainedItem; +import org.eclipse.emf.teneo.samples.emf.annotations.set.Item; +import org.eclipse.emf.teneo.samples.emf.annotations.set.ItemList; +import org.eclipse.emf.teneo.samples.emf.annotations.set.SetFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.set.SetPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests the library example of emf/xsd using a resource. Actually tests bidirectional references + * using resources. Most other aspects of resources are handled in the Catalog example. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.8 $ + */ +public class SetResourceAction extends AbstractTestAction { + /** The number of testitems created */ + private static int NO_ITEMS = 10; + + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public SetResourceAction() { + super(SetPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final SetFactory factory = SetFactory.eINSTANCE; + + // create a book, writer and library + try { + final ArrayList<String> names = new ArrayList<String>(); + final ArrayList<String> cnames = new ArrayList<String>(); + { + final Resource res = store.getResource(); + res.load(null); + + final ItemList list = factory.createItemList(); + list.setName("name"); + + for (int i = 0; i < NO_ITEMS; i++) { + final Item item = factory.createItem(); + item.setName("name_" + i); + names.add("name_" + i); + list.getItem().add(item); + + final ContainedItem citem = factory.createContainedItem(); + citem.setName("cname_" + i); + cnames.add("cname_" + i); + list.getContainedItem().add(citem); + + final Item joinedItem = factory.createItem(); + joinedItem.setName("joinedname_" + i); + list.getJoinedItem().add(joinedItem); + } + + res.getContents().add(list); + res.save(null); + res.unload(); + } + + // remove(i), removeAll, move + { + final Resource res = store.getResource(); + res.load(null); + ItemList list = null; + for (int i = 0; i < res.getContents().size(); i++) { + if (res.getContents().get(i) instanceof ItemList) { + list = (ItemList) res.getContents().get(i); + } + } + + assert (list != null); + assertEquals(NO_ITEMS, list.getItem().size()); + assertEquals(NO_ITEMS, list.getContainedItem().size()); + assertEquals(NO_ITEMS, list.getJoinedItem().size()); + + // do some actions + // remove from a certain position + for (int i = 0; i < list.getContainedItem().size(); i++) { + assertEquals(list, ((InternalEObject) list.getContainedItem().get(i)).eContainer()); + if (i % 2 == 0) { + final ContainedItem citem = list.getContainedItem().get(i); + cnames.remove(citem.getName()); // remove from here to check later + list.getContainedItem().remove(i); + } + } + + // test removeall + final ArrayList<Item> tobeDeleted = new ArrayList<Item>(); + for (int i = 0; i < NO_ITEMS; i++) { + assertTrue(list == list.getItem().get(i).getItemList()); + if (i % 2 == 0) { + tobeDeleted.add(list.getItem().get(i)); + names.remove(list.getItem().get(i).getName()); + } + } + for (final Object o : tobeDeleted) { + list.getItem().remove(o); + } + assertEquals(names.size(), list.getItem().size()); + + // test move (should not really change anything) + final Object obj = list.getItem().get(3); + list.getItem().move(1, 3); + assertEquals(1, list.getItem().indexOf(obj)); + + res.save(null); + res.unload(); + } + + int newCount = 0; + { + final Resource res = store.getResource(); + res.load(null); + ItemList list = null; + for (int i = 0; i < res.getContents().size(); i++) { + if (res.getContents().get(i) instanceof ItemList) { + list = (ItemList) res.getContents().get(i); + } + } + + assert (list != null); + + final ArrayList<String> checkNames = new ArrayList<String>(names); + for (int i = 0; i < list.getItem().size(); i++) { + assertTrue(checkNames.remove(list.getItem().get(i).getName())); + } + assertEquals(0, checkNames.size()); + + final ArrayList<String> checkCNames = new ArrayList<String>(cnames); + for (int i = 0; i < list.getContainedItem().size(); i++) { + assertTrue(checkCNames.remove(list.getContainedItem().get(i).getName())); + } + assertEquals(0, checkCNames.size()); + + final ArrayList<Item> newList = new ArrayList<Item>(); + newCount = list.getItem().size(); + for (int i = 0; i < NO_ITEMS; i++) { + final Item item = SetFactory.eINSTANCE.createItem(); + item.setName("do " + i); + newList.add(item); + newCount++; + } + final EList<Item> myList = list.getItem(); + myList.addAll(newList); + res.save(null); + res.unload(); + } + + { + final Resource res = store.getResource(); + res.load(null); + ItemList list = null; + for (int i = 0; i < res.getContents().size(); i++) { + if (res.getContents().get(i) instanceof ItemList) { + list = (ItemList) res.getContents().get(i); + } + } + assert (list != null); + assertEquals(newCount, list.getItem().size()); + res.save(null); + res.unload(); + } + } catch (final IOException e) { + throw new StoreTestException("IOException during save", e); + } + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true"); + return props; + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ToOneAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ToOneAction.java new file mode 100755 index 000000000..e94ceabd2 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ToOneAction.java @@ -0,0 +1,80 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: ToOneAction.java,v 1.6 2008/06/28 22:41:29 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import org.eclipse.emf.teneo.samples.emf.annotations.toone.Address; +import org.eclipse.emf.teneo.samples.emf.annotations.toone.Arm; +import org.eclipse.emf.teneo.samples.emf.annotations.toone.Head; +import org.eclipse.emf.teneo.samples.emf.annotations.toone.Person; +import org.eclipse.emf.teneo.samples.emf.annotations.toone.TooneFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.toone.ToonePackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.6 $ + */ +public class ToOneAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public ToOneAction() { + super(ToonePackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final TooneFactory factory = TooneFactory.eINSTANCE; + + { + store.beginTransaction(); + final Arm arm = factory.createArm(); + arm.setLength(50); + final Address a = factory.createAddress(); + a.setCity("Amersfoort"); + final Person p = factory.createPerson(); + final Head h = factory.createHead(); + h.setHairColor("braun"); + + p.setAddress(a); + p.setHead(h); + p.setLeftArm(arm); + store.store(arm); + store.store(p); + store.commitTransaction(); + } + + // read back and check it + { + store.beginTransaction(); + final Person p = store.getObject(Person.class); + store.deleteObject(p); + store.commitTransaction(); + } + + store.checkNumber(Person.class, 0); + store.checkNumber(Head.class, 0); + store.checkNumber(Address.class, 1); + store.checkNumber(Arm.class, 1); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ToOneAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ToOneAction.persistence.xml new file mode 100755 index 000000000..b4ba5e0bb --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ToOneAction.persistence.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <!-- Template for TestAction persistence mapping. --> + + <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/toone"> + + <eclass name="Head"> + <property name="person"> + <one-to-one target-entity="Person" optional="false" mapped-by="head" fetch="EAGER"> + <cascade>MERGE</cascade> + <cascade>PERSIST</cascade> + <cascade>REFRESH</cascade> + </one-to-one> + </property> + </eclass> + + <eclass name="Person"> + <property name="address"> + <many-to-one fetch="EAGER" target-entity="Address" optional="true"> + <cascade>MERGE</cascade> + <cascade>PERSIST</cascade> + <cascade>REFRESH</cascade> + </many-to-one> + </property> + <property name="head"> + <one-to-one fetch="EAGER" target-entity="Head" optional="true" cascade="ALL" /> + </property> + </eclass> + + </epackage> + +</persistence-mapping>
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/TransientAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/TransientAction.java new file mode 100755 index 000000000..2ffb5be68 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/TransientAction.java @@ -0,0 +1,69 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * TransientAction.java,v 1.3 2007/02/01 12:35:37 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.util.List; + +import org.eclipse.emf.teneo.samples.emf.annotations.transent.Body; +import org.eclipse.emf.teneo.samples.emf.annotations.transent.Head; +import org.eclipse.emf.teneo.samples.emf.annotations.transent.TransentFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.transent.TransentPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Test transient eclass + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.6 $ + */ +public class TransientAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public TransientAction() { + super(TransentPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final TransentFactory factory = TransentFactory.eINSTANCE; + { + store.beginTransaction(); + final Body bd = factory.createBody(); + bd.setTheID(5); + final Head hd = factory.createHead(); + hd.setMyID(5); + bd.setHead(hd); + store.store(bd); + store.commitTransaction(); + } + { + store.beginTransaction(); + final Body bd = (Body) store.getObject(Body.class); + assertEquals(null, bd.getHead()); + store.commitTransaction(); + } + { + store.beginTransaction(); + try { + final List<?> list = store.getObjects(Head.class); + assertTrue(list != null);// dummy to get rid of warning + store.commitTransaction(); + fail("head is not mapped!"); + } catch (final Throwable t) { + // success + } + } + + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/TransientAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/TransientAction.persistence.xml new file mode 100755 index 000000000..6bb9b660b --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/TransientAction.persistence.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/transent"> + + <eclass name="Body"> + <property name="theID"> + <id/> + </property> + </eclass> + + <eclass name="Head"> + <transient/> + </eclass> + + </epackage> + +</persistence-mapping>
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/UniqueConstraintsAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/UniqueConstraintsAction.java new file mode 100755 index 000000000..92ea05278 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/UniqueConstraintsAction.java @@ -0,0 +1,85 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * UniqueConstraintsAction.java,v 1.3 2007/02/11 21:52:19 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.annotations; + +import org.eclipse.emf.teneo.samples.emf.annotations.uniqueconstraints.Item; +import org.eclipse.emf.teneo.samples.emf.annotations.uniqueconstraints.Project; +import org.eclipse.emf.teneo.samples.emf.annotations.uniqueconstraints.UniqueconstraintsFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.uniqueconstraints.UniqueconstraintsPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.8 $ + */ +public class UniqueConstraintsAction extends AbstractTestAction { + /** + * Constructor + */ + public UniqueConstraintsAction() { + super(UniqueconstraintsPackage.eINSTANCE); + } + + /** Test */ + @Override + public void doAction(TestStore store) { + final UniqueconstraintsFactory factory = UniqueconstraintsFactory.eINSTANCE; + // create a book, writer and library + { + store.beginTransaction(); + final Project project = factory.createProject(); + project.setName("project_name"); + store.store(project); + final Item item = factory.createItem(); + item.setAge(5); + item.setName("name"); + item.setProject(project); + store.store(item); + store.commitTransaction(); + } + + try { + store.beginTransaction(); + final Project p = store.getObject(Project.class); + final Item item = factory.createItem(); + item.setAge(5); + item.setName("name"); + item.setProject(p); + store.store(item); + store.commitTransaction(); + fail("The uniqueconstraint has not been applied"); + } catch (final Exception s) { + // this is correct behavior + store.rollbackTransaction(); + } + + { + store.beginTransaction(); + final Item item = factory.createItem(); + item.setAge(5); + item.setName("otherName"); + store.store(item); + store.commitTransaction(); + } + + { + store.beginTransaction(); + final Item item = factory.createItem(); + item.setAge(6); + item.setName("name"); + store.store(item); + store.commitTransaction(); + } + + store.checkNumber(Item.class, 3); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/UniqueConstraintsAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/UniqueConstraintsAction.persistence.xml new file mode 100755 index 000000000..1189a6938 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/UniqueConstraintsAction.persistence.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/uniqueconstraints"> + + <eclass name="Item"> + <table> + <unique-constraint>MYSTR,MYINT,MYPROJECT</unique-constraint> + </table> + <property name="name"> + <column name="MYSTR" /> + </property> + <property name="project"> + <join-column name="MYPROJECT" /> + </property> + <property name="age"> + <column name="MYINT" /> + </property> + + </eclass> + + </epackage> + +</persistence-mapping>
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/VariousAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/VariousAction.java new file mode 100755 index 000000000..c05ee4008 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/VariousAction.java @@ -0,0 +1,117 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: VariousAction.java,v 1.3 2009/03/15 09:26:09 mtaal Exp $ + */ +package org.eclipse.emf.teneo.test.emf.annotations; + +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.annotations.various.Child; +import org.eclipse.emf.teneo.samples.emf.annotations.various.ImmutableCity; +import org.eclipse.emf.teneo.samples.emf.annotations.various.Parent; +import org.eclipse.emf.teneo.samples.emf.annotations.various.VariousFactory; +import org.eclipse.emf.teneo.samples.emf.annotations.various.VariousPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase for bz 239757, 239802, 239756 + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ + */ +public class VariousAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public VariousAction() { + super(VariousPackage.eINSTANCE); + } + + /** Add an option to force to use an idbag */ + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty( + PersistenceOptions.SQL_DISCRIMINATOR_VERSION_IMMUTABLE_ECLASS, + "false"); + return props; + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final VariousFactory factory = VariousFactory.eINSTANCE; + { + store.beginTransaction(); + final ImmutableCity c = factory.createImmutableCity(); + c.setName("test"); + final Parent p1 = createParent(); + store.store(p1); + c.getParents().add(p1); + final Parent p2 = createParent(); + store.store(p2); + c.getParents().add(p2); + store.store(c); + store.commitTransaction(); + } + + { + store.beginTransaction(); + final ImmutableCity c = store.getObject(ImmutableCity.class); + c.setName("test2"); + store.store(c); + store.commitTransaction(); + } + // name should not have changed + { + store.beginTransaction(); + final ImmutableCity c = store.getObject(ImmutableCity.class); + assertEquals("test", c.getName()); + store.store(c); + for (Parent p : c.getParents()) { + // 2 parents and 10 children + assertEquals(12, p.getTotalPeople()); + } + + store.commitTransaction(); + } + { + store.beginTransaction(); + final ImmutableCity c = store.getObject(ImmutableCity.class); + c.getParents().remove(1); + store.store(c); + try { + // collection change is not allowed + store.commitTransaction(); + fail(); + } catch (Exception e) { + store.rollbackTransaction(); + } + } + } + + private Parent createParent() { + final VariousFactory factory = VariousFactory.eINSTANCE; + final Parent p = factory.createParent(); + for (int i = 0; i < 5; i++) { + final Child c = factory.createChild(); + p.getChildren().add(c); + } + return p; + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/_template.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/_template.persistence.xml new file mode 100755 index 000000000..3b078bc35 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/_template.persistence.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> +<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <!-- Template for TestAction persistence mapping. --> + + <epackage namespace-uri="[NAMESPACEURI]"> + + <eclass name="[NAME]"> + + </eclass> + + </epackage> + +</persistence-mapping>
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/small_play.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/small_play.xml new file mode 100755 index 000000000..84f4dd1b1 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/small_play.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="ASCII"?> +<play:PlayType xmlns:play="http://www.eclipse.org/emf/teneo/samples/emf/sample/play" title="A Midsummer Night's Dream" sceneDescription="SCENE Athens, and a wood near it." playSubTitle="A MIDSUMMER NIGHT'S DREAM"> + <fm> + <p>Text placed in the public domain by Moby Lexical Tools, 1992.</p> + <p>SGML markup by Jon Bosak, 1992-1994.</p> + <p>XML version by Jon Bosak, 1996-1998.</p> + <p>Altered slightly by Bryan Dollery, 2003, for inclusion in an article on XML parsing in Java. Published in DevX (www.devx.com) in February 2003</p> + <p>This work may be freely copied and distributed worldwide.</p> + </fm> + <personae> + <title>Dramatis Personae</title> + <persona>THESEUS, Duke of Athens.</persona> + <persona>EGEUS, father to Hermia.</persona> + <personaGroup groupDescription="in love with Hermia."> + <persona>LYSANDER</persona> + <persona>DEMETRIUS</persona> + </personaGroup> + <persona>PHILOSTRATE, master of the revels to Theseus.</persona> + <persona>QUINCE, a carpenter.</persona> + <persona>SNUG, a joiner.</persona> + <persona>BOTTOM, a weaver.</persona> + <persona>FLUTE, a bellows-mender.</persona> + <persona>SNOUT, a tinker.</persona> + <persona>STARVELING, a tailor.</persona> + <persona>HIPPOLYTA, queen of the Amazons, betrothed to Theseus.</persona> + <persona>HERMIA, daughter to Egeus, in love with Lysander.</persona> + <persona>HELENA, in love with Demetrius.</persona> + <persona>OBERON, king of the fairies.</persona> + <persona>TITANIA, queen of the fairies.</persona> + <persona>PUCK, or Robin Goodfellow.</persona> + <personaGroup groupDescription="fairies."> + <persona>PEASEBLOSSOM</persona> + <persona>COBWEB</persona> + <persona>MOTH</persona> + <persona>MUSTARDSEED</persona> + </personaGroup> + <persona>Other fairies attending their King and Queen.</persona> + <persona>Attendants on Theseus and Hippolyta.</persona> + </personae> + <act pindex="1" title="I"> + <scene pindex="1" title="SCENE I. Athens. The palace of THESEUS."> + <stageDirections>Enter THESEUS, HIPPOLYTA, PHILOSTRATE, and Attendants</stageDirections> + <speech> + <speaker>THESEUS</speaker> + <line>Now, fair Hippolyta, our nuptial hour</line> + </speech> + </scene> + </act> +</play:PlayType> diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/detach/DetachAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/detach/DetachAction.java new file mode 100755 index 000000000..ba3e98762 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/detach/DetachAction.java @@ -0,0 +1,217 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: DetachAction.java,v 1.10 2008/06/02 07:15:40 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.detach; + +import java.io.IOException; +import java.util.Date; +import java.util.Iterator; + +import javax.xml.datatype.XMLGregorianCalendar; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.samples.emf.detach.detachtest.DetachtestFactory; +import org.eclipse.emf.teneo.samples.emf.detach.detachtest.DetachtestPackage; +import org.eclipse.emf.teneo.samples.emf.detach.detachtest.TestA; +import org.eclipse.emf.teneo.samples.emf.detach.detachtest.TestB; +import org.eclipse.emf.teneo.samples.emf.detach.detachtest.TestC; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Is a test case to test basic detach functionality in the dao resource; Specifically for JPOX/JDO + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.10 $ + */ +public abstract class DetachAction extends AbstractTestAction { + + /** Constructor */ + public DetachAction() { + super(DetachtestPackage.eINSTANCE); + } + + /** Stores a TopModel Object */ + @Override + public void doAction(TestStore store) { + try { + DetachtestFactory factory = DetachtestFactory.eINSTANCE; + // Create objects + { + Resource res = store.getResource(); + res.load(null); + + TestB testb = factory.createTestB(); + testb.setCode("testb"); + + TestA testa = factory.createTestA(); + testa.setCode("testa"); + testa.setTestB(testb); + + TestB testb2 = factory.createTestB(); + testb2.setCode("testb2"); + TestB testb3 = factory.createTestB(); + testb3.setCode("testb3"); + + TestC testc = factory.createTestC(); + testc.setCode("testc"); + testc.setMyDate((XMLGregorianCalendar) store.getDate(new Date())); + testc.getTestB().add(testb2); + testc.getTestB().add(testb3); + + res.getContents().add(testc); + res.getContents().add(testa); + + res.save(null); + + // check the state of some of the objects + // MT: in the new version objects are not detached anymore + // checkDetached(testa); + // checkDetached(testb); + // checkDetached(testb2); + // checkDetached(testb3); + // checkDetached(testc); + + // check some fields + if (testa.getTestB() == null || testa.getCode() == null) { + throw new Error("Values are lost in detached objects!"); + } + + // check some fields + if (testc.getTestB() == null || testc.getCode() == null) { + throw new Error("Values are lost in detached objects!"); + } + res.unload(); + } + + // Now retrieve TestA and TestC and detach them also + { + Resource res = store.getResource(); + res.load(null); + + Iterator<?> it = res.getContents().iterator(); + TestA testa = null; + TestC testc = null; + while (it.hasNext()) { + Object obj = it.next(); + if (obj instanceof TestA) { + assertTrue(testa == null); + testa = (TestA) obj; + } + if (obj instanceof TestC) { + assertTrue(testc == null); + testc = (TestC) obj; + } + } + + assert (testc != null); + assert (testa != null); + + // get testb to force a load + if (testc.getTestB().size() != 2 || (testc.getTestB().get(0)).getCode().compareTo("testb2") != 0) { + throw new Error("Where is testb?"); + } + + // now save and detach + res.save(null); + + // MT: in the new version objects are not detached anymore + // checkDetached(testa); + // checkDetached((EObject) testc.getTestB().get(0)); + // checkDetached(testc); + + if (testc.getMyDate() == null) { + throw new Error("This should not be possible"); + } + // now change the code of one, delete one testb from testc and add one + testa.setCode("detached"); + + TestB testb = factory.createTestB(); + testb.setCode("testb4"); + + testc.getTestB().remove(0); + testc.getTestB().add(testb); + + // reattach again! + res.save(null); + res.unload(); + } + + // Now retrieve TestA and TestC and detach them also + { + Resource res = store.getResource(); + res.load(null); + + Iterator<EObject> it = res.getContents().iterator(); + TestA testa = null; + TestC testc = null; + while (it.hasNext()) { + Object obj = it.next(); + if (obj instanceof TestA) { + assertTrue(testa == null); + testa = (TestA) obj; + } + if (obj instanceof TestC) { + assertTrue(testc == null); + testc = (TestC) obj; + } + } + + assert (testa != null); + assert (testc != null); + + if (testa.getCode().compareTo("detached") != 0) { + throw new StoreTestException("The code of testa was not set!"); + } + + if ((testc.getTestB().get(0)).getCode().compareTo("testb3") != 0 || + (testc.getTestB().get(1)).getCode().compareTo("testb4") != 0) { + throw new StoreTestException("TestB was not set"); + } + + // get testb to force a load + if (testc.getTestB().size() != 2) { + throw new Error("Testb should have 2 children!"); + } + res.save(null); + res.unload(); + + // do some final tests + // MT: in the new version objects are not detached anymore + // checkDetached(testa); + // checkDetached((EObject) testc.getTestB().get(0)); + // checkDetached((EObject) testc.getTestB().get(1)); + // checkDetached(testc); + } + } catch (IOException e) { + throw new StoreTestException("IOException in resource detach test", e); + } + } + + /** Checks if a certain object is really detached */ + protected abstract void checkDetached(EObject eObject); + // TODO specialize for hibernate/JPOX + // if (eObject instanceof PersistenceCapable) { + // PersistenceCapable pc = (PersistenceCapable) eObject; + // if (!pc.jdoIsDetached()) + // fail("The object with class: " + pc.getClass().getName() + " is not detached"); + // + // if (pc.jdoGetObjectId() == null) + // fail("The object with class: " + pc.getClass().getName() + " has no id!"); + // } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/detach/DetachEListAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/detach/DetachEListAction.java new file mode 100755 index 000000000..9923d1b01 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/detach/DetachEListAction.java @@ -0,0 +1,241 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * DetachEListAction.java,v 1.3 2007/02/01 12:35:37 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.detach; + +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; + +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.detach.detachelist.Contacts; +import org.eclipse.emf.teneo.samples.emf.detach.detachelist.DetachelistFactory; +import org.eclipse.emf.teneo.samples.emf.detach.detachelist.DetachelistPackage; +import org.eclipse.emf.teneo.samples.emf.detach.detachelist.Person; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Is a test case to test detach functionality in the dao resource using an elist, checks insert, + * move, etc. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.5 $ + */ +public class DetachEListAction extends AbstractTestAction { + + /** Constructor */ + public DetachEListAction() { + super(DetachelistPackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true"); + return props; + } + + /** Stores a TopModel Object */ + @Override + public void doAction(TestStore store) { + try { + DetachelistFactory factory = DetachelistFactory.eINSTANCE; + + { + final Resource resource = store.getResource(); + + resource.load(Collections.EMPTY_MAP); + assertTrue(resource.getContents().size() == 0); + + // add test data + Contacts contacts = factory.createContacts(); + Person person1 = factory.createPerson(); + person1.setName("001"); + Person person2 = factory.createPerson(); + person2.setName("002"); + + contacts.getPersons().add(person1); + contacts.getPersons().add(person2); + resource.getContents().add(contacts); + resource.getContents().add(person1); + resource.getContents().add(person2); + + // this prevents a null constraint exc in hibernate + // assertEquals(0, contacts.getContainedPersons().size()); + resource.save(Collections.EMPTY_MAP); + + contacts = (Contacts) resource.getContents().get(0); + person1 = contacts.getPersons().get(0); + person2 = contacts.getPersons().get(1); + + contacts.getPersons().clear(); + contacts.getPersons().add(person1); + contacts.getPersons().add(person2); + resource.save(Collections.EMPTY_MAP); + resource.unload(); + } + + assertFalse(store.transactionActive()); + + { + Resource resource = store.getResource(); + resource.load(Collections.EMPTY_MAP); + Contacts contacts = getContacts(resource); + Person person = contacts.getPersons().get(0); + assertEquals("001", person.getName()); + person = contacts.getPersons().get(1); + assertEquals("002", person.getName()); + resource.unload(); + } + + assertFalse(store.transactionActive()); + + // now move everything around + { + Resource resource = store.getResource(); + resource.load(Collections.EMPTY_MAP); + Contacts contacts = getContacts(resource); + Person person1 = contacts.getPersons().get(0); + Person person2 = contacts.getPersons().get(1); + contacts.getPersons().clear(); + contacts.getPersons().add(person2); + contacts.getPersons().add(person1); + resource.save(Collections.EMPTY_MAP); + resource.unload(); + } + assertFalse(store.transactionActive()); + + { + Resource resource = store.getResource(); + resource.load(Collections.EMPTY_MAP); + Contacts contacts = getContacts(resource); + Person person1 = contacts.getPersons().get(0); + Person person2 = contacts.getPersons().get(1); + assertTrue(person1.getName().compareTo("002") == 0); + assertTrue(person2.getName().compareTo("001") == 0); + resource.save(Collections.EMPTY_MAP); + resource.unload(); + } + assertFalse(store.transactionActive()); + + // add two and delete 1 + { + Resource resource = store.getResource(); + resource.load(Collections.EMPTY_MAP); + Contacts contacts = getContacts(resource); + Person person3 = factory.createPerson(); + person3.setName("003"); + Person person4 = factory.createPerson(); + person4.setName("004"); + + contacts.getPersons().add(person3); + contacts.getPersons().add(person4); + contacts.getPersons().remove(1); // remove person 001 + resource.save(Collections.EMPTY_MAP); + resource.unload(); + } + assertFalse(store.transactionActive()); + + // check if this actually worked + { + Resource resource = store.getResource(); + resource.load(Collections.EMPTY_MAP); + Contacts contacts = getContacts(resource); + assertEquals("002", (contacts.getPersons().get(0)).getName()); + assertEquals("003", (contacts.getPersons().get(1)).getName()); + assertEquals("004", (contacts.getPersons().get(2)).getName()); + resource.save(Collections.EMPTY_MAP); + resource.unload(); + } + assertFalse(store.transactionActive()); + + // do a set and move + { + Resource resource = store.getResource(); + resource.load(Collections.EMPTY_MAP); + Contacts contacts = getContacts(resource); + contacts.getPersons().move(0, 2); // order is now 004, 002, 003 + Person person5 = factory.createPerson(); + person5.setName("005"); + contacts.getPersons().set(2, person5); // order is now 004, 002, 005 + resource.save(Collections.EMPTY_MAP); + resource.unload(); + } + assertFalse(store.transactionActive()); + + // the order should be 004, 002, 005 + { + Resource resource = store.getResource(); + resource.load(Collections.EMPTY_MAP); + Contacts contacts = getContacts(resource); + assertEquals("004", (contacts.getPersons().get(0)).getName()); + assertEquals("002", (contacts.getPersons().get(1)).getName()); + assertEquals("005", (contacts.getPersons().get(2)).getName()); + resource.save(Collections.EMPTY_MAP); + resource.unload(); + } + assertFalse(store.transactionActive()); + + { + Resource resource = store.getResource(); + resource.load(Collections.EMPTY_MAP); + Contacts contacts = getContacts(resource); + Person person = factory.createPerson(); + person.setName("c1"); + contacts.getContainedPersons().add(person); + resource.save(Collections.EMPTY_MAP); + resource.unload(); + } + assertFalse(store.transactionActive()); + + { + Resource resource = store.getResource(); + resource.load(Collections.EMPTY_MAP); + Contacts contacts = getContacts(resource); + Person c1 = contacts.getContainedPersons().get(0); + Person person004_1 = factory.createPerson(); + person004_1.setName("004.1"); + c1.getChildren().add(person004_1); + resource.save(Collections.EMPTY_MAP); + contacts.getContainedPersons().remove(0); + resource.save(Collections.EMPTY_MAP); + resource.unload(); + } + { + // check that the previous step actually deleted the persons + store.beginTransaction(); + final List<?> list = store.getObjects(Person.class); + final Iterator<?> it = list.iterator(); + while (it.hasNext()) { + final Person person = (Person) it.next(); + assertTrue(person.getName().compareTo("c1") != 0 && person.getName().compareTo("004.1") != 0); + } + store.commitTransaction(); + } + assertFalse(store.transactionActive()); + } catch (Exception e) { + throw new StoreTestException("Exception during detach elist test", e); + } + } + + /** Get the contacts object */ + private Contacts getContacts(Resource resource) { + final Iterator<?> it = resource.getContents().iterator(); + while (it.hasNext()) { + final Object obj = it.next(); + if (obj instanceof Contacts) { + return (Contacts) obj; + } + } + return null; + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/detach/DetachFeatureMapAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/detach/DetachFeatureMapAction.java new file mode 100755 index 000000000..11ebdeb97 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/detach/DetachFeatureMapAction.java @@ -0,0 +1,284 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: DetachFeatureMapAction.java,v 1.6 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.detach; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Properties; + +import org.eclipse.emf.common.command.BasicCommandStack; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.util.FeatureMap; +import org.eclipse.emf.edit.command.CopyCommand; +import org.eclipse.emf.edit.command.CopyCommand.Helper; +import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.emf.edit.provider.ComposedAdapterFactory; +import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory; +import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory; +import org.eclipse.emf.teneo.samples.emf.detach.detachfeaturemap.Contacts; +import org.eclipse.emf.teneo.samples.emf.detach.detachfeaturemap.DetachfeaturemapFactory; +import org.eclipse.emf.teneo.samples.emf.detach.detachfeaturemap.DetachfeaturemapPackage; +import org.eclipse.emf.teneo.samples.emf.detach.detachfeaturemap.Person; +import org.eclipse.emf.teneo.samples.emf.detach.detachfeaturemap.SpecialPerson; +import org.eclipse.emf.teneo.samples.emf.detach.detachfeaturemap.provider.DetachfeaturemapItemProviderAdapterFactory; +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.resource.StoreResource; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Is a test case to test detach functionality for featuremap with different kinds of methods + * on the featuremap (move, set, etc). + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.6 $ + */ +public class DetachFeatureMapAction extends AbstractTestAction { + + /** Constructor */ + public DetachFeatureMapAction() { + super(DetachfeaturemapPackage.eINSTANCE); + } + + /** + * Says to use the mapping file, actually only relevant for hibernate + */ + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.put(PersistenceOptions.USE_MAPPING_FILE, "true"); + return props; + } + + /** Stores a TopModel Object */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + try { + DetachfeaturemapFactory factory = DetachfeaturemapFactory.eINSTANCE; + + { + final Resource resource = store.getResource(); + + resource.load(Collections.EMPTY_MAP); + assertTrue(resource.getContents().size() == 0); + + // add test data + Contacts contacts = factory.createContacts(); + Person person = factory.createPerson(); + person.setName(""); + person.getMobile().add("001"); + person.getMobile().add("002"); + + contacts.getPersons().add(person); + + SpecialPerson specialPerson = factory.createSpecialPerson(); + specialPerson.setName(""); + specialPerson.getMobile().add("001"); + specialPerson.getMobile().add("002"); + contacts.getPersons().add(specialPerson); + + resource.getContents().add(contacts); + + resource.save(Collections.EMPTY_MAP); + + contacts = (Contacts) resource.getContents().get(0); + person = (Person) contacts.getPersons().get(0); + + assertEquals(2, person.getMobile().size()); + + EList<Object> mobiles = person.getMobile(); + + Object m1 = mobiles.get(0); + Object m2 = mobiles.get(1); + + for (Object o : new ArrayList<Object>(mobiles)) { + mobiles.remove(o); + } + // mobiles.clear(); + + mobiles.add(m1); + mobiles.add(m2); + + resource.save(Collections.EMPTY_MAP); + resource.unload(); + } + + { + Resource resource = store.getResource(); + resource.load(Collections.EMPTY_MAP); + Contacts contacts = (Contacts) resource.getContents().get(0); + Person person = (Person) contacts.getPersons().get(0); + + assertEquals(2, person.getMobile().size()); + resource.unload(); + } + + // now move everything around + { + Resource resource = store.getResource(); + resource.load(Collections.EMPTY_MAP); + Contacts contacts = (Contacts) resource.getContents().get(0); + Person person = (Person) contacts.getPersons().get(0); + + Object p0 = person.getPhones().get(0); + Object p1 = person.getPhones().get(1); + person.getPhones().clear(); + person.getPhones().add((FeatureMap.Entry) p1); + person.getPhones().add((FeatureMap.Entry) p0); + + assertEquals(2, person.getMobile().size()); + resource.save(Collections.EMPTY_MAP); + resource.unload(); + } + + { + Resource resource = store.getResource(); + resource.load(Collections.EMPTY_MAP); + Contacts contacts = (Contacts) resource.getContents().get(0); + Person person = (Person) contacts.getPersons().get(0); + assertTrue(person.getMobile().get(0).toString().compareTo("002") == 0); + assertTrue(person.getMobile().get(1).toString().compareTo("001") == 0); + resource.save(Collections.EMPTY_MAP); + resource.unload(); + } + + // add two and delete 1 + { + Resource resource = store.getResource(); + resource.load(Collections.EMPTY_MAP); + Contacts contacts = (Contacts) resource.getContents().get(0); + Person person = (Person) contacts.getPersons().get(0); + person.getMobile().add("003"); + person.getMobile().add("004"); + person.getMobile().remove(1); // removes 001 + resource.save(Collections.EMPTY_MAP); + resource.unload(); + } + + // check if this actually worked + { + Resource resource = store.getResource(); + resource.load(Collections.EMPTY_MAP); + Contacts contacts = (Contacts) resource.getContents().get(0); + Person person = (Person) contacts.getPersons().get(0); + assertTrue(person.getMobile().get(0).toString().compareTo("002") == 0); + assertTrue(person.getMobile().get(1).toString().compareTo("003") == 0); + assertTrue(person.getMobile().get(2).toString().compareTo("004") == 0); + resource.save(Collections.EMPTY_MAP); + resource.unload(); + } + + // do a set and move + { + Resource resource = store.getResource(); + resource.load(Collections.EMPTY_MAP); + Contacts contacts = (Contacts) resource.getContents().get(0); + Person person = (Person) contacts.getPersons().get(0); + person.getPhones().move(0, 2); // order is now 004, 002, 003 + person.getMobile().set(2, "005"); // order is now 004, 002, 005 + resource.save(Collections.EMPTY_MAP); + resource.unload(); + } + + // the order should be 004, 002, 005 + { + Resource resource = store.getResource(); + resource.load(Collections.EMPTY_MAP); + Contacts contacts = (Contacts) resource.getContents().get(0); + Person person = (Person) contacts.getPersons().get(0); + assertTrue(person.getMobile().get(0).toString().compareTo("004") == 0); + assertTrue(person.getMobile().get(1).toString().compareTo("002") == 0); + assertTrue(person.getMobile().get(2).toString().compareTo("005") == 0); + resource.save(Collections.EMPTY_MAP); + resource.unload(); + } + + // test a specific feature related to copy action and then changing the changed object + { + List factories = new ArrayList(); + factories.add(new ResourceItemProviderAdapterFactory()); + factories.add(new DetachfeaturemapItemProviderAdapterFactory()); + factories.add(new ReflectiveItemProviderAdapterFactory()); + + // create an editing domain + ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(factories); + BasicCommandStack commandStack = new BasicCommandStack(); + EditingDomain editDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack, new HashMap()); + ; + + // get and load the resource + final String uriStr = getResourceUri(store); + final URI uri = URI.createURI(uriStr); + Resource resource = editDomain.getResourceSet().createResource(uri); + resource.load(Collections.EMPTY_MAP); + + // get contacts and person + Contacts contacts = (Contacts) resource.getContents().get(0); + Person person = (Person) contacts.getPersons().get(0); + + // copy + CopyCommand cpcmd = new CopyCommand(editDomain, person, new Helper()); // (CopyCommand)CopyCommand.create(editDomain, + // person); + cpcmd.execute(); + + // get the copied person, change it and add it to the resource + Person cpPerson = (Person) cpcmd.getResult().iterator().next(); + cpPerson.setName("copy"); + contacts.getPersons().add(cpPerson); + + // save it + resource.save(Collections.EMPTY_MAP); + + // change the copy + cpPerson.setName("copy2"); + + // before the next save gave an error but now it works fine. + resource.save(Collections.EMPTY_MAP); + resource.unload(); + } + + // the order should be 004, 002, 005 + { + Resource resource = store.getResource(); + resource.load(Collections.EMPTY_MAP); + Contacts contacts = (Contacts) resource.getContents().get(0); + Person person = (Person) contacts.getPersons().get(0); + assertTrue(person.getName().compareTo("copy2") != 0); + assertTrue(person.getPhones().size() > 0); + + person.getMobile().clear(); + + resource.save(Collections.EMPTY_MAP); + resource.unload(); + } + } catch (Exception e) { + throw new StoreTestException("Need to catch the resource ioexception", e); + } + } + + /** Returns the resource uri, jdo is default (for now) */ + public String getResourceUri(TestStore store) { + return "jpoxdao://?" + StoreResource.DS_NAME_PARAM + "=" + store.getDatabaseAdapter().getDbName(); + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/relation/Relation1to1Action.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/relation/Relation1to1Action.java new file mode 100755 index 000000000..2ed746471 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/relation/Relation1to1Action.java @@ -0,0 +1,260 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * Relation1to1Action.java,v 1.4 2007/02/01 12:35:37 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.relation; + +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.ContainedChildNR; +import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.ContainedChildR; +import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.Main; +import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.NotContainedChildNR; +import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.NotContainedChildNRT; +import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.NotContainedChildNRTNR; +import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.NotContainedChildR; +import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.NotContainedChildRTNR; +import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.Relation1to1Factory; +import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.Relation1to1Package; +import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.impl.MainImpl; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests many different kinds of 1:1 relations + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.6 $ + */ +public class Relation1to1Action extends AbstractTestAction { + /** + * Constructor + * + * @param arg0 + */ + public Relation1to1Action() { + super(Relation1to1Package.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true"); + return props; + } + + /** Tests cascading deletes, required relations, etc. for 1:1 relations */ + @Override + public void doAction(TestStore store) { + // are not able to generate correct foreign key constraints in the generated sql, therefor + // this does + // not work. + + final Relation1to1Factory factory = Relation1to1Factory.eINSTANCE; + + { + store.beginTransaction(); + + Main main = factory.createMain(); + main.setName("main"); + + // <element name="containedonewayrequired" type="this:ContainedChildR"/> + ContainedChildR containedChildR = factory.createContainedChildR(); + containedChildR.setName("contained one way required"); + main.setContainedonewayrequired(containedChildR); + + // <element name="containedoneWaynotrequired" type="this:ContainedChildNR" + // minOccurs="0"/> + ContainedChildNR containedChildNR = factory.createContainedChildNR(); + containedChildNR.setName("contained one way not required"); + main.setContainedoneWaynotrequired(containedChildNR); + + // <element name="notcontainedonewayrequired" type="xsd:IDREF" + // ecore:reference="this:NotContainedChildR"/> + NotContainedChildR notContainedChildR = factory.createNotContainedChildR(); + notContainedChildR.setName("not contained one way required"); + main.setNotcontainedonewayrequired(notContainedChildR); + + // <element name="notcontainedonewaynotrequired" type="xsd:IDREF" + // ecore:reference="this:NotContainedChildNR" minOccurs="0"/> + NotContainedChildNR notContainedChildNR = factory.createNotContainedChildNR(); + notContainedChildNR.setName("not contained one way not required"); + main.setNotcontainedonewaynotrequired(notContainedChildNR); + + // <element name="notcontainedtwowaynotrequired" type="xsd:IDREF" + // ecore:reference="this:NotContainedChildNRT" minOccurs="0" ecore:opposite="main"/> + NotContainedChildNRT notContainedChildNRT = factory.createNotContainedChildNRT(); + notContainedChildNRT.setName("not contained two wat not required"); + main.setNotcontainedtwowaynotrequired(notContainedChildNRT); + + assertTrue(notContainedChildNRT.getMain() != null); + + // <element name="notcontainedtwowayrequirednr" type="xsd:IDREF" + // ecore:reference="this:NotContainedChildRTNR" ecore:opposite="main"/> + NotContainedChildRTNR notContainedChildRTNR = factory.createNotContainedChildRTNR(); + notContainedChildRTNR.setName("not contained two way required - not required"); + main.setNotcontainedtwowayrequirednr(notContainedChildRTNR); + + // <element name="notcontainedtwowaynotrequirednr" type="xsd:IDREF" + // ecore:reference="this:NotContainedChildNRTNR" minOccurs="0" ecore:opposite="main"/> + NotContainedChildNRTNR notContainedChildNRTNR = factory.createNotContainedChildNRTNR(); + notContainedChildNRTNR.setName("not contained two way not required - not required"); + main.setNotcontainedtwowaynotrequirednr(notContainedChildNRTNR); + + store.store(main); + + store.commitTransaction(); + } + + // check that the main object can not be deleted + { + store.checkDeleteFails(Main.class); + } + + // <element name="containedonewayrequired" type="this:ContainedChildR"/> + // 1) we should check here that this child can not be deleted separately + // 2) if the main object is deleted then this child should also be deleted! + // ContainedChildR containedChildR = factory.createContainedChildR(); + { + + // check 1 + store.checkDeleteFails(ContainedChildR.class); + } + + // <element name="containedoneWaynotrequired" type="this:ContainedChildNR" minOccurs="0"/> + // 3) Direct delete of the child should not be possible as the parent points to it + // 4) if the main object is deleted then this child should also be deleted automatically + // ContainedChildNR containedChildNR = factory.createContainedChildNR(); + { + // check 3 + store.checkDeleteFails(ContainedChildNR.class); + + // restore again + store.beginTransaction(); + MainImpl main = (MainImpl) store.getObject(Main.class); + + // check the econtainer + assertTrue("EContainer is null", main.getContainedoneWaynotrequired().eContainer() != null); + assertTrue("EContainer is null", main.getContainedonewayrequired().eContainer() != null); + + ContainedChildNR containedChildNR = factory.createContainedChildNR(); + containedChildNR.setName("test1"); + main.setContainedoneWaynotrequired(containedChildNR); + store.commitTransaction(); + + // should be two now + store.beginTransaction(); + store.checkNumber(ContainedChildNR.class, 2); + store.commitTransaction(); + } + + // <element name="notcontainedonewayrequired" type="xsd:IDREF" + // ecore:reference="this:NotContainedChildR"/> + // 6) Child can not be deleted without first removing the reference from the parent + // 6b) Element has to be set when parent is saved + // 7) The main object can not be deleted + // NotContainedChildR notContainedChildR = factory.createNotContainedChildR(); + { + // check 6 + store.checkDeleteFails(NotContainedChildR.class); + + // check 6b + store.beginTransaction(); + MainImpl main = (MainImpl) store.getObject(Main.class); + main.setNotcontainedonewayrequired(null); + try { + store.commitTransaction(); + assertTrue(false); + } catch (Exception e) { + store.rollbackTransaction(); + } + } + + // <element name="notcontainedtwowaynotrequired" type="xsd:IDREF" + // ecore:reference="this:NotContainedChildNRT" minOccurs="0" ecore:opposite="main"/> + // NotContainedChildNRT notContainedChildNRT = factory.createNotContainedChildNRT(); + // 11) The main object can not be deleted without removing the ref to the child + // 12) Reference to child can be set to nullable and child/main object can be deleted + { + store.beginTransaction(); + // check 11 and 12 + MainImpl main = (MainImpl) store.getObject(Main.class); + NotContainedChildNRT delChild = main.getNotcontainedtwowaynotrequired(); + main.setNotcontainedtwowaynotrequired(null); + store.deleteObject(delChild); + store.commitTransaction(); + } + + // <element name="notcontainedtwowayrequirednr" type="xsd:IDREF" + // ecore:reference="this:NotContainedChildRTNR" ecore:opposite="main"/> + // NotContainedChildRTNR notContainedChildRTNR = factory.createNotContainedChildRTNR(); + // 13) The main object can not be deleted without removing the ref to the child + // 14) The ref to the child can be replaced with a reference to another child + { + // check 14 + store.checkDeleteFails(NotContainedChildRTNR.class); + + // check 14 + /* + * store.beginTransaction(); MainImpl main = (MainImpl)store.getObject(Main.class); + * NotContainedChildRTNR curChild = main.getNotcontainedtwowayrequirednr(); + * NotContainedChildRTNR newChild = factory.createNotContainedChildRTNR(); + * newChild.setName("test"); main.setNotcontainedtwowayrequirednr(newChild); + * store.deleteObject(curChild); store.commitTransaction(); + */ + } + + // <element name="notcontainedtwowaynotrequirednr" type="xsd:IDREF" + // ecore:reference="this:NotContainedChildNRTNR" minOccurs="0" ecore:opposite="main"/> + // NotContainedChildNRTNR notContainedChildNRTNR = factory.createNotContainedChildNRTNR(); + // 15) the child object can be deleted because all references are null + // 16) The child object can be unset from the main object + { + // check 14 + store.beginTransaction(); + MainImpl main = (MainImpl) store.getObject(Main.class); + NotContainedChildNRTNR child = main.getNotcontainedtwowaynotrequirednr(); + main.setNotcontainedtwowaynotrequirednr(null); + store.deleteObject(child); + store.commitTransaction(); + } + + // now make the main object deletable! + { + store.beginTransaction(); + + MainImpl main = (MainImpl) store.getObject(Main.class); + + main.setNotcontainedonewaynotrequired(null); + + // is null so can not be deleted + // store.deleteObject(main.getNotcontainedtwowaynotrequired()); + + main.setNotcontainedtwowaynotrequirednr(null); + main.setNotcontainedtwowayrequirednr(null); + + store.deleteObject(main); + + store.commitTransaction(); + } + + // and do some counts + { + store.beginTransaction(); + store.checkNumber(ContainedChildR.class, 0); + store.checkNumber(ContainedChildNR.class, 1); + store.checkNumber(NotContainedChildNR.class, 1); + store.checkNumber(NotContainedChildNRTNR.class, 0); + store.checkNumber(NotContainedChildRTNR.class, 1); + store.checkNumber(NotContainedChildNRT.class, 0); + store.checkNumber(NotContainedChildR.class, 1); + store.commitTransaction(); + + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/relation/Relation1tonAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/relation/Relation1tonAction.java new file mode 100755 index 000000000..56d3d835a --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/relation/Relation1tonAction.java @@ -0,0 +1,276 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * Relation1tonAction.java,v 1.3 2007/02/01 12:35:37 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.relation; + +import java.util.Properties; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.Main; +import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.OneCN; +import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.OneCR; +import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.OneNN; +import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.OneNR; +import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.Relation1tonFactory; +import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.Relation1tonPackage; +import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.TwoCN; +import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.TwoCR; +import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.TwoNN; +import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.TwoNR; +import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.impl.MainImpl; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests many different kinds of 1:n relations + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.5 $ + */ +public class Relation1tonAction extends AbstractTestAction { + /** value used to create multiple entries in a list */ + private static final int ELEM_CNT = 10; + + /** + * Constructor + * + * @param arg0 + */ + public Relation1tonAction() { + super(Relation1tonPackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true"); + return props; + } + + /** Tests cascading deletes, required relations, etc. for 1:1 relations */ + @Override + public void doAction(TestStore store) { + // are not able to generate correct foreign key constraints in the generated sql, therefor + // this does + // not work. + final Relation1tonFactory factory = Relation1tonFactory.eINSTANCE; + + { + store.beginTransaction(); + + Main main = factory.createMain(); + main.setName("main"); + + OneCR oneCr1 = factory.createOneCR(); + oneCr1.setName("onecr1"); + main.getOnecr().add(oneCr1); + OneCR oneCr2 = factory.createOneCR(); + oneCr2.setName("onecr2"); + main.getOnecr().add(oneCr2); + + OneCN oneCn1 = factory.createOneCN(); + oneCn1.setName("onecn1"); + main.getOnecn().add(oneCn1); + OneCN oneCn2 = factory.createOneCN(); + oneCn2.setName("onecn2"); + main.getOnecn().add(oneCn2); + + OneNN oneNn1 = factory.createOneNN(); + oneNn1.setName("onenn1"); + main.getOnenn().add(oneNn1); + OneNN oneNn2 = factory.createOneNN(); + oneNn2.setName("onenn2"); + main.getOnenn().add(oneNn2); + + OneNR oneNr1 = factory.createOneNR(); + oneNr1.setName("onenr1"); + main.getOnenr().add(oneNr1); + OneNR oneNr2 = factory.createOneNR(); + oneNr2.setName("onenr2"); + main.getOnenr().add(oneNr2); + + TwoCR twoCr1 = factory.createTwoCR(); + twoCr1.setName("twocr1"); + main.getTwocr().add(twoCr1); + TwoCR twoCr2 = factory.createTwoCR(); + twoCr2.setName("twocr2"); + main.getTwocr().add(twoCr2); + + for (int i = 0; i < ELEM_CNT; i++) { + TwoCN twoCn = factory.createTwoCN(); + twoCn.setName("twocn" + i); + main.getTwocn().add(twoCn); + } + + for (int i = 0; i < ELEM_CNT; i++) { + TwoNN twoNn = factory.createTwoNN(); + twoNn.setName("twonn" + i); + main.getTwonn().add(twoNn); + } + + TwoNR twoNr1 = factory.createTwoNR(); + twoNr1.setName("twonr1"); + main.getTwonr().add(twoNr1); + TwoNR twoNr2 = factory.createTwoNR(); + twoNr2.setName("twonr2"); + main.getTwonr().add(twoNr2); + + store.store(main); + store.commitTransaction(); + } + + // check that the main object can not be deleted + { + // this test fails for hibernate because hibernate apparently does not support + // foreign key constraints checking when removing a parent. Apparently foreign keys + // are always nulled out. Imo this is incorrect for two way relations. + // store.checkDeleteFails(Main.class); + } + + // <element name="containedonewayrequired" type="this:ContainedChildR"/> + // 1) we should check here that this child can not be deleted separately + { + // childs of 1:n relations can be deleted directly! + // check 1 + // store.checkDeleteFails(OneNR.class); + } + + // <element name="containedoneWaynotrequired" type="this:ContainedChildNR" minOccurs="0"/> + // 3) Direct delete of the child should not be possible as the parent points to it + // 4) if the main object is deleted then this child should also be deleted automatically + // ContainedChildNR containedChildNR = factory.createContainedChildNR(); + { + // childs in 1:n relations can be deleted directly! + // check 3 + // store.checkDeleteFails(OneNR.class); + + // restore again + store.beginTransaction(); + MainImpl main = (MainImpl) store.getObject(Main.class); + + // check the econtainer + assertEquals(2, main.getOnecr().size()); + assertEquals(2, main.getOnecn().size()); + assertEquals(2, main.getOnenr().size()); + assertEquals(2, main.getOnenn().size()); + assertEquals(2, main.getTwocr().size()); + assertEquals(ELEM_CNT, main.getTwocn().size()); + assertEquals(2, main.getTwonr().size()); + assertEquals(ELEM_CNT, main.getTwonn().size()); + + assertTrue("EContainer is not null", ((EObject) main.getOnecn().get(0)).eContainer() != null); + assertTrue("EContainer is not null", ((EObject) main.getOnecr().get(1)).eContainer() != null); + assertTrue("EContainer is null", ((EObject) main.getTwonn().get(1)).eContainer() == null); + assertTrue("EContainer is null", ((EObject) main.getTwonr().get(1)).eContainer() == null); + + OneCR onecr = factory.createOneCR(); + onecr.setName("onecr3"); + main.getOnecr().add(onecr); + main.getOnecr().remove(0); + store.commitTransaction(); + + // should be two now (no cascading delete yet!) + store.beginTransaction(); + store.checkNumber(OneCR.class, 2); + store.commitTransaction(); + } + + // <element name="notcontainedonewayrequired" type="xsd:IDREF" + // ecore:reference="this:NotContainedChildR"/> + // 6b) Element has to be set when parent is saved + { + // check 6 + // childs in 1:n relations can be deleted if there is no join table! + // store.checkDeleteFails(OneNR.class); + } + + // <element name="notcontainedtwowaynotrequired" type="xsd:IDREF" + // ecore:reference="this:NotContainedChildNRT" minOccurs="0" + // ecore:opposite="main"/> + // NotContainedChildNRT notContainedChildNRT = factory.createNotContainedChildNRT(); + // 11) The main object can not be deleted without removing the ref to the child + // 12) Reference to child can be set to nullable and child/main object can be deleted + { + store.beginTransaction(); + // check 11 and 12 + MainImpl main = (MainImpl) store.getObject(Main.class); + OneCN delChild = main.getOnecn().get(0); + main.getOnecn().remove(0); + + assertTrue(((EObject) main.getTwocr().get(0)).eContainer() == main); + assertTrue((main.getTwocr().get(0)).getMain() == main); + + store.deleteObject(delChild); + store.commitTransaction(); + } + + // <element name="notcontainedtwowaynotrequirednr" type="xsd:IDREF" + // ecore:reference="this:NotContainedChildNRTNR" minOccurs="0" + // ecore:opposite="main"/> + // NotContainedChildNRTNR notContainedChildNRTNR = factory.createNotContainedChildNRTNR(); + // 15) the child object can be deleted because all references are null + // 16) The child object can be unset from the main object + { + // check 14 + store.beginTransaction(); + MainImpl main = (MainImpl) store.getObject(Main.class); + OneNN child = main.getOnenn().get(0); + main.getOnenn().remove(0); + store.deleteObject(child); + store.commitTransaction(); + } + + // and do some counts + { + store.beginTransaction(); + store.checkNumber(OneCN.class, 1); // 0 + store.checkNumber(OneCR.class, 2); // 0 + store.checkNumber(OneNN.class, 1); + store.checkNumber(OneNR.class, 2); + store.checkNumber(TwoCR.class, 2); // 0 + store.checkNumber(TwoCN.class, ELEM_CNT); // 0 + store.checkNumber(TwoNR.class, 2); + store.checkNumber(TwoNN.class, ELEM_CNT); + store.commitTransaction(); + + } + + // now make the main object deletable! + { + store.beginTransaction(); + + MainImpl main = (MainImpl) store.getObject(Main.class); + + main.getOnenn().clear(); + main.getOnenr().clear(); + + main.getTwonn().clear(); + main.getTwonr().clear(); + + store.deleteObject(main); + + store.commitTransaction(); + } + + // and do some counts + { + store.beginTransaction(); + store.checkNumber(OneCN.class, 0); + store.checkNumber(OneCR.class, 0); + store.checkNumber(OneNN.class, 1); + store.checkNumber(OneNR.class, 2); + store.checkNumber(TwoCR.class, 0); + store.checkNumber(TwoCN.class, 0); + store.checkNumber(TwoNR.class, 2); + store.checkNumber(TwoNN.class, ELEM_CNT); + store.commitTransaction(); + + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/relation/RelationntomAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/relation/RelationntomAction.java new file mode 100755 index 000000000..768873f57 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/relation/RelationntomAction.java @@ -0,0 +1,196 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * RelationntomAction.java,v 1.3 2007/02/08 23:11:22 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.relation; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.relation.relationntom.Main; +import org.eclipse.emf.teneo.samples.emf.relation.relationntom.MultiNN; +import org.eclipse.emf.teneo.samples.emf.relation.relationntom.MultiNR; +import org.eclipse.emf.teneo.samples.emf.relation.relationntom.MultiRN; +import org.eclipse.emf.teneo.samples.emf.relation.relationntom.RelationntomFactory; +import org.eclipse.emf.teneo.samples.emf.relation.relationntom.RelationntomPackage; +import org.eclipse.emf.teneo.samples.emf.relation.relationntom.impl.MainImpl; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests many different kinds of 1:n relations + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.5 $ + */ +public class RelationntomAction extends AbstractTestAction { + /** test constants */ + private static int NO_MAINS = 2; + private static int NO_MULTIS = 2; + + /** + * Constructor + * + * @param arg0 + */ + public RelationntomAction() { + super(RelationntomPackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true"); + return props; + } + + /** Tests cascading deletes, required relations, etc. for 1:1 relations */ + @Override + public void doAction(TestStore store) { + // are not able to generate correct foreign key constraints in the generated sql, therefor + // this does + // not work. + final RelationntomFactory factory = RelationntomFactory.eINSTANCE; + + { + store.beginTransaction(); + + final ArrayList<MultiNN> multinns = new ArrayList<MultiNN>(); + for (int i = 0; i < NO_MULTIS; i++) { + MultiNN multinn = factory.createMultiNN(); + multinn.setName(" multinn " + i); + multinns.add(multinn); + store.store(multinn); + } + + final ArrayList<MultiNR> multinrs = new ArrayList<MultiNR>(); + for (int i = 0; i < NO_MULTIS; i++) { + MultiNR multi = factory.createMultiNR(); + multi.setName(" multinr " + i); + multinrs.add(multi); + } + + final ArrayList<MultiRN> multirns = new ArrayList<MultiRN>(); + for (int i = 0; i < NO_MULTIS; i++) { + MultiRN multi = factory.createMultiRN(); + multi.setName(" multirn " + i); + multirns.add(multi); + } + + for (int m = 0; m < NO_MAINS; m++) { + Main main = factory.createMain(); + main.setName("main"); + + main.getMultirn().addAll(multirns); + for (int i = 0; i < multinns.size(); i++) { + main.getMultinn().add(multinns.get(i)); + } + + main.getMultinr().addAll(multinrs); + store.store(main); + } + store.commitTransaction(); + } + + { + store.beginTransaction(); + + final List<?> mains = store.getObjects(Main.class); + assertTrue(mains.size() == NO_MAINS); + for (int i = 0; i < mains.size(); i++) { + final MainImpl main = (MainImpl) mains.get(i); + assertEquals(NO_MULTIS, main.getMultinn().size()); + assertEquals(NO_MULTIS, main.getMultirn().size()); + assertEquals(NO_MULTIS, main.getMultinr().size()); + + for (int k = 0; k < main.getMultinn().size(); k++) { + MultiNN multinn = main.getMultinn().get(k); + assertEquals(NO_MAINS, multinn.getMain().size()); + assertTrue(mains.containsAll(multinn.getMain())); + } + for (int k = 0; k < main.getMultinr().size(); k++) { + MultiNR multinr = main.getMultinr().get(k); + assertEquals(NO_MAINS, multinr.getMain().size()); + assertTrue(mains.containsAll(multinr.getMain())); + } + for (int k = 0; k < main.getMultirn().size(); k++) { + MultiRN multirn = main.getMultirn().get(k); + assertEquals(NO_MAINS, multirn.getMain().size()); + assertTrue(mains.containsAll(multirn.getMain())); + } + } + + // prod = (ProductType)store.query("SELECT FROM + // org.eclipse.emf.teneo.test.emf.catalog.gen.impl.ProductTypeImpl WHERE + // remark.contains(rem) && rem.value == \"remarka\" VARIABLES + // org.eclipse.emf.teneo.test.emf.catalog.gen.impl.StringTypeImpl rem", 1).get(0); + store.commitTransaction(); + } + + /* + * // check that the main object can not be deleted { store.checkDeleteFails(Main.class); } // + * <element name="containedonewayrequired" type="this:ContainedChildR"/> // 1) we should + * check here that this child can not be deleted separately { // check 1 + * store.checkDeleteFails(OneNR.class); } //<element name="containedoneWaynotrequired" + * type="this:ContainedChildNR" minOccurs="0"/> // 3) Direct delete of the child should not + * be possible as the parent points to it // 4) if the main object is deleted then this + * child should also be deleted automatically //ContainedChildNR containedChildNR = + * factory.createContainedChildNR(); { // check 3 store.checkDeleteFails(OneNR.class); // + * restore again store.beginTransaction(); MainImpl main = + * (MainImpl)store.getObject(Main.class); // check the econtainer assertTrue("Size of all + * collections is 2", main.getOnecr().size() == 2); assertTrue("Size of all collections is + * 2", main.getOnecn().size() == 2); assertTrue("Size of all collections is 2", + * main.getOnenr().size() == 2); assertTrue("Size of all collections is 2", + * main.getOnenn().size() == 2); assertTrue("Size of all collections is 2", + * main.getTwocr().size() == 2); assertTrue("Size of all collections is 2", + * main.getTwocn().size() == 100); assertTrue("Size of all collections is 2", + * main.getTwonr().size() == 2); assertTrue("Size of all collections is 2", + * main.getTwonn().size() == 100); assertTrue("EContainer is null", + * ((EObject)main.getOnecn().get(0)).eContainer() != null); assertTrue("EContainer is null", + * ((EObject)main.getOnecr().get(1)).eContainer() != null); assertTrue("EContainer is null", + * ((EObject)main.getTwonn().get(1)).eContainer() == null); assertTrue("EContainer is null", + * ((EObject)main.getTwonr().get(1)).eContainer() == null); OneCR onecr = + * factory.createOneCR(); onecr.setName("onecr3"); main.getOnecr().add(onecr); + * main.getOnecr().remove(0); store.commitTransaction(); // should be two now (no cascading + * delete yet!) store.beginTransaction(); store.checkNumber(OneCR.class, 2); + * store.commitTransaction(); } //<element name="notcontainedonewayrequired" + * type="xsd:IDREF" ecore:reference="this:NotContainedChildR"/> // 6b) Element has to be set + * when parent is saved { // check 6 store.checkDeleteFails(OneNR.class); } //<element + * name="notcontainedtwowaynotrequired" type="xsd:IDREF" + * ecore:reference="this:NotContainedChildNRT" minOccurs="0" ecore:opposite="main"/> + * //NotContainedChildNRT notContainedChildNRT = factory.createNotContainedChildNRT(); // + * 11) The main object can not be deleted without removing the ref to the child // 12) + * Reference to child can be set to nullable and child/main object can be deleted { + * store.beginTransaction(); // check 11 and 12 MainImpl main = + * (MainImpl)store.getObject(Main.class); OneCN delChild = (OneCN)main.getOnecn().get(0); + * main.getOnecn().remove(0); store.deleteObject(delChild); store.commitTransaction(); } //<element + * name="notcontainedtwowaynotrequirednr" type="xsd:IDREF" + * ecore:reference="this:NotContainedChildNRTNR" minOccurs="0" ecore:opposite="main"/> + * //NotContainedChildNRTNR notContainedChildNRTNR = factory.createNotContainedChildNRTNR(); // + * 15) the child object can be deleted because all references are null // 16) The child + * object can be unset from the main object { // check 14 store.beginTransaction(); MainImpl + * main = (MainImpl)store.getObject(Main.class); OneNN child = + * (OneNN)main.getOnenn().get(0); main.getOnenn().remove(0); store.deleteObject(child); + * store.commitTransaction(); } // and do some counts { store.beginTransaction(); + * store.checkNumber(OneCN.class, 1); //0 store.checkNumber(OneCR.class, 2); //0 + * store.checkNumber(OneNN.class, 1); store.checkNumber(OneNR.class, 2); + * store.checkNumber(TwoCR.class, 2); //0 store.checkNumber(TwoCN.class, 100); //0 + * store.checkNumber(TwoNR.class, 2); store.checkNumber(TwoNN.class, 100); + * store.commitTransaction(); } // now make the main object deletable! { + * store.beginTransaction(); MainImpl main = (MainImpl)store.getObject(Main.class); + * main.getOnenn().clear(); main.getOnenr().clear(); main.getTwonn().clear(); + * main.getTwonr().clear(); store.deleteObject(main); store.commitTransaction(); } // and do + * some counts { store.beginTransaction(); store.checkNumber(OneCN.class, 0); + * store.checkNumber(OneCR.class, 0); store.checkNumber(OneNN.class, 1); + * store.checkNumber(OneNR.class, 2); store.checkNumber(TwoCR.class, 0); + * store.checkNumber(TwoCN.class, 0); store.checkNumber(TwoNR.class, 2); + * store.checkNumber(TwoNN.class, 100); store.commitTransaction(); } + */ + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/AccountingAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/AccountingAction.java new file mode 100755 index 000000000..8b34ad32d --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/AccountingAction.java @@ -0,0 +1,81 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: AccountingAction.java,v 1.5 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.io.InputStream; + +import org.eclipse.emf.teneo.samples.emf.sample.accounting.Account; +import org.eclipse.emf.teneo.samples.emf.sample.accounting.AccountGroup; +import org.eclipse.emf.teneo.samples.emf.sample.accounting.Accounting; +import org.eclipse.emf.teneo.samples.emf.sample.accounting.AccountingFactory; +import org.eclipse.emf.teneo.samples.emf.sample.accounting.AccountingPackage; +import org.eclipse.emf.teneo.samples.emf.sample.accounting.JournalGroup; +import org.eclipse.emf.teneo.samples.emf.sample.accounting.Vat; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Performs a number of test actions on the catalog example. Create products, link a supplier, + * add to catalog, delete from catalog. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.5 $ +*/ +public abstract class AccountingAction extends AbstractTestAction +{ + public AccountingAction() + { + super(AccountingPackage.eINSTANCE); + } + + /** Creates a supplier, a product, relates then, saves and retrieves them again. */ + public void doAction(TestStore store) + { + final AccountingFactory factory = AccountingFactory.eINSTANCE; + { + store.beginTransaction(); + + Accounting all = factory.createAccounting(); + all.setName("Accounting Data"); + + Vat vat = factory.createVat(); + vat.setName("19%"); + vat.setRate(0.19f); + + Account account = factory.createBalanceAccount(); + account.setName("Software Development Costs"); + + AccountGroup accGroup = factory.createAccountGroup(); + accGroup.setName("Activa"); + accGroup.getAccount().add(account); + + JournalGroup yearJournal = factory.createJournalGroup(); + yearJournal.setName("journalgroup"); + + all.getVat().add(vat); + all.getJournalGroup().add(yearJournal); + all.getAccountGroup().add(accGroup); + + store.store(all); + store.commitTransaction(); + } + imTestExport(AccountingPackage.class.getResourceAsStream("import.xmi"), store); + } + + /** Import/export, from and to */ + protected abstract void imTestExport(InputStream is, TestStore store); +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CapaAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CapaAction.java new file mode 100755 index 000000000..4cfcad26e --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CapaAction.java @@ -0,0 +1,110 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: CapaAction.java,v 1.5 2008/02/28 07:08:15 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.emf.teneo.samples.emf.sample.capa.CapaFactory; +import org.eclipse.emf.teneo.samples.emf.sample.capa.CapaPackage; +import org.eclipse.emf.teneo.samples.emf.sample.capa.Machine; +import org.eclipse.emf.teneo.samples.emf.sample.capa.MachineList; +import org.eclipse.emf.teneo.samples.emf.sample.capa.WorkDay; +import org.eclipse.emf.teneo.samples.emf.sample.capa.WorkWeek; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests the capa, detach and update + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.5 $ + */ +public class CapaAction extends AbstractTestAction { + + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public CapaAction() { + super(CapaPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + final CapaFactory factory = CapaFactory.eINSTANCE; + MachineList ml = factory.createMachineList(); + { + store.beginTransaction(); + Machine m = getNewMachine(factory, "id0"); + WorkWeek ww = factory.createWorkWeek(); + ww.getDays().add(factory.createWorkDay()); + ww.getDays().add(factory.createWorkDay()); + ww.getDays().add(factory.createWorkDay()); + ww.getDays().add(factory.createWorkDay()); + ww.getDays().add(factory.createWorkDay()); + ww.getDays().add(factory.createWorkDay()); + ww.getDays().add(factory.createWorkDay()); + m.setWorkWeek(ww); + ml.getMachines().add(m); + store.store(ml); + store.commitTransaction(); + } + + { + store.beginTransaction(); + ml = (MachineList) store.getObject(MachineList.class); + store.commitTransaction(); + } + + checkReAttach(factory, store, ml); + } + + /** Creates a machine */ + @SuppressWarnings("unchecked") + protected Machine getNewMachine(CapaFactory factory, String id) { + final Machine m = factory.createMachine(); + final WorkWeek wk = factory.createWorkWeek(); + wk.getDays().addAll(getWorkDays(factory)); + m.setWorkWeek(wk); + m.setMachineId(id); + // m.setMachineSearchString("search"); + // m.setTaskSearchString("tss"); + return m; + } + + /** Returns a list of workdays */ + private List<WorkDay> getWorkDays(CapaFactory factory) { + final ArrayList<WorkDay> list = new ArrayList<WorkDay>(); + for (int i = 1; i < 8; i++) { + final WorkDay wd = factory.createWorkDay(); + // wd.setDayOfWeek(i); + // wd.setDuration(8); + // wd.setStartTime(8); + list.add(wd); + } + return list; + } + + /** Reattach machinelist and check */ + protected void checkReAttach(CapaFactory factory, TestStore store, MachineList ml) { + + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CarAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CarAction.java new file mode 100755 index 000000000..3819eeaf9 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CarAction.java @@ -0,0 +1,100 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: CarAction.java,v 1.3 2008/03/07 13:13:53 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.io.IOException; +import java.util.Collections; +import java.util.Properties; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +import com.example.car.CarFactory; +import com.example.car.CarPackage; +import com.example.car.CarsList; + +/** + * Test bugzilla 199373 + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ + */ +public class CarAction extends AbstractTestAction { + + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public CarAction() { + super(CarPackage.eINSTANCE); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties() + */ + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPPING, "true"); + return props; + } + + /** Creates an item, an address and links them to a po. */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + { + final CarsList carsList = CarFactory.eINSTANCE.createCarsList(); + store.beginTransaction(); + store.store(carsList); + store.commitTransaction(); + } + + try { + final Resource dbResource = store.getResource(); + try { + dbResource.load(null); + } catch (IOException e) { + throw new IllegalStateException(e); + } + final CarsList carsList = (CarsList) dbResource.getContents().get(0); + final EList eListDatabaseCarType = carsList.getCarType(); + final EList eListDatabaseCarLink = carsList.getCarLink(); + + final Resource fileRes = new XMLResourceImpl(); + fileRes.load(CarFactory.class.getResourceAsStream("model/cars.xml"), Collections.EMPTY_MAP); + + final CarsList rootElementFile = (CarsList) fileRes.getContents().get(0); + EList eListFileCarType = rootElementFile.getCarType(); + EList eListFileCarLink = rootElementFile.getCarLink(); + + eListDatabaseCarType.addAll(eListFileCarType); + eListDatabaseCarLink.addAll(eListFileCarLink); + dbResource.save(Collections.EMPTY_MAP); + } catch (Exception e) { + throw new StoreTestException(e.getMessage(), e); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CatalogAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CatalogAction.java new file mode 100755 index 000000000..d6dac3ddb --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CatalogAction.java @@ -0,0 +1,301 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: CatalogAction.java,v 1.8 2008/06/02 07:15:39 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.Iterator; +import java.util.List; +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.sample.catalog.CatalogFactory; +import org.eclipse.emf.teneo.samples.emf.sample.catalog.CatalogPackage; +import org.eclipse.emf.teneo.samples.emf.sample.catalog.CatalogType; +import org.eclipse.emf.teneo.samples.emf.sample.catalog.PriceType; +import org.eclipse.emf.teneo.samples.emf.sample.catalog.ProductType; +import org.eclipse.emf.teneo.samples.emf.sample.catalog.StringType; +import org.eclipse.emf.teneo.samples.emf.sample.catalog.SupplierType; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Performs a number of test actions on the catalog example. Create products, link a supplier, add + * to catalog, delete from catalog. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.8 $ + */ +public abstract class CatalogAction extends AbstractTestAction { + + private static int COMMENT_LENGTH = 10; + + public CatalogAction() { + super(CatalogPackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true"); + props.setProperty(PersistenceOptions.MAX_COMMENT_LENGTH, COMMENT_LENGTH + ""); + return props; + } + + /** Creates a supplier, a product, relates then, saves and retrieves them again. */ + @Override + public void doAction(TestStore store) { + long millis = (112671594); + millis = millis * 10000; + millis = millis + 4562; + + final CatalogFactory factory = CatalogFactory.eINSTANCE; + { + store.beginTransaction(); + final SupplierType supplier = factory.createSupplierType(); + supplier.setName("supplier1"); + supplier.setNoOfEmployees(1); + store.store(supplier); + + final PriceType price = factory.createPriceType(); + price.setPrice(69.96); + price.setSupplier(supplier); + price.setQuantityTo(100.0); + store.store(price); + + final ProductType product = factory.createProductType(); + product.setCode("product1"); + product.setDescription("This is a very nice product"); + final StringType str1 = factory.createStringType(); + str1.setValue("remarka"); + final StringType str2 = factory.createStringType(); + str2.setValue("remarkb"); + product.getRemark().add(str1); + product.getRemark().add(str2); + product.setPrice(price); + store.store(product); + + // and create another product + final PriceType price2 = factory.createPriceType(); + price2.setPrice(75.0); + price2.setSupplier(supplier); + price2.setQuantityTo(100.0); + // store.store(price2); + + final ProductType product2 = factory.createProductType(); + product2.setCode("product2"); + // product2.setDescription("This is a very nice product"); + final StringType strfor2 = factory.createStringType(); + strfor2.setValue("remarkb"); + product2.getRemark().add(strfor2); + product2.setPrice(price2); + product2.setDescription("description2"); + store.store(product2); + + store.commitTransaction(); + } + + // retrieve one product + // delete one of its remarks and add another remark + { + store.beginTransaction(); + + final List<?> results = store.query(ProductType.class, "code", "product1", 1); + + assertTrue(results.size() == 1); + + ProductType result = (ProductType) results.get(0); + + assertTrue(result != null); + assertTrue(result.getCode().compareTo("product1") == 0); + assertTrue(result.getRemark().size() == 2); + + assertTrue((result.getRemark().get(0)).getValue().compareTo("remarka") == 0); + assertTrue((result.getRemark().get(1)).getValue().compareTo("remarkb") == 0); + + // then remove one + result.getRemark().remove(1); + + // add another + final StringType str1 = factory.createStringType(); + str1.setValue("remarkc"); + + result.getRemark().add(str1); + + // store.store(result); + + // and store again + store.commitTransaction(); + } + + // directly checks if the following StringTypes are in the database: remarka, remarkb and + // remarkc + // this test fails for jpox + { + store.beginTransaction(); + + final List<?> results = store.getObjects(StringType.class); + assertEquals(3, results.size()); + + int remarka = 0; + int remarkb = 0; + int remarkc = 0; + Iterator<?> it = results.iterator(); + while (it.hasNext()) { + StringType str = (StringType) it.next(); + if (str.getValue().compareTo("remarka") == 0) { + remarka++; + } else if (str.getValue().compareTo("remarkb") == 0) { + remarkb++; + } else if (str.getValue().compareTo("remarkc") == 0) { + remarkc++; + } else { + fail(); + } + } + assertTrue(remarka == 1); + assertTrue(remarkb == 1); + assertTrue(remarkc == 1); + store.commitTransaction(); + } + + // now retrieve the second product and check it + { + store.beginTransaction(); + + final List<?> results = store.query(ProductType.class, "code", "product2", 1); + + assertTrue(results.size() == 1); + + ProductType result = (ProductType) results.get(0); + + assertTrue(result.getCode().compareTo("product2") == 0); + assertTrue(result.getRemark().size() == 1); + final StringType remark = result.getRemark().get(0); + assertTrue(remark.eContainer() != null); + + assertTrue((result.getRemark().get(0)).getValue().compareTo("remarkb") == 0); + + store.commitTransaction(); + } + + // again retrieve two products + // create a main catalog and add the two products to it + // create a subcatalog and attach it to the main catalog + // and save the lot + { + store.beginTransaction(); + + ProductType result = (ProductType) store.query(ProductType.class, "code", "product1", 1).get(0); + ProductType result2 = (ProductType) store.query(ProductType.class, "code", "product2", 1).get(0); + + final CatalogType mainCatalog = factory.createCatalogType(); + mainCatalog.setName("MainCatalog"); + mainCatalog.setDescription("my description"); + mainCatalog.getProduct().add(result); + mainCatalog.getProduct().add(result2); + final CatalogType subCatalog = factory.createCatalogType(); + subCatalog.setName("SubCatalog"); + subCatalog.setDescription("mydescription"); + + mainCatalog.getSubCatalog().add(subCatalog); + + store.store(mainCatalog); + + store.commitTransaction(); + } + + // retrieve the main catalog and check that all products are present + // remove one product + { + store.beginTransaction(); + + CatalogType cat = (CatalogType) store.query(CatalogType.class, "name", "MainCatalog", 1).get(0); + + assertTrue(cat != null); + assert (cat != null); + assertTrue(cat.getName().compareTo("MainCatalog") == 0); + assertTrue(cat.getProduct().size() == 2); + assertTrue((cat.getProduct().get(0)).getCode().compareTo("product1") == 0); + assertTrue((cat.getProduct().get(1)).getCode().compareTo("product2") == 0); + cat.getProduct().remove(1); // this product will not be deleted, only the reference + assertTrue((cat.getSubCatalog().get(0)).getName().compareTo("SubCatalog") == 0); + + store.commitTransaction(); + } + + // test if the product2 was not deleted + { + store.beginTransaction(); + ProductType result2 = (ProductType) store.query(ProductType.class, "code", "product2", 1).get(0); + assertTrue(result2 != null); + store.commitTransaction(); + } + + // retrieve both catalogs + { + store.beginTransaction(); + final List<?> result = store.getObjects(CatalogType.class); + assertTrue(result.size() == 2); + Iterator<?> it = result.iterator(); + while (it.hasNext()) { + CatalogType cat = (CatalogType) it.next(); + assertTrue(cat.getName().compareTo("MainCatalog") == 0 || cat.getName().compareTo("SubCatalog") == 0); + } + store.commitTransaction(); + } + + // select a product based on one of its remark values + { + store.beginTransaction(); + + ProductType prod = null; + prod = (ProductType) store.query(getQueryText(), 1).get(0); + + assertTrue((prod.getRemark().get(0)).getValue().compareTo("remarka") == 0); + store.commitTransaction(); + } + + // test the comments in the hdm + if (store.isHibernateTestStore()) { + final String[] test = + new String[] { "My product documentation".substring(0, COMMENT_LENGTH), + "My description documentation".substring(0, COMMENT_LENGTH), + "My producttype documentation".substring(0, COMMENT_LENGTH) }; + final String xml = store.getMappingXML(); + for (String t : test) { + if (xml.indexOf(t) == -1) { + fail("The following documentation does not appear: " + t); + } + } + } + } + + /** + * @return Returns the string used to query a product with remarks containing the text 'remarka' + */ + protected abstract String getQueryText(); + // TODO specialize + // for jpox + // SELECT FROM org.eclipse.emf.teneo.test.emf.sample.catalog.gen.impl.ProductTypeImpl + // WHERE remark.contains(rem) && rem.value == \"remarka\" + // VARIABLES org.eclipse.emf.teneo.test.emf.sample.catalog.gen.impl.StringTypeImpl rem + // for hibernate + // SELECT product FROM org.eclipse.emf.teneo.test.emf.sample.catalog.gen.ProductType product, + // org.eclipse.emf.teneo.test.emf.sample.catalog.gen.StringType rem + // WHERE rem in elements(product.remark) and rem.value = 'remarka' + // } + +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CatalogResourceAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CatalogResourceAction.java new file mode 100755 index 000000000..915e66c23 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CatalogResourceAction.java @@ -0,0 +1,378 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: CatalogResourceAction.java,v 1.8 2008/06/02 07:15:40 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.Iterator; +import java.util.List; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.samples.emf.sample.catalog.CatalogFactory; +import org.eclipse.emf.teneo.samples.emf.sample.catalog.CatalogPackage; +import org.eclipse.emf.teneo.samples.emf.sample.catalog.CatalogType; +import org.eclipse.emf.teneo.samples.emf.sample.catalog.PriceType; +import org.eclipse.emf.teneo.samples.emf.sample.catalog.ProductType; +import org.eclipse.emf.teneo.samples.emf.sample.catalog.StringType; +import org.eclipse.emf.teneo.samples.emf.sample.catalog.SupplierType; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Performs a number of test actions on the catalog example. Create products, link a supplier, add + * to catalog, delete from catalog. + * + * All using a resource, tests add, delete and update of objects in a resource. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.8 $ + */ +public class CatalogResourceAction extends AbstractTestAction { + /** + * Constructor + * + * @param arg0 + */ + public CatalogResourceAction() { + super(CatalogPackage.eINSTANCE); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.AbstractTestAction#hibernateEnabled() + */ + protected boolean hibernateEnabled() { + return true; + } + + /** + * Creates a supplier, a product, relates then, saves them in a resource and retrieves them + * again. and does sme + */ + Resource resource; + + @Override + public void doAction(TestStore store) { + final CatalogFactory factory = CatalogFactory.eINSTANCE; + try { + double checkPrice = 69.96; // is checked later + + { + resource = store.getResource(); + resource.load(null); + + final SupplierType supplier = factory.createSupplierType(); + supplier.setName("supplier1"); + supplier.setNoOfEmployees(1); + resource.getContents().add(supplier); + + final PriceType price = factory.createPriceType(); + price.setPrice(checkPrice); + price.setSupplier(supplier); + price.setQuantityTo(100.0); + resource.getContents().add(price); + + final ProductType product = factory.createProductType(); + product.setCode("product1"); + product.setDescription("This is a very nice product"); + final StringType str1 = factory.createStringType(); + str1.setValue("remarka"); + final StringType str2 = factory.createStringType(); + str2.setValue("remarkb"); + product.getRemark().add(str1); + product.getRemark().add(str2); + product.setPrice(price); + resource.getContents().add(product); + resource.save(null); + resource.unload(); + } + + { + // test retrieval by connection params + resource = store.getResource(); + resource.load(null); + + assertTrue("There should be two top objects in the resource but there are " + + resource.getContents().size(), resource.getContents().size() == 2); + + // get the supplier + SupplierType supplier = null; + for (int i = 0; i < resource.getContents().size(); i++) { + if (resource.getContents().get(i) instanceof SupplierType) { + supplier = (SupplierType) resource.getContents().get(i); + } + } + + // and create another product + final PriceType price2 = factory.createPriceType(); + price2.setPrice(75.0); + price2.setSupplier(supplier); + price2.setQuantityTo(100.0); + + final ProductType product2 = factory.createProductType(); + product2.setCode("product2"); + product2.setDescription("This is a very nice product"); + final StringType strfor2 = factory.createStringType(); + strfor2.setValue("remarkb"); + product2.getRemark().add(strfor2); + product2.setPrice(price2); + resource.getContents().add(product2); + resource.save(null); + resource.unload(); + } + + store.beginTransaction(); + store.checkNumber(ProductType.class, 2); + store.checkNumber(SupplierType.class, 1); + store.checkNumber(PriceType.class, 2); + store.checkNumber(StringType.class, 3); + store.commitTransaction(); + + // directly checks if the following StringTypes are in the database: remarka, remarkb + // and remarkc + { + store.beginTransaction(); + final List<?> results = store.getObjects(StringType.class); + assertTrue(results.size() == 3); + int remarka = 0; + int remarkb = 0; + int remarkc = 0; + Iterator<?> it = results.iterator(); + while (it.hasNext()) { + StringType str = (StringType) it.next(); + if (str.getValue().compareTo("remarka") == 0) { + remarka++; + } else if (str.getValue().compareTo("remarkb") == 0) { + remarkb++; + } else if (str.getValue().compareTo("remarkc") == 0) { + remarkc++; + } else { + fail(); + } + } + assertTrue(remarka == 1); + assertTrue(remarkb == 2); + assertTrue(remarkc == 0); + store.commitTransaction(); + } + + store.beginTransaction(); + store.checkNumber(ProductType.class, 2); + store.checkNumber(SupplierType.class, 1); + store.checkNumber(PriceType.class, 2); + store.checkNumber(StringType.class, 3); + store.commitTransaction(); + + // again retrieve two products + // create a main catalog and add the two products to it + // create a subcatalog and attach it to the main catalog + // and save the lot + { + // test retrieval using minimal connection params + resource = store.getResource("fetch_minimal=true"); + resource.load(null); + + // this should force a load of the products + Iterator<?> it = resource.getContents().iterator(); + while (it.hasNext()) { + Object obj = it.next(); + if (obj instanceof ProductType) { + assertTrue(((ProductType) obj).getDescription() != null); + } + } + + final CatalogType mainCatalog = factory.createCatalogType(); + mainCatalog.setName("MainCatalog"); + mainCatalog.setDescription("my description"); + + // add the products to the maincatalog + it = resource.getContents().iterator(); + while (it.hasNext()) { + Object obj = it.next(); + if (obj instanceof ProductType) { + mainCatalog.getProduct().add((ProductType) obj); + } + } + final CatalogType subCatalog = factory.createCatalogType(); + subCatalog.setName("SubCatalog"); + subCatalog.setDescription("mydescription"); + + mainCatalog.getSubCatalog().add(subCatalog); + resource.getContents().add(mainCatalog); + resource.getContents().add(subCatalog); + resource.save(null); + resource.unload(); + } + + store.beginTransaction(); + store.checkNumber(CatalogType.class, 2); + store.commitTransaction(); + + // retrieve the main catalog and check that all products are present + // remove one product, note that because this is a non-containment relation + { + resource = store.getResource(); + resource.load(null); + Iterator<?> it = resource.getContents().iterator(); + CatalogType cat = null; + while (it.hasNext()) { + final Object obj = it.next(); + + assertTrue("Only top classes should be returned", obj instanceof ProductType || + obj instanceof SupplierType || obj instanceof CatalogType); + + if (obj instanceof CatalogType && ((CatalogType) obj).getName().compareTo("MainCatalog") == 0) { + assertTrue("There should only be one MainCatalog", cat == null); + cat = (CatalogType) obj; + } + } + assertTrue(cat != null); + assert (cat != null); + assertEquals(0, cat.getName().compareTo("MainCatalog")); + assertEquals(2, cat.getProduct().size()); + assertTrue((cat.getProduct().get(0)).getCode().compareTo("product1") == 0); + assertTrue((cat.getProduct().get(1)).getCode().compareTo("product2") == 0); + cat.getProduct().remove(1); // this product will not be deleted, only the reference + assertTrue((cat.getSubCatalog().get(0)).getName().compareTo("SubCatalog") == 0); + + resource.save(null); + resource.unload(); + } + + // product was not deleted + store.beginTransaction(); + store.checkNumber(ProductType.class, 2); + store.commitTransaction(); + + // retrieve the resource and delete one product + { + resource = store.getResource(); + resource.load(null); + + // count the products in the resource + List<?> list = resource.getContents(); + int cnt = 0; + ProductType delProduct = null; + for (int i = 0; i < list.size(); i++) { + Object obj = list.get(i); + if (obj instanceof ProductType) { + cnt++; + + // test if the containment is set correctly + // there is always at least one remark! + EObject eobj = ((ProductType) obj).getRemark().get(0); + assertTrue("The remark should be contained in the product", eobj.eContainer() == obj); + + // delete the product with 1 remark, this is then tested below + if (((ProductType) obj).getRemark().size() == 1) { + delProduct = (ProductType) obj; + } + } + } + assertTrue("There should be two products in the resource.", cnt == 2); + + // now remove one product from the resource + resource.getContents().remove(delProduct); + resource.save(null); + resource.unload(); + } + + // do some counts + store.beginTransaction(); + store.checkNumber(ProductType.class, 1); + store.checkNumber(SupplierType.class, 1); + store.checkNumber(PriceType.class, 1); + // note the product with one remark was deleted therefore there are 2 left + store.checkNumber(StringType.class, 2); + store.commitTransaction(); + + // now update an object in the resource, update a derived element (the price) and + // remove one remark from the list and a new one. + { + resource = store.getResource(); + resource.load(null); + ProductType result = null; + for (int i = 0; i < resource.getContents().size(); i++) { + if (resource.getContents().get(i) instanceof ProductType) { + // there should only be one product + assertTrue("There should only be one product", result == null); + result = (ProductType) resource.getContents().get(i); + } + } + + assertTrue(result != null); + assertTrue(result.getCode().compareTo("product1") == 0); + assertTrue(result.getRemark().size() == 2); + + assertTrue((result.getRemark().get(0)).getValue().compareTo("remarka") == 0); + assertTrue((result.getRemark().get(1)).getValue().compareTo("remarkb") == 0); + + // then remove one + result.getRemark().remove(1); + + // add another + final StringType str1 = factory.createStringType(); + str1.setValue("remarkc"); + + result.getRemark().add(str1); + + result.getPrice().setPrice(result.getPrice().getPrice() + 100.0); + resource.save(null); + resource.unload(); + } + + // there should now only be a remarka and a remarkc + { + store.beginTransaction(); + final List<?> results = store.getObjects(StringType.class); + assertTrue(results.size() == 2); + int remarka = 0; + int remarkb = 0; + int remarkc = 0; + Iterator<?> it = results.iterator(); + while (it.hasNext()) { + StringType str = (StringType) it.next(); + if (str.getValue().compareTo("remarka") == 0) { + remarka++; + } else if (str.getValue().compareTo("remarkb") == 0) { + remarkb++; + } else if (str.getValue().compareTo("remarkc") == 0) { + remarkc++; + } else { + fail(); + } + } + assertTrue(remarka == 1); + assertTrue(remarkb == 0); + assertTrue(remarkc == 1); + store.commitTransaction(); + } + + // check if the update of the price was passed on + { + store.beginTransaction(); + ProductType result = (ProductType) store.query(ProductType.class, "code", "product1", 1).get(0); + assertTrue(result != null); + assertEquals(169.96, result.getPrice().getPrice(), 0.01); + store.commitTransaction(); + } + } catch (Exception e) { + throw new StoreTestException(e.getMessage(), e); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ClaimAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ClaimAction.java new file mode 100755 index 000000000..310cec8df --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ClaimAction.java @@ -0,0 +1,117 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: ClaimAction.java,v 1.3 2009/11/10 10:05:34 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.math.BigDecimal; +import java.util.List; +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.sample.claim.Claim; +import org.eclipse.emf.teneo.samples.emf.sample.claim.ClaimCompositeKey; +import org.eclipse.emf.teneo.samples.emf.sample.claim.ClaimFactory; +import org.eclipse.emf.teneo.samples.emf.sample.claim.ClaimLine; +import org.eclipse.emf.teneo.samples.emf.sample.claim.ClaimLineCompositeKey; +import org.eclipse.emf.teneo.samples.emf.sample.claim.ClaimPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests the capa, detach and update + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ + */ +public class ClaimAction extends AbstractTestAction { + + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public ClaimAction() { + super(ClaimPackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.EXTRA_ANNOTATION_SOURCES, + "teneo.extra, teneo.extra.test, teneo.extra.test2"); + return props; + } + + /** Creates an item, an address and links them to a po. */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + store.beginTransaction(); + store.store(createClaim(1)); + store.store(createClaim(2)); + store.store(createClaim(3)); + store.commitTransaction(); + + store.beginTransaction(); + List<?> claims = store.getObjects(Claim.class); + for (Object o : claims) { + final Claim c = (Claim) o; + final int t = Integer.parseInt(c.getBillingName()); + assertEquals("v" + t, c.getClaimGroupVSPId()); + assertEquals("s" + t, c.getClaimStatus()); + assertEquals(t, c.getClaimLine().size()); + assertEquals("ext" + t, c.getClaimCompositeKey().getClaimExtensionNumber()); + assertEquals("num" + t, c.getClaimCompositeKey().getClaimNumber()); + int k = 0; + for (Object co : c.getClaimLine()) { + final ClaimLine cl = (ClaimLine) co; + int number = (1 + k++) * 10 * t; + assertEquals(number, Integer.parseInt(cl.getClaimLineCompositeKey().getClaimLineNumber())); + assertEquals("" + number, cl.getClaimLineStatus()); + assertTrue(c == cl.getClaimLineCompositeKey().getClaim()); + } + } + store.commitTransaction(); + } + + private Claim createClaim(int i) { + final Claim c = ClaimFactory.eINSTANCE.createClaim(); + c.setBillingName("" + i); + c.setClaimGroupVSPId("v" + i); + c.setClaimStatus("s" + i); + + ClaimCompositeKey ckey = ClaimFactory.eINSTANCE.createClaimCompositeKey(); + ckey.setClaimExtensionNumber("ext" + i); + ckey.setClaimNumber("num" + i); + c.setClaimCompositeKey(ckey); + for (int j = 0; j < i; j++) { + c.getClaimLine().add(createClaimLine((j + 1) * 10 * i)); + } + return c; + } + + private static ClaimLine createClaimLine(int i) { + ClaimLine cl = ClaimFactory.eINSTANCE.createClaimLine(); + cl.setClaimLineBilledAmount(new BigDecimal(400.0 + i)); + cl.setClaimLineStatus("" + i); + cl.setServiceCode("servicecode" + i); + + ClaimLineCompositeKey clkey = ClaimFactory.eINSTANCE.createClaimLineCompositeKey(); + clkey.setClaimLineNumber(i + ""); + cl.setClaimLineCompositeKey(clkey); + return cl; + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/Ecore.ecore b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/Ecore.ecore new file mode 100755 index 000000000..7ef58de7a --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/Ecore.ecore @@ -0,0 +1,357 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ecore:EPackage xmi:version="2.0" + xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="ecore" + nsURI="http://www.eclipse.org/emf/2002/Ecore" nsPrefix="ecore"> + <eClassifiers xsi:type="ecore:EClass" name="EAttribute" eSuperTypes="#//EStructuralFeature"> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="iD" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eAttributeType" lowerBound="1" + eType="#//EDataType" changeable="false" volatile="true" transient="true" derived="true"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="EAnnotation" eSuperTypes="#//EModelElement"> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="source" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="details" upperBound="-1" + eType="#//EStringToStringMapEntry" containment="true" resolveProxies="false"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eModelElement" eType="#//EModelElement" + transient="true" resolveProxies="false" eOpposite="#//EModelElement/eAnnotations"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="contents" upperBound="-1" + eType="#//EObject" containment="true" resolveProxies="false"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="references" upperBound="-1" + eType="#//EObject"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="EClass" eSuperTypes="#//EClassifier"> + <eOperations name="isSuperTypeOf" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"> + <eParameters name="someClass" eType="#//EClass"/> + </eOperations> + <eOperations name="getFeatureCount" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/> + <eOperations name="getEStructuralFeature" eType="#//EStructuralFeature"> + <eParameters name="featureID" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/> + </eOperations> + <eOperations name="getFeatureID" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"> + <eParameters name="feature" eType="#//EStructuralFeature"/> + </eOperations> + <eOperations name="getEStructuralFeature" eType="#//EStructuralFeature"> + <eParameters name="featureName" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> + </eOperations> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="abstract" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="interface" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eSuperTypes" upperBound="-1" + eType="#//EClass"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eOperations" upperBound="-1" + eType="#//EOperation" containment="true" resolveProxies="false" eOpposite="#//EOperation/eContainingClass"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eAllAttributes" upperBound="-1" + eType="#//EAttribute" changeable="false" volatile="true" transient="true" + derived="true"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eAllReferences" upperBound="-1" + eType="#//EReference" changeable="false" volatile="true" transient="true" + derived="true"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eReferences" upperBound="-1" + eType="#//EReference" changeable="false" volatile="true" transient="true" + derived="true"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eAttributes" upperBound="-1" + eType="#//EAttribute" changeable="false" volatile="true" transient="true" + derived="true"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eAllContainments" upperBound="-1" + eType="#//EReference" changeable="false" volatile="true" transient="true" + derived="true"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eAllOperations" upperBound="-1" + eType="#//EOperation" changeable="false" volatile="true" transient="true" + derived="true"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eAllStructuralFeatures" + upperBound="-1" eType="#//EStructuralFeature" changeable="false" volatile="true" + transient="true" derived="true"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eAllSuperTypes" upperBound="-1" + eType="#//EClass" changeable="false" volatile="true" transient="true" derived="true"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eIDAttribute" eType="#//EAttribute" + changeable="false" volatile="true" transient="true" derived="true" resolveProxies="false"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eStructuralFeatures" upperBound="-1" + eType="#//EStructuralFeature" containment="true" resolveProxies="false" eOpposite="#//EStructuralFeature/eContainingClass"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="EClassifier" abstract="true" eSuperTypes="#//ENamedElement"> + <eOperations name="isInstance" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"> + <eParameters name="object" eType="#//EJavaObject"/> + </eOperations> + <eOperations name="getClassifierID" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="instanceClassName" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="instanceClass" eType="#//EJavaClass" + changeable="false" volatile="true" transient="true" derived="true"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="defaultValue" eType="#//EJavaObject" + changeable="false" volatile="true" transient="true" derived="true"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="ePackage" eType="#//EPackage" + changeable="false" transient="true" eOpposite="#//EPackage/eClassifiers"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="EDataType" eSuperTypes="#//EClassifier"> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="serializable" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean" + defaultValueLiteral="true"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="EEnum" eSuperTypes="#//EDataType"> + <eOperations name="getEEnumLiteral" eType="#//EEnumLiteral"> + <eParameters name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> + </eOperations> + <eOperations name="getEEnumLiteral" eType="#//EEnumLiteral"> + <eParameters name="value" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/> + </eOperations> + <eOperations name="getEEnumLiteralByLiteral" eType="#//EEnumLiteral"> + <eParameters name="literal" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> + </eOperations> + <eStructuralFeatures xsi:type="ecore:EReference" name="eLiterals" upperBound="-1" + eType="#//EEnumLiteral" containment="true" resolveProxies="false" eOpposite="#//EEnumLiteral/eEnum"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="EEnumLiteral" eSuperTypes="#//ENamedElement"> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="value" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="instance" eType="#//EEnumerator" + transient="true"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="literal" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eEnum" eType="#//EEnum" + changeable="false" transient="true" resolveProxies="false" eOpposite="#//EEnum/eLiterals"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="EFactory" eSuperTypes="#//EModelElement"> + <eOperations name="create" eType="#//EObject"> + <eParameters name="eClass" eType="#//EClass"/> + </eOperations> + <eOperations name="createFromString" eType="#//EJavaObject"> + <eParameters name="eDataType" eType="#//EDataType"/> + <eParameters name="literalValue" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> + </eOperations> + <eOperations name="convertToString" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"> + <eParameters name="eDataType" eType="#//EDataType"/> + <eParameters name="instanceValue" eType="#//EJavaObject"/> + </eOperations> + <eStructuralFeatures xsi:type="ecore:EReference" name="ePackage" lowerBound="1" + eType="#//EPackage" transient="true" resolveProxies="false" eOpposite="#//EPackage/eFactoryInstance"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="EModelElement" abstract="true" eSuperTypes="#//EObject"> + <eOperations name="getEAnnotation" eType="#//EAnnotation"> + <eParameters name="source" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> + </eOperations> + <eStructuralFeatures xsi:type="ecore:EReference" name="eAnnotations" upperBound="-1" + eType="#//EAnnotation" containment="true" resolveProxies="false" eOpposite="#//EAnnotation/eModelElement"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="ENamedElement" abstract="true" eSuperTypes="#//EModelElement"> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="EObject"> + <eOperations name="eClass" eType="#//EClass"/> + <eOperations name="eIsProxy" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/> + <eOperations name="eResource" eType="#//EResource"/> + <eOperations name="eContainer" eType="#//EObject"/> + <eOperations name="eContainingFeature" eType="#//EStructuralFeature"/> + <eOperations name="eContainmentFeature" eType="#//EReference"/> + <eOperations name="eContents" eType="#//EEList"/> + <eOperations name="eAllContents" eType="#//ETreeIterator"/> + <eOperations name="eCrossReferences" eType="#//EEList"/> + <eOperations name="eGet" eType="#//EJavaObject"> + <eParameters name="feature" eType="#//EStructuralFeature"/> + </eOperations> + <eOperations name="eGet" eType="#//EJavaObject"> + <eParameters name="feature" eType="#//EStructuralFeature"/> + <eParameters name="resolve" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/> + </eOperations> + <eOperations name="eSet"> + <eParameters name="feature" eType="#//EStructuralFeature"/> + <eParameters name="newValue" eType="#//EJavaObject"/> + </eOperations> + <eOperations name="eIsSet" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"> + <eParameters name="feature" eType="#//EStructuralFeature"/> + </eOperations> + <eOperations name="eUnset"> + <eParameters name="feature" eType="#//EStructuralFeature"/> + </eOperations> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="EOperation" eSuperTypes="#//ETypedElement"> + <eStructuralFeatures xsi:type="ecore:EReference" name="eContainingClass" eType="#//EClass" + changeable="false" transient="true" resolveProxies="false" eOpposite="#//EClass/eOperations"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eParameters" upperBound="-1" + eType="#//EParameter" containment="true" resolveProxies="false" eOpposite="#//EParameter/eOperation"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eExceptions" upperBound="-1" + eType="#//EClassifier"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="EPackage" eSuperTypes="#//ENamedElement"> + <eOperations name="getEClassifier" eType="#//EClassifier"> + <eParameters name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> + </eOperations> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="nsURI" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="nsPrefix" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eFactoryInstance" lowerBound="1" + eType="#//EFactory" transient="true" resolveProxies="false" eOpposite="#//EFactory/ePackage"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eClassifiers" upperBound="-1" + eType="#//EClassifier" containment="true" eOpposite="#//EClassifier/ePackage"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eSubpackages" upperBound="-1" + eType="#//EPackage" containment="true" eOpposite="#//EPackage/eSuperPackage"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eSuperPackage" eType="#//EPackage" + changeable="false" transient="true" eOpposite="#//EPackage/eSubpackages"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="EParameter" eSuperTypes="#//ETypedElement"> + <eStructuralFeatures xsi:type="ecore:EReference" name="eOperation" eType="#//EOperation" + changeable="false" transient="true" resolveProxies="false" eOpposite="#//EOperation/eParameters"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="EReference" eSuperTypes="#//EStructuralFeature"> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="containment" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="container" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean" + changeable="false" volatile="true" transient="true" derived="true"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="resolveProxies" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean" + defaultValueLiteral="true"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eOpposite" eType="#//EReference"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eReferenceType" lowerBound="1" + eType="#//EClass" changeable="false" volatile="true" transient="true" derived="true"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="EStructuralFeature" abstract="true" + eSuperTypes="#//ETypedElement"> + <eOperations name="getFeatureID" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/> + <eOperations name="getContainerClass" eType="#//EJavaClass"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="changeable" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean" + defaultValueLiteral="true"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="volatile" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="transient" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="defaultValueLiteral" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="defaultValue" eType="#//EJavaObject" + changeable="false" volatile="true" transient="true" derived="true"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="unsettable" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="derived" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eContainingClass" eType="#//EClass" + changeable="false" transient="true" resolveProxies="false" eOpposite="#//EClass/eStructuralFeatures"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="ETypedElement" abstract="true" eSuperTypes="#//ENamedElement"> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="ordered" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean" + defaultValueLiteral="true"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="unique" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean" + defaultValueLiteral="true"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="lowerBound" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="upperBound" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt" + defaultValueLiteral="1"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="many" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean" + changeable="false" volatile="true" transient="true" derived="true"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="required" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean" + changeable="false" volatile="true" transient="true" derived="true"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="eType" eType="#//EClassifier"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="EBigDecimal" instanceClassName="java.math.BigDecimal"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="baseType" value="http://www.w3.org/2001/XMLSchema#decimal"/> + </eAnnotations> + </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="EBigInteger" instanceClassName="java.math.BigInteger"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="baseType" value="http://www.w3.org/2001/XMLSchema#integer"/> + </eAnnotations> + </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="EBoolean" instanceClassName="boolean"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="baseType" value="http://www.w3.org/2001/XMLSchema#boolean"/> + </eAnnotations> + </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="EBooleanObject" instanceClassName="java.lang.Boolean"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="baseType" value="EBoolean"/> + <details key="name" value="EBoolean:Object"/> + </eAnnotations> + </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="EByte" instanceClassName="byte"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="baseType" value="http://www.w3.org/2001/XMLSchema#byte"/> + </eAnnotations> + </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="EByteArray" instanceClassName="byte[]"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="baseType" value="http://www.w3.org/2001/XMLSchema#hexBinary"/> + </eAnnotations> + </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="EByteObject" instanceClassName="java.lang.Byte"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="baseType" value="EByte"/> + <details key="name" value="EByte:Object"/> + </eAnnotations> + </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="EChar" instanceClassName="char"/> + <eClassifiers xsi:type="ecore:EDataType" name="ECharacterObject" instanceClassName="java.lang.Character"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="baseType" value="EChar"/> + <details key="name" value="EChar:Object"/> + </eAnnotations> + </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="EDate" instanceClassName="java.util.Date"/> + <eClassifiers xsi:type="ecore:EDataType" name="EDiagnosticChain" instanceClassName="org.eclipse.emf.common.util.DiagnosticChain" + serializable="false"/> + <eClassifiers xsi:type="ecore:EDataType" name="EDouble" instanceClassName="double"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="baseType" value="http://www.w3.org/2001/XMLSchema#double"/> + </eAnnotations> + </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="EDoubleObject" instanceClassName="java.lang.Double"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="baseType" value="EDouble"/> + <details key="name" value="EDouble:Object"/> + </eAnnotations> + </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="EEList" instanceClassName="org.eclipse.emf.common.util.EList" + serializable="false"/> + <eClassifiers xsi:type="ecore:EDataType" name="EEnumerator" instanceClassName="org.eclipse.emf.common.util.Enumerator" + serializable="false"/> + <eClassifiers xsi:type="ecore:EDataType" name="EFeatureMap" instanceClassName="org.eclipse.emf.ecore.util.FeatureMap" + serializable="false"/> + <eClassifiers xsi:type="ecore:EDataType" name="EFeatureMapEntry" instanceClassName="org.eclipse.emf.ecore.util.FeatureMap$Entry"/> + <eClassifiers xsi:type="ecore:EDataType" name="EFloat" instanceClassName="float"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="baseType" value="http://www.w3.org/2001/XMLSchema#float"/> + </eAnnotations> + </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="EFloatObject" instanceClassName="java.lang.Float"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="baseType" value="EFloat"/> + <details key="name" value="EFloat:Object"/> + </eAnnotations> + </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="EInt" instanceClassName="int"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="baseType" value="http://www.w3.org/2001/XMLSchema#int"/> + </eAnnotations> + </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="EIntegerObject" instanceClassName="java.lang.Integer"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="baseType" value="EInt"/> + <details key="name" value="EInt:Object"/> + </eAnnotations> + </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="EJavaClass" instanceClassName="java.lang.Class"/> + <eClassifiers xsi:type="ecore:EDataType" name="EJavaObject" instanceClassName="java.lang.Object" + serializable="false"/> + <eClassifiers xsi:type="ecore:EDataType" name="ELong" instanceClassName="long"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="baseType" value="http://www.w3.org/2001/XMLSchema#long"/> + </eAnnotations> + </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="ELongObject" instanceClassName="java.lang.Long"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="baseType" value="ELong"/> + <details key="name" value="ELong:Object"/> + </eAnnotations> + </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="EMap" instanceClassName="java.util.Map" + serializable="false"/> + <eClassifiers xsi:type="ecore:EDataType" name="EResource" instanceClassName="org.eclipse.emf.ecore.resource.Resource" + serializable="false"/> + <eClassifiers xsi:type="ecore:EDataType" name="EResourceSet" instanceClassName="org.eclipse.emf.ecore.resource.ResourceSet" + serializable="false"/> + <eClassifiers xsi:type="ecore:EDataType" name="EShort" instanceClassName="short"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="baseType" value="http://www.w3.org/2001/XMLSchema#short"/> + </eAnnotations> + </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="EShortObject" instanceClassName="java.lang.Short"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="baseType" value="EShort"/> + <details key="name" value="EShort:Object"/> + </eAnnotations> + </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="EString" instanceClassName="java.lang.String"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="baseType" value="http://www.w3.org/2001/XMLSchema#string"/> + </eAnnotations> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="EStringToStringMapEntry" instanceClassName="java.util.Map$Entry"> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="key" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="value" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="ETreeIterator" instanceClassName="org.eclipse.emf.common.util.TreeIterator" + serializable="false"/> +</ecore:EPackage> diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/EcoreAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/EcoreAction.java new file mode 100755 index 000000000..edd3e127f --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/EcoreAction.java @@ -0,0 +1,198 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: EcoreAction.java,v 1.19 2010/04/02 15:25:47 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.io.IOException; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; + +import org.eclipse.emf.common.util.TreeIterator; +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EcorePackage; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl; +import org.eclipse.emf.ecore.xml.type.XMLTypePackage; +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.annotations.pannotation.InheritanceType; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests persisting of ecore models in a relational store. Only stores them and then reads them again. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.19 $ + */ +public class EcoreAction extends AbstractTestAction { + + /** Constructor */ + public EcoreAction() { + super(new EPackage[] { EcorePackage.eINSTANCE, org.eclipse.emf.ecore.xml.type.XMLTypePackage.eINSTANCE }); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties() + */ + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true"); + return props; + } + + /** Reads the library model and persists it. */ + @Override + public void doAction(TestStore store) { + if (store.getInheritanceType().equals(InheritanceType.SINGLE_TABLE)) { + // ignore this as this fails any way + return; + } + if (store.getDatabaseAdapter().getDbName().contains("mysql")) { + // too many joins error so ignore... + return; + } + // read ecore as a resource + final Resource resourceOne = new XMIResourceImpl(); + try { + // read from the resource + { + resourceOne.load(EcoreAction.class.getResourceAsStream("library.ecore"), Collections.EMPTY_MAP); + // EPackage epack = (EPackage)resource.getContents().get(0); + // resource.unload(); + final EPackage epack = (EPackage) resourceOne.getContents().get(0); + + // some logic adds adapters (for example the EAV schema, get rid of them...) + for (TreeIterator<EObject> it = epack.eAllContents(); it.hasNext();) { + it.next().eAdapters().clear(); + } + final EPackage ecorePackage = EcorePackage.eINSTANCE; + for (TreeIterator<EObject> it = ecorePackage.eAllContents(); it.hasNext();) { + it.next().eAdapters().clear(); + } + final EPackage xmlTypePackage = XMLTypePackage.eINSTANCE; + for (TreeIterator<EObject> it = xmlTypePackage.eAllContents(); it.hasNext();) { + it.next().eAdapters().clear(); + } + + store.beginTransaction(); + store.store(epack); + store.store(ecorePackage); + store.store(xmlTypePackage); + store.commitTransaction(); + } + + // test 285409 + { + store.beginTransaction(); + List<EAnnotation> eas = store.getObjects(EAnnotation.class); + assertTrue(eas.size() > 0); + for (EAnnotation eAnnotation : eas) { + assertTrue(eAnnotation.getDetails().size() > 0); + } + store.commitTransaction(); + } + + // read from the relational store + // and save it in a xml byte array + final Resource resourceTwo = new XMIResourceImpl(); + if (true) { + store.beginTransaction(); + final List<?> result = store.getObjects(EPackage.class); + // get the library ecore from the result + // EPackage libEPack = null; + for (int i = 0; i < result.size(); i++) { + final EPackage epack = (EPackage) result.get(i); + resourceTwo.getContents().add(epack); + // very simple test on name, ouch! + // if (epack.getName().compareToIgnoreCase("library") == 0) { + // libEPack = epack; + // } + } + // assertNotNull(libEPack); + // just iterate over the contents + int cnt = 0; + final Iterator<?> it = resourceTwo.getAllContents(); + while (it.hasNext()) { + it.next(); + cnt++; + } + // now compare the two resources + // compares fails for now + // compareResult(resourceOne, resourceTwo); + store.commitTransaction(); + } + + // and now delete the ecorepackage + { + store.beginTransaction(); + final List<?> list = store.getObjects(EPackage.class); + for (Object o : list) { + store.deleteObject(o); + } + store.commitTransaction(); + } + + // now try the debfile + { + final Resource fileRes = new XMIResourceImpl(); + fileRes.load(EcoreAction.class.getResourceAsStream("debFile.ecore"), Collections.EMPTY_MAP); + store.beginTransaction(); + for (Object o : fileRes.getContents()) { + store.store(o); + } + store.commitTransaction(); + } + // { + // store.beginTransaction(); + // final Resource res = new XMIResourceImpl(); + // for (Object o : store.getObjects(EPackage.class)) { + // res.getContents().add((EObject) o); + // } + // final OutputStream os = new FileOutputStream("/home/mtaal/mytmp/test.ecore"); + // res.save(os, Collections.EMPTY_MAP); + // store.commitTransaction(); + // } + + } catch (Exception e) { + throw new StoreTestException("Exception when testing persistence of ecore", e); + } + } + + /** Compare the original and the generated xml file */ + protected void compareResult(Resource resourceOne, Resource ResourceTwo) throws IOException { + final Iterator<?> original_iterator = resourceOne.getAllContents(); + + final Iterator<?> new_iterator = ResourceTwo.getAllContents(); + + // rough structural test + while (new_iterator.hasNext()) { + assertTrue(original_iterator.hasNext()); + + final EObject original_object = (EObject) original_iterator.next(); + final EObject new_object = (EObject) new_iterator.next(); + assertEquals(original_object.getClass(), new_object.getClass()); + } + assertTrue(!new_iterator.hasNext()); + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ExtendedPO2Action.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ExtendedPO2Action.java new file mode 100755 index 000000000..c05979366 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ExtendedPO2Action.java @@ -0,0 +1,190 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: ExtendedPO2Action.java,v 1.6 2008/02/28 07:08:14 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.List; + +import org.eclipse.emf.teneo.samples.emf.sample.epo2.Customer; +import org.eclipse.emf.teneo.samples.emf.sample.epo2.EPO2Factory; +import org.eclipse.emf.teneo.samples.emf.sample.epo2.EPO2Package; +import org.eclipse.emf.teneo.samples.emf.sample.epo2.GlobalAddress; +import org.eclipse.emf.teneo.samples.emf.sample.epo2.Item; +import org.eclipse.emf.teneo.samples.emf.sample.epo2.OrderStatus; +import org.eclipse.emf.teneo.samples.emf.sample.epo2.PurchaseOrder; +import org.eclipse.emf.teneo.samples.emf.sample.epo2.Supplier; +import org.eclipse.emf.teneo.samples.emf.sample.epo2.USAddress; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests the extended po 2 example + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.6 $ $Date: 2008/02/28 07:08:14 $ + */ +public abstract class ExtendedPO2Action extends AbstractTestAction { + public ExtendedPO2Action() { + super(EPO2Package.eINSTANCE); + } + + /** Stores a TopModel Object */ + @Override + public void doAction(TestStore store) { + final EPO2Factory factory = EPO2Factory.eINSTANCE; + { + Supplier supplier = factory.createSupplier(); // This is the root. Keep it .... + supplier.setName("Computer City"); + + PurchaseOrder po = factory.createPurchaseOrder(); + supplier.getOrders().add(po); + PurchaseOrder prevpo = factory.createPurchaseOrder(); + supplier.getOrders().add(prevpo); + + po.setComment("a new purchase order"); + prevpo.setComment("the previous purchase order"); + + USAddress adr = factory.createUSAddress(); + adr.setCity("Doorn"); + adr.setCountry("Netherlands"); + adr.setName("M. Taal"); + adr.setState("Utrecht"); + adr.setStreet("Nassaulaan 7"); + adr.setZip(3941); + + USAddress adr1 = factory.createUSAddress(); + adr1.setCity("Doorn"); + adr1.setCountry("Netherlands"); + adr1.setName("M. Taal"); + adr1.setState("Utrecht"); + adr1.setStreet("Nassaulaan 7"); + adr1.setZip(3941); + + // both have same billto + po.setBillTo(adr); + prevpo.setBillTo(adr1); + + po.setOrderDate(new Date()); + Calendar cal = new GregorianCalendar(); + cal.add(Calendar.DAY_OF_MONTH, -5); + prevpo.setOrderDate(cal.getTime()); + + Customer cust = factory.createCustomer(); + supplier.getCustomers().add(cust); + cust.setCustomerID(5000); + cust.getOrders().add(po); // Added by DSC for JCR validation. Remove later.... + cust.getOrders().add(prevpo); // Added by DSC for JCR validation. Remove later.... + po.setCustomer(cust); + prevpo.setCustomer(cust); + + GlobalAddress globadr = factory.createGlobalAddress(); + globadr.setCountry("Belgium"); + globadr.setCountryCode(36); + globadr.setName("Belgium Office"); + globadr.getLocation().add("MY GLOBAL LOCATION"); + + GlobalAddress globadr1 = factory.createGlobalAddress(); + globadr1.setCountry("Belgium"); + globadr1.setCountryCode(36); + globadr1.setName("Belgium Office"); + globadr1.getLocation().add("MY GLOBAL LOCATION"); + + // both have same shipto + po.setShipTo(globadr); + prevpo.setShipTo(globadr1); + + po.setStatus(OrderStatus.COMPLETE_LITERAL); + prevpo.setStatus(OrderStatus.BACK_ORDER_LITERAL); + + Item item = factory.createItem(); + item.setComment("I like this product"); + item.setPartNum("500.11.22"); + item.setProductName("Dell Latitude"); + item.setQuantity(50); + item.setShipDate(new Date()); + item.setOrder(po); // Added by DSC for JCR validation. Remove later.... + + Item item2 = factory.createItem(); + item2.setComment("A few of these for me."); + item2.setPartNum("500.11.2000"); + item2.setProductName("Sun Opteron Workstation"); + item2.setQuantity(200); + item2.setShipDate(new Date()); + item2.setOrder(prevpo); // Added by DSC for JCR validation. Remove later.... + + po.getItems().add(item); + prevpo.getItems().add(item2); + po.setPreviousOrder(prevpo); + store.beginTransaction(); + store.store(supplier); + store.commitTransaction(); + /* + * final Resource res = store.getResource(); res.getContents().add(supplier); try { + * res.save(Collections.EMPTY_MAP); } catch (IOException e) { throw new + * StoreTestException("IOException", e); } + */ + } + + { + store.beginTransaction(); + // final Resource res2 = store.getResource(); + // Supplier supplierTest = (Supplier)res2.getContents().get(0); + Supplier supplierTest = (Supplier) store.getObject(Supplier.class); + List<?> customers = supplierTest.getCustomers(); + assertNotNull(customers); + assertTrue(customers.size() == 1); + assertNotNull(customers.get(0)); + assertTrue(((Customer) customers.get(0)).getCustomerID() > 0); + assertNotNull(((Customer) customers.get(0)).getOrders()); + assertTrue(((Customer) customers.get(0)).getOrders().size() == 2); + for (Object name : supplierTest.getOrders()) { + PurchaseOrder potest = (PurchaseOrder) name; + assertNotNull(potest.getStatus().getLiteral()); + assertTrue(potest.getItems().size() > 0); + Item itemtest = potest.getItems().get(0); + assertNotNull(itemtest.eContainer()); + assertNotNull(itemtest.getOrder()); + assertNotNull(itemtest.getShipDate()); + assertNotNull(itemtest.getPartNum()); + assertNotNull(potest.getCustomer()); + USAddress billTo = (USAddress) potest.getBillTo(); + assertNotNull(billTo); + assertNotNull(billTo.getStreet()); + GlobalAddress shipTo = (GlobalAddress) potest.getShipTo(); + assertNotNull(shipTo); + assertTrue(shipTo.getCountryCode() > 0); + } + store.commitTransaction(); + } + + checkContainerForSeparatelyReadItem(store); + } + + protected abstract void checkContainerForSeparatelyReadItem(TestStore store); + // TODO jpox was + // // if a contained item is read separately from the db then the + // // container is not set! + // if (store instanceof JPOXTestStore) + // { + // store.beginTransaction(); + // Item itemtest2 = (Item)store.getObject(Item.class); + // assertTrue(itemtest2.eContainer() == null); + // store.commitTransaction(); + // } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/FleetAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/FleetAction.java new file mode 100755 index 000000000..f0e74b443 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/FleetAction.java @@ -0,0 +1,129 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: FleetAction.java,v 1.3 2009/08/21 15:02:00 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.Date; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +import temporal.TemporalPackage; +import fleet.Address; +import fleet.Car; +import fleet.Fleet; +import fleet.FleetFactory; +import fleet.FleetPackage; +import fleet.Garage; +import fleet.Person; +import fleet.Tire; +import fleet.VehicleInfo; + +/** + * Tests EStore + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ + */ +public class FleetAction extends AbstractTestAction { + + public FleetAction() { + super(new EPackage[] { FleetPackage.eINSTANCE, TemporalPackage.eINSTANCE }); + } + + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + final FleetFactory factory = FleetFactory.eINSTANCE; + final Garage garage = factory.createGarage(); + garage.setName("Great Garage1"); + final Address address = factory.createAddress(); + address.setCity("doorn"); + address.setCountry("NL"); + address.setStreetName("Dutchlane"); + address.setStreetNumber("25"); + garage.setAddress(address); + + final Fleet fl1 = factory.createFleet(); + fl1.setId("fl1"); + fl1.setServiceGarage(garage); + createData(fl1); + + final Fleet fl2 = factory.createFleet(); + fl2.setId("fl2"); + fl2.setServiceGarage(garage); + createData(fl2); + + store.beginTransaction(); + store.store(garage); + store.store(fl1); + store.store(fl2); + store.commitTransaction(); + + } + + private void createData(Fleet fleet) { + final FleetFactory factory = FleetFactory.eINSTANCE; + + String indexStr = fleet.getId(); + final Address address = factory.createAddress(); + address.setCity(indexStr + "doorn"); + address.setCountry(indexStr + "NL"); + address.setStreetName(indexStr + "Dutchlane"); + address.setStreetNumber(indexStr + "25"); + + final Person person = factory.createPerson(); + person.setBirthAddress(address); + person.setEmployed(false); + person.setId(indexStr + "111-222-333-444"); + person.setName(indexStr + "Piet Hein"); + + final Tire tire = factory.createTire(); + tire.setMake("michellin"); + tire.setModel("winter"); + tire.setProfile(2); + tire.setRadius(2); + tire.setWidth(3); + + final Car car = factory.createCar(); + car.setId(indexStr + "01-ps-fb"); + car.setBrand(indexStr + "volvo"); + car.setColor(indexStr + "dark-metalic-blue"); + car.setLength(5); + car.setMake(indexStr + "TD5"); + car.setModel(indexStr + "v70"); + car.setNumPassengers(7); + car.setNumTires(4); + car.setOwner(person); + + assertTrue(person.eContainmentFeature() != null); + + car.setPassengerName(indexStr + "p"); + car.setPlate("01-ps-fb"); + car.setYear(2004); + car.setTireSpec(tire); + fleet.getVehicles().add(car); + + fleet.getServiceGarage().getVehicles().add(car); + + VehicleInfo vInfo = factory.createVehicleInfo(); + vInfo.setAcquisitionDate(new Date()); + vInfo.setVehicle(car); + fleet.getVehicleInformation().add(vInfo); + + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ForumAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ForumAction.java new file mode 100755 index 000000000..3e1cec972 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ForumAction.java @@ -0,0 +1,89 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: ForumAction.java,v 1.4 2008/02/28 07:08:14 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.sample.forum.Forum; +import org.eclipse.emf.teneo.samples.emf.sample.forum.ForumFactory; +import org.eclipse.emf.teneo.samples.emf.sample.forum.ForumPackage; +import org.eclipse.emf.teneo.samples.emf.sample.forum.Member; +import org.eclipse.emf.teneo.samples.emf.sample.forum.Post; +import org.eclipse.emf.teneo.samples.emf.sample.forum.Topic; +import org.eclipse.emf.teneo.samples.emf.sample.forum.TopicCategory; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests the forum example + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.4 $ + */ +public class ForumAction extends AbstractTestAction { + public ForumAction() { + super(ForumPackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true"); + return props; + } + + /** Test */ + @Override + public void doAction(TestStore store) { + final ForumFactory factory = ForumFactory.eINSTANCE; + + store.beginTransaction(); + final Forum forum = factory.createForum(); + forum.setTitle("my first forum1"); + + final Member member = factory.createMember(); + member.setNickname("martin"); + + final Topic topic = factory.createTopic(); + topic.setCategory(TopicCategory.ANNOUNCEMENT_LITERAL); + topic.setCreator(member); + topic.setTitle("my first topic!"); + + // is a two-way relation! + assertTrue((member.getCreated().get(0)).getTitle().compareTo("my first topic!") == 0); + + final Post post = factory.createPost(); + post.setTopic(topic); + post.setAuthor(member); + post.setComment("my post"); + + forum.getTopics().add(topic); + forum.getMembers().add(member); + + store.store(forum); + + for (int i = 0; i < 100; i++) { + final Member newMember = factory.createMember(); + newMember.setNickname("martin" + i); + forum.getMembers().add(newMember); + store.store(newMember); + } + store.store(forum); + store.commitTransaction(); + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/GMFNotationAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/GMFNotationAction.java new file mode 100755 index 000000000..d9a3d378d --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/GMFNotationAction.java @@ -0,0 +1,92 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: GMFNotationAction.java,v 1.8 2009/06/08 07:44:05 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.net.URL; +import java.util.HashMap; +import java.util.Properties; + +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.ecore.xmi.XMIResource; +import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests persisting of gmf diagram. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.8 $ + */ +public class GMFNotationAction extends AbstractTestAction { + + /** Constructor */ + public GMFNotationAction() { + throw new UnsupportedOperationException("Not supported"); + // super(new EPackage[] { EcorePackage.eINSTANCE, NotationPackage.eINSTANCE, MindmapPackage.eINSTANCE }); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties() + */ + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + // props.setProperty(PersistenceOptions.USE_MAPPING_FILE, "true"); + return props; + } + + /** Reads the library model and persists it. */ + @Override + public void doAction(TestStore store) { + final URL mindmapURL = getClass().getResource("default.mindmap"); + final URI mindmapURI = URI.createURI(mindmapURL.toString()); + final URL diagramURL = getClass().getResource("default.mmd"); + final URI diagramURI = URI.createURI(diagramURL.toString()); + Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("mmd", new XMIResourceFactoryImpl()); + Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("mindmap", new XMIResourceFactoryImpl()); + final ResourceSet rs = new ResourceSetImpl(); + final XMIResource mindmapResource = (XMIResource) rs.createResource(mindmapURI); + final XMIResource diagramResource = (XMIResource) rs.createResource(diagramURI); + try { + // default load options. + final HashMap<Object, Object> loadOptions = new HashMap<Object, Object>(); + loadOptions.putAll(mindmapResource.getDefaultLoadOptions()); + // loadOptions.put(XMLResource.OPTION_USE_DEPRECATED_METHODS, Boolean.FALSE); + loadOptions.put(XMIResource.OPTION_LAX_FEATURE_PROCESSING, Boolean.TRUE); + mindmapResource.load(loadOptions); + diagramResource.load(loadOptions); + store.beginTransaction(); + for (Object element : mindmapResource.getContents()) { + store.store(element); + } + for (Object element : diagramResource.getContents()) { + store.store(element); + } + store.commitTransaction(); + } catch (Exception e) { + throw new StoreTestException("Exception", e); + } + + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/GMFNotationAction_old.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/GMFNotationAction_old.persistence.xml new file mode 100755 index 000000000..39e55580a --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/GMFNotationAction_old.persistence.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> +<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <epackage namespace-uri="http://www.eclipse.org/gmf/runtime/1.0.0/notation"> + + <eclass name="SortingStyle"> + <property name="sortingKeys"> + <transient/> + </property> + </eclass> + + </epackage> + +</persistence-mapping>
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/InventoryAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/InventoryAction.java new file mode 100755 index 000000000..1abef38a6 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/InventoryAction.java @@ -0,0 +1,92 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: InventoryAction.java,v 1.5 2008/02/28 07:08:14 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.List; +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.sample.inv.InventoryFactory; +import org.eclipse.emf.teneo.samples.emf.sample.inv.InventoryPackage; +import org.eclipse.emf.teneo.samples.emf.sample.inv.PDeclaration; +import org.eclipse.emf.teneo.samples.emf.sample.inv.PType; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.5 $ + */ +public class InventoryAction extends AbstractTestAction { + public InventoryAction() { + super(InventoryPackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true"); + return props; + } + + /** Creates a supplier, a product, relates then, saves and retrieves them again. */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + final InventoryFactory factory = InventoryFactory.eINSTANCE; + { + store.beginTransaction(); + PType pt = factory.createPType(); + pt.setName("myname"); + + PType ptChild = factory.createPType(); + ptChild.setName("child"); + ptChild.setBase(pt); + + PType ptOther = factory.createPType(); + ptOther.setName("other"); + pt.getSubNOTypes().add(ptOther); + + PDeclaration pd = factory.createPDeclaration(); + pd.setName("pd"); + pt.getInfoReferences().add(pd); + PDeclaration pd1 = factory.createPDeclaration(); + pd1.setName("pd1"); + pt.getInfoReferences().add(pd1); + pt.getInfoReferences().add(pd); + + store.store(pt); + store.store(ptChild); + store.store(ptOther); + store.commitTransaction(); + } + + store.checkNumber(PType.class, 3); + + { + store.beginTransaction(); + List list = store.query(PType.class, "name", "myname", 1); + PType pt = (PType) list.get(0); + assertEquals(((PType) pt.getSubNOTypes().get(0)).getName(), "other"); + assertEquals(((PType) pt.getSubTypes().get(0)).getName(), "child"); + pt.getInfoReferences().add(pt.getInfoReferences().get(0)); + store.store(pt); + store.commitTransaction(); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/JuliaAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/JuliaAction.java new file mode 100755 index 000000000..cb014dc15 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/JuliaAction.java @@ -0,0 +1,60 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: JuliaAction.java,v 1.3 2008/04/11 03:21:48 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.Properties; + +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +import com.ibm.websphere.appserver.schemas._6._0.ibm.portal.test.TestPackage; + +/** + * Test bugzilla 199373 + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ + */ +public class JuliaAction extends AbstractTestAction { + + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public JuliaAction() { + super(TestPackage.eINSTANCE); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties() + */ + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); +// props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPPING, "true"); + return props; + } + + /** Creates an item, an address and links them to a po. */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryAction.java new file mode 100755 index 000000000..91679d355 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryAction.java @@ -0,0 +1,345 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: LibraryAction.java,v 1.26 2010/11/12 13:35:58 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.sample.library.Book; +import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory; +import org.eclipse.emf.teneo.samples.emf.sample.library.Library; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage; +import org.eclipse.emf.teneo.samples.emf.sample.library.Writer; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests the library example of emf/xsd. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.26 $ + */ +public class LibraryAction extends AbstractTestAction { + + public LibraryAction() { + super(LibraryPackage.eINSTANCE); + } + + // public void setExtensions(ExtensionManager extensionManager) { + // extensionManager.registerExtension(EntityNameStrategy.class.getName(), + // ClassNameEntityNameStrategy.class.getName()); + // } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY, + "READ_WRITE"); + props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false"); + props.setProperty(PersistenceOptions.DEFAULT_VARCHAR_LENGTH, "50"); + props.setProperty(PersistenceOptions.DEFAULT_VARCHAR_LENGTH, "50"); + return props; + } + + /** Creates an item, an address and links them to a po. */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + final LibraryFactory factory = LibraryFactory.eINSTANCE; + + // { + // store.beginTransaction(); + // + // // Create a library. + // Library library = LibraryFactory.eINSTANCE.createLibrary(); + // library.setName("My Library"); + // // Make it persistent. + // store.store(library); + // + // // Create a writer... + // Writer writer = LibraryFactory.eINSTANCE.createWriter(); + // writer.setName("JRR Tolkien"); + // + // // ...and one of his books. + // Book book = LibraryFactory.eINSTANCE.createBook(); + // book.setAuthor(writer); + // book.setPages(305); + // book.setTitle("The Hobbit"); + // book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + // + // // Add the Writer and Book to the Library. They are made + // // persistent automatically because the Library is already + // // persistent. + // library.getWriters().add(writer); + // library.getBooks().add(book); + // store.commitTransaction(); + // } + + // create a book, writer and library + { + store.beginTransaction(); + + final Writer writer = factory.createWriter(); + writer.setName("JRR Tolkien"); + + final Book book = factory.createBook(); + + book.setAuthor(writer); + book.setPages(5); + book.setTitle("The Hobbit"); + book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Book book2 = factory.createBook(); + book2.setAuthor(writer); + book2.setPages(5); + book2.setTitle("The fellowship of the ring"); + book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Library library = factory.createLibrary(); + library.getBooks().add(book); + library.setName("Science Fiction Library"); + library.getBooks().add(book2); + library.getWriters().add(writer); + store.store(library); + + store.commitTransaction(); + assertEquals(2, writer.getBooks().size()); + } + + // walk through the structure starting from the library + { + store.beginTransaction(); + Library lib = (Library) store.query(Library.class, "name", + "Science Fiction Library", 1).get(0); + + testLazySize(lib.getWriters()); + testLazySize(lib.getBooks()); + + assertTrue((lib.getWriters().get(0)).getName().compareTo( + "JRR Tolkien") == 0); + testLazySize(lib.getWriters().get(0).getBooks()); + + // final Object[] eobjs = + // store.getCrossReferencers((EObject)lib.getWriters().get(0), + // false); + + // these two books should be the same as this book is the first in + // the writers + // collection + // and in the library collection + Book wBook = (lib.getWriters().get(0)).getBooks().get(0); + Book lBook = lib.getBooks().get(0); + + // check container + assertTrue(lBook.eContainer() == lib); + + assertTrue(wBook.getTitle().compareTo(lBook.getTitle()) == 0); + assertTrue(wBook.getPages() == lBook.getPages()); + assertTrue(wBook.getCategory() instanceof BookCategory); + assertTrue(wBook.getCategory() == BookCategory.SCIENCE_FICTION_LITERAL); + store.commitTransaction(); + } + + // check container relations + if (true) { + store.beginTransaction(); + + final Writer writ = store.getObjects(Writer.class).get(0); + + // store.refresh(writ); + + // test notifications of the elist + // disabled this test as the elist notifications have been disabled + // WriterAdapter writerAdapter = new WriterAdapter(); + // writ.eAdapters().add(writerAdapter); + // assertEquals(2, writ.getBooks().size()); // this should not + // trigger the adapter to be + // called + // assertEquals(1, writerAdapter.getCountNotifications()); + + checkContainerAfterWriterRetrieve(store, writ); + + Library lib = (Library) store.getCrossReferencers(writ, true)[0]; + checkContainerAfterLibraryRetrieve(store, writ); + checkDetachCopy(store, writ); + + // now set the container of the writer + assertTrue("The container of the writer should be set!", + store.setContainer(writ)); + + assertEquals(LibraryPackage.eINSTANCE.getLibrary_Writers() + .getFeatureID(), writ.eContainingFeature().getFeatureID()); + + assertTrue( + "The container of the writer should be equal to the earlier retrieved Library", + lib == writ.eContainer()); + + final Object[] eobjs = store.getCrossReferencers(writ, false); + assertEquals(3, eobjs.length); + for (final Object obj : eobjs) { + if (obj instanceof Library) { + assertTrue(obj == lib); + } else { + assertTrue(((Book) obj).getAuthor() == writ); + assertTrue(lib.getBooks().contains(obj)); + } + } + + final Book bk = store.getObjects(Book.class).get(0); + assertTrue(bk.eContainer() == lib); + + // check if the containing feature is also set correctly + assertTrue(bk.eContainingFeature() == LibraryPackage.eINSTANCE + .getLibrary_Books()); + + assertTrue(lib.getBooks().contains(bk)); + + store.refresh(lib); + + store.commitTransaction(); + } + + // test https://bugs.eclipse.org/bugs/show_bug.cgi?id=297627 + checkIndexName(store); + + dumpPAModel(store); + checkTeneoSQLNameStrategy(); + testMerge(store); + } + + protected void testMerge(TestStore store) { + + } + + protected void testLazySize(List<?> list) { + + } + + /** Reads objects in multiple sessions and checks that they are unequal */ + @SuppressWarnings("unchecked") + protected void checkUseCache(TestStore store) { + // read the writers in the cache + store.refresh(); + store.beginTransaction(); + final Writer writer = store.getObject(Writer.class); + assertTrue(writer != null); + store.commitTransaction(); + store.refresh(); + store.beginTransaction(); + final List books1 = new ArrayList(store.getObjects(Book.class)); + store.commitTransaction(); + store.refresh(); + store.beginTransaction(); + final List books2 = new ArrayList(store.getObjects(Book.class)); + assertTrue(books1.size() == books2.size()); + store.commitTransaction(); + for (int i = 0; i < books1.size(); i++) { + final Book bk1 = (Book) books1.get(i); + final Book bk2 = (Book) books2.get(i); + assertEquals(bk1.getTitle(), bk2.getTitle()); + assertTrue(bk1 != bk2); + assertTrue(bk1.getAuthor() != bk2.getAuthor()); + } + } + + // check detachcopy for jpox + protected void checkDetachCopy(TestStore store, Writer writ) { + } + + protected void checkContainerAfterLibraryRetrieve(TestStore store, + final Writer writ) { + // TODO specialize for Hibernate/JPOX, was: + // if (store instanceof JPOXTestStore) + // { + // assertTrue("Container of writer is not yet set now, because of lazy + // loading of container + // relations", + // writ.eContainer() == null); + // } + } + + protected void checkContainerAfterWriterRetrieve(TestStore store, + final Writer writ) { + // TODO specialize for Hibernate/JPOX, was: + // if (store instanceof HibernateTestStore) + // { + // assertTrue(writ.eContainer() != null); + // assertTrue(writ.eContainer() instanceof Library); + // } + } + + /** + * @return Returns <code>true</code> the given value indeed encodes a list + */ + protected boolean listValueOfCorrectType(Object value) { + // TODO specialize hibernate/jpox, was + // return (value instanceof PersistableEList || value instanceof + // org.eclipse.emf.teneo.jpox.emf.elist.EListWrapper) + return true; + } + + /** Dump the annotated model to standard output */ + protected void dumpPAModel(TestStore testStore) { + } + + protected void checkTeneoSQLNameStrategy() { + } + + protected void checkIndexName(TestStore store) { + } + + // /** Small adapter test + // private class WriterAdapter extends AdapterImpl { + // /** Counts the number of changes */ + // private int countNotifications = 0; + // + // /** + // * Returns <code>false</code> + // * + // * @param type + // * the type. + // * @return <code>false</code> + // */ + // public boolean isAdapterForType(Object type) { + // return type instanceof Writer; + // } + // + // /** + // * Does nothing; clients may override so that it does something. + // */ + // public void notifyChanged(Notification msg) { + // assertTrue("The new value is of type: " + + // msg.getNewValue().getClass().getName(), + // listValueOfCorrectType(msg.getNewValue())); + // + // // must be a load event + // assertTrue("Eventtype is not load notification but: " + + // msg.getEventType(), + // msg.getEventType() == AnnotationUtil.ELIST_LOAD_NOTIFICATION); + // + // countNotifications++; + // } + // + // /** Returns the number of notifications */ + // public int getCountNotifications() { + // return countNotifications; + // } + // } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryCheckNameAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryCheckNameAction.java new file mode 100755 index 000000000..7a6b5a0d3 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryCheckNameAction.java @@ -0,0 +1,59 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: LibraryCheckNameAction.java,v 1.3 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.extension.ExtensionManager; + +/** + * Tests the library example of emf/xsd. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ + */ +public class LibraryCheckNameAction extends LibraryColLengthAction { + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.AbstractTestAction#setExtensions(org.eclipse.emf.teneo.extension.ExtensionManager) + */ + @Override + public void setExtensions(ExtensionManager extensionManager) { + // purposely empty, do not remove + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties() + */ + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.put(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH, "8"); + props.put(PersistenceOptions.ID_COLUMN_NAME, "myID"); + return props; + } + + @Override + protected String getTestQuery() { + return "SELECT * FROM BOOK WHERE lb_bk_d<>0 AND lb_bk_dx>0 AND wr_bk_dx>0".toLowerCase(); + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryColLengthAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryColLengthAction.java new file mode 100755 index 000000000..970038ab6 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryColLengthAction.java @@ -0,0 +1,149 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: LibraryColLengthAction.java,v 1.9 2009/04/03 06:15:39 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.extension.ExtensionManager; +import org.eclipse.emf.teneo.mapping.strategy.SQLNameStrategy; +import org.eclipse.emf.teneo.mapping.strategy.impl.ClassicSQLNameStrategy; +import org.eclipse.emf.teneo.samples.emf.sample.library.Book; +import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory; +import org.eclipse.emf.teneo.samples.emf.sample.library.Library; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage; +import org.eclipse.emf.teneo.samples.emf.sample.library.Writer; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests the library example of emf/xsd. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.9 $ + */ +public class LibraryColLengthAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public LibraryColLengthAction() { + super(LibraryPackage.eINSTANCE); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.emf.teneo.test.AbstractTestAction#setExtensions(org.eclipse.emf.teneo.extension.ExtensionManager) + */ + @Override + public void setExtensions(ExtensionManager extensionManager) { + extensionManager.registerExtension(SQLNameStrategy.class.getName(), ClassicSQLNameStrategy.class.getName()); + extensionManager.registerExtension("org.eclipse.emf.teneo.hibernate.mapper.MappingContext", + "org.eclipse.emf.teneo.hibernate.mapper.classic.ClassicMappingContext"); + super.setExtensions(extensionManager); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties() + */ + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.put(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH, "5"); + props.put(PersistenceOptions.ID_COLUMN_NAME, "myID"); + props.put(PersistenceOptions.ID_FEATURE_AS_PRIMARY_KEY, "false"); + return props; + } + + /** Creates an item, an address and links them to a po. */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + final LibraryFactory factory = LibraryFactory.eINSTANCE; + // create a book, writer and library + { + store.beginTransaction(); + + final Writer writer = factory.createWriter(); + writer.setName("JRR Tolkien"); + + final Book book = factory.createBook(); + book.setAuthor(writer); + book.setPages(5); + book.setTitle("The Hobbit"); + book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Book book2 = factory.createBook(); + book2.setAuthor(writer); + book2.setPages(5); + book2.setTitle("The fellowship of the ring"); + book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Library library = factory.createLibrary(); + library.getBooks().add(book); + library.setName("Science Fiction Library"); + library.getBooks().add(book2); + library.getWriters().add(writer); + store.store(library); + + store.commitTransaction(); + assertEquals(2, writer.getBooks().size()); + } + + if (true) { + Connection conn = null; + Statement stmt = null; + try { + conn = store.getConnection(); + stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(getTestQuery()); + assertTrue(rs.next()); + } catch (SQLException s) { + throw new StoreTestException("SQL Exception", s); + } finally { + try { + if (stmt != null) { + stmt.close(); + stmt = null; + } + + if (conn != null) { + conn.close(); + conn = null; + } + } catch (SQLException s) { + throw new StoreTestException("SQL Exception", s); + } + } + } + } + + protected String getTestQuery() { + return "SELECT * FROM BOOK WHERE BO_ID<>0 AND L_IDX>0 AND W_IDX>0".toLowerCase(); + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryContainerFeatureIDBothAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryContainerFeatureIDBothAction.java new file mode 100644 index 000000000..a57497256 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryContainerFeatureIDBothAction.java @@ -0,0 +1,38 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: LibraryContainerFeatureIDBothAction.java,v 1.1 2009/03/15 14:49:53 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; + +/** + * Tests the library example of emf/xsd. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.1 $ + */ +public class LibraryContainerFeatureIDBothAction extends LibraryAction { + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty( + PersistenceOptions.ECONTAINER_FEATURE_PERSISTENCE_STRATEGY, + "both"); + return props; + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryContainerFeatureIDFeatureIDAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryContainerFeatureIDFeatureIDAction.java new file mode 100644 index 000000000..e51c22e1a --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryContainerFeatureIDFeatureIDAction.java @@ -0,0 +1,39 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: LibraryContainerFeatureIDFeatureIDAction.java,v 1.1 2009/03/15 14:49:53 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; + +/** + * Tests the library example of emf/xsd. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.1 $ + */ +public class LibraryContainerFeatureIDFeatureIDAction extends LibraryAction { + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty( + PersistenceOptions.ECONTAINER_FEATURE_PERSISTENCE_STRATEGY, + "featureid"); + return props; + } + +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryFKAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryFKAction.java new file mode 100755 index 000000000..b1c9b1620 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryFKAction.java @@ -0,0 +1,37 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: LibraryFKAction.java,v 1.2 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; + +/** + * Tests foreign key + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.2 $ + */ +public class LibraryFKAction extends LibraryAction { + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = super.getExtraConfigurationProperties(); + props.setProperty(PersistenceOptions.SET_FOREIGN_KEY_NAME, "true"); + return props; + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryGlobalEagerAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryGlobalEagerAction.java new file mode 100755 index 000000000..679576b7b --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryGlobalEagerAction.java @@ -0,0 +1,221 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: LibraryGlobalEagerAction.java,v 1.9 2009/04/03 06:15:39 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.io.IOException; +import java.util.Properties; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.impl.AdapterImpl; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.mapping.elist.PersistableEList; +import org.eclipse.emf.teneo.resource.StoreResource; +import org.eclipse.emf.teneo.samples.emf.sample.library.Book; +import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory; +import org.eclipse.emf.teneo.samples.emf.sample.library.Library; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage; +import org.eclipse.emf.teneo.samples.emf.sample.library.Writer; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests setting of eager loading of containment at global level + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.9 $ + */ +public class LibraryGlobalEagerAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public LibraryGlobalEagerAction() { + super(LibraryPackage.eINSTANCE); + + } + + /** + * Can be overridden by subclass returns properties which control the or layer. Such as setting of eager loading. + */ + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.put(PersistenceOptions.FETCH_CONTAINMENT_EAGERLY, "true"); + return props; + } + + /** Creates an item, an address and links them to a po. */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + final LibraryFactory factory = LibraryFactory.eINSTANCE; + + // create a book, writer and library + try { + { + Resource res = store.getResource(); + res.load(null); + + final Writer writer = factory.createWriter(); + writer.setName("JRR_Tolkien"); + + final Book book = factory.createBook(); + book.setAuthor(writer); + book.setPages(510); + book.setTitle("Fellowship_of_the_Ring"); + book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Book book2 = factory.createBook(); + book2.setAuthor(writer); + book2.setPages(500); + book2.setTitle("The_Hobbit"); + book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + // sorry george making a mistake here, will correct this below + final Book book3 = factory.createBook(); + book3.setAuthor(writer); + book3.setPages(500); + book3.setTitle("nineteeneightyfour"); + book3.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Library library = factory.createLibrary(); + library.setName("Science_Fiction"); + library.getBooks().add(book); + library.getBooks().add(book2); + library.getBooks().add(book3); + library.getWriters().add(writer); + + res.getContents().add(library); + res.save(null); + res.unload(); + } + + // test settrackingmodification before load + { + Resource res = store.getResource(); + // default is false + // ((StoreResource)res).setAutoResolve(false); + res.setTrackingModification(true); + res.load(null); + testResolving(res); + } + + // test settrackingmodification after load + { + Resource res = store.getResource(); + // default is false + // ((StoreResource)res).setAutoResolve(false); + res.load(null); + res.setTrackingModification(true); + testResolving(res); + } + + // test with resolving + { + Resource res = store.getResource(); + // default is false + res.load(null); + res.setTrackingModification(true); + testResolving(res); + } + + // simple test without setTrackingModification + { + Resource res = store.getResource(); + res.load(null); + + Library lib = (Library) res.getContents().get(0); + PersistableEList writers = (PersistableEList) lib.getWriters(); + assertTrue("Elist should be loaded", writers.isLoaded()); + } + } catch (IOException e) { + throw new StoreTestException("IOException during save", e); + } + } + + /** Check adapters and lazy loading of nonresolving */ + @SuppressWarnings("unchecked") + private void testResolving(Resource res) { + final LibraryAdapter libraryAdapter = new LibraryAdapter(); + res.eAdapters().add(libraryAdapter); + + Library lib = (Library) res.getContents().get(0); + PersistableEList writers = (PersistableEList) lib.getWriters(); + PersistableEList books = (PersistableEList) lib.getBooks(); + assertTrue("Elist is not loaded", writers.isLoaded()); + assertTrue("Elist is not loaded", books.isLoaded()); + assertTrue("BasicIterator should have next true", books.basicIterator().hasNext()); + assertTrue("BasicListIterator should have next true", books.basicListIterator().hasNext()); + assertTrue("BasicIterator should have next true", writers.basicIterator().hasNext()); + assertTrue("BasicListIterator should have next true", writers.basicListIterator().hasNext()); + + lib.setName("test" + lib.getName()); + + // get the first book and change it + final Book book = (Book) books.get(0); + book.setTitle("test" + book.getTitle()); + + assertEquals(2, libraryAdapter.getCountNotifications()); + + boolean fndLibrary = false; + boolean fndBook = false; + for (EObject element : ((StoreResource) res).getModifiedEObjects()) { + fndLibrary = fndLibrary || element == lib; + fndBook = fndBook || element == book; + } + assertTrue("Library should be a modified object", fndLibrary); + assertTrue("Book should be a modified object", fndBook); + assertEquals(2, ((StoreResource) res).getModifiedEObjects().size()); + res.unload(); + } + + /** Small adapter test */ + private class LibraryAdapter extends AdapterImpl { + /** Counts the number of changes */ + private int countNotifications = 0; + + /** + * Returns <code>false</code> + * + * @param type + * the type. + * @return <code>false</code> + */ + @Override + public boolean isAdapterForType(Object type) { + return type instanceof Writer; + } + + /** + * Does nothing; clients may override so that it does something. + */ + @Override + public void notifyChanged(Notification msg) { + countNotifications++; + } + + /** Returns the number of notifications */ + public int getCountNotifications() { + return countNotifications; + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryJoinTableNamingAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryJoinTableNamingAction.java new file mode 100755 index 000000000..2d744b3fa --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryJoinTableNamingAction.java @@ -0,0 +1,123 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: LibraryJoinTableNamingAction.java,v 1.5 2008/02/28 07:08:14 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.sample.library.Book; +import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory; +import org.eclipse.emf.teneo.samples.emf.sample.library.Library; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage; +import org.eclipse.emf.teneo.samples.emf.sample.library.Writer; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests the library example of emf/xsd. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.5 $ + */ +public class LibraryJoinTableNamingAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public LibraryJoinTableNamingAction() { + super(LibraryPackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY, "READ_WRITE"); + props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS, "true"); + props.setProperty(PersistenceOptions.JOIN_TABLE_NAMING_STRATEGY, "unique"); + props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true"); + props.setProperty(PersistenceOptions.SQL_CASE_STRATEGY, "uppercase"); + return props; + } + + /** Creates an item, an address and links them to a po. */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + final LibraryFactory factory = LibraryFactory.eINSTANCE; + // create a book, writer and library + { + store.beginTransaction(); + + final Writer writer = factory.createWriter(); + writer.setName("JRR Tolkien"); + + final Book book = factory.createBook(); + + book.setAuthor(writer); + book.setPages(5); + book.setTitle("The Hobbit"); + book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Book book2 = factory.createBook(); + book2.setAuthor(writer); + book2.setPages(5); + book2.setTitle("The fellowship of the ring"); + book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Library library = factory.createLibrary(); + library.getBooks().add(book); + library.setName("Science Fiction Library"); + library.getBooks().add(book2); + library.getWriters().add(writer); + store.store(library); + + store.commitTransaction(); + assertEquals(2, writer.getBooks().size()); + } + + if (true) { + Connection conn = null; + Statement stmt = null; + try { + conn = store.getConnection(); + stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT * FROM WRITER_BOOKS"); + assertTrue(rs.next()); + } catch (SQLException s) { + throw new StoreTestException("SQL Exception", s); + } finally { + try { + if (stmt != null) { + stmt.close(); + } + if (conn != null) { + conn.close(); + } + } catch (SQLException s) { + throw new StoreTestException("SQL Exception", s); + } + } + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryLargeAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryLargeAction.java new file mode 100755 index 000000000..f5a7500b9 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryLargeAction.java @@ -0,0 +1,161 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: LibraryLargeAction.java,v 1.3 2008/10/12 11:24:40 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.sample.library.Book; +import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory; +import org.eclipse.emf.teneo.samples.emf.sample.library.Library; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage; +import org.eclipse.emf.teneo.samples.emf.sample.library.Writer; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests the library example of emf/xsd using a larger dataset. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ + */ +public class LibraryLargeAction extends AbstractTestAction { + + private static final int BK_CNT = 1000; + private static final int WRITER_CNT = 100; + private static final int LIB_CNT = 1; + private static final int NUM_OF_TRANS = 3; + + private static final int NUM_WRITER_TRANSACTION = LIB_CNT * WRITER_CNT; + private static final int NUM_BOOK_TRANSACTION = NUM_WRITER_TRANSACTION * BK_CNT; + + public LibraryLargeAction() { + super(LibraryPackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); +// props.setProperty(PersistenceOptions.MAP_ALL_LISTS_AS_IDBAG, "true"); + props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true"); + return props; + } + + @Override + public void doAction(TestStore store) { + { + long t = System.currentTimeMillis(); + for (int j = 0; j < NUM_OF_TRANS; j++) { + store.beginTransaction(); + for (int i = 0; i < LIB_CNT; i++) { + store.store(createLibrary(i + " Number " + j)); + } + System.err.println("before commit"); + long commitTime = System.currentTimeMillis(); + store.commitTransaction(); + System.err.println("Transaction " + (j + 1) + " inserted library(#" + LIB_CNT + ") and Writer(#" + + NUM_WRITER_TRANSACTION + ") and Book(#" + NUM_BOOK_TRANSACTION + ") in " + + ((System.currentTimeMillis() - t) / 1000) + " seconds of which the commit took " + + ((System.currentTimeMillis() - commitTime) / 1000)); + t = System.currentTimeMillis(); + } + } + + // load each writer and add a book + { + long t = System.currentTimeMillis(); + store.beginTransaction(); + final List<?> ls = store.getObjects(Library.class); + for (Object o : ls) { + final Library l = (Library) o; + System.err.println(l.getName()); + for (Writer w : l.getWriters()) { + // removed the book in the middle + final Book removeBk = w.getBooks().remove(BK_CNT / 2); + l.getBooks().remove(removeBk); + + // and add a book in the middle + final Book bk = LibraryFactory.eINSTANCE.createBook(); + bk.setPages(BK_CNT); + bk.setTitle(w.getName() + "bk"); + bk.setCategory(BookCategory.MYSTERY_LITERAL); + bk.setAuthor(w); + + l.getBooks().add(BK_CNT / 2, bk); + } + } + store.commitTransaction(); + System.err.println("Time to remove and add " + (LIB_CNT * WRITER_CNT) + " books: " + + ((System.currentTimeMillis() - t) / 1000) + " seconds "); + } + } + + private Library createLibrary(String prefix) { + final LibraryFactory factory = LibraryFactory.eINSTANCE; + final Library l = factory.createLibrary(); + l.setName(prefix + " Library"); + for (int i = 0; i < WRITER_CNT; i++) { + final Writer w = factory.createWriter(); + w.setName(prefix + " Writer " + i); + l.getWriters().add(w); + createBooks(l, w, prefix); + } + return l; + } + + private void createBooks(Library l, Writer w, String prefix) { + final LibraryFactory factory = LibraryFactory.eINSTANCE; + for (int i = 0; i < BK_CNT; i++) { + final Book bk = factory.createBook(); + bk.setTitle(prefix + " Book " + i); + bk.setAuthor(w); + bk.setPages(i); + bk.setCategory(BookCategory.BIOGRAPHY_LITERAL); + l.getBooks().add(bk); + } + } + + /** Reads objects in multiple sessions and checks that they are unequal */ + @SuppressWarnings("unchecked") + protected void checkUseCache(TestStore store) { + // read the writers in the cache + store.refresh(); + store.beginTransaction(); + final Writer writer = store.getObject(Writer.class); + assertTrue(writer != null); + store.commitTransaction(); + store.refresh(); + store.beginTransaction(); + final List books1 = new ArrayList(store.getObjects(Book.class)); + store.commitTransaction(); + store.refresh(); + store.beginTransaction(); + final List books2 = new ArrayList(store.getObjects(Book.class)); + assertTrue(books1.size() == books2.size()); + store.commitTransaction(); + for (int i = 0; i < books1.size(); i++) { + final Book bk1 = (Book) books1.get(i); + final Book bk2 = (Book) books2.get(i); + assertEquals(bk1.getTitle(), bk2.getTitle()); + assertTrue(bk1 != bk2); + assertTrue(bk1.getAuthor() != bk2.getAuthor()); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryListAsBagAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryListAsBagAction.java new file mode 100755 index 000000000..8ebb2c7c0 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryListAsBagAction.java @@ -0,0 +1,105 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: LibraryListAsBagAction.java,v 1.5 2009/04/03 06:15:39 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.sample.library.Book; +import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory; +import org.eclipse.emf.teneo.samples.emf.sample.library.Library; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage; +import org.eclipse.emf.teneo.samples.emf.sample.library.Writer; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests the library example of emf/xsd. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.5 $ + */ +public class LibraryListAsBagAction extends AbstractTestAction { + + public LibraryListAsBagAction() { + super(LibraryPackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true"); + return props; + } + + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + final LibraryFactory factory = LibraryFactory.eINSTANCE; + // create a book, writer and library + { + store.beginTransaction(); + + final Writer writer = factory.createWriter(); + writer.setName("writer"); + + final Book book = factory.createBook(); + + book.setAuthor(writer); + book.setPages(1); + book.setTitle("The Hobbit"); + book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Book book2 = factory.createBook(); + book2.setAuthor(writer); + book2.setPages(2); + book2.setTitle("The fellowship of the ring"); + book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Library library = factory.createLibrary(); + library.getBooks().add(book); + library.setName("Science Fiction Library"); + library.getBooks().add(book2); + library.getWriters().add(writer); + store.store(library); + + store.commitTransaction(); + } + + // move the books arround + int page0 = 0; + int page1 = 1; + { + store.beginTransaction(); + final Library lib = store.getObject(Library.class); + page0 = lib.getBooks().get(0).getPages(); + page1 = lib.getBooks().get(1).getPages(); + lib.getBooks().move(0, 1); // moved second book to first location + store.commitTransaction(); + } + + // check if it succeeded, should not + { + store.beginTransaction(); + final Library lib = store.getObject(Library.class); + assertEquals(page0, (lib.getBooks().get(0)).getPages()); + assertEquals(page1, (lib.getBooks().get(1)).getPages()); + store.commitTransaction(); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryNonResolvingAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryNonResolvingAction.java new file mode 100755 index 000000000..c63a8f23d --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryNonResolvingAction.java @@ -0,0 +1,231 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: LibraryNonResolvingAction.java,v 1.11 2009/04/03 06:15:39 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.io.IOException; +import java.util.Collections; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.impl.AdapterImpl; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.mapping.elist.PersistableEList; +import org.eclipse.emf.teneo.resource.StoreResource; +import org.eclipse.emf.teneo.samples.emf.sample.library.Book; +import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory; +import org.eclipse.emf.teneo.samples.emf.sample.library.Library; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage; +import org.eclipse.emf.teneo.samples.emf.sample.library.Writer; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests non-resolving behavior of containment references. Main test is that setTrackingModification does not result in + * loaded containment elists. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.11 $ + */ +public class LibraryNonResolvingAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public LibraryNonResolvingAction() { + super(LibraryPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + final LibraryFactory factory = LibraryFactory.eINSTANCE; + + // create a book, writer and library + try { + { + Resource res = store.getResource(); + res.load(null); + + final Writer writer = factory.createWriter(); + writer.setName("JRR_Tolkien"); + + final Book book = factory.createBook(); + book.setAuthor(writer); + book.setPages(510); + book.setTitle("Fellowship_of_the_Ring"); + book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Book book2 = factory.createBook(); + book2.setAuthor(writer); + book2.setPages(500); + book2.setTitle("The_Hobbit"); + book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + // sorry george making a mistake here, will correct this below + final Book book3 = factory.createBook(); + book3.setAuthor(writer); + book3.setPages(500); + book3.setTitle("nineteeneightyfour"); + book3.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Library library = factory.createLibrary(); + library.setName("Science_Fiction"); + library.getBooks().add(book); + library.getBooks().add(book2); + library.getBooks().add(book3); + library.getWriters().add(writer); + + res.getContents().add(library); + res.save(null); + res.unload(); + } + + // test settrackingmodification before load + { + Resource res = store.getResource(); + // default is false + // ((StoreResource)res).setAutoResolve(false); + res.setTrackingModification(true); + res.load(null); + testResolving(res); + } + + // test settrackingmodification before load + { + Resource res = store.getResource(); + // default is false + // ((StoreResource)res).setAutoResolve(false); + res.load(null); + res.setTrackingModification(true); + testResolving(res); + } + { + Resource res = store.getResource(); + // default is false + // ((StoreResource)res).setAutoResolve(false); + res.load(null); + Library lib = (Library) res.getContents().get(0); + lib.setName(lib.getName() + "_"); + res.save(Collections.EMPTY_MAP); + // testResolving(res); + } + + { + Resource res = store.getResource(); + // default is false + // ((StoreResource)res).setAutoResolve(false); + res.setTrackingModification(true); + res.load(null); + testResolving(res); + } + + // test with resolving + { + Resource res = store.getResource(); + // default is false + res.load(null); + res.setTrackingModification(true); + testResolving(res); + } + + // simple test without setTrackingModification + { + Resource res = store.getResource(); + res.load(null); + + Library lib = (Library) res.getContents().get(0); + PersistableEList writers = (PersistableEList) lib.getWriters(); + assertFalse("Elist should not be loaded", writers.isLoaded()); + } + } catch (IOException e) { + throw new StoreTestException("IOException during save", e); + } + } + + /** Check adapters and lazy loading of nonresolving */ + @SuppressWarnings("unchecked") + private void testResolving(Resource res) { + final LibraryAdapter libraryAdapter = new LibraryAdapter(); + res.eAdapters().add(libraryAdapter); + + Library lib = (Library) res.getContents().get(0); + PersistableEList writers = (PersistableEList) lib.getWriters(); + PersistableEList books = (PersistableEList) lib.getBooks(); + + assertFalse("Elist should not be loaded", writers.isLoaded()); + assertFalse("Elist should not be loaded", books.isLoaded()); + assertFalse("BasicIterator should have next false", books.basicIterator().hasNext()); + assertFalse("BasicListIterator should have next false", books.basicListIterator().hasNext()); + assertFalse("BasicIterator should have next false", writers.basicIterator().hasNext()); + assertFalse("BasicListIterator should have next false", writers.basicListIterator().hasNext()); + + lib.setName("test" + lib.getName()); + + // get the first book and change it + final Book book = (Book) books.get(0); + book.setTitle("test" + book.getTitle()); + + assertEquals(2, libraryAdapter.getCountNotifications()); + + boolean fndLibrary = false; + boolean fndBook = false; + for (EObject element : ((StoreResource) res).getModifiedEObjects()) { + fndLibrary = fndLibrary || element == lib; + fndBook = fndBook || element == book; + } + assertTrue("Library should be a modified object", fndLibrary); + assertTrue("Book should be a modified object", fndBook); + assertEquals(2, ((StoreResource) res).getModifiedEObjects().size()); + + res.unload(); + } + + /** Small adapter test */ + private class LibraryAdapter extends AdapterImpl { + /** Counts the number of changes */ + private int countNotifications = 0; + + /** + * Returns <code>false</code> + * + * @param type + * the type. + * @return <code>false</code> + */ + @Override + public boolean isAdapterForType(Object type) { + return type instanceof Writer; + } + + /** + * Does nothing; clients may override so that it does something. + */ + @Override + public void notifyChanged(Notification msg) { + countNotifications++; + } + + /** Returns the number of notifications */ + public int getCountNotifications() { + return countNotifications; + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryNotifyingTestAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryNotifyingTestAction.java new file mode 100644 index 000000000..133721ee7 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryNotifyingTestAction.java @@ -0,0 +1,205 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: LibraryNotifyingTestAction.java,v 1.2 2009/03/15 23:26:03 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.teneo.samples.emf.sample.library.Book; +import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory; +import org.eclipse.emf.teneo.samples.emf.sample.library.Library; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage; +import org.eclipse.emf.teneo.samples.emf.sample.library.Writer; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; +import org.eclipse.emf.teneo.type.PersistentStoreAdapter; +import org.eclipse.emf.teneo.util.StoreUtil; + +/** + * Tests the library example of emf/xsd and specifically the notifications when + * objects are updated. Tests the new PersistentStoreAdapter which keeps the + * persistentList in the adapter. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.2 $ + */ +public class LibraryNotifyingTestAction extends AbstractTestAction { + public LibraryNotifyingTestAction() { + super(LibraryPackage.eINSTANCE); + } + + @Override + public void doAction(TestStore store) { + final LibraryFactory factory = LibraryFactory.eINSTANCE; + + // create a book, writer and library + { + store.beginTransaction(); + + final Writer writer = factory.createWriter(); + writer.setName("JRR Tolkien"); + + final Book book = factory.createBook(); + book.setAuthor(writer); + book.setPages(5); + book.setTitle("The Hobbit"); + book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Book book2 = factory.createBook(); + book2.setAuthor(writer); + book2.setPages(5); + book2.setTitle("The fellowship of the ring"); + book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Library library = factory.createLibrary(); + + // set name + library.setName("Science Fiction Library"); + + library.getBooks().add(book); + library.getBooks().add(book2); + library.getWriters().add(writer); + + final EList<?> libraryBooks = library.getBooks(); + final EList<?> libraryWriters = library.getWriters(); + final EList<?> writerBooks = writer.getBooks(); + + store.store(library); + store.commitTransaction(); + + store.beginTransaction(); + + library.getBooks().clear(); + + // add action + library.getBooks().add(book); + + // remove action + library.getBooks().remove(book); + + // add action + library.getBooks().add(book2); + + // set action + library.getBooks().set(0, book); + + // add again + library.getBooks().add(book2); + + // move it + library.getBooks().move(0, 1); + + library.getBooks().move(1, book2); + + // count them + assertTrue(library.getBooks().size() == 2); + + // clear it all + library.getBooks().clear(); + + final List<Book> books = new ArrayList<Book>(); + books.add(book); + books.add(book2); + library.getBooks().addAll(books); + + library.getBooks().removeAll(books); + + library.getWriters().add(writer); + + store.commitTransaction(); + store.beginTransaction(); + { + assertTrue(libraryBooks == library.getBooks()); + assertTrue(libraryWriters == library.getWriters()); + assertTrue(writerBooks == writer.getBooks()); + PersistentStoreAdapter libraryAdapter = StoreUtil + .getPersistentStoreAdapter(library); + final List<?> persistentLibraryBooks = (List<?>) libraryAdapter + .getStoreCollection(LibraryPackage.eINSTANCE + .getLibrary_Books()); + final List<?> persistentLibraryWriters = (List<?>) libraryAdapter + .getStoreCollection(LibraryPackage.eINSTANCE + .getLibrary_Writers()); + PersistentStoreAdapter writerAdapter = StoreUtil + .getPersistentStoreAdapter(writer); + final List<?> persistentWriterBooks = (List<?>) writerAdapter + .getStoreCollection(LibraryPackage.eINSTANCE + .getWriter_Books()); + checkEqualList(persistentLibraryWriters, libraryWriters); + checkEqualList(persistentLibraryBooks, libraryBooks); + checkEqualList(persistentWriterBooks, writerBooks); + } + store.commitTransaction(); + { + assertTrue(libraryBooks == library.getBooks()); + assertTrue(libraryWriters == library.getWriters()); + assertTrue(writerBooks == writer.getBooks()); + PersistentStoreAdapter libraryAdapter = StoreUtil + .getPersistentStoreAdapter(library); + final List<?> persistentLibraryBooks = (List<?>) libraryAdapter + .getStoreCollection(LibraryPackage.eINSTANCE + .getLibrary_Books()); + final List<?> persistentLibraryWriters = (List<?>) libraryAdapter + .getStoreCollection(LibraryPackage.eINSTANCE + .getLibrary_Writers()); + PersistentStoreAdapter writerAdapter = StoreUtil + .getPersistentStoreAdapter(writer); + final List<?> persistentWriterBooks = (List<?>) writerAdapter + .getStoreCollection(LibraryPackage.eINSTANCE + .getWriter_Books()); + checkEqualList(persistentLibraryWriters, libraryWriters); + checkEqualList(persistentLibraryBooks, libraryBooks); + checkEqualList(persistentWriterBooks, writerBooks); + } + } + { + store.beginTransaction(); + final Library lib = store.getObject(Library.class); + final List<?> libBooks = lib.getBooks(); + final List<?> libWriters = lib.getWriters(); + lib.setName(lib.getName() + "0"); + assertEquals(2, lib.getBooks().size()); + + assertTrue(libBooks == lib.getBooks()); + assertTrue(libWriters == lib.getWriters()); + + final Book book = factory.createBook(); + book.setAuthor(lib.getWriters().get(0)); + book.setPages(5); + book.setTitle("The Hobbit AGAIN"); + book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + lib.getBooks().add(book); + store.commitTransaction(); + } + { + store.beginTransaction(); + final Library lib = store.getObject(Library.class); + assertEquals(3, lib.getBooks().size()); + store.commitTransaction(); + } + } + + private void checkEqualList(List<?> l1, List<?> l2) { + assertTrue(l1 != l2); + assertTrue(l1.size() == l2.size()); + for (Object o : l1) { + assertEquals(l1.indexOf(o), l2.indexOf(o)); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryQualifyActionHB.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryQualifyActionHB.java new file mode 100755 index 000000000..b1673ad65 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryQualifyActionHB.java @@ -0,0 +1,102 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: LibraryQualifyActionHB.java,v 1.7 2008/02/28 07:08:14 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import org.eclipse.emf.teneo.extension.ExtensionManager; +import org.eclipse.emf.teneo.mapping.strategy.EntityNameStrategy; +import org.eclipse.emf.teneo.mapping.strategy.impl.QualifyingEntityNameStrategy; +import org.eclipse.emf.teneo.samples.emf.sample.library.Book; +import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory; +import org.eclipse.emf.teneo.samples.emf.sample.library.Library; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage; +import org.eclipse.emf.teneo.samples.emf.sample.library.Writer; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests setting of qualified enames + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.7 $ + */ +public class LibraryQualifyActionHB extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public LibraryQualifyActionHB() { + super(LibraryPackage.eINSTANCE); + + } + + /** Add extensions if you want */ + @Override + public void setExtensions(ExtensionManager extensionManager) { + extensionManager.registerExtension(EntityNameStrategy.class.getName(), QualifyingEntityNameStrategy.class + .getName()); + } + + /** Creates an item, an address and links them to a po. */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + final LibraryFactory factory = LibraryFactory.eINSTANCE; + // create a book, writer and library + { + store.beginTransaction(); + + final Writer writer = factory.createWriter(); + writer.setName("JRR Tolkien"); + + final Book book = factory.createBook(); + book.setAuthor(writer); + book.setPages(5); + book.setTitle("The Hobbit"); + book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Book book2 = factory.createBook(); + book2.setAuthor(writer); + book2.setPages(5); + book2.setTitle("The fellowship of the ring"); + book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Library library = factory.createLibrary(); + library.getBooks().add(book); + library.setName("Science Fiction Library"); + library.getBooks().add(book2); + library.getWriters().add(writer); + store.store(library); + + store.commitTransaction(); + assertEquals(2, writer.getBooks().size()); + } + + // now test some qualified queries + { + store.beginTransaction(); + Library lib = (Library) store.query("select l from " + LibraryPackage.eNS_PREFIX + ".Library l").get(0); + assertTrue(lib != null); + Writer writ = (Writer) store.query("select w from " + LibraryPackage.eNS_PREFIX + ".Writer w").get(0); + assertTrue(writ != null); + Book bk = (Book) store.query("select b from " + LibraryPackage.eNS_PREFIX + ".Book b").get(0); + assertTrue(bk != null); + store.commitTransaction(); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceAction.java new file mode 100755 index 000000000..79d086acc --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceAction.java @@ -0,0 +1,277 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: LibraryResourceAction.java,v 1.20 2010/02/07 23:12:02 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.io.IOException; + +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.resource.StoreResource; +import org.eclipse.emf.teneo.samples.emf.sample.library.Book; +import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory; +import org.eclipse.emf.teneo.samples.emf.sample.library.Library; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage; +import org.eclipse.emf.teneo.samples.emf.sample.library.Writer; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests the library example of emf/xsd using a resource. Actually tests bidirectional references using resources. Most + * other aspects of resources are handled in the Catalog example. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.20 $ + */ +public class LibraryResourceAction extends AbstractTestAction { + public LibraryResourceAction() { + super(LibraryPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final LibraryFactory factory = LibraryFactory.eINSTANCE; + + // create a book, writer and library + try { + { + Resource res = getResource(store); + res.load(null); + + final Writer writer = factory.createWriter(); + writer.setName("JRR_Tolkien"); + + final Book book = factory.createBook(); + book.setAuthor(writer); + book.setPages(510); + book.setTitle("Fellowship_of_the_Ring"); + book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + final Book book2 = factory.createBook(); + book2.setAuthor(writer); + book2.setPages(500); + book2.setTitle("The_Hobbit"); + book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + // sorry george making a mistake here, will correct this below + final Book book3 = factory.createBook(); + book3.setAuthor(writer); + book3.setPages(500); + book3.setTitle("nineteeneightyfour"); + book3.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + final Library library = factory.createLibrary(); + library.setName("Science_Fiction"); + library.getBooks().add(book); + library.getBooks().add(book2); + library.getBooks().add(book3); + library.getWriters().add(writer); + + res.getContents().add(library); + res.save(null); + res.save(null); + res.unload(); + assertTrue(res.getContents().size() == 0); + assertTrue(library.getBooks().size() > 0); + assertTrue(library.getWriters().size() > 0); + } + + // walk through the structure starting from the library + String libURI = null; + String writerURI = null; + { + Resource res = getResource(store); + // res.setTrackingModification(true); + res.load(null); + + Library lib = (Library) res.getContents().get(0); + + Writer tolkien = lib.getWriters().get(0); + + libURI = res.getURIFragment(lib); + writerURI = res.getURIFragment(tolkien); + + /* + * final Object[] obj = ((StoreResource)res).getCrossReferencers(tolkien); for (int i = 0; i < + * obj.length; i++) { + */ + + /* + * assertEquals(3, tolkien.getBooks().size()); + * + * assertEquals(0 , tolkien.getName().compareTo("JRR Tolkien")); Book wBook = + * (Book)tolkien.getBooks().get(0); Book lBook = (Book)lib.getBooks().get(0); + * assertTrue("Book is contained in the library", wBook.eContainer() == lib); + * assertTrue("Book is contained in the library", lBook.eContainer() == lib); + * + * assertTrue(lBook.getAuthor() == tolkien); assertTrue(tolkien.getBooks().contains(lBook)); + * assertTrue(tolkien.getBooks().contains(wBook)); // ordering is the same + * assertTrue(wBook.getTitle().compareTo(lBook.getTitle()) == 0); assertTrue(wBook.getPages() == + * lBook.getPages()); assertTrue(wBook.getCategory() instanceof BookCategory); + * assertTrue(wBook.getCategory() == BookCategory.SCIENCE_FICTION_LITERAL); + */ + // correct the mistake we made + Book orwellsBook = tolkien.getBooks().get(2); + assertTrue(orwellsBook.getTitle().compareTo("nineteeneightyfour") == 0); + + // add orwell as a writer + final Writer george = factory.createWriter(); + george.setName("George_Orwell"); + orwellsBook.setAuthor(george); + + // and put george in our library + lib.getWriters().add(george); + + if (!isEAVTest()) { + assertEquals(2, tolkien.getBooks().size()); + assertEquals(3, lib.getBooks().size()); + } + + // and save it all + res.save(null); + res.save(null); + + george.setName("G._Orwell"); // there was a bug in which this + // failed, reported by + // Georgi Manev + res.save(null); + res.save(null); + res.unload(); + assertTrue(res.getContents().size() == 0); + assertTrue(lib.getBooks().size() > 0); + assertTrue(lib.getWriters().size() > 0); + } + + { + Resource res = getResource(store); + Library lib = (Library) res.getEObject(libURI); + + final StoreResource sr = (StoreResource) res; + assertFalse(sr.getNewEObjects().contains(lib)); + + Writer w = (Writer) res.getEObject(writerURI); + assertFalse(sr.getNewEObjects().contains(w)); + assertEquals("JRR_Tolkien", w.getName()); + if (!isEAVTest()) { + assertEquals(2, w.getBooks().size()); + } + assertEquals("The_Hobbit", w.getBooks().get(1).getTitle()); + assertEquals(lib.getName(), "Science_Fiction"); + assertTrue(lib.getWriters().contains(w)); + assertTrue(lib.getBooks().contains(w.getBooks().get(0))); + res.unload(); + assertTrue(res.getContents().size() == 0); + assertTrue(lib.getBooks().size() > 0); + assertTrue(lib.getWriters().size() > 0); + } + + { + Resource res = getResource(store); + Library lib = (Library) res.getEObject(libURI); + Writer w = factory.createWriter(); + w.setName("writer"); + Book b = factory.createBook(); + b.setTitle("title"); + b.setPages(1); + b.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + w.getBooks().add(b); + lib.getWriters().add(0, w); + lib.getBooks().add(b); + res.save(null); + assertTrue(lib.getBooks().size() > 0); + assertTrue(lib.getWriters().size() > 0); + } + + // { + // + // XMLResourceImpl xi = new XMLResourceImpl(); + // xi.getContents().add(tolkien); + // FileOutputStream fos = new + // FileOutputStream("/home/mtaal/mytmp/test.xml"); + // xi.save(fos, Collections.EMPTY_MAP); + // + // ResourceSet rs = new ResourceSetImpl(); + // Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xml", + // new + // XMLResourceFactoryImpl()); + // + // Resource xi = + // rs.createResource(URI.createFileURI("/home/mtaal/mytmp/test.xml")); + // //xi.load(fis, Collections.EMPTY_MAP); + // xi.load(Collections.EMPTY_MAP); + // Writer wt = (Writer)xi.getContents().get(0); + // } + + // TODO put in JPOX specific test code + // // now retrieve the writer using a simple query + // if (store instanceof JPOXTestStore) + // { + // store.beginTransaction(); + // Writer george = (Writer)store.query("SELECT FROM " + + // JPOXHelper.INSTANCE.getInstanceClassName(Writer.class) + + // " WHERE name == \"G. Orwell\"", 1).get(0); + // assertTrue(george.getBooks().size() == 1); + // Book georgesBook = (Book)george.getBooks().get(0); + // assertTrue(georgesBook.getAuthor() == george); + // store.commitTransaction(); + // } + } catch (IOException e) { + throw new StoreTestException("IOException during save", e); + } + + try { + Resource res = getResource(store); + res.load(null); + Library lib = (Library) res.getContents().get(0); + assertTrue(lib.getBooks().size() > 0); + assertTrue(lib.getWriters().size() > 0); + res.unload(); + assertTrue(res.getContents().size() == 0); + assertTrue(lib.getBooks().size() > 0); + assertTrue(lib.getWriters().size() > 0); + } catch (IOException e) { + throw new StoreTestException(e.getMessage(), e); + } + + try { + Resource res = getResource(store); + res.load(null); + + Library lib = (Library) res.getContents().get(0); + + Writer writer = lib.getWriters().get(0); + + Library newLib = factory.createLibrary(); + newLib.setName("tstlib"); + res.getContents().add(newLib); + lib.getWriters().remove(writer); + assertTrue(lib.getBooks().size() > 0); // force load of books to + // prevent dangling error + // in jpox + newLib.getWriters().add(writer); + res.save(null); + res.unload(); + fail("Orphan delete was not set"); // should fail + } catch (Exception e) { + // note the above fail will throw an error so that one + // does not end up here + } + } + + protected Resource getResource(TestStore store) { + return store.getResource(); + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceCutPasteAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceCutPasteAction.java new file mode 100755 index 000000000..fd72f65d6 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceCutPasteAction.java @@ -0,0 +1,148 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: LibraryResourceCutPasteAction.java,v 1.9 2009/04/03 06:15:39 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.io.IOException; +import java.util.Collections; +import java.util.Properties; + +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.sample.library.Book; +import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory; +import org.eclipse.emf.teneo.samples.emf.sample.library.Library; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage; +import org.eclipse.emf.teneo.samples.emf.sample.library.Writer; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests cut/paste action + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.9 $ + */ +public class LibraryResourceCutPasteAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public LibraryResourceCutPasteAction() { + super(LibraryPackage.eINSTANCE); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties() + */ + @Override + public Properties getExtraConfigurationProperties() { + Properties props = new Properties(); + props.setProperty(PersistenceOptions.SET_CASCADE_ALL_ON_CONTAINMENT, "false"); + props.setProperty(PersistenceOptions.CASCADE_POLICY_ON_CONTAINMENT, "REMOVE,MERGE,PERSIST,REFRESH"); + return props; + } + + /** Runs testcase */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + final LibraryFactory factory = LibraryFactory.eINSTANCE; + + // create a book, writer and library + try { + { + Resource res = store.getResource(); + res.load(null); + + final Writer writer = factory.createWriter(); + writer.setName("JRR_Tolkien"); + + final Book book = factory.createBook(); + book.setAuthor(writer); + book.setPages(510); + book.setTitle("Fellowship_of_the_Ring"); + book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Book book2 = factory.createBook(); + book2.setAuthor(writer); + book2.setPages(500); + book2.setTitle("The_Hobbit"); + book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Library library = factory.createLibrary(); + library.setName("Science_Fiction"); + library.getBooks().add(book); + library.getBooks().add(book2); + library.getWriters().add(writer); + + final Library library2 = factory.createLibrary(); + library2.setName("Literature"); + + res.getContents().add(library); + res.getContents().add(library2); + res.save(null); + res.unload(); + } + + // walk through the structure starting from the library + { + Resource res = store.getResource(); + res.load(null); + + Library lib = (Library) res.getContents().get(0); + Library lib2 = (Library) res.getContents().get(1); + + // cut from paste to + Library from = null; + Library to = null; + + if (lib.getName().compareTo("Literature") == 0) { + from = lib2; + to = lib; + } else { + to = lib2; + from = lib; + } + + to.getWriters().add(from.getWriters().get(0)); + res.save(Collections.EMPTY_MAP); + res.unload(); + } + + // check cascade deletes + { + Resource res = store.getResource(); + res.load(null); + res.getContents().remove(0); + res.getContents().remove(0); + res.save(null); + res.unload(); + } + + store.checkNumber(Writer.class, 0); + store.checkNumber(Book.class, 0); + store.checkNumber(Library.class, 0); + } catch (IOException e) { + throw new StoreTestException("IOException during save", e); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceVisitTreeAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceVisitTreeAction.java new file mode 100755 index 000000000..4d211d09f --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceVisitTreeAction.java @@ -0,0 +1,99 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: LibraryResourceVisitTreeAction.java,v 1.3 2010/02/06 20:50:51 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.TeneoException; +import org.eclipse.emf.teneo.samples.emf.sample.library.Book; +import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory; +import org.eclipse.emf.teneo.samples.emf.sample.library.Library; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage; +import org.eclipse.emf.teneo.samples.emf.sample.library.Writer; +import org.eclipse.emf.teneo.samples.emf.sample.library.impl.LibraryImpl; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests how children are added to a resource. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ + */ +public class LibraryResourceVisitTreeAction extends AbstractTestAction { + public LibraryResourceVisitTreeAction() { + super(LibraryPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final LibraryFactory factory = LibraryFactory.eINSTANCE; + + // create a book, writer and library + try { + { + Resource res = store.getResource(); + res.load(null); + + final Writer writer = factory.createWriter(); + writer.setName("JRR_Tolkien"); + + final Book book = factory.createBook(); + book.setAuthor(writer); + book.setPages(510); + book.setTitle("Fellowship_of_the_Ring"); + book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + final Book book2 = factory.createBook(); + book2.setAuthor(writer); + book2.setPages(500); + book2.setTitle("The_Hobbit"); + book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + // sorry george making a mistake here, will correct this below + final Book book3 = factory.createBook(); + book3.setAuthor(writer); + book3.setPages(500); + book3.setTitle("nineteeneightyfour"); + book3.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + final Library library = factory.createLibrary(); + library.setName("Science_Fiction"); + library.getBooks().add(book); + library.getBooks().add(book2); + library.getBooks().add(book3); + library.getWriters().add(writer); + + res.getContents().add(library); + res.save(null); + res.unload(); + } + + { + Resource res = store.getResource("query1=From " + LibraryImpl.class.getName()); + + // res.setTrackingModification(true); + res.load(null); + + Library lib = (Library) res.getContents().get(0); + assertTrue(lib != null); + res.unload(); + } + } catch (Exception e) { + throw new TeneoException(e.getMessage(), e); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibrarySerializationAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibrarySerializationAction.java new file mode 100755 index 000000000..49ac4526c --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibrarySerializationAction.java @@ -0,0 +1,183 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: LibrarySerializationAction.java,v 1.10 2010/03/23 16:35:14 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.ObjectStreamClass; + +import org.eclipse.emf.teneo.classloader.ClassLoaderResolver; +import org.eclipse.emf.teneo.samples.emf.sample.library.Book; +import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory; +import org.eclipse.emf.teneo.samples.emf.sample.library.Library; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage; +import org.eclipse.emf.teneo.samples.emf.sample.library.Writer; +import org.eclipse.emf.teneo.samples.emf.sample.library.impl.BookImpl; +import org.eclipse.emf.teneo.samples.emf.sample.library.impl.LibraryImpl; +import org.eclipse.emf.teneo.samples.emf.sample.library.impl.WriterImpl; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests serialization of the library example, also after persistence solution has replaced members. + * + * Test case uses Impl classes to facilitate build on emft server (encountered class loading + * errors). + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.10 $ + */ +public class LibrarySerializationAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public LibrarySerializationAction() { + super(LibraryPackage.eINSTANCE); + } + + /** Does its thing */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + final LibraryFactory factory = LibraryFactory.eINSTANCE; + + // first serialize a non persisted document set + serialize(getTestSet(factory, "one"), "one"); + + // then persist a set and check serialization after persisting + { + store.beginTransaction(); + Library lib = getTestSet(factory, "two"); + store.store(lib); + store.commitTransaction(); + serialize(lib, "two"); + } + + // then serialize after reading + { + store.beginTransaction(); + LibraryImpl lib = (LibraryImpl) store.getObject(Library.class); + assertEquals(2, lib.getBooks().size()); + // load the list + assertTrue(lib.getBooks().get(0) != null); + assertEquals(1, lib.getWriters().size()); + assertEquals(2, (lib.getWriters().get(0)).getBooks().size()); + assertTrue(null != (lib.getWriters().get(0)).getBooks().get(0)); + serialize(lib, "two"); + store.commitTransaction(); + } + } + + /** Serialize and check result */ + private void serialize(Library lib, String prefix) { + try { + final ByteArrayOutputStream bos = new ByteArrayOutputStream(); + final ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(lib); + oos.close(); + + final byte[] bytes = bos.toByteArray(); + + final ObjectInputStream ois = new ElverObjectInputStream(new ByteArrayInputStream(bytes)); + checkTestSet((Library) ois.readObject(), prefix); + ois.close(); + } catch (Exception e) { + throw new StoreTestException("IOException during serialization test", e); + } + + } + + /** Creates a test set and returns a library */ + @SuppressWarnings("unchecked") + private Library getTestSet(LibraryFactory factory, String preFix) { + final WriterImpl writer = (WriterImpl) factory.createWriter(); + writer.setName(preFix + "JRR Tolkien"); + + final BookImpl book = (BookImpl) factory.createBook(); + book.setAuthor(writer); + book.setPages(5); + book.setTitle(preFix + "The Hobbit"); + book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Book book2 = factory.createBook(); + book2.setAuthor(writer); + book2.setPages(7); + book2.setTitle(preFix + "The fellowship of the ring"); + book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Library library = factory.createLibrary(); + library.getBooks().add(book); + library.setName(preFix + "Science Fiction Library"); + library.getBooks().add(book2); + library.getWriters().add(writer); + return library; + } + + /** Checks the test set */ + @SuppressWarnings("unchecked") + private void checkTestSet(Library library, String preFix) { + assertEquals(preFix + "Science Fiction Library", library.getName()); + assertEquals(2, library.getBooks().size()); + assertEquals(1, library.getWriters().size()); + + Writer writer = library.getWriters().get(0); + assertEquals(preFix + "JRR Tolkien", writer.getName()); + assertEquals(2, writer.getBooks().size()); + + Book bk1 = library.getBooks().get(0); + assertEquals(preFix + "The Hobbit", bk1.getTitle()); + assertEquals(5, bk1.getPages()); + assertEquals(BookCategory.SCIENCE_FICTION_LITERAL, bk1.getCategory()); + + Book bk2 = library.getBooks().get(1); + assertEquals(preFix + "The fellowship of the ring", bk2.getTitle()); + assertEquals(7, bk2.getPages()); + assertEquals(BookCategory.SCIENCE_FICTION_LITERAL, bk2.getCategory()); + } + + /** Specific Object input stream to get rid of classloading issue */ + private class ElverObjectInputStream extends ObjectInputStream { + + /** Constructor */ + public ElverObjectInputStream(InputStream in) throws IOException { + super(in); + } + + /* + * (non-Javadoc) + * + * @see java.io.ObjectInputStream#resolveClass(java.io.ObjectStreamClass) + */ + @Override + protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { + final String clsName = desc.getName(); + final Class<?> cls = ClassLoaderResolver.classForName(clsName); + if (cls == null) { + return super.resolveClass(desc); + } + return cls; + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryUseMappingFileAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryUseMappingFileAction.java new file mode 100755 index 000000000..66f861d11 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryUseMappingFileAction.java @@ -0,0 +1,129 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: LibraryUseMappingFileAction.java,v 1.6 2008/03/30 15:12:08 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.sample.library.Book; +import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory; +import org.eclipse.emf.teneo.samples.emf.sample.library.Library; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage; +import org.eclipse.emf.teneo.samples.emf.sample.library.Writer; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.HsqldbTestDatabaseAdapter; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.6 $ + */ +public class LibraryUseMappingFileAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public LibraryUseMappingFileAction() { + super(LibraryPackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props + .setProperty(PersistenceOptions.MAPPING_FILE_PATH, + "/org/eclipse/emf/teneo/hibernate/test/emf/test.hbm.xml,/org/eclipse/emf/teneo/hibernate/test/emf/test2.hbm.xml"); + return props; + } + + /** Creates an item, an address and links them to a po. */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + final LibraryFactory factory = LibraryFactory.eINSTANCE; + // create a book, writer and library + { + store.beginTransaction(); + + final Writer writer = factory.createWriter(); + writer.setName("JRR Tolkien"); + + final Book book = factory.createBook(); + book.setAuthor(writer); + book.setPages(5); + book.setTitle("The Hobbit"); + book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Book book2 = factory.createBook(); + book2.setAuthor(writer); + book2.setPages(5); + book2.setTitle("The fellowship of the ring"); + book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Library library = factory.createLibrary(); + library.getBooks().add(book); + library.setName("Science Fiction Library"); + library.getBooks().add(book2); + library.getWriters().add(writer); + store.store(library); + + store.commitTransaction(); + assertEquals(2, writer.getBooks().size()); + + testTables(store); + } + } + + private void testTables(TestStore store) { + final Connection conn = store.getConnection(); + Statement stmt = null; + ResultSet rs = null; + try { + stmt = conn.createStatement(); + if (store.getDatabaseAdapter() instanceof HsqldbTestDatabaseAdapter) { + rs = stmt.executeQuery("select count(*) from \"testBook\""); + } else { + rs = stmt.executeQuery("select count(*) from testBook"); + } + rs.next(); + assertEquals(2, rs.getInt(1)); + rs.close(); + } catch (final SQLException e) { + assertTrue(e.getMessage(), false); + } finally { + try { + if (stmt != null) { + stmt.close(); + } + } catch (final SQLException e) { + } + try { + if (rs != null) { + rs.close(); + } + } catch (final SQLException e) { + } + } + } + +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryValidateResourceAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryValidateResourceAction.java new file mode 100755 index 000000000..2c5f84c31 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryValidateResourceAction.java @@ -0,0 +1,184 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: LibraryValidateResourceAction.java,v 1.11 2010/04/02 22:42:54 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.io.IOException; +import java.util.HashSet; +import java.util.List; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.resource.StoreResource; +import org.eclipse.emf.teneo.samples.emf.sample.library.Book; +import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory; +import org.eclipse.emf.teneo.samples.emf.sample.library.Library; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage; +import org.eclipse.emf.teneo.samples.emf.sample.library.Writer; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests if simple validation works for the resource implementation. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.11 $ + */ +public class LibraryValidateResourceAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public LibraryValidateResourceAction() { + super(LibraryPackage.eINSTANCE); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.AbstractTestAction#hibernateEnabled() + */ + protected boolean hibernateEnabled() { + return true; + } + + /** Creates an item, an address and links them to a po. */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + final LibraryFactory factory = LibraryFactory.eINSTANCE; + + // create a book, writer and library + try { + { + Resource res = store.getResource(); + res.load(null); + + final Writer writer = factory.createWriter(); + writer.setName("JRR_Tolkien"); + + final Book book = factory.createBook(); + book.setAuthor(writer); + book.setPages(510); + book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Library library = factory.createLibrary(); + library.getBooks().add(book); + library.getWriters().add(writer); + + res.getContents().add(library); + try { + res.save(null); + fail("Validation did not work"); + } catch (Exception e) { + library.setName("Science_Fiction"); + book.setTitle("Fellowship_of_the_Ring"); + res.save(null); + res.save(null); + } + + res.save(null); + res.unload(); + } + + { + Resource res = store.getResource(); + res.load(null); + + // test tracking modification + res.setTrackingModification(true); + + Library lib = null; + for (int i = 0; i < res.getContents().size(); i++) { + Object obj = res.getContents().get(i); + if (obj instanceof Library) { + lib = (Library) obj; + break; + } + } + + assert (lib != null); + Writer tolkien = lib.getWriters().get(0); + + tolkien.setName("Mr._Tolkien"); + + Writer orwell = factory.createWriter(); + orwell.setName("G._Orwell"); + lib.getWriters().add(orwell); + + final StoreResource sr = (StoreResource) res; + final List<EObject> ca = sr.getNewEObjects(); + final HashSet<EObject> cm = sr.getModifiedEObjects(); + assertEquals(2, ca.size() + cm.size()); + assertTrue(cm.contains(tolkien)); + assertTrue(ca.contains(orwell)); + + res.save(null); + res.unload(); + } + + { + // special test case which occurs when an invalid object is added to an elist which + // was + Resource res = store.getResource(); + res.load(null); + + Library lib = (Library) res.getContents().get(0); + + // create a writer + Writer martin = factory.createWriter(); + + // and then set the name + martin.setName("martin"); + + // add to library, writer name not set so invalid + lib.getWriters().add(martin); + + // now we can savely save + res.save(null); + res.unload(); + } + + { + Resource res = store.getResource(); + res.load(null); + Library lib = (Library) res.getContents().get(0); + boolean martinFound = false; + for (int i = 0; i < lib.getWriters().size(); i++) { + Writer wt = lib.getWriters().get(i); + martinFound = martinFound || wt.getName().compareTo("martin") == 0; + } + assertTrue("New writer martin was not committed", martinFound); + res.unload(); + } + } catch (IOException e) { + throw new StoreTestException("IOException during save", e); + } + } + + /** Specific Hibernate flush test */ + protected void testFlush(Resource res) { + /* + * if (res instanceof HibernateResource) { HibernateResource hres = (HibernateResource)res; Session session = + * hres.getSession(); Transaction tx = session.beginTransaction(); // this should not fail! try { tx.commit(); } + * // there should be a finally block but this is only a test catch (Exception e) { fail("The transaction commit + * should not flush illegal objects to the database"); } } + */ + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ListAsIdBagAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ListAsIdBagAction.java new file mode 100755 index 000000000..1723ce29f --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ListAsIdBagAction.java @@ -0,0 +1,106 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: ListAsIdBagAction.java,v 1.2 2009/03/15 14:49:53 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.issues.bz237790.Bz237790Factory; +import org.eclipse.emf.teneo.samples.issues.bz237790.Bz237790Package; +import org.eclipse.emf.teneo.samples.issues.bz237790.Many; +import org.eclipse.emf.teneo.samples.issues.bz237790.One; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.2 $ + */ +public class ListAsIdBagAction extends AbstractTestAction { + + private final Bz237790Factory factory = Bz237790Factory.eINSTANCE; + + public ListAsIdBagAction() { + super(Bz237790Package.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.MAP_ALL_LISTS_AS_IDBAG, "true"); + return props; + } + + @Override + public void doAction(TestStore store) { + { + store.beginTransaction(); + addDataSet(store, 1); + addDataSet(store, 2); + store.commitTransaction(); + } + + // read the writers and add the second book to the second writer + { + store.beginTransaction(); + final List<One> os = store.getObjects(One.class); + One o1 = null; + One o2 = null; + for (One o : os) { + if (o.getManies().size() == 2) { + o1 = o; + } else { + o2 = o; + } + } + final List<Many> reserve = new ArrayList<Many>(o1.getManies()); + o1.getManies().clear(); + reserve.add(1, o2.getManies().get(1)); + o1.getManies().addAll(reserve); + store.commitTransaction(); + } + + { + store.beginTransaction(); + final List<One> os = store.getObjects(One.class); + for (One o : os) { + assertEquals(3, o.getManies().size()); + } + store.commitTransaction(); + } + } + + private void addDataSet(TestStore store, int index) { + { + final One one = factory.createOne(); + store.store(one); + int num = 3; + if (index == 2) { + num = 2; + } + for (int i = 0; i < num; i++) { + final Many many = factory.createMany(); + many.setName("" + index); + one.getManies().add(many); + store.store(many); + } + } + + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/MindMapAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/MindMapAction.java new file mode 100755 index 000000000..4168e25a8 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/MindMapAction.java @@ -0,0 +1,146 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: MindMapAction.java,v 1.8 2008/02/28 07:08:14 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; +import org.example.mindmap.Map; +import org.example.mindmap.MindmapFactory; +import org.example.mindmap.MindmapPackage; +import org.example.mindmap.Priority; +import org.example.mindmap.Relationship; +import org.example.mindmap.RelationshipType; +import org.example.mindmap.Resource; +import org.example.mindmap.Topic; + +/** + * Tests the gmf mindmap example + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.8 $ + */ +public class MindMapAction extends AbstractTestAction { + + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public MindMapAction() { + super(MindmapPackage.eINSTANCE); + } + + @Override + @SuppressWarnings("unchecked") + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true"); + return props; + } + + /** Creates an item, an address and links them to a po. */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + final MindmapFactory factory = MindmapFactory.eINSTANCE; + { + final Map map = factory.createMap(); + map.setTitle("Persistency Discussions"); + + final Resource res1 = factory.createResource(); + res1.setEmail("mtaal@elver.org"); + res1.setName("Martin Taal"); + + final Resource res2 = factory.createResource(); + res2.setEmail("test@elver.org"); + res2.setName("Test Me"); + + map.getResources().add(res1); + map.getResources().add(res2); + + map.getRootTopics().add(createTopic(store, map.getResources(), factory, "Teneo JPOX", 5)); + map.getRootTopics().add(createTopic(store, new ArrayList(), factory, "Teneo Hibernate", 3)); + + final Relationship rel = factory.createRelationship(); + rel.setSource((Topic) map.getRootTopics().get(0)); + rel.setTarget((Topic) map.getRootTopics().get(1)); + rel.setType(RelationshipType.EXTENDS_LITERAL); + + map.getRelations().add(rel); + + store.beginTransaction(); + store.store(map); + store.commitTransaction(); + } + + { + store.beginTransaction(); + Map map = store.getObject(Map.class); + assertEquals(2, map.getRootTopics().size()); + checkTopic(map, (Topic) map.getRootTopics().get(0), "Teneo JPOX", 5); + checkTopic(map, (Topic) map.getRootTopics().get(1), "Teneo Hibernate", 3); + Relationship rs = (Relationship) map.getRelations().get(0); + assertEquals(rs.getSource(), map.getRootTopics().get(0)); + assertEquals(rs.getTarget(), map.getRootTopics().get(1)); + map.getRelations().remove(0); + map.getRootTopics().remove(1); + store.commitTransaction(); + } + { + store.beginTransaction(); + Map map = store.getObject(Map.class); + assertEquals(1, map.getRootTopics().size()); + checkTopic(map, (Topic) map.getRootTopics().get(0), "Teneo JPOX", 5); + store.commitTransaction(); + } + } + + /** Create a default topic */ + @SuppressWarnings("unchecked") + private Topic createTopic(TestStore store, List resources, MindmapFactory factory, String name, int level) { + final Topic topic = factory.createTopic(); + topic.setEndDate(store.getDate(new Date())); + topic.setStartDate(store.getDate(new Date())); + topic.setName(name + level); + topic.setPriority(Priority.get(level)); + topic.setPercentComplete((float) (level * 10.0 / 100.0)); + topic.getResources().addAll(resources); + for (int i = 0; i < level; i++) { + topic.getSubtopics().add(createTopic(store, resources, factory, name + "_", level - 1)); + } + return topic; + } + + private void checkTopic(Map map, Topic topic, String name, int level) { + assertEquals(name + level, topic.getName()); + assertEquals(level, topic.getSubtopics().size()); + assertEquals(Priority.get(level), topic.getPriority()); + assertEquals((float) (level * 10.0 / 100.0), topic.getPercentComplete(), 0.1f); + for (int i = 0; i < topic.getResources().size(); i++) { + assertEquals(topic.getResources().get(i), map.getResources().get(i)); + } + for (int i = 0; i < level; i++) { + checkTopic(map, (Topic) topic.getSubtopics().get(i), name + "_", level - 1); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/NoEscapeLibraryAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/NoEscapeLibraryAction.java new file mode 100755 index 000000000..fffc34c84 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/NoEscapeLibraryAction.java @@ -0,0 +1,45 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: NoEscapeLibraryAction.java,v 1.2 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests the library example of emf/xsd without escape character. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.2 $ + */ +public class NoEscapeLibraryAction extends LibraryAction { + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.SQL_NAME_ESCAPE_CHARACTER, ""); + props.putAll(super.getExtraConfigurationProperties()); + return props; + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + assertTrue(store.getMappingXML().indexOf("`") == -1); + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/PlayAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/PlayAction.java new file mode 100755 index 000000000..1225544bb --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/PlayAction.java @@ -0,0 +1,139 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: PlayAction.java,v 1.9 2008/02/28 07:08:14 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Collections; +import java.util.Iterator; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl; +import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; +import org.eclipse.emf.teneo.samples.emf.sample.play.PlayPackage; +import org.eclipse.emf.teneo.samples.emf.sample.play.PlayType; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests by reading a play.xml file storing it in the database, then retrieve it again, store it in an xml file and + * compare the data in this xml file with the original. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.9 $ + */ +public class PlayAction extends AbstractTestAction { + public PlayAction() { + super(PlayPackage.eINSTANCE); + } + + /** Creates a supplier, a product, relates then, saves and retrieves them again. */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + // read play.xml as a resource! + PlayType play = null; + try { + // read from the resource + { + // a file handle to the current class + // the play.xml is in the model directory + final Resource resource = new XMLResourceImpl(); + resource.load(PlayType.class.getResourceAsStream("data/small_play.xml"), Collections.EMPTY_MAP); + resource.load(Collections.EMPTY_MAP); + play = (PlayType) resource.getContents().get(0); + // resource.unload(); + } + + // store the play in the database + { + store.beginTransaction(); + store.store(play); + /* + * apparently jpox started to find the element name group a reserved word which was + * not allowed anymore in the where clause. List list = store.query("SELECT FROM + * org.eclipse.emf.teneo.test.emf.sample.play.impl.SceneTypeImpl WHERE " + " + * group.contains(sceneGroup) && sceneGroup.speech == speech &&" + " + * speech.group.contains(puckSpeaker) && puckSpeaker.speaker==\"PUCK\"" + " + * VARIABLES org.eclipse.emf.teneo.test.emf.sample.play.impl.SceneTypeImplgroup + * sceneGroup; " + " org.eclipse.emf.teneo.test.emf.sample.play.impl.SpeechTypeImpl + * speech; " + " org.eclipse.emf.teneo.test.emf.sample.play.impl.SpeechTypeImplgroup + * puckSpeaker"); assertEquals(6, list.size()); + */ + store.commitTransaction(); + play = null; + } + + // read from the relational store + // and save it in a xml byte array + byte[] bytes; + { + store.beginTransaction(); + final PlayType myplay = store.getObject(PlayType.class); + final ByteArrayOutputStream bos = new ByteArrayOutputStream(); + final Resource resource = new XMLResourceImpl(); + resource.getContents().add(myplay); + resource.save(bos, Collections.EMPTY_MAP); + bytes = bos.toByteArray(); + store.commitTransaction(); + } + + // now compare the two resources + compareResult("small_play.xml", bytes, true); + } catch (Exception e) { + throw new StoreTestException("Exception when loading play.xml", e); + } + } + + /** Compare the original and the generated xml file */ + @SuppressWarnings("unchecked") + protected void compareResult(String fileNameOne, byte[] bytes, boolean asXML) throws IOException { + final InputStream isOne = PlayType.class.getResourceAsStream("data/" + fileNameOne); + + final Resource original_resource; + if (asXML) { + original_resource = new XMLResourceImpl(); + } else { + original_resource = new XMIResourceImpl(); + } + original_resource.load(isOne, Collections.EMPTY_MAP); + final Iterator original_iterator = original_resource.getAllContents(); + + final Resource new_resource; + if (asXML) { + new_resource = new XMLResourceImpl(); + } else { + new_resource = new XMIResourceImpl(); + } + new_resource.load(new ByteArrayInputStream(bytes), Collections.EMPTY_MAP); + final Iterator new_iterator = new_resource.getAllContents(); + + // rough structural test + while (original_iterator.hasNext()) { + assertTrue("The new_play.xml has less nodes", new_iterator.hasNext()); + + final EObject original_object = (EObject) original_iterator.next(); + final EObject new_object = (EObject) new_iterator.next(); + assertEquals(original_object.getClass(), new_object.getClass()); + } + assertTrue("The original_play.xml has less nodes", !new_iterator.hasNext()); + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/PlayImExportAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/PlayImExportAction.java new file mode 100755 index 000000000..0d375c3d6 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/PlayImExportAction.java @@ -0,0 +1,54 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: PlayImExportAction.java,v 1.4 2008/02/28 07:08:14 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import org.eclipse.emf.teneo.samples.emf.sample.play.PlayType; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests by reading a play.xml file storing it in the database, then retrieve it again, store it in an xml file + * and compare the data in this xml file with the original. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.4 $ +*/ +public abstract class PlayImExportAction extends PlayAction { + /** Creates a supplier, a product, relates then, saves and retrieves them again. */ + public void doAction(TestStore store) { + try { + final ByteArrayOutputStream bos = new ByteArrayOutputStream(); + imExport(PlayType.class.getResourceAsStream("data" + File.separator + "original_play.xml"), + bos, store); + + // and compare the result + compareResult("original_play.xml", bos.toByteArray(), true); + } catch (IOException e) { + throw new StoreTestException("IOException ", e); + } + } + + /** Import/export, from and to */ + protected abstract void imExport(InputStream is, OutputStream os, TestStore store); + +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/PrimerPOAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/PrimerPOAction.java new file mode 100755 index 000000000..02bee9d47 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/PrimerPOAction.java @@ -0,0 +1,90 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: PrimerPOAction.java,v 1.6 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Date; + +import javax.xml.datatype.XMLGregorianCalendar; + +import org.eclipse.emf.teneo.samples.emf.sample.schemaprimerpo.Item; +import org.eclipse.emf.teneo.samples.emf.sample.schemaprimerpo.PurchaseOrder; +import org.eclipse.emf.teneo.samples.emf.sample.schemaprimerpo.SchemaprimerpoFactory; +import org.eclipse.emf.teneo.samples.emf.sample.schemaprimerpo.SchemaprimerpoPackage; +import org.eclipse.emf.teneo.samples.emf.sample.schemaprimerpo.USAddress; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests the library example of emf/xsd. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.6 $ + */ +public class PrimerPOAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public PrimerPOAction() { + super(SchemaprimerpoPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + { + store.beginTransaction(); + final SchemaprimerpoFactory factory = SchemaprimerpoFactory.eINSTANCE; + final Item item = factory.createItem(); + item.setComment("This is my test item"); + item.setPartNum("partnumber"); + item.setProductName("productname"); + item.setQuantity(new BigInteger("500")); + item.setUSPrice(new BigDecimal(50.123)); + item.setShipDate((XMLGregorianCalendar) store.getDate(new Date())); + + final Item item2 = factory.createItem(); + item2.setComment("This is my second test item"); + item2.setPartNum("partnumber"); + item2.setProductName("productname"); + item2.setQuantity(new BigInteger("500")); + item2.setUSPrice(new BigDecimal(50.123)); + item2.setShipDate((XMLGregorianCalendar) store.getDate(new Date())); + + final USAddress addr = factory.createUSAddress(); + addr.setCity("c"); + addr.setCountry("country"); + addr.setName("name"); + addr.setState("state"); + addr.setStreet("street"); + addr.setZip(new BigDecimal("3941")); + + final PurchaseOrder po = factory.createPurchaseOrder(); + po.setComment("this is my comment"); + po.setBillTo(addr); + po.getItems().add(item); + po.getItems().add(item2); + po.setOrderDate((XMLGregorianCalendar) store.getDate(new Date())); + + store.store(po); + store.commitTransaction(); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ProductAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ProductAction.java new file mode 100755 index 000000000..fadcebd54 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ProductAction.java @@ -0,0 +1,136 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: ProductAction.java,v 1.12 2010/11/12 09:33:38 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.Date; +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.sample.product.ClassificationType; +import org.eclipse.emf.teneo.samples.emf.sample.product.ProductFactory; +import org.eclipse.emf.teneo.samples.emf.sample.product.ProductPackage; +import org.eclipse.emf.teneo.samples.emf.sample.product.ProductType; +import org.eclipse.emf.teneo.samples.emf.sample.product.SupplierType; +import org.eclipse.emf.teneo.samples.emf.sample.product.impl.ProductTypeImpl; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Very simple emf test which tests a simple relation between a product and its + * supplier and some primitive types (double and date). + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.12 $ + */ +public class ProductAction extends AbstractTestAction { + public ProductAction() { + super(ProductPackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty( + PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, + "true"); + return props; + } + + /** + * Creates a supplier, a product, relates then, saves and retrieves them + * again. + */ + @Override + public void doAction(TestStore store) { + { + store.beginTransaction(); + + final ProductFactory factory = ProductFactory.eINSTANCE; + + final SupplierType supplier = factory.createSupplierType(); + supplier.setName("supplier1"); + supplier.setNoOfEmployees(1); + store.store(supplier); + + final ProductType product = factory.createProductType(); + product.setCode("product1"); + product.setCreatedOn(store.getDate(new Date())); + product.setId("productid1"); + product.setPrice(199.95); + product.setSupplier(supplier); + + ClassificationType c1 = factory.createClassificationType(); + c1.setName("c1"); + ClassificationType c2 = factory.createClassificationType(); + c2.setName("c2"); + ClassificationType c3 = factory.createClassificationType(); + c3.setName("c3"); + + product.setAnyOne(c1); + product.getAnyList().add(c2); + product.getAnyList().add(c3); + product.getAnyList().add(supplier); + + store.store(product); + store.commitTransaction(); + } + + { + store.beginTransaction(); + ProductTypeImpl result = (ProductTypeImpl) store + .getObject(ProductType.class); + assertTrue(result != null); + assert (result != null); + assertTrue(result.getCode().compareTo("product1") == 0); + assertTrue(result.getSupplier() != null); + assertEquals(199.95, result.getPrice(), 0.01); + assertTrue(result.getSupplier().getName().compareTo("supplier1") == 0); + + ClassificationType c1 = (ClassificationType) result.getAnyOne(); + assertEquals("c1", c1.getName()); + assertEquals("c2", + ((ClassificationType) result.getAnyList().get(0)).getName()); + assertEquals("c3", + ((ClassificationType) result.getAnyList().get(1)).getName()); + assertEquals(result.getSupplier(), result.getAnyList().get(2)); + result.setAnyOne(result.getSupplier()); + result.getAnyList().remove(1); + result.getAnyList().remove(0); + store.commitTransaction(); + } + + { + store.beginTransaction(); + ProductTypeImpl result = (ProductTypeImpl) store + .getObject(ProductType.class); + assertEquals(1, result.getAnyList().size()); + result.setAnyOne(null); + store.commitTransaction(); + } + + // test update of pk, is not supported by hb + /* + * { store.beginTransaction(); ProductTypeImpl result = + * (ProductTypeImpl) store.getObject(ProductType.class); + * result.setId("newid"); store.store(result); + * store.commitTransaction(); } { store.beginTransaction(); + * ProductTypeImpl result = (ProductTypeImpl) + * store.getObject(ProductType.class); assertEquals("newid", + * result.getId()); store.commitTransaction(); } + */ + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/RentalMapAsClassAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/RentalMapAsClassAction.java new file mode 100755 index 000000000..dbeffd536 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/RentalMapAsClassAction.java @@ -0,0 +1,164 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: RentalMapAsClassAction.java,v 1.4 2008/02/28 07:08:14 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Properties; + +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.rental.Currency; +import org.eclipse.emf.teneo.rental.Manufacturer; +import org.eclipse.emf.teneo.rental.RentalBicycle; +import org.eclipse.emf.teneo.rental.RentalBicycleType; +import org.eclipse.emf.teneo.rental.RentalCar; +import org.eclipse.emf.teneo.rental.RentalCarSize; +import org.eclipse.emf.teneo.rental.RentalContract; +import org.eclipse.emf.teneo.rental.RentalFactory; +import org.eclipse.emf.teneo.rental.RentalPackage; +import org.eclipse.emf.teneo.rental.impl.RentalContractImpl; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests mapping an eclass as a class. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.4 $ + */ +public class RentalMapAsClassAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public RentalMapAsClassAction() { + super(RentalPackage.eINSTANCE); + } + + /** + * Set the SET_PROXY property to true. + * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties() + */ + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.SET_PROXY, "true"); + props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true"); + return props; + } + + /** Test */ + @Override + public void doAction(TestStore store) { + final RentalFactory rf = RentalFactory.eINSTANCE; + + { + RentalContract rcontract = rf.createRentalContract(); + RentalCar rcar = rf.createRentalCar(); + RentalBicycle rb = rf.createRentalBicycle(); + rcar.setDescription("car"); + rcar.setSize(RentalCarSize.FAMILY); + rb.setDescription("bicycle"); + rb.setType(RentalBicycleType.MOUNTAIN_BIKE); + Manufacturer m = rf.createManufacturer(); + m.setCode("gazelle"); + rb.setManufacturer(m); + rcontract.getRentalUnits().add(rcar); + rcontract.getRentalUnits().add(rb); + rcontract.setCost(4.5f); + rcontract.setStartDate(new Date()); + rcontract.setEndDate(new Date()); + rcontract.setRentToBusinessPartner("business partner"); + + Currency c = rf.createCurrency(); + c.setCode("EUR"); + rcontract.setCurrency(c); + store.beginTransaction(); + store.store(rcontract.getRentalUnits()); + store.store(rcontract); + store.commitTransaction(); + } + + { + store.beginTransaction(); + final RentalContract rc = (RentalContract) store.query("select rc from RentalContract as rc").get(0); + assertEquals(2, rc.getRentalUnits().size()); + final RentalCar rcar = (RentalCar) rc.getRentalUnits().get(0); + final RentalBicycle rb = (RentalBicycle) rc.getRentalUnits().get(1); + Currency c = rc.getCurrency(); + assertEquals("EUR", c.getCode()); + assertTrue(c.getClass().getSimpleName().indexOf("$$") != -1); // rough test, no + // dependencies on + // hibernate from this + // package + assertEquals("car", rcar.getDescription()); + assertEquals(RentalBicycleType.MOUNTAIN_BIKE, rb.getType()); + assertEquals("bicycle", rb.getDescription()); + store.commitTransaction(); + } + + { + store.beginTransaction(); + List<?> list = store.query("select rc from " + RentalContractImpl.class.getName() + " as rc"); + RentalContract rc = (RentalContract) list.get(0); + assertEquals(2, rc.getRentalUnits().size()); + final RentalCar rcar = (RentalCar) rc.getRentalUnits().get(0); + final RentalBicycle rb = (RentalBicycle) rc.getRentalUnits().get(1); + Currency c = rc.getCurrency(); + assertEquals("EUR", c.getCode()); + assertTrue(c.getClass().getSimpleName().indexOf("$$") != -1); // rough test, no + // dependencies on + // hibernate from this + // package + assertEquals("car", rcar.getDescription()); + assertEquals(RentalBicycleType.MOUNTAIN_BIKE, rb.getType()); + assertEquals("bicycle", rb.getDescription()); + store.commitTransaction(); + } + + { + store.beginTransaction(); + List<?> list = store.query("select rc from " + RentalContract.class.getName() + " as rc"); + RentalContract rc = (RentalContract) list.get(0); + assertEquals(2, rc.getRentalUnits().size()); + final RentalCar rcar = (RentalCar) rc.getRentalUnits().get(0); + final RentalBicycle rb = (RentalBicycle) rc.getRentalUnits().get(1); + Currency c = rc.getCurrency(); + assertEquals("EUR", c.getCode()); + assertTrue(c.getClass().getSimpleName().indexOf("$$") != -1); // rough test, no + // dependencies on + // hibernate from this + // package + assertEquals("car", rcar.getDescription()); + assertEquals(RentalBicycleType.MOUNTAIN_BIKE, rb.getType()); + assertEquals("bicycle", rb.getDescription()); + store.commitTransaction(); + } + + try { + Resource res = store.getResource(); + res.load(Collections.EMPTY_MAP); + assertEquals(5, res.getContents().size()); + } catch (Exception e) { + throw new StoreTestException(e.getMessage(), e); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/RentalResourceReferenceAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/RentalResourceReferenceAction.java new file mode 100755 index 000000000..818c23695 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/RentalResourceReferenceAction.java @@ -0,0 +1,131 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: RentalResourceReferenceAction.java,v 1.4 2008/02/28 07:08:15 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Collections; +import java.util.Date; +import java.util.Properties; + +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.ecore.xmi.impl.XMLResourceFactoryImpl; +import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.rental.Manufacturer; +import org.eclipse.emf.teneo.rental.RentalBicycle; +import org.eclipse.emf.teneo.rental.RentalBicycleType; +import org.eclipse.emf.teneo.rental.RentalCar; +import org.eclipse.emf.teneo.rental.RentalCarSize; +import org.eclipse.emf.teneo.rental.RentalContract; +import org.eclipse.emf.teneo.rental.RentalFactory; +import org.eclipse.emf.teneo.rental.RentalPackage; +import org.eclipse.emf.teneo.resource.StoreResource; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests references from an xml to a db resource. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.4 $ + */ +public class RentalResourceReferenceAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public RentalResourceReferenceAction() { + super(RentalPackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true"); + return props; + } + + /** Test */ + @Override + public void doAction(TestStore store) { + final RentalFactory rf = RentalFactory.eINSTANCE; + byte[] bytes = null; + + try { + RentalContract rcontract = rf.createRentalContract(); + RentalCar rcar = rf.createRentalCar(); + RentalBicycle rb = rf.createRentalBicycle(); + rcar.setDescription("car"); + rcar.setSize(RentalCarSize.FAMILY); + rb.setDescription("bicycle"); + rb.setType(RentalBicycleType.MOUNTAIN_BIKE); + Manufacturer m = rf.createManufacturer(); + m.setCode("gazelle"); + rb.setManufacturer(m); + rcontract.getRentalUnits().add(rcar); + rcontract.getRentalUnits().add(rb); + rcontract.setCost(4.5f); + rcontract.setEndDate(new Date()); + rcontract.setRentToBusinessPartner("business partner"); + + // save the car and bicycle in a database resource + Resource res = store.getResource(); + res.load(null); + res.getContents().add(rcar); + res.getContents().add(rb); + res.save(Collections.EMPTY_MAP); + + // save the contract in an xml file + final ByteArrayOutputStream bos = new ByteArrayOutputStream(); + final Resource resource = new XMLResourceImpl(); + resource.getContents().add(rcontract); + resource.save(bos, Collections.EMPTY_MAP); + + // now also save to a file + // final FileOutputStream fos = new FileOutputStream("/home/mtaal/mytmp/rental.xml"); + // resource.save(fos, Collections.EMPTY_MAP); + bytes = bos.toByteArray(); + } catch (IOException e) { + throw new StoreTestException("IOException during save", e); + } + + try { + final ResourceSet rs = new ResourceSetImpl(); + rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xml", new XMLResourceFactoryImpl()); + final Resource new_resource = rs.createResource(URI.createFileURI("rental.xml")); + new_resource.load(new ByteArrayInputStream(bytes), Collections.EMPTY_MAP); + final RentalContract rc = (RentalContract) new_resource.getContents().get(0); + assertEquals(2, rc.getRentalUnits().size()); + final RentalCar rcar = (RentalCar) rc.getRentalUnits().get(0); + final RentalBicycle rb = (RentalBicycle) rc.getRentalUnits().get(1); + assertEquals("car", rcar.getDescription()); + assertEquals(rb.eResource(), rcar.eResource()); + assertTrue(rb.eResource() instanceof StoreResource); + assertEquals(RentalBicycleType.MOUNTAIN_BIKE, rb.getType()); + assertEquals("bicycle", rb.getDescription()); + } catch (IOException e) { + throw new StoreTestException("IOException during save", e); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SchoolLibraryAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SchoolLibraryAction.java new file mode 100755 index 000000000..3d7f2e95b --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SchoolLibraryAction.java @@ -0,0 +1,257 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: SchoolLibraryAction.java,v 1.14 2008/06/04 20:15:49 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.io.IOException; +import java.util.Collections; +import java.util.Iterator; +import java.util.Properties; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.InternalEObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.library.Book; +import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.library.BookCategory; +import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.library.Library; +import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.library.LibraryFactory; +import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.library.LibraryPackage; +import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.library.Writer; +import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.library.impl.BookImpl; +import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.library.impl.WriterImpl; +import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.schoollibrary.SchoolBook; +import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.schoollibrary.SchoolLibrary; +import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.schoollibrary.SchoollibraryFactory; +import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.schoollibrary.SchoollibraryPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.AbstractTestStore; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests the schoollibrary example which has some more inheritance structures. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.14 $ + */ +public class SchoolLibraryAction extends AbstractTestAction { + + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public SchoolLibraryAction() { + super(new EPackage[] { LibraryPackage.eINSTANCE, SchoollibraryPackage.eINSTANCE }); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties() + */ + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY, "READ_WRITE"); + props.setProperty(AbstractTestStore.STORE_MAPPING_FILE_ONE_DIRECTORY_HIGHER, "true"); + return props; + } + + /** Creates simple types and tests against */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + // test a simple type + final LibraryFactory libFactory = LibraryFactory.eINSTANCE; + final SchoollibraryFactory schoolFactory = SchoollibraryFactory.eINSTANCE; + { + store.beginTransaction(); + + SchoolLibrary sl = schoolFactory.createSchoolLibrary(); + sl.setName("Primary School Library"); + + Writer teacher = libFactory.createWriter(); + teacher.setName("mr. Mathematics"); + + SchoolBook sb = schoolFactory.createSchoolBook(); + sb.setCategory(BookCategory.MYSTERY_LITERAL); + sb.setTitle("Mathematics Level 1"); + sb.setPages(243); + sb.setValue(34.59f); + sb.setAuthor(teacher); + + SchoolBook sb2 = schoolFactory.createSchoolBook(); + sb2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + sb2.setTitle("Mathematics Level 2"); + sb2.setPages(244); + sb2.setValue(35.70f); + sb2.setAuthor(teacher); + + sl.getBooks().add(sb); + sl.getBooks().add(sb2); + sl.getWriters().add(teacher); + sl.setLocation("Schoolbuilding 1"); + store.store(sb); + store.store(sb2); + store.store(sl); + store.commitTransaction(); + } + + // now use a resource to read! + try { + final Resource res = store.getResource(getQuery1()); + res.load(Collections.EMPTY_MAP); + assertEquals(3, res.getContents().size()); + Iterator it = res.getContents().iterator(); + int cntTeachers = 0; + int cntBooks = 0; + while (it.hasNext()) { + Object obj = it.next(); + if (obj instanceof Writer) { + cntTeachers++; + } + if (obj instanceof Book) { + cntBooks++; + } + } + assertEquals(1, cntTeachers); + assertEquals(2, cntBooks); + res.unload(); + } catch (IOException e) { + throw new StoreTestException("Exception", e); + } + + try { + final Resource res = store.getResource(getQuery2()); + res.load(Collections.EMPTY_MAP); + assertEquals(1, res.getContents().size()); + Writer writ = (Writer) res.getContents().get(0); + // in case of direct load into a resource the containers are not set correctly, only + // if the container was loaded earlier then this is done. + // assertTrue(hasContainer((InternalEObject) writ)); + writ.getBooks().remove(0); + res.save(Collections.EMPTY_MAP); + res.unload(); + } catch (IOException e) { + throw new StoreTestException("Exception", e); + } + + // test result + try { + final Resource res = store.getResource(getQuery3()); + res.load(Collections.EMPTY_MAP); + assertEquals(3, res.getContents().size()); + Iterator it = res.getContents().iterator(); + int cntTeachers = 0; + int cntBooks = 0; + int bookNoWriter = 0; + Writer checkWriter1 = null; + Writer checkWriter2 = null; + while (it.hasNext()) { + Object obj = it.next(); + if (obj instanceof Writer) { + assertEquals(1, ((Writer) obj).getBooks().size()); + checkWriter1 = (Writer) obj; + cntTeachers++; + } + if (obj instanceof Book) { + if (((Book) obj).getAuthor() == null) { + bookNoWriter++; + } else { + checkWriter2 = ((Book) obj).getAuthor(); + } + cntBooks++; + if (obj instanceof SchoolBook) { + SchoolBook sb = (SchoolBook) obj; + if (sb.getValue() < 35f) { + assertEquals(34.59f, sb.getValue(), 0.001); + } else { + assertEquals(35.70f, sb.getValue(), 0.001); + } + } + } + } + assertEquals(1, cntTeachers); + assertEquals(2, cntBooks); + assertEquals(1, bookNoWriter); + assertTrue(checkWriter1 != null); + assertTrue(checkWriter2 == checkWriter1); + res.unload(); + } catch (IOException e) { + throw new StoreTestException("Exception", e); + } + + // now use a resource to read! +// try { +// final Resource res = store.getResource(getQuery4()); +// res.load(Collections.EMPTY_MAP); +// Iterator it = res.getContents().iterator(); +// while (it.hasNext()) { +// Book obj = (Book)it.next(); +// if (obj.getAuthor() != null) { +// assertEquals(obj.eResource(), obj.getAuthor().eResource()); +// } +// } +// res.unload(); +// } catch (IOException e) { +// throw new StoreTestException("Exception", e); +// } + + try { + Resource res = store.getResource(); + res.load(Collections.EMPTY_MAP); + // 1 in case multiple inheritance is not supported + assertEquals(1, res.getContents().size()); + final Library lib = (Library) res.getContents().get(0); + assertEquals(2, lib.getBooks().size()); + res.unload(); + + } catch (IOException e) { + throw new StoreTestException("Exception", e); + } + } + + /** Returns one test query */ + protected String getQuery1() { + return "query1=SELECT FROM " + WriterImpl.class.getName() + "&query2=SELECT FROM " + BookImpl.class.getName(); + // "query1=FROM " + Writer.class.getName() + "&query2=FROM " + Book.class.getName() + } + + /** Returns one test query */ + protected String getQuery2() { + return "query1=SELECT FROM " + WriterImpl.class.getName(); + // "query1=FROM " + Writer.class.getName(); + } + + /** Returns one test query */ + protected String getQuery3() { + return "query1=SELECT FROM " + WriterImpl.class.getName() + "&query2=SELECT FROM " + BookImpl.class.getName(); + // "query1=FROM " + Writer.class.getName() + "&query2=FROM " + Book.class.getName(); + } + + /** Returns one test query */ + protected String getQuery4() { + return "query1=SELECT FROM " + BookImpl.class.getName(); + // "query1=FROM " + Writer.class.getName() + "&query2=FROM " + Book.class.getName(); + } + + /** Container present */ + protected boolean hasContainer(InternalEObject obj) { + return true; + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SimpleLibraryResourceAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SimpleLibraryResourceAction.java new file mode 100755 index 000000000..f2a11c669 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SimpleLibraryResourceAction.java @@ -0,0 +1,107 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: SimpleLibraryResourceAction.java,v 1.2 2009/04/03 06:15:39 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.io.IOException; + +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.samples.emf.sample.library.Book; +import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory; +import org.eclipse.emf.teneo.samples.emf.sample.library.Library; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage; +import org.eclipse.emf.teneo.samples.emf.sample.library.Writer; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.2 $ + */ +public class SimpleLibraryResourceAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public SimpleLibraryResourceAction() { + super(LibraryPackage.eINSTANCE); + } + + protected boolean hibernateEnabled() { + return true; + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final LibraryFactory factory = LibraryFactory.eINSTANCE; + + // create a book, writer and library + try { + { + Resource res = getResource(store); + res.load(null); + + final Writer writer = factory.createWriter(); + writer.setName("JRR_Tolkien"); + + final Book book = factory.createBook(); + book.setAuthor(writer); + book.setPages(510); + book.setTitle("Fellowship_of_the_Ring"); + book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); + + final Library library = factory.createLibrary(); + library.setName("Science_Fiction"); + library.getBooks().add(book); + library.getWriters().add(writer); + + res.getContents().add(library); + assertTrue(book.eDeliver()); + assertTrue(writer.eDeliver()); + res.save(null); + assertTrue(book.eDeliver()); + assertTrue(writer.eDeliver()); + res.unload(); + } + + // walk through the structure starting from the library + { + Resource res = getResource(store); + res.load(null); + + Library lib = (Library) res.getContents().get(0); + Writer tolkien = lib.getWriters().get(0); + assertEquals("JRR_Tolkien", tolkien.getName()); + tolkien.setName("Tolkien"); + assertTrue(tolkien.eDeliver()); + res.save(null); + assertTrue(tolkien.eDeliver()); + assertTrue(lib.getBooks().get(0).eDeliver()); + } + } catch (IOException e) { + throw new StoreTestException("IOException during save", e); + } + } + + protected Resource getResource(TestStore store) { + return store.getResource(); + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SimpleRentalAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SimpleRentalAction.java new file mode 100755 index 000000000..3b41dcbfc --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SimpleRentalAction.java @@ -0,0 +1,105 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: SimpleRentalAction.java,v 1.3 2010/10/29 09:35:22 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.Date; +import java.util.List; + +import org.eclipse.emf.teneo.rental.Manufacturer; +import org.eclipse.emf.teneo.rental.RentalCar; +import org.eclipse.emf.teneo.rental.RentalCarSize; +import org.eclipse.emf.teneo.rental.RentalContract; +import org.eclipse.emf.teneo.rental.RentalFactory; +import org.eclipse.emf.teneo.rental.RentalPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests creating holes in a list index in the db + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ + */ +public class SimpleRentalAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public SimpleRentalAction() { + super(RentalPackage.eINSTANCE); + } + + /** Test */ + @Override + public void doAction(TestStore store) { + final RentalFactory rf = RentalFactory.eINSTANCE; + { + RentalContract rcontract = rf.createRentalContract(); + RentalCar rcar1 = rf.createRentalCar(); + rcar1.setDescription("car1"); + rcar1.setSize(RentalCarSize.FAMILY); + RentalCar rcar2 = rf.createRentalCar(); + rcar2.setDescription("car2"); + rcar2.setSize(RentalCarSize.FAMILY); + RentalCar rcar3 = rf.createRentalCar(); + rcar3.setDescription("car3"); + rcar3.setSize(RentalCarSize.FAMILY); + rcontract.getRentalUnits().add(rcar1); + rcontract.getRentalUnits().add(rcar2); + rcontract.getRentalUnits().add(rcar3); + rcontract.setCost(4.5f); + rcontract.setEndDate(new Date()); + rcontract.setStartDate(new Date()); + rcontract.setRentToBusinessPartner("business partner"); + store.beginTransaction(); + store.store(rcontract); + + Manufacturer man = rf.createManufacturer(); + man.setCode("code"); + man.setTrusted(false); + store.store(man); + + store.commitTransaction(); + } + + { + store.beginTransaction(); + List<?> cars = store.getObjects(RentalCar.class); + for (Object o : cars) { + final RentalCar rc = (RentalCar) o; + if (rc.getDescription().compareTo("car2") == 0) { + store.deleteObject(rc); + } + } + store.commitTransaction(); + } + + { + try { + store.beginTransaction(); + final RentalContract rc = store.getObject(RentalContract.class); + assertTrue(null == rc.getRentalUnits().get(1)); + store.commitTransaction(); + fail(); + } catch (NullPointerException npe) { + // do nothing we should get here + } + } + + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SunBooksAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SunBooksAction.java new file mode 100755 index 000000000..3f71504e3 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SunBooksAction.java @@ -0,0 +1,297 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: SunBooksAction.java,v 1.7 2010/02/06 20:50:51 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +import org.eclipse.emf.teneo.samples.emf.sample.sunBooks.AuthorsType; +import org.eclipse.emf.teneo.samples.emf.sample.sunBooks.BookCategoryType1; +import org.eclipse.emf.teneo.samples.emf.sample.sunBooks.BookType; +import org.eclipse.emf.teneo.samples.emf.sample.sunBooks.BooksType; +import org.eclipse.emf.teneo.samples.emf.sample.sunBooks.CollectionType; +import org.eclipse.emf.teneo.samples.emf.sample.sunBooks.PromotionType; +import org.eclipse.emf.teneo.samples.emf.sample.sunBooks.SunBooksFactory; +import org.eclipse.emf.teneo.samples.emf.sample.sunBooks.SunBooksPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests the sun books example, is mainly used to test EList methods (move, set, contains, move, etc) + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.7 $ +*/ +@SuppressWarnings({ "unchecked", "deprecation" }) +public class SunBooksAction extends AbstractTestAction { + public SunBooksAction() { + super(SunBooksPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final SunBooksFactory factory = SunBooksFactory.eINSTANCE; + + // create a book, writer and library + { + store.beginTransaction(); + + BookType book = factory.createBookType(); + { + book.setBookCategory(BookCategoryType1.FICTION_LITERAL); + book.setDescription("In this prequel story to George R. R. Martin's Award winning...."); + book.setName("The Hedge Knight"); + book.setISBN(97640110); + book.setItemId("097640110K"); + book.setPrice("£6.99"); + + PromotionType promotion = factory.createPromotionType(); + promotion.setDiscount("10%"); + book.setPromotion(promotion); + + book.setPublicationDate(store.getDate(new Date("10/10/2003"))); + + AuthorsType author = factory.createAuthorsType(); + author.getAuthorName().add("George R.R. Martin"); + author.getAuthorName().add("Ben Avery"); + book.setAuthors(author); + } + + BookType book1 = factory.createBookType(); + { + book1.setBookCategory(BookCategoryType1.FICTION_LITERAL); + book1 + .setDescription("The first book in a brand new series from world-wide bestselling author of MAGICIAN, Raymond E. Feist...."); + book1.setName("Flight of the Nighthawks: Darkwar (Conclave of Shadows S.)"); + book1.setISBN(713374); + book1.setItemId("000713374X"); + book1.setPrice("£12.53"); + + PromotionType promotion = factory.createPromotionType(); + promotion.setNone("none"); + book1.setPromotion(promotion); + + book1.setPublicationDate(store.getDate(new Date("10/10/2003"))); + + AuthorsType author = factory.createAuthorsType(); + author.getAuthorName().add("Raymond Feist"); + book1.setAuthors(author); + } + + BookType book2 = factory.createBookType(); + { + book2.setBookCategory(BookCategoryType1.FICTION_LITERAL); + book2 + .setDescription("Foundation marks the first of a series of tales set so far in the future that Earth is all...."); + book2.setName("Foundation (The Foundation Series)"); + book2.setISBN(586010807); + book2.setItemId("0586010807"); + book2.setPrice("£5.59"); + + PromotionType promotion = factory.createPromotionType(); + promotion.setNone("none"); + book2.setPromotion(promotion); + + book2.setPublicationDate(store.getDate(new Date("10/10/2003"))); + + AuthorsType author = factory.createAuthorsType(); + author.getAuthorName().add("Isaac Asimov"); + book2.setAuthors(author); + } + + // put the book in the collection + CollectionType coll = factory.createCollectionType(); + BooksType booksType = factory.createBooksType(); + booksType.getBook().add(book); + booksType.getBook().add(book1); + booksType.getBook().add(book2); + coll.setBooks(booksType); + store.store(coll); + store.commitTransaction(); + } + + // The following methods of the Elist are checked + // move + // isEmpty (false) + // get + // size + // contains + // containsAll + // iterator + // listiterator + { + store.beginTransaction(); + final CollectionType coll = store.getObject(CollectionType.class); + final BooksType books = coll.getBooks(); + + // get Isaacs book + BookType isaac = books.getBook().get(2); + + // move Isaac to the first position + books.getBook().move(0, 2); + assertTrue("Index of Isaacs book is " + books.getBook().indexOf(isaac), books.getBook().indexOf(isaac) == 0); + assertTrue(books.getBook().size() == 3); // move does not delete + + // check contains on false + assertFalse(books.getBook().contains(factory.createBookType())); + assertTrue(books.getBook().contains(books.getBook().get(0))); + + // is empty + assertFalse(books.getBook().isEmpty()); + + ArrayList checkContains = new ArrayList(); + Iterator it = books.getBook().iterator(); + while (it.hasNext()) { + checkContains.add(it.next()); + } + assertTrue(books.getBook().containsAll(checkContains)); + + assertTrue(books.getBook().size() == 3); + + ArrayList checkContains2 = new ArrayList(); + ListIterator itList = books.getBook().listIterator(); + while (itList.hasNext()) { + checkContains2.add(itList.next()); + } + assertTrue(books.getBook().containsAll(checkContains2)); + + List subList = books.getBook().subList(0, 2); + assertTrue(subList.size() == 2); + assertTrue(books.getBook().containsAll(subList)); + + store.commitTransaction(); + } + + // test remove(int) and removeAll + { + store.beginTransaction(); + final CollectionType coll = store.getObject(CollectionType.class); + final BooksType books = coll.getBooks(); + + // the first book should be Isaac, check the move + BookType isaacsBook = books.getBook().get(0); + String authorName = isaacsBook.getAuthors().getAuthorName().get(0); + assertTrue(authorName.compareTo("Isaac Asimov") == 0); + + assertTrue(books.getBook().size() == 3); + + books.getBook().remove(0); // remove Isaac + List removeList = new ArrayList(books.getBook().subList(0, 1)); + books.getBook().removeAll(removeList); + + store.commitTransaction(); + } + + // add a new book using set + BookType book4 = factory.createBookType(); + { + book4.setBookCategory(BookCategoryType1.FICTION_LITERAL); + book4.setDescription(" The second volume in the Foundation saga. Catastrophic event...."); + book4.setName("Foundation and Empire (The Foundation Series)"); + book4.setISBN(586013555); + book4.setItemId("0586013555"); + book4.setPrice("£5.59"); + + PromotionType promotion = factory.createPromotionType(); + promotion.setNone("none"); + book4.setPromotion(promotion); + + book4.setPublicationDate(store.getDate(new Date("10/10/2003"))); + + AuthorsType author = factory.createAuthorsType(); + author.getAuthorName().add("Isaac Asimov"); + book4.setAuthors(author); + + store.beginTransaction(); + final CollectionType coll = store.getObject(CollectionType.class); + final BooksType books = coll.getBooks(); + books.getBook().set(0, book4); + store.commitTransaction(); + } + + // add the first book again + BookType book0 = factory.createBookType(); + { + book0.setBookCategory(BookCategoryType1.FICTION_LITERAL); + book0.setDescription("In this prequel story to George R. R. Martin's Award winning...."); + book0.setName("The Hedge Knight"); + book0.setISBN(97640110); + book0.setItemId("097640110K"); + book0.setPrice("£6.99"); + + PromotionType promotion = factory.createPromotionType(); + promotion.setDiscount("10%"); + book0.setPromotion(promotion); + + book0.setPublicationDate(store.getDate(new Date("10/10/2003"))); + + AuthorsType author = factory.createAuthorsType(); + author.getAuthorName().add("George R.R. Martin"); + author.getAuthorName().add("Ben Avery"); + book0.setAuthors(author); + + store.beginTransaction(); + final CollectionType coll = store.getObject(CollectionType.class); + final BooksType books = coll.getBooks(); + books.getBook().add(book0); + store.commitTransaction(); + } + + // test remove(object) + { + store.beginTransaction(); + final CollectionType coll = store.getObject(CollectionType.class); + final BooksType books = coll.getBooks(); + assertTrue(books.getBook().size() == 2); + BookType book = books.getBook().get(0); + books.getBook().remove(book); + store.commitTransaction(); + } + + // test clear + { + store.beginTransaction(); + final CollectionType coll = store.getObject(CollectionType.class); + final BooksType books = coll.getBooks(); + assertTrue(books.getBook().size() == 1); + books.getBook().clear(); + store.commitTransaction(); + } + + // now everything should be zero + { + store.beginTransaction(); + final CollectionType coll = store.getObject(CollectionType.class); + final BooksType books = coll.getBooks(); + assertTrue(books.getBook().size() == 0); + store.commitTransaction(); + } + + // these should all be gone + { + store.beginTransaction(); + store.checkNumber(BookType.class, 0); + store.checkNumber(AuthorsType.class, 0); + store.checkNumber(PromotionType.class, 0); + store.commitTransaction(); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/WorkFlowAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/WorkFlowAction.java new file mode 100755 index 000000000..e50b22f3f --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/WorkFlowAction.java @@ -0,0 +1,40 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: WorkFlowAction.java,v 1.3 2008/02/28 07:08:14 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.sample; + +import org.eclipse.emf.teneo.samples.emf.sample.workflow.WorkflowPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests the workflow example. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ +*/ +public class WorkFlowAction extends AbstractTestAction +{ + public WorkFlowAction() + { + super(WorkflowPackage.eINSTANCE); + } + + /** Test */ + public void doAction(TestStore store) + { + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/debFile.ecore b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/debFile.ecore new file mode 100755 index 000000000..0e14027b4 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/debFile.ecore @@ -0,0 +1,77 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<xmi:XMI xmi:version="2.0" + xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"> + <ecore:EPackage name="PrimitiveTypes" nsURI="atl.primitive.type" nsPrefix="ptyp"> + <eClassifiers xsi:type="ecore:EDataType" name="Boolean" instanceClassName="boolean"/> + <eClassifiers xsi:type="ecore:EDataType" name="Integer" instanceClassName="int"/> + <eClassifiers xsi:type="ecore:EDataType" name="String" instanceClassName="java.lang.String"/> + </ecore:EPackage> + <ecore:EPackage name="deb" nsURI="my.model.of.debian.package" nsPrefix="deb"> + <eClassifiers xsi:type="ecore:EClass" name="Deb"> + <eStructuralFeatures xsi:type="ecore:EReference" name="metadata" ordered="false" + lowerBound="1" eType="#/1/Databin" containment="true" eOpposite="#/1/Databin/debpm"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="control" ordered="false" + lowerBound="1" eType="#/1/Archcontrol" containment="true" eOpposite="#/1/Archcontrol/debc"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="data" ordered="false" + lowerBound="1" eType="#/1/Archdata" containment="true" eOpposite="#/1/Archdata/debd"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" ordered="false" + unique="false" lowerBound="1" eType="#/0/String"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="Databin"> + <eStructuralFeatures xsi:type="ecore:EReference" name="debpm" ordered="false" + lowerBound="1" eType="#/1/Deb" eOpposite="#/1/Deb/metadata"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="blocs" ordered="false" + upperBound="-1" eType="#/1/Bloc" containment="true" eOpposite="#/1/Bloc/meta"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="Bloc"> + <eStructuralFeatures xsi:type="ecore:EReference" name="meta" ordered="false" + lowerBound="1" eType="#/1/Databin" eOpposite="#/1/Databin/blocs"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="field" ordered="false" + upperBound="-1" eType="#/1/Field" containment="true" eOpposite="#/1/Field/blocs"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="Field" abstract="true"> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="val" ordered="false" + unique="false" lowerBound="1" eType="#/0/String"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="type" ordered="false" + unique="false" lowerBound="1" eType="#/0/String"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="blocs" ordered="false" + lowerBound="1" eType="#/1/Bloc" eOpposite="#/1/Bloc/field"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="Version" eSuperTypes="#/1/Field"/> + <eClassifiers xsi:type="ecore:EClass" name="package_name" eSuperTypes="#/1/Field"/> + <eClassifiers xsi:type="ecore:EClass" name="Dependancy" eSuperTypes="#/1/Field"/> + <eClassifiers xsi:type="ecore:EClass" name="package_descriptions" eSuperTypes="#/1/Field"/> + <eClassifiers xsi:type="ecore:EClass" name="Script_descriptions" eSuperTypes="#/1/Field"/> + <eClassifiers xsi:type="ecore:EClass" name="Archcontrol"> + <eStructuralFeatures xsi:type="ecore:EReference" name="debc" ordered="false" + lowerBound="1" eType="#/1/Deb" eOpposite="#/1/Deb/control"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="scripts" ordered="false" + upperBound="-1" eType="#/1/Script" containment="true" eOpposite="#/1/Script/archscript"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="Script"> + <eStructuralFeatures xsi:type="ecore:EReference" name="archscript" ordered="false" + lowerBound="1" eType="#/1/Archcontrol" eOpposite="#/1/Archcontrol/scripts"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="script_name" ordered="false" + unique="false" lowerBound="1" eType="#/0/String"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="code" ordered="false" + unique="false" lowerBound="1" eType="#/0/String"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="Archdata"> + <eStructuralFeatures xsi:type="ecore:EReference" name="debd" ordered="false" + lowerBound="1" eType="#/1/Deb" eOpposite="#/1/Deb/data"/> + <eStructuralFeatures xsi:type="ecore:EReference" name="fil" ordered="false" + upperBound="-1" eType="#/1/File" containment="true" eOpposite="#/1/File/data"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" ordered="false" + unique="false" lowerBound="1" eType="#/0/String"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="File"> + <eStructuralFeatures xsi:type="ecore:EReference" name="data" ordered="false" + lowerBound="1" eType="#/1/Archdata" eOpposite="#/1/Archdata/fil"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="filename" ordered="false" + unique="false" lowerBound="1" eType="#/0/String"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="location" ordered="false" + unique="false" lowerBound="1" eType="#/0/String"/> + </eClassifiers> + </ecore:EPackage> +</xmi:XMI> diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/default.mindmap b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/default.mindmap new file mode 100755 index 000000000..d9138ff2f --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/default.mindmap @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8"?> +<mindmap:Map xmlns:mindmap="http://www.example.org/mindmap" title="Eclipse Modeling Project"> + <rootTopics name="Eclipse Modeling Project" resources="#//@resources.0 #//@resources.5 #//@resources.2 #//@resources.3 #//@resources.1 #//@resources.4" subtopics="#//@rootTopics.1"> + <comments subject="Sites of interest"> + <items body="http://www.eclipse.org/modeling"/> + <items body="http://wiki.eclipse.org/index.php/Modeling_Corner"/> + </comments> + </rootTopics> + <rootTopics name="Structure" subtopics="#//@rootTopics.2 #//@rootTopics.3 #//@rootTopics.4 #//@rootTopics.5 #//@rootTopics.28 #//@rootTopics.30"/> + <rootTopics name="Abstract Syntax Development" subtopics="#//@rootTopics.6"/> + <rootTopics name="Concrete Syntax Development" subtopics="#//@rootTopics.13 #//@rootTopics.14"/> + <rootTopics name="Model Transformation" subtopics="#//@rootTopics.15 #//@rootTopics.16"/> + <rootTopics name="Model Development Tools" resources="#//@resources.3" subtopics="#//@rootTopics.17 #//@rootTopics.18 #//@rootTopics.22"/> + <rootTopics name="Eclipse Modeling Framework" resources="#//@resources.0" subtopics="#//@rootTopics.7 #//@rootTopics.8 #//@rootTopics.9 #//@rootTopics.10 #//@rootTopics.11 #//@rootTopics.12"> + <comments subject="Ed's Famous Sayings"> + <items body=""A model is a model, is a model.""/> + </comments> + </rootTopics> + <rootTopics name="Model Query"/> + <rootTopics name="Model Transaction"/> + <rootTopics name="Validation Framework"/> + <rootTopics name="CDO"/> + <rootTopics name="Net4j"/> + <rootTopics name="Teneo"/> + <rootTopics name="Graphical Modeling Framework" resources="#//@resources.1"/> + <rootTopics name="Textual Modeling Framework"/> + <rootTopics name="Model to Model Transformation" subtopics="#//@rootTopics.23 #//@rootTopics.24 #//@rootTopics.25"/> + <rootTopics name="Model to Text Transformation" subtopics="#//@rootTopics.26 #//@rootTopics.27"/> + <rootTopics name="EMF Ontology Definition Metamodel"/> + <rootTopics name="UML2" subtopics="#//@rootTopics.19 #//@rootTopics.20 #//@rootTopics.21"/> + <rootTopics name="Object Constraint Language"/> + <rootTopics name="Unified Modeling Language"/> + <rootTopics name="UML2 Tools"/> + <rootTopics name="XML Schema Infoset Model"/> + <rootTopics name="ATL"/> + <rootTopics name="QVT (Procedural)"/> + <rootTopics name="QVT (Relational)"/> + <rootTopics name="Java Emitter Templates"/> + <rootTopics name="xPand"/> + <rootTopics name="Model Integration" resources="#//@resources.4" subtopics="#//@rootTopics.29"/> + <rootTopics name="MDDi"/> + <rootTopics name="Generative Modeling Technologies" resources="#//@resources.2" subtopics="#//@rootTopics.31 #//@rootTopics.32 #//@rootTopics.33 #//@rootTopics.34 #//@rootTopics.35 #//@rootTopics.36 #//@rootTopics.37 #//@rootTopics.38 #//@rootTopics.39"/> + <rootTopics name="Atlas MegaModel Management (AM3)"/> + <rootTopics name="Atlas Model Weaver (AMW)"/> + <rootTopics name="MOFScript"/> + <rootTopics name="openArchitectureWare"/> + <rootTopics name="UMLX"/> + <rootTopics name="VIATRA2"/> + <rootTopics name="Epsilon"/> + <rootTopics name="GEMS"/> + <rootTopics name="Modisco"/> + <relations label="depends" source="#//@rootTopics.24" target="#//@rootTopics.19" type="DEPENDENCY"/> + <relations label="depends" source="#//@rootTopics.13" target="#//@rootTopics.6" type="DEPENDENCY"/> + <relations label="extends" source="#//@rootTopics.10" target="#//@rootTopics.11" type="EXTENDS"/> + <relations label="includes" source="#//@rootTopics.21" target="#//@rootTopics.20" type="INCLUDES"/> + <resources email="merks@ca.ibm.com" name="Ed Merks" topics="#//@rootTopics.6 #//@rootTopics.0"/> + <resources email="richard.gronback@borland.com" name="Richard Gronback" topics="#//@rootTopics.13 #//@rootTopics.0"/> + <resources email="Jean.Bezivin@univ-nantes.fr" name="Jean Bezivin" topics="#//@rootTopics.30 #//@rootTopics.0"/> + <resources email="khussey@ca.ibm.com" name="Kenn Hussey" topics="#//@rootTopics.5 #//@rootTopics.0"/> + <resources email="sebastien.demathieu@thalesgroup.com" name="Sébastien Demathieu" topics="#//@rootTopics.28 #//@rootTopics.0"/> + <resources email="fplante@ca.ibm.com" name="Fred Plante" topics="#//@rootTopics.0"/> +</mindmap:Map>
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/default.mmd b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/default.mmd new file mode 100755 index 000000000..ef6126139 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/default.mmd @@ -0,0 +1,988 @@ +<?xml version="1.0" encoding="UTF-8"?> +<notation:Diagram xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mindmap="http://www.example.org/mindmap" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.0/notation" xmi:id="_j-cpAHV7Eduq7aELuvLT0w" type="Mindmap" name="default.mmd" measurementUnit="Pixel"> + <children xmi:type="notation:Node" xmi:id="_puU88HV7Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_puXZMHV7Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_puZ1cHV7Eduq7aELuvLT0w" type="7001"> + <children xmi:type="notation:Node" xmi:id="_J-hNMHWEEdummIdfP9dqlw" type="3001"> + <children xmi:type="notation:Node" xmi:id="_J-ibUHWEEdummIdfP9dqlw" type="5001"/> + <children xmi:type="notation:Node" xmi:id="_J-jpcHWEEdummIdfP9dqlw" type="7002"> + <children xmi:type="notation:Node" xmi:id="_LnOQYHWEEdummIdfP9dqlw" type="3002"> + <element xmi:type="mindmap:ThreadItem" href="default.mindmap#//@rootTopics.0/@comments.0/@items.0"/> + <layoutConstraint xmi:type="notation:Location" xmi:id="_LnOQYXWEEdummIdfP9dqlw"/> + </children> + <children xmi:type="notation:Node" xmi:id="_QI8vIHWEEdummIdfP9dqlw" type="3002"> + <element xmi:type="mindmap:ThreadItem" href="default.mindmap#//@rootTopics.0/@comments.0/@items.1"/> + <layoutConstraint xmi:type="notation:Location" xmi:id="_QI8vIXWEEdummIdfP9dqlw"/> + </children> + <styles xmi:type="notation:SortingStyle" xmi:id="_J-jpcXWEEdummIdfP9dqlw"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_J-jpcnWEEdummIdfP9dqlw"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_J-hNMXWEEdummIdfP9dqlw" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_J-hNMnWEEdummIdfP9dqlw"/> + <styles xmi:type="notation:FillStyle" xmi:id="_J-hNM3WEEdummIdfP9dqlw"/> + <styles xmi:type="notation:LineStyle" xmi:id="_J-hNNHWEEdummIdfP9dqlw"/> + <element xmi:type="mindmap:Thread" href="default.mindmap#//@rootTopics.0/@comments.0"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_J-hNNXWEEdummIdfP9dqlw" x="58" y="3"/> + </children> + <styles xmi:type="notation:DrawerStyle" xmi:id="_puZ1cXV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_puZ1cnV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_puZ1c3V7Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_puU88XV7Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_puU88nV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_puU883V7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_puU89HV7Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.0"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_puU89XV7Eduq7aELuvLT0w" x="-36" y="598" width="375" height="114"/> + </children> + <children xmi:type="notation:Node" xmi:id="_sWw-0HV7Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_sWxl4HV7Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_sWxl4XV7Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_sWxl4nV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_sWxl43V7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_sWxl5HV7Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_sWw-0XV7Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_sWw-0nV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_sWw-03V7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_sWw-1HV7Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.1"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_sWw-1XV7Eduq7aELuvLT0w" x="399" y="617"/> + </children> + <children xmi:type="notation:Node" xmi:id="_tLrNkHV7Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_tLr0o3V7Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_tLr0pHV7Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_tLsbsHV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_tLsbsXV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_tLsbsnV7Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_tLrNkXV7Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_tLrNknV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_tLr0oHV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_tLr0oXV7Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.2"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_tLr0onV7Eduq7aELuvLT0w" x="519" y="296"/> + </children> + <children xmi:type="notation:Node" xmi:id="_y5mZsHV7Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_y5nAwHV7Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_y5oO4HV7Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_y5oO4XV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_y5oO4nV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_y5oO43V7Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_y5mZsXV7Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_y5mZsnV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_y5mZs3V7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_y5mZtHV7Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.3"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_y5mZtXV7Eduq7aELuvLT0w" x="519" y="196"/> + </children> + <children xmi:type="notation:Node" xmi:id="_0g5usHV7Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_0g6VwHV7Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_0g6VwXV7Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_0g6VwnV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_0g6Vw3V7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_0g6VxHV7Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_0g5usXV7Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_0g5usnV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_0g5us3V7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_0g5utHV7Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.4"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_0g5utXV7Eduq7aELuvLT0w" x="519" y="817"/> + </children> + <children xmi:type="notation:Node" xmi:id="_4v--QHV7Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_4v_lU3V7Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_4wBagHV7Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_4wBagXV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_4wBagnV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_4wBag3V7Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_4v--QXV7Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_4v--QnV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_4v_lUHV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_4v_lUXV7Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.5"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_4v_lUnV7Eduq7aELuvLT0w" x="519" y="467"/> + </children> + <children xmi:type="notation:Node" xmi:id="_uTC98HV-Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_uTEMEHV-Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_uTEzIHV-Eduq7aELuvLT0w" type="7001"> + <children xmi:type="notation:Node" xmi:id="_hRY-IHWBEduq7aELuvLT0w" type="3001"> + <children xmi:type="notation:Node" xmi:id="_hRZlMHWBEduq7aELuvLT0w" type="5001"/> + <children xmi:type="notation:Node" xmi:id="_hRZlMXWBEduq7aELuvLT0w" type="7002"> + <children xmi:type="notation:Node" xmi:id="_jBaKQHWBEduq7aELuvLT0w" type="3002"> + <element xmi:type="mindmap:ThreadItem" href="default.mindmap#//@rootTopics.6/@comments.0/@items.0"/> + <layoutConstraint xmi:type="notation:Location" xmi:id="_jBaKQXWBEduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:SortingStyle" xmi:id="_hRZlMnWBEduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_hRZlM3WBEduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_hRY-IXWBEduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_hRY-InWBEduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_hRY-I3WBEduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_hRY-JHWBEduq7aELuvLT0w"/> + <element xmi:type="mindmap:Thread" href="default.mindmap#//@rootTopics.6/@comments.0"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_hRY-JXWBEduq7aELuvLT0w" x="78" y="-2"/> + </children> + <styles xmi:type="notation:DrawerStyle" xmi:id="_uTEzIXV-Eduq7aELuvLT0w" collapsed="true"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_uTEzInV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_uTEzI3V-Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_uTC98XV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_uTC98nV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_uTC983V-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_uTC99HV-Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.6"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_uTC99XV-Eduq7aELuvLT0w" x="1002" y="231"/> + </children> + <children xmi:type="notation:Node" xmi:id="_xSBQgHV-Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_xSB3kHV-Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_xSB3kXV-Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_xSB3knV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_xSB3k3V-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_xSB3lHV-Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_xSBQgXV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_xSBQgnV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_xSBQg3V-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_xSBQhHV-Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.7"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_xSBQhXV-Eduq7aELuvLT0w" x="1211" y="30"/> + </children> + <children xmi:type="notation:Node" xmi:id="_y2kzgHV-Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_y2lakHV-Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_y2lakXV-Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_y2laknV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_y2lak3V-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_y2lalHV-Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_y2kzgXV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_y2kzgnV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_y2kzg3V-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_y2kzhHV-Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.8"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_y2kzhXV-Eduq7aELuvLT0w" x="1211" y="251"/> + </children> + <children xmi:type="notation:Node" xmi:id="_0D3tEHV-Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_0D3tFnV-Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_0D4UIHV-Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_0D4UIXV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_0D4UInV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_0D4UI3V-Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_0D3tEXV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_0D3tEnV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_0D3tE3V-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_0D3tFHV-Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.9"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_0D3tFXV-Eduq7aELuvLT0w" x="1211" y="351"/> + </children> + <children xmi:type="notation:Node" xmi:id="_2BOKkHV-Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_2BPYsHV-Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_2BPYsXV-Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_2BPYsnV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_2BPYs3V-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_2BPYtHV-Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_2BOKkXV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_2BOKknV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_2BOKk3V-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_2BOxoHV-Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.10"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_2BOxoXV-Eduq7aELuvLT0w" x="1211" y="130"/> + </children> + <children xmi:type="notation:Node" xmi:id="_23o1MHV-Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_23o1NnV-Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_23pcQHV-Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_23pcQXV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_23pcQnV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_23pcQ3V-Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_23o1MXV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_23o1MnV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_23o1M3V-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_23o1NHV-Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.11"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_23o1NXV-Eduq7aELuvLT0w" x="1416" y="190"/> + </children> + <children xmi:type="notation:Node" xmi:id="_3uHKMHV-Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_3uHKNnV-Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_3uHxQHV-Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_3uHxQXV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_3uHxQnV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_3uHxQ3V-Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_3uHKMXV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_3uHKMnV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_3uHKM3V-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_3uHKNHV-Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.12"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_3uHKNXV-Eduq7aELuvLT0w" x="1211" y="451"/> + </children> + <children xmi:type="notation:Node" xmi:id="_558voHV-Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_558vpnV-Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_559WsHV-Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_559WsXV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_559WsnV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_559Ws3V-Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_558voXV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_558vonV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_558vo3V-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_558vpHV-Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.13"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_558vpXV-Eduq7aELuvLT0w" x="757" y="196"/> + </children> + <children xmi:type="notation:Node" xmi:id="_7ZyKsHV-Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_7ZyxwHV-Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_7ZyxwXV-Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_7ZyxwnV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_7Zyxw3V-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_7ZyxxHV-Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_7ZyKsXV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_7ZyKsnV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_7ZyKs3V-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_7ZyKtHV-Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.14"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_7ZyKtXV-Eduq7aELuvLT0w" x="757" y="96"/> + </children> + <children xmi:type="notation:Node" xmi:id="_8w5uoHV-Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_8w6VsHV-Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_8w6VsXV-Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_8w6VsnV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_8w6Vs3V-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_8w6VtHV-Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_8w5uoXV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_8w5uonV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_8w5uo3V-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_8w5upHV-Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.15"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_8w5upXV-Eduq7aELuvLT0w" x="757" y="817"/> + </children> + <children xmi:type="notation:Node" xmi:id="_-TossHV-Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_-TostnV-Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_-TpTwHV-Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_-TpTwXV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_-TpTwnV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_-TpTw3V-Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_-TossXV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_-TossnV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_-Toss3V-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_-TostHV-Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.16"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_-TostXV-Eduq7aELuvLT0w" x="757" y="917"/> + </children> + <children xmi:type="notation:Node" xmi:id="_AgBEsHV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_AgBrwHV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_AgBrwXV_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_AgBrwnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_AgBrw3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_AgBrxHV_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_AgBEsXV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_AgBEsnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_AgBEs3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_AgBEtHV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.17"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_AgBEtXV_Eduq7aELuvLT0w" x="757" y="317"/> + </children> + <children xmi:type="notation:Node" xmi:id="_DU_twHV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_DU_txnV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_DU_tx3V_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_DVAU0HV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_DVAU0XV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_DVAU0nV_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_DU_twXV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_DU_twnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_DU_tw3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_DU_txHV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.18"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_DU_txXV_Eduq7aELuvLT0w" x="757" y="517"/> + </children> + <children xmi:type="notation:Node" xmi:id="_EFNpwHV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_EFNpxnV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_EFOQ0HV_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_EFOQ0XV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_EFOQ0nV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_EFOQ03V_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_EFNpwXV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_EFNpwnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_EFNpw3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_EFNpxHV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.19"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_EFNpxXV_Eduq7aELuvLT0w" x="1211" y="551"/> + </children> + <children xmi:type="notation:Node" xmi:id="_GG6bwHV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_GG7C0HV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_GG7C0XV_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_GG7C0nV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_GG7C03V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_GG7C1HV_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_GG6bwXV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_GG6bwnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_GG6bw3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_GG6bxHV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.20"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_GG6bxXV_Eduq7aELuvLT0w" x="1002" y="517"/> + </children> + <children xmi:type="notation:Node" xmi:id="_JESL0HV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_JETZ8HV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_JEUBAHV_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_JEUBAXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_JEUBAnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_JEUBA3V_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_JESL0XV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_JESL0nV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_JESL03V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_JESL1HV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.21"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_JESL1XV_Eduq7aELuvLT0w" x="1002" y="617"/> + </children> + <children xmi:type="notation:Node" xmi:id="_Kszo0HV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_Ks0P4HV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_Ks0P4XV_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_Ks0P4nV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_Ks0P43V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_Ks0P5HV_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_Kszo0XV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_Kszo0nV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_Kszo03V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_Kszo1HV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.22"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_Kszo1XV_Eduq7aELuvLT0w" x="757" y="417"/> + </children> + <children xmi:type="notation:Node" xmi:id="_PHwxMHV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_PHwxNnV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_PHwxN3V_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_PHxYQHV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_PHxYQXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_PHxYQnV_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_PHwxMXV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_PHwxMnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_PHwxM3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_PHwxNHV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.23"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_PHwxNXV_Eduq7aELuvLT0w" x="1002" y="817"/> + </children> + <children xmi:type="notation:Node" xmi:id="_PwiocHV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_PwjPgHV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_PwjPgXV_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_PwjPgnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_PwjPg3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_PwjPhHV_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_PwiocXV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_PwiocnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_Pwioc3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_PwiodHV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.24"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_PwiodXV_Eduq7aELuvLT0w" x="1002" y="717"/> + </children> + <children xmi:type="notation:Node" xmi:id="_Q6odAHV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_Q6odBnV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_Q6odB3V_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_Q6odCHV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_Q6odCXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_Q6odCnV_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_Q6odAXV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_Q6odAnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_Q6odA3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_Q6odBHV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.25"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_Q6odBXV_Eduq7aELuvLT0w" x="1002" y="917"/> + </children> + <children xmi:type="notation:Node" xmi:id="_leWYsHV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_leWYtnV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_leW_wHV_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_leW_wXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_leW_wnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_leW_w3V_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_leWYsXV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_leWYsnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_leWYs3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_leWYtHV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.26"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_leWYtXV_Eduq7aELuvLT0w" x="1002" y="1017"/> + </children> + <children xmi:type="notation:Node" xmi:id="_nHXk8HV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_nHYMAHV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_nHYMAXV_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_nHYMAnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_nHYMA3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_nHYMBHV_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_nHXk8XV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_nHXk8nV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_nHXk83V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_nHXk9HV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.27"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_nHXk9XV_Eduq7aELuvLT0w" x="1002" y="1117"/> + </children> + <children xmi:type="notation:Node" xmi:id="_omnxMHV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_omoYQHV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_omoYQXV_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_omoYQnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_omoYQ3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_omoYRHV_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_omnxMXV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_omnxMnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_omnxM3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_omnxNHV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.28"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_omnxNXV_Eduq7aELuvLT0w" x="519" y="617"/> + </children> + <children xmi:type="notation:Node" xmi:id="_pSTygHV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_pSTyhnV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_pSTyh3V_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_pSTyiHV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_pSTyiXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_pSUZkHV_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_pSTygXV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_pSTygnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_pSTyg3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_pSTyhHV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.29"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_pSTyhXV_Eduq7aELuvLT0w" x="757" y="617"/> + </children> + <children xmi:type="notation:Node" xmi:id="_qlstAHV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_qltUEHV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_qltUEXV_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_qltUEnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_qltUE3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_qltUFHV_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_qlstAXV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_qlstAnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_qlstA3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_qlstBHV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.30"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_qlstBXV_Eduq7aELuvLT0w" x="519" y="1337"/> + </children> + <children xmi:type="notation:Node" xmi:id="_sGSWAHV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_sGS9EHV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_sGS9EXV_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_sGS9EnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_sGS9E3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_sGS9FHV_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_sGSWAXV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_sGSWAnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_sGSWA3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_sGSWBHV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.31"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_sGSWBXV_Eduq7aELuvLT0w" x="757" y="1017"/> + </children> + <children xmi:type="notation:Node" xmi:id="_xXMO8HV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_xXMO9nV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_xXM2AHV_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_xXM2AXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_xXM2AnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_xXM2A3V_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_xXMO8XV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_xXMO8nV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_xXMO83V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_xXMO9HV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.32"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_xXMO9XV_Eduq7aELuvLT0w" x="757" y="1117"/> + </children> + <children xmi:type="notation:Node" xmi:id="_zoUkEHV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_zoVLIHV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_zoVLIXV_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_zoVLInV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_zoVLI3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_zoVLJHV_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_zoUkEXV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_zoUkEnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_zoUkE3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_zoUkFHV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.33"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_zoUkFXV_Eduq7aELuvLT0w" x="757" y="1217"/> + </children> + <children xmi:type="notation:Node" xmi:id="_3q_vUHV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_3rAWYHV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_3rAWYXV_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_3rAWYnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_3rAWY3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_3rAWZHV_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_3q_vUXV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_3q_vUnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_3q_vU3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_3q_vVHV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.34"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_3q_vVXV_Eduq7aELuvLT0w" x="757" y="1317"/> + </children> + <children xmi:type="notation:Node" xmi:id="_5iD-oHV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_5iElsHV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_5iElsXV_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_5iElsnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_5iEls3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_5iEltHV_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_5iD-oXV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_5iD-onV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_5iD-o3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_5iD-pHV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.35"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_5iD-pXV_Eduq7aELuvLT0w" x="757" y="1417"/> + </children> + <children xmi:type="notation:Node" xmi:id="_6vCvIHV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_6vDWMHV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_6vDWMXV_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_6vDWMnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_6vDWM3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_6vDWNHV_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_6vCvIXV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_6vCvInV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_6vCvI3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_6vCvJHV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.36"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_6vCvJXV_Eduq7aELuvLT0w" x="757" y="1517"/> + </children> + <children xmi:type="notation:Node" xmi:id="_7qoNoHV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_7qo0sHV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_7qo0sXV_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_7qo0snV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_7qo0s3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_7qo0tHV_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_7qoNoXV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_7qoNonV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_7qoNo3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_7qoNpHV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.37"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_7qoNpXV_Eduq7aELuvLT0w" x="757" y="1617"/> + </children> + <children xmi:type="notation:Node" xmi:id="_8fqYMHV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_8fqYNnV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_8fq_QHV_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_8fq_QXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_8fq_QnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_8fq_Q3V_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_8fqYMXV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_8fqYMnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_8fqYM3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_8fqYNHV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.38"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_8fqYNXV_Eduq7aELuvLT0w" x="757" y="1717"/> + </children> + <children xmi:type="notation:Node" xmi:id="_9g5LsHV_Eduq7aELuvLT0w" type="2001"> + <children xmi:type="notation:Node" xmi:id="_9g5LtnV_Eduq7aELuvLT0w" type="5002"/> + <children xmi:type="notation:Node" xmi:id="_9g5ywHV_Eduq7aELuvLT0w" type="7001"> + <styles xmi:type="notation:DrawerStyle" xmi:id="_9g5ywXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_9g5ywnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_9g5yw3V_Eduq7aELuvLT0w"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_9g5LsXV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_9g5LsnV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_9g5Ls3V_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_9g5LtHV_Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Topic" href="default.mindmap#//@rootTopics.39"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_9g5LtXV_Eduq7aELuvLT0w" x="757" y="1817"/> + </children> + <children xmi:type="notation:Node" xmi:id="_wh_P0HWAEduq7aELuvLT0w" type="2002"> + <children xmi:type="notation:Node" xmi:id="_wiAd8HWAEduq7aELuvLT0w" type="5003"> + <layoutConstraint xmi:type="notation:Location" xmi:id="_wiAd8XWAEduq7aELuvLT0w" y="5"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_wh_P0XWAEduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_wh_P0nWAEduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_wh_P03WAEduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_wh_P1HWAEduq7aELuvLT0w"/> + <element xmi:type="mindmap:Resource" href="default.mindmap#//@resources.0"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_wh_P1XWAEduq7aELuvLT0w" x="30" y="140"/> + </children> + <children xmi:type="notation:Node" xmi:id="_10pcQHWAEduq7aELuvLT0w" type="2002"> + <children xmi:type="notation:Node" xmi:id="_10pcRnWAEduq7aELuvLT0w" type="5003"> + <layoutConstraint xmi:type="notation:Location" xmi:id="_10pcR3WAEduq7aELuvLT0w" y="5"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_10pcQXWAEduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_10pcQnWAEduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_10pcQ3WAEduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_10pcRHWAEduq7aELuvLT0w"/> + <element xmi:type="mindmap:Resource" href="default.mindmap#//@resources.1"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_10pcRXWAEduq7aELuvLT0w" x="30" y="369"/> + </children> + <children xmi:type="notation:Node" xmi:id="_OdwgAHWBEduq7aELuvLT0w" type="2002"> + <children xmi:type="notation:Node" xmi:id="_OdxuIHWBEduq7aELuvLT0w" type="5003"> + <layoutConstraint xmi:type="notation:Location" xmi:id="_OdxuIXWBEduq7aELuvLT0w" y="5"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_OdwgAXWBEduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_OdwgAnWBEduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_OdwgA3WBEduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_OdwgBHWBEduq7aELuvLT0w"/> + <element xmi:type="mindmap:Resource" href="default.mindmap#//@resources.2"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_OdwgBXWBEduq7aELuvLT0w" x="30" y="875"/> + </children> + <children xmi:type="notation:Node" xmi:id="_SnHiEHWBEduq7aELuvLT0w" type="2002"> + <children xmi:type="notation:Node" xmi:id="_SnHiFnWBEduq7aELuvLT0w" type="5003"> + <layoutConstraint xmi:type="notation:Location" xmi:id="_SnHiF3WBEduq7aELuvLT0w" y="5"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_SnHiEXWBEduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_SnHiEnWBEduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_SnHiE3WBEduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_SnHiFHWBEduq7aELuvLT0w"/> + <element xmi:type="mindmap:Resource" href="default.mindmap#//@resources.3"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_SnHiFXWBEduq7aELuvLT0w" x="30" y="1134"/> + </children> + <children xmi:type="notation:Node" xmi:id="_VSxQAHWBEduq7aELuvLT0w" type="2002"> + <children xmi:type="notation:Node" xmi:id="_VSx3EHWBEduq7aELuvLT0w" type="5003"> + <layoutConstraint xmi:type="notation:Location" xmi:id="_VSx3EXWBEduq7aELuvLT0w" y="5"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_VSxQAXWBEduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_VSxQAnWBEduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_VSxQA3WBEduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_VSxQBHWBEduq7aELuvLT0w"/> + <element xmi:type="mindmap:Resource" href="default.mindmap#//@resources.4"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_VSxQBXWBEduq7aELuvLT0w" x="30" y="1394"/> + </children> + <children xmi:type="notation:Node" xmi:id="_b4xToHWBEduq7aELuvLT0w" type="2002"> + <children xmi:type="notation:Node" xmi:id="_b4xTpnWBEduq7aELuvLT0w" type="5003"> + <layoutConstraint xmi:type="notation:Location" xmi:id="_b4xTp3WBEduq7aELuvLT0w" y="5"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_b4xToXWBEduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_b4xTonWBEduq7aELuvLT0w"/> + <styles xmi:type="notation:FillStyle" xmi:id="_b4xTo3WBEduq7aELuvLT0w"/> + <styles xmi:type="notation:LineStyle" xmi:id="_b4xTpHWBEduq7aELuvLT0w"/> + <element xmi:type="mindmap:Resource" href="default.mindmap#//@resources.5"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_b4xTpXWBEduq7aELuvLT0w" x="30" y="1655"/> + </children> + <styles xmi:type="notation:PageStyle" xmi:id="_j-dQEHV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:GuideStyle" xmi:id="_j-dQEXV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:DescriptionStyle" xmi:id="_j-dQEnV7Eduq7aELuvLT0w"/> + <element xmi:type="mindmap:Map" href="default.mindmap#//@map"/> + <edges xmi:type="notation:Edge" xmi:id="_sXNDsHV7Eduq7aELuvLT0w" type="4001" source="_puU88HV7Eduq7aELuvLT0w" target="_sWw-0HV7Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_sXNDsXV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_sXNDsnV7Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_sXNDs3V7Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_sXNDtHV7Eduq7aELuvLT0w" points="[155, 0, -90, 0]$[215, 0, -30, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_tL3a0HV7Eduq7aELuvLT0w" type="4001" source="_sWw-0HV7Eduq7aELuvLT0w" target="_tLrNkHV7Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_tL3a0XV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_tL3a0nV7Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_tL3a03V7Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_tL3a1HV7Eduq7aELuvLT0w" points="[30, 0, -149, 321]$[90, -321, -89, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_y5xY0HV7Eduq7aELuvLT0w" type="4001" source="_sWw-0HV7Eduq7aELuvLT0w" target="_y5mZsHV7Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_y5xY0XV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_y5xY0nV7Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_y5xY03V7Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_y5xY1HV7Eduq7aELuvLT0w" points="[30, 0, -149, 421]$[90, -421, -89, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_0hC4oHV7Eduq7aELuvLT0w" type="4001" source="_sWw-0HV7Eduq7aELuvLT0w" target="_0g5usHV7Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_0hC4oXV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_0hC4onV7Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_0hC4o3V7Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_0hC4pHV7Eduq7aELuvLT0w" points="[30, 0, -149, -200]$[90, 200, -89, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_4wHhIHV7Eduq7aELuvLT0w" type="4001" source="_sWw-0HV7Eduq7aELuvLT0w" target="_4v--QHV7Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_4wHhIXV7Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_4wHhInV7Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_4wIIMHV7Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_4wIIMXV7Eduq7aELuvLT0w" points="[30, 0, -149, 150]$[90, -150, -89, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_uTJroHV-Eduq7aELuvLT0w" type="4001" source="_tLrNkHV7Eduq7aELuvLT0w" target="_uTC98HV-Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_uTJroXV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_uTJronV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_uTJro3V-Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_uTJrpHV-Eduq7aELuvLT0w" points="[89, 0, -379, 65]$[241, -40, -227, 25]$[394, -65, -74, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_xSIlQHV-Eduq7aELuvLT0w" type="4001" source="_uTC98HV-Eduq7aELuvLT0w" target="_xSBQgHV-Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_xSIlQXV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_xSIlQnV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_xSIlQ3V-Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_xSIlRHV-Eduq7aELuvLT0w" points="[75, 0, -132, 201]$[135, -201, -72, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_y2q6IHV-Eduq7aELuvLT0w" type="4001" source="_uTC98HV-Eduq7aELuvLT0w" target="_y2kzgHV-Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_y2q6IXV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_y2q6InV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_y2q6I3V-Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_y2q6JHV-Eduq7aELuvLT0w" points="[75, 0, -132, -20]$[135, 20, -72, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_0D9MoHV-Eduq7aELuvLT0w" type="4001" source="_uTC98HV-Eduq7aELuvLT0w" target="_0D3tEHV-Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_0D9MoXV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_0D9MonV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_0D9Mo3V-Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_0D9MpHV-Eduq7aELuvLT0w" points="[75, 0, -132, -120]$[135, 120, -72, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_2BWGYHV-Eduq7aELuvLT0w" type="4001" source="_uTC98HV-Eduq7aELuvLT0w" target="_2BOKkHV-Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_2BWGYXV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_2BWGYnV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_2BWGY3V-Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_2BWGZHV-Eduq7aELuvLT0w" points="[75, 0, -132, 101]$[135, -101, -72, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_23vi4HV-Eduq7aELuvLT0w" type="4001" source="_uTC98HV-Eduq7aELuvLT0w" target="_23o1MHV-Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_23vi4XV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_23vi4nV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_23vi43V-Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_23vi5HV-Eduq7aELuvLT0w" points="[75, 0, -286, 41]$[207, -41, -154, 0]$[340, -41, -21, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_3uOe8HV-Eduq7aELuvLT0w" type="4001" source="_uTC98HV-Eduq7aELuvLT0w" target="_3uHKMHV-Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_3uOe8XV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_3uOe8nV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_3uOe83V-Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_3uOe9HV-Eduq7aELuvLT0w" points="[75, 0, -132, -220]$[135, 220, -72, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_56DdUHV-Eduq7aELuvLT0w" type="4001" source="_y5mZsHV7Eduq7aELuvLT0w" target="_558voHV-Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_56DdUXV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_56DdUnV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_56DdU3V-Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_56DdVHV-Eduq7aELuvLT0w" points="[89, 0, -152, 0]$[149, 0, -92, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_7Z6tkHV-Eduq7aELuvLT0w" type="4001" source="_y5mZsHV7Eduq7aELuvLT0w" target="_7ZyKsHV-Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_7Z6tkXV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_7Z6tknV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_7Z6tk3V-Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_7Z6tlHV-Eduq7aELuvLT0w" points="[89, 0, -152, 100]$[149, -100, -92, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_8xAcUHV-Eduq7aELuvLT0w" type="4001" source="_0g5usHV7Eduq7aELuvLT0w" target="_8w5uoHV-Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_8xAcUXV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_8xBDYHV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_8xBDYXV-Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_8xBDYnV-Eduq7aELuvLT0w" points="[89, 0, -152, 0]$[149, 0, -92, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_-TwBcHV-Eduq7aELuvLT0w" type="4001" source="_0g5usHV7Eduq7aELuvLT0w" target="_-TossHV-Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_-TwBcXV-Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_-TwBcnV-Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_-TwBc3V-Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_-TwBdHV-Eduq7aELuvLT0w" points="[89, 0, -152, -100]$[149, 100, -92, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_AgKOoHV_Eduq7aELuvLT0w" type="4001" source="_4v--QHV7Eduq7aELuvLT0w" target="_AgBEsHV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_AgKOoXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_AgKOonV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_AgKOo3V_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_AgKOpHV_Eduq7aELuvLT0w" points="[89, 0, -152, 150]$[149, -150, -92, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_DVF0YHV_Eduq7aELuvLT0w" type="4001" source="_4v--QHV7Eduq7aELuvLT0w" target="_DU_twHV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_DVF0YXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_DVF0YnV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_DVF0Y3V_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_DVF0ZHV_Eduq7aELuvLT0w" points="[89, 0, -152, -50]$[149, 50, -92, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_EFUXcHV_Eduq7aELuvLT0w" type="4001" source="_DU_twHV_Eduq7aELuvLT0w" target="_EFNpwHV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_EFUXcXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_EFUXcnV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_EFUXc3V_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_EFUXdHV_Eduq7aELuvLT0w" points="[93, 0, -341, -34]$[227, -61, -207, -95]$[362, 34, -72, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_GHC-oHV_Eduq7aELuvLT0w" type="4001" source="_DU_twHV_Eduq7aELuvLT0w" target="_GG6bwHV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_GHC-oXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_GHC-onV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_GHC-o3V_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_GHC-pHV_Eduq7aELuvLT0w" points="[93, 0, -134, 0]$[153, 0, -74, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_JEdK8HV_Eduq7aELuvLT0w" type="4001" source="_DU_twHV_Eduq7aELuvLT0w" target="_JESL0HV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_JEdK8XV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_JEdK8nV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_JEdK83V_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_JEdK9HV_Eduq7aELuvLT0w" points="[93, 0, -134, -100]$[153, 100, -74, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_Ks6WgHV_Eduq7aELuvLT0w" type="4001" source="_4v--QHV7Eduq7aELuvLT0w" target="_Kszo0HV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_Ks6WgXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_Ks6WgnV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_Ks6Wg3V_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_Ks6WhHV_Eduq7aELuvLT0w" points="[89, 0, -152, 50]$[149, -50, -92, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_PH3e4HV_Eduq7aELuvLT0w" type="4001" source="_8w5uoHV-Eduq7aELuvLT0w" target="_PHwxMHV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_PH3e4XV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_PH3e4nV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_PH3e43V_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_PH3e5HV_Eduq7aELuvLT0w" points="[93, 0, -134, 0]$[153, 0, -74, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_PwpWIHV_Eduq7aELuvLT0w" type="4001" source="_8w5uoHV-Eduq7aELuvLT0w" target="_PwiocHV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_PwpWIXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_PwpWInV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_PwpWI3V_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_PwpWJHV_Eduq7aELuvLT0w" points="[93, 0, -134, 100]$[153, -100, -74, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_Q6w_4HV_Eduq7aELuvLT0w" type="4001" source="_8w5uoHV-Eduq7aELuvLT0w" target="_Q6odAHV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_Q6w_4XV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_Q6w_4nV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_Q6w_43V_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_Q6w_5HV_Eduq7aELuvLT0w" points="[93, 0, -134, -100]$[153, 100, -74, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_ledtcHV_Eduq7aELuvLT0w" type="4001" source="_-TossHV-Eduq7aELuvLT0w" target="_leWYsHV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_ledtcXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_ledtcnV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_ledtc3V_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_ledtdHV_Eduq7aELuvLT0w" points="[93, 0, -134, -100]$[153, 100, -74, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_nHdrkHV_Eduq7aELuvLT0w" type="4001" source="_-TossHV-Eduq7aELuvLT0w" target="_nHXk8HV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_nHdrkXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_nHdrknV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_nHdrk3V_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_nHdrlHV_Eduq7aELuvLT0w" points="[93, 0, -134, -200]$[153, 200, -74, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_omz-cHV_Eduq7aELuvLT0w" type="4001" source="_sWw-0HV7Eduq7aELuvLT0w" target="_omnxMHV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_omz-cXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_omz-cnV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_omz-c3V_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_omz-dHV_Eduq7aELuvLT0w" points="[30, 0, -149, 0]$[90, 0, -89, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_pSZSEHV_Eduq7aELuvLT0w" type="4001" source="_omnxMHV_Eduq7aELuvLT0w" target="_pSTygHV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_pSZSEXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_pSZSEnV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_pSZSE3V_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_pSZSFHV_Eduq7aELuvLT0w" points="[89, 0, -152, 0]$[149, 0, -92, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_ql0BwHV_Eduq7aELuvLT0w" type="4001" source="_sWw-0HV7Eduq7aELuvLT0w" target="_qlstAHV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_ql0o0HV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_ql0o0XV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_ql0o0nV_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_ql0o03V_Eduq7aELuvLT0w" points="[30, 0, -149, -720]$[90, 720, -89, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_sGYcoHV_Eduq7aELuvLT0w" type="4001" source="_qlstAHV_Eduq7aELuvLT0w" target="_sGSWAHV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_sGYcoXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_sGYconV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_sGYco3V_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_sGYcpHV_Eduq7aELuvLT0w" points="[89, 0, -152, 320]$[149, -320, -92, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_xXRugHV_Eduq7aELuvLT0w" type="4001" source="_qlstAHV_Eduq7aELuvLT0w" target="_xXMO8HV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_xXRugXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_xXRugnV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_xXRug3V_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_xXRuhHV_Eduq7aELuvLT0w" points="[89, 0, -152, 220]$[149, -220, -92, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_zoaDoHV_Eduq7aELuvLT0w" type="4001" source="_qlstAHV_Eduq7aELuvLT0w" target="_zoUkEHV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_zoaDoXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_zoaDonV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_zoaDo3V_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_zoaDpHV_Eduq7aELuvLT0w" points="[89, 0, -152, 120]$[149, -120, -92, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_3rHEEHV_Eduq7aELuvLT0w" type="4001" source="_qlstAHV_Eduq7aELuvLT0w" target="_3q_vUHV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_3rHEEXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_3rHEEnV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_3rHEE3V_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_3rHEFHV_Eduq7aELuvLT0w" points="[89, 0, -152, 20]$[149, -20, -92, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_5iKFQHV_Eduq7aELuvLT0w" type="4001" source="_qlstAHV_Eduq7aELuvLT0w" target="_5iD-oHV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_5iKsUHV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_5iKsUXV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_5iKsUnV_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_5iKsU3V_Eduq7aELuvLT0w" points="[89, 0, -152, -80]$[149, 80, -92, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_6vJc0HV_Eduq7aELuvLT0w" type="4001" source="_qlstAHV_Eduq7aELuvLT0w" target="_6vCvIHV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_6vJc0XV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_6vJc0nV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_6vJc03V_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_6vJc1HV_Eduq7aELuvLT0w" points="[89, 0, -152, -180]$[149, 180, -92, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_7qu7UHV_Eduq7aELuvLT0w" type="4001" source="_qlstAHV_Eduq7aELuvLT0w" target="_7qoNoHV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_7qu7UXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_7qu7UnV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_7qu7U3V_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_7qu7VHV_Eduq7aELuvLT0w" points="[89, 0, -152, -280]$[149, 280, -92, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_8fwe0HV_Eduq7aELuvLT0w" type="4001" source="_qlstAHV_Eduq7aELuvLT0w" target="_8fqYMHV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_8fwe0XV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_8fwe0nV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_8fwe03V_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_8fwe1HV_Eduq7aELuvLT0w" points="[89, 0, -152, -380]$[149, 380, -92, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_9g_SUHV_Eduq7aELuvLT0w" type="4001" source="_qlstAHV_Eduq7aELuvLT0w" target="_9g5LsHV_Eduq7aELuvLT0w"> + <styles xmi:type="notation:RoutingStyle" xmi:id="_9g_SUXV_Eduq7aELuvLT0w"/> + <styles xmi:type="notation:FontStyle" xmi:id="_9g_SUnV_Eduq7aELuvLT0w" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_9g_SU3V_Eduq7aELuvLT0w"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_9g_SVHV_Eduq7aELuvLT0w" points="[89, 0, -152, -480]$[149, 480, -92, 0]"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_Ah7W8HWEEdummIdfP9dqlw" type="4003" source="_PwiocHV_Eduq7aELuvLT0w" target="_EFNpwHV_Eduq7aELuvLT0w"> + <children xmi:type="notation:Node" xmi:id="_Ah-aQHWEEdummIdfP9dqlw" type="6002"> + <layoutConstraint xmi:type="notation:Location" xmi:id="_Ah-aQXWEEdummIdfP9dqlw" y="40"/> + </children> + <styles xmi:type="notation:RoutingStyle" xmi:id="_Ah7-AHWEEdummIdfP9dqlw"/> + <styles xmi:type="notation:FontStyle" xmi:id="_Ah7-AXWEEdummIdfP9dqlw" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_Ah7-AnWEEdummIdfP9dqlw"/> + <element xmi:type="mindmap:Relationship" href="default.mindmap#//@relations.0"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_Ah7-A3WEEdummIdfP9dqlw" points="[75, 0, -132, 166]$[135, -166, -72, 0]"/> + <sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_AiIyUHWEEdummIdfP9dqlw" id="(0.75,0.15)"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_FNvl0HWEEdummIdfP9dqlw" type="4003" source="_558voHV-Eduq7aELuvLT0w" target="_uTC98HV-Eduq7aELuvLT0w"> + <children xmi:type="notation:Node" xmi:id="_FNwM4HWEEdummIdfP9dqlw" type="6002"> + <layoutConstraint xmi:type="notation:Location" xmi:id="_FNwM4XWEEdummIdfP9dqlw" y="40"/> + </children> + <styles xmi:type="notation:RoutingStyle" xmi:id="_FNvl0XWEEdummIdfP9dqlw"/> + <styles xmi:type="notation:FontStyle" xmi:id="_FNvl0nWEEdummIdfP9dqlw" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_FNvl03WEEdummIdfP9dqlw"/> + <element xmi:type="mindmap:Relationship" href="default.mindmap#//@relations.1"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_FNvl1HWEEdummIdfP9dqlw" points="[93, 0, -134, -35]$[153, 35, -74, 0]"/> + <targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_FNypIHWEEdummIdfP9dqlw" id="(0.45637584,0.125)"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_HedEMHWEEdummIdfP9dqlw" type="4002" source="_2BOKkHV-Eduq7aELuvLT0w" target="_23o1MHV-Eduq7aELuvLT0w"> + <children xmi:type="notation:Node" xmi:id="_HeeSUHWEEdummIdfP9dqlw" type="6001"> + <layoutConstraint xmi:type="notation:Location" xmi:id="_HeeSUXWEEdummIdfP9dqlw" y="40"/> + </children> + <styles xmi:type="notation:RoutingStyle" xmi:id="_HedEMXWEEdummIdfP9dqlw"/> + <styles xmi:type="notation:FontStyle" xmi:id="_HedEMnWEEdummIdfP9dqlw" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_HedEM3WEEdummIdfP9dqlw"/> + <element xmi:type="mindmap:Relationship" href="default.mindmap#//@relations.2"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_HedENHWEEdummIdfP9dqlw" points="[73, 0, -81, -60]$[133, 60, -21, 0]"/> + <targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_HekY8HWEEdummIdfP9dqlw" id="(0.55813956,0.175)"/> + </edges> + <edges xmi:type="notation:Edge" xmi:id="_gXWQYHWEEdummIdfP9dqlw" type="4004" source="_JESL0HV_Eduq7aELuvLT0w" target="_GG6bwHV_Eduq7aELuvLT0w"> + <children xmi:type="notation:Node" xmi:id="_gXXegHWEEdummIdfP9dqlw" type="6003"> + <layoutConstraint xmi:type="notation:Location" xmi:id="_gXXegXWEEdummIdfP9dqlw" y="40"/> + </children> + <styles xmi:type="notation:RoutingStyle" xmi:id="_gXWQYXWEEdummIdfP9dqlw"/> + <styles xmi:type="notation:FontStyle" xmi:id="_gXWQYnWEEdummIdfP9dqlw" fontName="Lucida Grande"/> + <styles xmi:type="notation:LineStyle" xmi:id="_gXWQY3WEEdummIdfP9dqlw"/> + <element xmi:type="mindmap:Relationship" href="default.mindmap#//@relations.3"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_gXWQZHWEEdummIdfP9dqlw" points="[-7, -8, -30, 80]$[-49, -94, -72, -6]"/> + <sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_gXc-EHWEEdummIdfP9dqlw" id="(0.6712329,0.2)"/> + </edges> +</notation:Diagram> diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/library.ecore b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/library.ecore new file mode 100755 index 000000000..f23b12e84 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/library.ecore @@ -0,0 +1,104 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ecore:EPackage xmi:version="2.0" + xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="library" + nsURI="http://www.eclipse.org/emf/teneo/samples/emf/sample/Library" nsPrefix="library"> + <eClassifiers xsi:type="ecore:EClass" name="Book"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="name" value="Book"/> + <details key="kind" value="elementOnly"/> + </eAnnotations> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="title" unique="false" lowerBound="1" + eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="kind" value="element"/> + <details key="name" value="title"/> + </eAnnotations> + </eStructuralFeatures> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="pages" unique="false" lowerBound="1" + eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//Int" unsettable="true"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="kind" value="element"/> + <details key="name" value="pages"/> + </eAnnotations> + </eStructuralFeatures> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="category" unique="false" + lowerBound="1" eType="#//BookCategory" defaultValueLiteral="Mystery" unsettable="true"> + <eAnnotations source="teneo.jpa"> + <details key="appinfo" value="@Enumerated(ORDINAL)"/> + </eAnnotations> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="kind" value="element"/> + <details key="name" value="category"/> + </eAnnotations> + </eStructuralFeatures> + <eStructuralFeatures xsi:type="ecore:EReference" name="author" lowerBound="1" + eType="#//Writer" eOpposite="#//Writer/books"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="kind" value="element"/> + <details key="name" value="author"/> + </eAnnotations> + </eStructuralFeatures> + </eClassifiers> + <eClassifiers xsi:type="ecore:EEnum" name="BookCategory"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="name" value="BookCategory"/> + </eAnnotations> + <eLiterals name="Mystery"/> + <eLiterals name="ScienceFiction" value="1"/> + <eLiterals name="Biography" value="2"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EDataType" name="BookCategoryObject" instanceClassName="org.eclipse.emf.common.util.Enumerator"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="name" value="BookCategory:Object"/> + <details key="baseType" value="BookCategory"/> + </eAnnotations> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="Library"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="name" value="Library"/> + <details key="kind" value="elementOnly"/> + </eAnnotations> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" unique="false" lowerBound="1" + eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="kind" value="element"/> + <details key="name" value="name"/> + </eAnnotations> + </eStructuralFeatures> + <eStructuralFeatures xsi:type="ecore:EReference" name="writers" upperBound="-1" + eType="#//Writer" containment="true" resolveProxies="false"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="kind" value="element"/> + <details key="name" value="writers"/> + </eAnnotations> + </eStructuralFeatures> + <eStructuralFeatures xsi:type="ecore:EReference" name="books" upperBound="-1" + eType="#//Book" containment="true" resolveProxies="false"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="kind" value="element"/> + <details key="name" value="books"/> + </eAnnotations> + </eStructuralFeatures> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="Writer"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="name" value="Writer"/> + <details key="kind" value="elementOnly"/> + </eAnnotations> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" unique="false" lowerBound="1" + eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="kind" value="element"/> + <details key="name" value="name"/> + </eAnnotations> + </eStructuralFeatures> + <eStructuralFeatures xsi:type="ecore:EReference" name="books" upperBound="-1" + eType="#//Book" eOpposite="#//Book/author"> + <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData"> + <details key="kind" value="element"/> + <details key="name" value="books"/> + </eAnnotations> + </eStructuralFeatures> + </eClassifiers> +</ecore:EPackage> diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/AnyTypeAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/AnyTypeAction.java new file mode 100755 index 000000000..b9a03ffa9 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/AnyTypeAction.java @@ -0,0 +1,237 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: AnyTypeAction.java,v 1.6 2008/04/07 15:14:15 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.schemaconstructs; + +import java.util.Collection; +import java.util.Iterator; + +import org.eclipse.emf.ecore.util.FeatureMap; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.anytype.A; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.anytype.AnytypeFactory; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.anytype.AnytypePackage; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.anytype.B; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.anytype.TestAny; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Test: - Single occurence any type - any - any with ecore:name + * + * Test: - Create and insert - Retrieve - Delete with cascading delete + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.6 $ + */ +public class AnyTypeAction extends AbstractTestAction { + + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public AnyTypeAction() { + super(AnytypePackage.eINSTANCE); + } + + /** Creates simple types and tests against */ + @Override + public void doAction(TestStore store) { + // test a simple type + final AnytypeFactory factory = AnytypeFactory.eINSTANCE; + { + store.beginTransaction(); + + TestAny testAny = factory.createTestAny(); + testAny.setName("my name"); + + // test single AnyType + // 1 + B b = factory.createB(); + b.setName("myb1"); + testAny.setSingleAnyType(b); + + // test multi AnyType + // 2 + B b2 = factory.createB(); + b2.setName("myb2"); + testAny.getMultiAnyType().add(b2); + + A a = factory.createA(); + a.setDoub(5.4); + a.setLon(150); + a.setName("mya"); + B b3 = factory.createB(); + b3.setName("myb3"); + a.setMyB(b3); + // 3 + testAny.getMultiAnyType().add(a); + + // test any type + testAny.getAny().add(AnytypePackage.eINSTANCE.getB_Name(), "my b"); + testAny.getAny().add(AnytypePackage.eINSTANCE.getA_Doub(), new Double(3.0)); + testAny.setA("a"); + B b4 = factory.createB(); + b4.setName("myb4"); + testAny.getAny().add(AnytypePackage.eINSTANCE.getA_MyB(), b4); + + testAny.getMyAny().add(AnytypePackage.eINSTANCE.getB_Name(), "my b my any"); + testAny.getMyAny().add(AnytypePackage.eINSTANCE.getA_Doub(), new Double(3.4)); + B b5 = factory.createB(); + b5.setName("myb5"); + testAny.getMyAny().add(AnytypePackage.eINSTANCE.getA_MyB(), b5); + + store.store(testAny); + store.commitTransaction(); + } + { + store.beginTransaction(); + TestAny testAny = store.getObject(TestAny.class); + + // check singleAny + { + B b = (B) testAny.getSingleAnyType(); + assertTrue(b.getName().compareTo("myb1") == 0); + assertTrue(b.eContainer() == testAny); + } + + // check MultiAny + for (int i = 0; i < testAny.getMultiAnyType().size(); i++) { + if (i == 0) // a b2 + { + B b = (B) testAny.getMultiAnyType().get(i); + assertTrue(b.getName().compareTo("myb2") == 0); + assertTrue(b.eContainer() == testAny); + } else if (i == 1) { + A a = (A) testAny.getMultiAnyType().get(i); + assertEquals(5.4, a.getDoub(), 0.01); + assertTrue(a.getLon() == 150); + assertTrue(a.getName().compareTo("mya") == 0); + assertTrue(a.getMyB().getName().compareTo("myb3") == 0); + assertTrue(a.eContainer() == testAny); + } else { + assertTrue("The multiAnyType should have only 2 elements but it has " + + testAny.getMultiAnyType().size(), false); + } + } + + // test xsd:any + assertTrue("Size of testAny.getAny should be 3 but it is: " + testAny.getAny().size(), testAny.getAny() + .size() == 3); + for (int i = 0; i < testAny.getAny().size(); i++) { + final FeatureMap.Entry entry = testAny.getAny().get(i); + if (i == 0) { + assertTrue("Feature expected/found: " + AnytypePackage.eINSTANCE.getB_Name().getName() + "/" + + entry.getEStructuralFeature().getName(), AnytypePackage.eINSTANCE.getB_Name() == entry + .getEStructuralFeature()); + assertTrue("Expected/found: 'my b'/" + entry.getValue(), "my b" + .compareTo((String) entry.getValue()) == 0); + } else if (i == 1) { + assertTrue("Feature expected/found: " + AnytypePackage.eINSTANCE.getA_Doub().getName() + "/" + + entry.getEStructuralFeature().getName(), AnytypePackage.eINSTANCE.getA_Doub() == entry + .getEStructuralFeature()); + assertTrue("Expected/found: 3.0/" + entry.getValue(), new Double(3.0).equals(entry.getValue())); + } else if (i == 2) { + assertTrue("Feature expected/found: " + AnytypePackage.eINSTANCE.getA_MyB().getName() + "/" + + entry.getEStructuralFeature().getName(), AnytypePackage.eINSTANCE.getA_MyB() == entry + .getEStructuralFeature()); + B b4 = (B) entry.getValue(); + assertTrue(b4.getName().compareTo("myb4") == 0); + } + } + /* + * testAny.getMyAny().add(AnytypePackage.eINSTANCE.getB_Name(), "my b my any"); + * testAny.getMyAny().add(AnytypePackage.eINSTANCE.getA_Doub(), new Double(3.4)); B b5 = + * factory.createB(); b5.setName("myb5"); + * testAny.getMyAny().add(AnytypePackage.eINSTANCE.getA_MyB(), b5); + */ + assertTrue("Size of testAny.getMyAny should be 3 but it is: " + testAny.getMyAny().size(), testAny + .getMyAny().size() == 3); + for (int i = 0; i < testAny.getMyAny().size(); i++) { + final FeatureMap.Entry entry = testAny.getMyAny().get(i); + if (i == 0) { + assertTrue("Feature expected/found: " + AnytypePackage.eINSTANCE.getB_Name().getName() + "/" + + entry.getEStructuralFeature().getName(), AnytypePackage.eINSTANCE.getB_Name() == entry + .getEStructuralFeature()); + assertTrue("Expected/found: 'my b my any'/" + entry.getValue(), "my b my any" + .compareTo((String) entry.getValue()) == 0); + } else if (i == 1) { + assertTrue("Feature expected/found: " + AnytypePackage.eINSTANCE.getA_Doub().getName() + "/" + + entry.getEStructuralFeature().getName(), AnytypePackage.eINSTANCE.getA_Doub() == entry + .getEStructuralFeature()); + assertTrue("Expected/found: 3.4/" + entry.getValue(), new Double(3.4).equals(entry.getValue())); + } else if (i == 2) { + assertTrue("Feature expected/found: " + AnytypePackage.eINSTANCE.getA_MyB().getName() + "/" + + entry.getEStructuralFeature().getName(), AnytypePackage.eINSTANCE.getA_MyB() == entry + .getEStructuralFeature()); + B b5 = (B) entry.getValue(); + assertTrue(b5.getName().compareTo("myb5") == 0); + } + } + + store.commitTransaction(); + } + + { + store.beginTransaction(); + TestAny testAny = store.getObject(TestAny.class); + testAny.getMultiAnyType().remove(0); + store.commitTransaction(); + } + + // now test cascading deletes and non-cascading deletes + { + store.beginTransaction(); + TestAny testAny = store.getObject(TestAny.class); + store.deleteObject(testAny); + store.commitTransaction(); + } + + // after the delete, the following should have been deleted: + // The myb1 B object because it was set as anytype which had a containment setting + // The myb2 B object because it was added to multianytype which had a containment setting + // The mya A object because it was added to multianytype which had a containment setting + // so there should only be a mb3, myb4 or myb5 left + { + store.beginTransaction(); + Collection acoll = store.getObjects(A.class); + assertEquals(0, acoll.size()); + Collection coll = store.getObjects(B.class); + assertEquals(3, coll.size()); + int cnt3 = 0; + int cnt4 = 0; + int cnt5 = 0; + final Iterator it = coll.iterator(); + while (it.hasNext()) { + B b = (B) it.next(); + if (b.getName().compareTo("myb3") == 0) { + cnt3++; + } else if (b.getName().compareTo("myb4") == 0) { + cnt4++; + } else if (b.getName().compareTo("myb5") == 0) { + cnt5++; + } else { + assertTrue("Not expected a B with name: " + b.getName(), false); + } + } + assertTrue("There should only be one B with name myb3, there are: " + cnt3, cnt3 == 1); + assertTrue("There should only be one B with name myb4, there are: " + cnt4, cnt4 == 1); + assertTrue("There should only be one B with name myb5, there are: " + cnt5, cnt5 == 1); + + store.commitTransaction(); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/AttributesAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/AttributesAction.java new file mode 100755 index 000000000..631a6db8b --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/AttributesAction.java @@ -0,0 +1,106 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * AttributesAction.java,v 1.2 2007/02/01 12:35:37 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.schemaconstructs; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.attributes.A; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.attributes.AttributesFactory; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.attributes.AttributesPackage; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.attributes.R; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Very simple test to test that attributes also work. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.5 $ + */ +public abstract class AttributesAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public AttributesAction() { + super(AttributesPackage.eINSTANCE); + } + + /** Creates simple types and tests against */ + @Override + public void doAction(TestStore store) { + // test a simple type + final AttributesFactory factory = AttributesFactory.eINSTANCE; + { + { + store.beginTransaction(); + A a = factory.createA(); + a.setId("myniceid"); + a.setB(500); + a.setC("c"); + a.setComment(100.4); + a.setD("myd"); + R r = factory.createR(); + r.setName("myr"); + a.setMyR(r); + a.setName("name"); + store.store(r); + store.store(a); + store.commitTransaction(); + } + { + store.beginTransaction(); + A a = store.getObject(A.class); + assertEquals(500, a.getB()); + assertEquals("c", a.getC()); + assertTrue(100.4 == a.getComment()); + assertEquals("myd", a.getD()); + assertEquals("myr", a.getMyR().getName()); + + // rough test that an id attribute works + checkIdIs(a, "myniceid"); + + store.commitTransaction(); + } + + { + store.beginTransaction(); + A a = store.getObject(A.class); + try { + a.setD(null); // this is not allowed a required attribute + store.commitTransaction(); + fail("The D field is mandatory and should not be allowed to be set to empty"); + } catch (Exception e) { + // this is good + store.rollbackTransaction(); + } + } + + // all the other fields (except name) are optional + { + store.beginTransaction(); + A a = store.getObject(A.class); + a.setName("test"); + a.unsetB(); + a.unsetComment(); + a.setC(null); + a.setMyR(null); + store.commitTransaction(); + } + } + } + + protected abstract void checkIdIs(EObject a, String string); + // TODO specialize for jpox/hibernate was: + // if (store instanceof JPOXTestStore) + // assertTrue(((PersistenceCapable)a).jdoGetObjectId().toString().indexOf("myniceid") != -1); + // else if (store instanceof HibernateTestStore) + // assertTrue(IdentifierCacheHandler.getID(a).toString().compareTo("myniceid") == 0); + +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/DateTimeAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/DateTimeAction.java new file mode 100755 index 000000000..479c1e256 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/DateTimeAction.java @@ -0,0 +1,108 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: DateTimeAction.java,v 1.4 2011/03/17 09:21:24 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.schemaconstructs; + +import java.util.Calendar; +import java.util.Date; + +import javax.xml.datatype.XMLGregorianCalendar; + +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.datetime.DatetimeFactory; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.datetime.DatetimePackage; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.datetime.TestDate; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; +import org.eclipse.emf.teneo.util.EcoreDataTypes; + +/** + * Tests for xsd datetime + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.4 $ + */ +public class DateTimeAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public DateTimeAction() { + super(DatetimePackage.eINSTANCE); + } + + /** Returns true if hibernate is enabled for a test, false otherwise */ + protected boolean hibernateEnabled() { + return true; + } + + /** Creates simple types and tests against */ + @Override + public void doAction(TestStore store) { + final DatetimeFactory factory = DatetimeFactory.eINSTANCE; + final Calendar calendar = Calendar.getInstance(); + XMLGregorianCalendar xcd = EcoreDataTypes.INSTANCE + .getXMLGregorianCalendar(calendar.getTime()); + XMLGregorianCalendar xcdt = EcoreDataTypes.INSTANCE + .getXMLGregorianCalendarDateTime(calendar.getTime()); + XMLGregorianCalendar xct = EcoreDataTypes.INSTANCE + .getXMLGregorianCalendarDateTime(calendar.getTime()); + { + store.beginTransaction(); + TestDate td = factory.createTestDate(); + + td.setDate(xcd); + td.setDatetime(xcdt); + td.setTime(xct); + store.store(td); + store.commitTransaction(); + } + { + store.beginTransaction(); + TestDate td = store.getObject(TestDate.class); + // XMLGregorianCalendar xc = (XMLGregorianCalendar) + // td.getDatetime(); + checkDate(calendar, ((XMLGregorianCalendar) td.getDatetime()) + .toGregorianCalendar().getTime(), true, true); + checkDate(calendar, ((XMLGregorianCalendar) td.getDate()) + .toGregorianCalendar().getTime(), true, false); + checkDate(calendar, ((XMLGregorianCalendar) td.getTime()) + .toGregorianCalendar().getTime(), false, true); + store.commitTransaction(); + } + } + + // Checks the date + private void checkDate(Calendar original, Date retrieved, + boolean checkDate, boolean checkSeconds) { + final Calendar loaded = Calendar.getInstance(); + loaded.setTime(retrieved); + + if (checkDate) { + assertEquals(original.get(Calendar.DATE), loaded.get(Calendar.DATE)); + assertEquals(original.get(Calendar.MONTH), + loaded.get(Calendar.MONTH)); + assertEquals(original.get(Calendar.YEAR), loaded.get(Calendar.YEAR)); + } + if (checkSeconds) { + assertEquals(original.get(Calendar.HOUR), loaded.get(Calendar.HOUR)); + assertEquals(original.get(Calendar.MINUTE), + loaded.get(Calendar.MINUTE)); + assertEquals(original.get(Calendar.SECOND), + loaded.get(Calendar.SECOND)); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/DocumentRootAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/DocumentRootAction.java new file mode 100755 index 000000000..6d84ff434 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/DocumentRootAction.java @@ -0,0 +1,131 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: DocumentRootAction.java,v 1.3 2009/08/22 00:10:05 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.schemaconstructs; + +import java.io.IOException; +import java.net.URL; +import java.util.Collections; +import java.util.Properties; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.documentroot.ComplexType; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.documentroot.DocumentRoot; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.documentroot.DocumentrootFactory; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.documentroot.DocumentrootPackage; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.documentroot.util.DocumentrootResourceFactoryImpl; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests persisting DocumentRoot. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ + */ +public class DocumentRootAction extends AbstractTestAction { + + public DocumentRootAction() { + super(DocumentrootPackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.MAP_DOCUMENT_ROOT, "true"); + return props; + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + { + store.beginTransaction(); + final DocumentRoot dr = DocumentrootFactory.eINSTANCE.createDocumentRoot(); + dr.getMixed().add(DocumentrootPackage.eINSTANCE.getDocumentRoot_Test(), "test"); + dr.getMixed().add(DocumentrootPackage.eINSTANCE.getDocumentRoot_OtherTest(), "otherTest"); + + final ComplexType complexType = DocumentrootFactory.eINSTANCE.createComplexType(); + complexType.setTest("complexTest"); + store.store(dr); + store.commitTransaction(); + + // try { + // final XMLResource xmlResource = new XMLResourceImpl(); + // xmlResource.getContents().add(dr); + // xmlResource.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE); + // xmlResource.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE); + // + // xmlResource.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE); + // + // xmlResource.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE); + // xmlResource.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE); + // + // xmlResource.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE); + // final StringWriter sw = new StringWriter(); + // xmlResource.save(sw, Collections.EMPTY_MAP); + // System.err.println(sw.toString()); + // } catch (IOException e) { + // throw new IllegalStateException(e); + // } + } + + { + store.beginTransaction(); + final DocumentRoot dr = store.getObject(DocumentRoot.class); + assertEquals(DocumentrootPackage.eINSTANCE.getDocumentRoot_Test(), dr.getMixed().get(0) + .getEStructuralFeature()); + assertEquals("test", dr.getMixed().get(0).getValue()); + assertEquals(DocumentrootPackage.eINSTANCE.getDocumentRoot_OtherTest(), dr.getMixed().get(1) + .getEStructuralFeature()); + assertEquals("otherTest", dr.getMixed().get(1).getValue()); + store.commitTransaction(); + } + + { + final Resource resource = readResource("document_root.xml"); + assertEquals(1, resource.getContents().size()); + final DocumentRoot dr = (DocumentRoot) resource.getContents().get(0); + assertEquals(DocumentrootPackage.eINSTANCE.getDocumentRoot_Test(), dr.getMixed().get(0) + .getEStructuralFeature()); + assertEquals("test", dr.getMixed().get(0).getValue()); + } + } + + private Resource readResource(String fileName) { + // read the xml's + final URL url = DocumentRootAction.class.getResource(fileName); + final Resource resource = new DocumentrootResourceFactoryImpl().createResource(URI.createURI(url.toString())); + // xmlResource.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE); + // xmlResource.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE); + // + // xmlResource.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE); + // + // xmlResource.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE); + // xmlResource.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE); + // + // xmlResource.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE); + try { + resource.load(Collections.EMPTY_MAP); + System.err.println(resource.getContents().size()); + } catch (IOException e) { + throw new IllegalStateException(e); + } + return resource; + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/DurationAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/DurationAction.java new file mode 100755 index 000000000..1be4deb5d --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/DurationAction.java @@ -0,0 +1,102 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: DurationAction.java,v 1.3 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.schemaconstructs; + +import java.util.List; + +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.Duration; + +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.duration.DurationFactory; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.duration.DurationPackage; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.duration.DurationTest; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests xsd duration type. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ + */ +public class DurationAction extends AbstractTestAction { + + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public DurationAction() { + super(DurationPackage.eINSTANCE); + } + + /** Creates simple types and tests against */ + @Override + public void doAction(TestStore store) { + // test a simple type + final DurationFactory factory = DurationFactory.eINSTANCE; + try { + final DatatypeFactory dtf = DatatypeFactory.newInstance(); + { + + store.beginTransaction(); + for (int i = 0; i < 5; i++) { + final DurationTest dt = factory.createDurationTest(); + dt.setName(i + ""); + final Duration duration = dtf.newDurationDayTime(true, i, i, i, i); + dt.setDuration(duration); + for (int j = 0; j < i; j++) { + final Duration dur = dtf.newDurationYearMonth(true, j, j); + dt.getDurations().add(dur); + } + store.store(dt); + } + store.commitTransaction(); + } + store.refresh(); + { + @SuppressWarnings("unchecked") + final List<DurationTest> durations = (List<DurationTest>) store.getObjects(DurationTest.class); + for (DurationTest dt : durations) { + final int index = Integer.parseInt(dt.getName()); + final Duration d = dt.getDuration(); + assertEquals(index, d.getDays()); + assertEquals(index, d.getHours()); + assertEquals(index, d.getMinutes()); + assertEquals(index, d.getSeconds()); + assertEquals(0, d.getYears()); + assertEquals(0, d.getMonths()); + + for (int j = 0; j < dt.getDurations().size(); j++) { + final Duration dur = dt.getDurations().get(j); + assertEquals(j, dur.getYears()); + assertEquals(j, dur.getMonths()); + assertEquals(0, dur.getDays()); + assertEquals(0, dur.getHours()); + assertEquals(0, dur.getMinutes()); + assertEquals(0, dur.getSeconds()); + } + assertEquals(index, dt.getDurations().size()); + + } + } + } catch (Exception e) { + throw new StoreTestException(e.getMessage(), e); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/EcoreAttrsAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/EcoreAttrsAction.java new file mode 100755 index 000000000..41ae15ab0 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/EcoreAttrsAction.java @@ -0,0 +1,127 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: EcoreAttrsAction.java,v 1.5 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.schemaconstructs; + +import org.eclipse.emf.ecore.util.FeatureMap; +import org.eclipse.emf.teneo.Constants; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.ecoreattrs.EcoreattrsFactory; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.ecoreattrs.EcoreattrsPackage; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.ecoreattrs.Element; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.ecoreattrs.Feature; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.ecoreattrs.Mixed; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.ecoreattrs.NameList; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests number of ecore attributes. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.5 $ +*/ +public class EcoreAttrsAction extends AbstractTestAction +{ + + /** + * Constructor for ClassHierarchyParsing. + * @param arg0 + */ + public EcoreAttrsAction() + { + super(EcoreattrsPackage.eINSTANCE); + } + + /** Creates simple types and tests against */ + public void doAction(TestStore store) + { + // test a simple type + final EcoreattrsFactory factory = EcoreattrsFactory.eINSTANCE; + { + store.beginTransaction(); + Feature feature = factory.createFeature(); + feature.setName("001"); + feature.setValue(1.5); + store.store(feature); + store.commitTransaction(); + + store.beginTransaction(); + feature = (Feature)store.getObject(Feature.class); + assertEquals("001", feature.getAMap().getValue(0)); + assertEquals("001", feature.getName()); + assertEquals(1.5, ((Double)feature.getAMap().getValue(1)).doubleValue(), 0.01); + assertEquals(1.5, feature.getValue(), 0.01); + store.commitTransaction(); + } + + { + store.beginTransaction(); + Mixed mixed = factory.createMixed(); + mixed.getMixed().add(Constants.TEXT, "001"); + mixed.setName("name"); + mixed.getMixed().add(Constants.TEXT, "002"); + mixed.setValue(1.5); + store.store(mixed); + store.commitTransaction(); + + store.beginTransaction(); + mixed = (Mixed)store.getObject(Mixed.class); + FeatureMap.Entry entry = (FeatureMap.Entry)mixed.getMixed().get(0); + assertEquals(entry.getEStructuralFeature(), Constants.TEXT); + assertEquals("001", entry.getValue()); + + entry = (FeatureMap.Entry)mixed.getMixed().get(1); + assertEquals(entry.getEStructuralFeature(), EcoreattrsPackage.eINSTANCE.getMixed_Name()); + assertEquals(entry.getValue(), "name"); + assertTrue(mixed.getName() == entry.getValue()); + + entry = (FeatureMap.Entry)mixed.getMixed().get(2); + assertEquals(entry.getEStructuralFeature(), Constants.TEXT); + assertEquals("002", entry.getValue()); + + entry = (FeatureMap.Entry)mixed.getMixed().get(3); + assertEquals(entry.getEStructuralFeature(), EcoreattrsPackage.eINSTANCE.getMixed_Value()); + assertEquals(1.5, ((Double)entry.getValue()).doubleValue(), 0.01); + assertEquals(mixed.getValue(), ((Double)entry.getValue()).doubleValue(), 0.01); + + store.commitTransaction(); + } + + // namelist + { + store.beginTransaction(); + Element elem = factory.createElement(); + NameList namelist = factory.createNameList(); + namelist.setFirstName("first"); + namelist.setMiddleName("middle"); + namelist.setLastName("last"); + elem.setNames(namelist); + store.store(elem); + store.commitTransaction(); + + store.beginTransaction(); + elem = (Element)store.getObject(Element.class); + namelist = (NameList)elem.getNameMap().getValue(0); + assertTrue(namelist == elem.getNames()); + assertEquals(namelist.getFirstName(), "first"); + assertEquals(namelist.getMiddleName(), "middle"); + assertEquals(namelist.getLastName(), "last"); + + store.commitTransaction(); + } + + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/ExtensionAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/ExtensionAction.java new file mode 100755 index 000000000..9fe154332 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/ExtensionAction.java @@ -0,0 +1,195 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: ExtensionAction.java,v 1.9 2010/10/29 13:25:00 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.schemaconstructs; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.extension.Address; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.extension.AddressList; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.extension.DistrictUKAddress; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.extension.ExtensionFactory; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.extension.ExtensionPackage; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.extension.FirstAddressHolder; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.extension.InternationalPrice; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.extension.UKAddress; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.extension.USAddress; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.extension.USState; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests for: - Restriction simple type - Extension from simple to complex type - Abstract type - IDREFS - Inheritance + * and abstract - Extension of complex type - Reference to abstract type - nillable of string (district) and integer + * (zip) + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.9 $ + */ +public class ExtensionAction extends AbstractTestAction { + + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public ExtensionAction() { + super(ExtensionPackage.eINSTANCE); + } + + /** Creates simple types and tests against */ + @Override + public void doAction(TestStore store) { + // test a simple type + final ExtensionFactory factory = ExtensionFactory.eINSTANCE; + { + store.beginTransaction(); + + USAddress usaddress = factory.createUSAddress(); + usaddress.setName("Montgomery"); + usaddress.setCity("Montgomery"); + usaddress.setState(USState.AL_LITERAL); + usaddress.setZip(new BigInteger("36101")); + usaddress.setStreet("Montgomery street"); + store.store(usaddress); + + // test nullable fields + USAddress emptyaddress = factory.createUSAddress(); + emptyaddress.setName("empty"); + emptyaddress.setCity("empty"); + emptyaddress.setStreet("empty"); + emptyaddress.setState(USState.AL_LITERAL); + emptyaddress.setZip(new BigInteger("12313")); + // if (emptyaddress.isSetState()) + // { + // emptyaddress.unsetState(); + // } + // if (emptyaddress.isSetZip()) + // { + // emptyaddress.unsetZip(); + // } + + store.store(usaddress); + store.store(emptyaddress); + + // create a uk address and a uk district address + UKAddress ukaddress = factory.createUKAddress(); + ukaddress.setCity("London"); + ukaddress.setStreet("Downingstreet 10"); + ukaddress.setName("Primeminister"); + ukaddress.setPostcode("0000"); + store.store(ukaddress); + + DistrictUKAddress districtaddress = factory.createDistrictUKAddress(); + districtaddress.setCity("district"); + districtaddress.setDistrict("district1"); + districtaddress.setExportCode(new BigInteger("500")); + districtaddress.setName("My districtaddress"); + districtaddress.setPostcode("postcode1"); + districtaddress.setStreet("street1"); + store.store(districtaddress); + + FirstAddressHolder holder = factory.createFirstAddressHolder(); + holder.getValue().add(usaddress); + holder.getValue().add(emptyaddress); + holder.getValue().add(ukaddress); + holder.getValue().add(districtaddress); + + AddressList addresslist = factory.createAddressList(); + addresslist.setName("addressList"); + addresslist.setFirstAddress(holder); + addresslist.getSecondAddress().add(usaddress); + addresslist.getSecondAddress().add(emptyaddress); + addresslist.getSecondAddress().add(ukaddress); + addresslist.getSecondAddress().add(districtaddress); + store.store(addresslist); + + InternationalPrice price = factory.createInternationalPrice(); + price.setCurrency("EUR"); + price.setValue(new BigDecimal("100.50")); + store.store(price); + + store.commitTransaction(); + } + + { + store.beginTransaction(); + AddressList addressList = store.getObject(AddressList.class); + checkAddressList(addressList.getFirstAddress().getValue().iterator()); + checkAddressList(addressList.getSecondAddress().iterator()); + store.commitTransaction(); + } + + { + store.beginTransaction(); + InternationalPrice price = store.getObject(InternationalPrice.class); + assertTrue(price.getValue() != null); + assertTrue(price.getCurrency() != null); + store.commitTransaction(); + } + + { + store.beginTransaction(); + List list = store.getObjects(Address.class); + checkAddressList(list.iterator()); + + if (!isEAVTest()) { + // take one address and check its crossreferencers, there should be two + final Object[] crs = store.getCrossReferencers((EObject) list.get(0), false); + assertEquals(2, crs.length); + } + + store.commitTransaction(); + } + } + + /** Checks that the address types occur in the passed list */ + private void checkAddressList(Iterator it) { + int cntus = 0; + int cntuk = 0; + int cntdistrict = 0; + while (it.hasNext()) { + Address address = (Address) it.next(); + if (address instanceof DistrictUKAddress) { + cntdistrict++; + } else if (address instanceof UKAddress) { + cntuk++; + if (address.getName().compareTo("Primeminister") == 0) { + UKAddress ukaddress = (UKAddress) address; + assertTrue(ukaddress.getExportCode().intValue() == 1); + assertTrue(!ukaddress.isSetExportCode()); + } + } else if (address instanceof USAddress) { + cntus++; + + if (address.getName().compareTo("empty") == 0) { + // assertFalse(((USAddress) address).isSetState()); + // assertFalse(((USAddress) address).isSetZip()); + } else { + assertTrue(((USAddress) address).isSetState()); + assertTrue(((USAddress) address).isSetZip()); + } + } + } + assertTrue(cntus == 2); + assertTrue(cntuk == 1); + assertTrue(cntdistrict == 1); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/GroupAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/GroupAction.java new file mode 100755 index 000000000..d12fa19da --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/GroupAction.java @@ -0,0 +1,197 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: GroupAction.java,v 1.3 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.schemaconstructs; + +import java.util.Collection; +import java.util.Iterator; + +import org.eclipse.emf.ecore.util.FeatureMap; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.groupall.Address; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.groupall.AddressGroup; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.groupall.AddressList; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.groupall.GroupallFactory; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.groupall.GroupallPackage; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.groupall.SimpleAllMapType; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.groupall.SimpleAllType; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Simple test for: xsd:group, xsd:all, ecore:name on xsd:group, repeating xsd:sequence, repeating xsd:group + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ +*/ +public class GroupAction extends AbstractTestAction +{ + /** + * Constructor for ClassHierarchyParsing. + * @param arg0 + */ + public GroupAction() + { + super(GroupallPackage.eINSTANCE); + } + + /** Creates simple types and tests against */ + public void doAction(TestStore store) + { + // test a simple type + final GroupallFactory factory = GroupallFactory.eINSTANCE; + // store an all type + { + store.beginTransaction(); + SimpleAllType all = factory.createSimpleAllType(); + all.setAaa("aaa"); + all.setBbb("bbb"); + all.setCcc("ccc"); + store.store(all); + store.commitTransaction(); + } + + // get an all type + { + store.beginTransaction(); + SimpleAllType all = (SimpleAllType)store.getObject(SimpleAllType.class); + assertEquals(all.getAaa(), "aaa"); + assertEquals(all.getBbb(), "bbb"); + assertEquals(all.getCcc(), "ccc"); + store.commitTransaction(); + } + + // store a featuremap all type + { + store.beginTransaction(); + SimpleAllMapType all = factory.createSimpleAllMapType(); + all.setBbb("bbb"); // note the ordering, test below + all.setAaa("aaa"); + all.setCcc("ccc"); + store.store(all); + store.commitTransaction(); + } + + // get a featuremap all type + { + store.beginTransaction(); + SimpleAllMapType all = (SimpleAllMapType)store.getObject(SimpleAllMapType.class); + assertEquals(all.getAllMap().getValue(0), "bbb"); + assertEquals(all.getAllMap().getValue(1), "aaa"); + assertEquals(all.getAllMap().getValue(2), "ccc"); + assertEquals(all.getAllMap().getEStructuralFeature(0), GroupallPackage.eINSTANCE.getSimpleAllMapType_Bbb()); + assertEquals(all.getAllMap().getEStructuralFeature(1), GroupallPackage.eINSTANCE.getSimpleAllMapType_Aaa()); + assertEquals(all.getAllMap().getEStructuralFeature(2), GroupallPackage.eINSTANCE.getSimpleAllMapType_Ccc()); + store.store(all); + store.commitTransaction(); + } + + // store an address group + { + store.beginTransaction(); + AddressGroup group0 = factory.createAddressGroup(); + group0.setGroupName("mygroup0"); + group0.setBillTo(createAddress(factory, 0)); + group0.setShipTo(createAddress(factory, 1)); + store.store(group0); + + AddressGroup group1 = factory.createAddressGroup(); + group1.setGroupName("mygroup1"); + group1.setSimpleAddress("s0"); + store.store(group1); + store.commitTransaction(); + } + + // check the address group + { + store.beginTransaction(); + Collection coll = store.getObjects(AddressGroup.class); + Iterator it = coll.iterator(); + while (it.hasNext()) + { + AddressGroup group = (AddressGroup)it.next(); + if (group.getGroupName().endsWith("1")) // group0 + { + assertEquals(group.getBillTo(), null); + assertEquals(group.getShipTo(), null); + assertEquals(group.getSimpleAddress(), "s0"); + } + else if (group.getGroupName().endsWith("0")) // group1 + { + checkAddress(group.getBillTo(), 0); + checkAddress(group.getShipTo(), 1); + } + else + { + assertTrue("Group with name: " + group.getGroupName() + " unknown ", false); + } + } + store.commitTransaction(); + } + + // store a address list + { + store.beginTransaction(); + AddressList list0 = factory.createAddressList(); + list0.setGroupName("list0"); + list0.getBillTo().add(createAddress(factory, 2)); + list0.getShipTo().add(createAddress(factory, 3)); + list0.getBillTo().add(createAddress(factory, 4)); + list0.getShipTo().add(createAddress(factory, 5)); + store.store(list0); + store.commitTransaction(); + } + + store.checkNumber(Address.class, 6); + + // now test if it was all stored correctly + // addresslit + { + store.beginTransaction(); + AddressList list0 = (AddressList)store.getObject(AddressList.class); + checkAddress((Address)((FeatureMap.Entry)list0.getAddrs().get(0)).getValue(), 2); + checkAddress((Address)((FeatureMap.Entry)list0.getAddrs().get(1)).getValue(), 3); + checkAddress((Address)((FeatureMap.Entry)list0.getAddrs().get(2)).getValue(), 4); + checkAddress((Address)((FeatureMap.Entry)list0.getAddrs().get(3)).getValue(), 5); + store.commitTransaction(); + } + + } + + /** Creates an address */ + private Address createAddress(GroupallFactory factory, int index) + { + Address adr = factory.createAddress(); + adr.getGroup().add(GroupallPackage.eINSTANCE.getAddress_Name(), index + "n1"); + adr.getGroup().add(GroupallPackage.eINSTANCE.getAddress_LongName(), index + "l1"); + adr.getGroup().add(GroupallPackage.eINSTANCE.getAddress_Name(), index + "n2"); + adr.getGroup().add(GroupallPackage.eINSTANCE.getAddress_LongName(), index + "l2"); + return adr; + } + + /** Checks if an address is valid */ + private void checkAddress(Address adr, int index) + { + assertEquals(adr.getLongName().get(0), index + "l1"); + assertEquals(adr.getLongName().get(1), index + "l2"); + assertEquals(adr.getName().get(0), index + "n1"); + assertEquals(adr.getName().get(1), index + "n2"); + + assertEquals(adr.getGroup().getValue(0), index + "n1"); + assertEquals(adr.getGroup().getValue(1), index + "l1"); + assertEquals(adr.getGroup().getValue(2), index + "n2"); + assertEquals(adr.getGroup().getValue(3), index + "l2"); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/ListAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/ListAction.java new file mode 100755 index 000000000..97643b07b --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/ListAction.java @@ -0,0 +1,99 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: ListAction.java,v 1.5 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.schemaconstructs; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.list.ListFactory; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.list.ListPackage; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.list.statesByCountry; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Simple test for: xsd:list + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.5 $ + */ +public class ListAction extends AbstractTestAction { + /** The number of test objects created */ + private static final int NO_TEST_OBJECTS = 5; + + /** + * Constructor for ClassHierarchyParsing. + * @param arg0 + */ + public ListAction() { + super(ListPackage.eINSTANCE); + } + + /** Creates simple types and tests against */ + @Override + public void doAction(TestStore store) { + // test a simple type + final ListFactory factory = ListFactory.eINSTANCE; + + // store an all type + { + store.beginTransaction(); + + for (int i = 0; i < NO_TEST_OBJECTS; i++) { + statesByCountry sbc = factory.createstatesByCountry(); + sbc.setCountry(i + "NL"); + sbc.setIndex(i); + final ArrayList<String> allStates = new ArrayList<String>(); + for (int j = 0; j < i; j++) { + allStates.add(j + "AL"); + } + sbc.setAllStates(allStates); + final ArrayList<String> sixStates = new ArrayList<String>(); + for (int j = 0; j < i; j++) { + sixStates.add(j + "AR"); + } + sbc.setSixImportantStates(sixStates); + + store.store(sbc); + } + store.commitTransaction(); + } + + { + store.beginTransaction(); + final Collection<?> coll = store.getObjects(statesByCountry.class); + assertEquals(NO_TEST_OBJECTS, coll.size()); + final Iterator<?> it = coll.iterator(); + while (it.hasNext()) { + final statesByCountry sbc = (statesByCountry) it.next(); + int cnt = sbc.getIndex(); + assertEquals(cnt + "NL", sbc.getCountry()); + for (int i = 0; i < cnt; i++) { + assertEquals(i + "AL", sbc.getAllStates().get(i)); + if (!(i + "AR").equals(sbc.getSixImportantStates().get(i))) { + Object obj = sbc.getSixImportantStates().get(i); + assertNotNull(obj); + } + assertEquals(i + "AR", sbc.getSixImportantStates().get(i)); + } + } + store.commitTransaction(); + } + } + +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/ListUnionAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/ListUnionAction.java new file mode 100755 index 000000000..6a740dff7 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/ListUnionAction.java @@ -0,0 +1,111 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: ListUnionAction.java,v 1.3 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.schemaconstructs; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.listunion.ListunionFactory; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.listunion.ListunionPackage; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.listunion.statesByCountry; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Simple test for: xsd:group, xsd:all, ecore:name on xsd:group, repeating xsd:sequence, repeating xsd:group + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ +*/ +public class ListUnionAction extends AbstractTestAction +{ + /** The number of test objects created */ + private static final int NO_TEST_OBJECTS = 5; + + /** + * Constructor for ClassHierarchyParsing. + * @param arg0 + */ + public ListUnionAction() + { + super(ListunionPackage.eINSTANCE); + } + + /** Creates simple types and tests against */ + public void doAction(TestStore store) + { + // test a simple type + final ListunionFactory factory = ListunionFactory.eINSTANCE; + + // store an all type + { + store.beginTransaction(); + + for (int i = 0; i < NO_TEST_OBJECTS; i++) + { + statesByCountry sbc = factory.createstatesByCountry(); + sbc.setCountry(i + "NL"); + sbc.setSimpleStringUnion(i + "union"); + sbc.setSimpleUnion(new BigInteger(i + "")); + sbc.setZipUnion(i + "AK"); + final ArrayList allStates = new ArrayList(); + for (int j = 0; j < i; j++) + { + allStates.add(j + "AL"); + } + sbc.setAllStates(allStates); + final ArrayList sixStates = new ArrayList(); + for (int j = 0; j < i; j++) + { + sixStates.add(j + "AR"); + sbc.getSimpleUnions().add(new BigInteger(j + "")); + sbc.getSimpleStringUnions().add(j + "AK"); + } + sbc.setSixImportantStates(sixStates); + + store.store(sbc); + } + store.commitTransaction(); + } + + { + store.beginTransaction(); + final Collection coll = store.getObjects(statesByCountry.class); + assertEquals(NO_TEST_OBJECTS, coll.size()); + final Iterator it = coll.iterator(); + while (it.hasNext()) + { + final statesByCountry sbc = (statesByCountry)it.next(); + final int index = ((BigInteger)sbc.getSimpleUnion()).intValue(); + assertEquals(index + "NL", sbc.getCountry()); + assertEquals(index + "union", sbc.getSimpleStringUnion()); + assertEquals(index + "AK", sbc.getZipUnion()); + for (int i = 0; i < index; i++) + { + assertEquals(i + "AL", sbc.getAllStates().get(i)); + assertEquals(i + "AR", sbc.getSixImportantStates().get(i)); + assertEquals(i, ((BigInteger)sbc.getSimpleUnions().get(i)).intValue()); + assertEquals(i + "AK", sbc.getSimpleStringUnions().get(i)); + } + } + store.commitTransaction(); + } + } + +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/MixedAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/MixedAction.java new file mode 100755 index 000000000..617a43b9a --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/MixedAction.java @@ -0,0 +1,206 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: MixedAction.java,v 1.7 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.schemaconstructs; + +import java.math.BigInteger; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.Iterator; + +import javax.xml.datatype.XMLGregorianCalendar; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.util.FeatureMap; +import org.eclipse.emf.teneo.Constants; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.mixed.LetterBodyType; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.mixed.MixedFactory; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.mixed.MixedPackage; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.mixed.SalutationType; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests for the mixed construction. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.7 $ +*/ +public class MixedAction extends AbstractTestAction { + /** Two days in millis to work around an issue in emf xml calendar */ + private static long TWO_DAYS = 1000 * 60 * 60 * 24 * 2; + + /** + * Constructor for ClassHierarchyParsing. + * @param arg0 + */ + public MixedAction() { + super(MixedPackage.eINSTANCE); + } + + /** Creates simple types and tests against */ + @Override + public void doAction(TestStore store) { + int maxCnt = 5; + final Calendar cal = new GregorianCalendar(); + cal.set(Calendar.YEAR, 2005); + cal.set(Calendar.MONTH, 8); + + // test a simple type + final MixedFactory factory = MixedFactory.eINSTANCE; + { + store.beginTransaction(); + + // the index is stored in the biginteger + for (int i = 0; i < maxCnt; i++) { + LetterBodyType letter = factory.createLetterBodyType(); + SalutationType salutation = factory.createSalutationType(); + salutation.getMixed().add(Constants.TEXT, i + "Dear mr."); + salutation.setName(i + " Taal"); + salutation.getMixed().add(Constants.TEXT, i + ","); + + letter.getMixed().add(Constants.TEXT, i + "Amsterdam, The Netherlands"); // 0 + letter.setSalutation(salutation); // 1 + letter.getMixed().add(Constants.TEXT, i + "Please order the following product for me"); // 2 + letter.setProductName(i + "bicycle"); // 3 + letter.getMixed().add(Constants.TEXT, i + "Description: Bicycle"); // 4 + letter.getMixed().add(Constants.COMMENT, i + "With two wheels!"); // 5 + letter.setQuantity(new BigInteger(i + "")); // 6 + letter.getMixed().add(Constants.TEXT, i + "Unit: pieces"); // 7 + cal.set(Calendar.DAY_OF_MONTH, i + 1); + letter.setShipDate(store.getDate(cal.getTime())); // 8 + letter.getMixed().add(Constants.COMMENT, + i + "Comment: please ensure that the product is delivered on time."); // 9 + letter.getMixed().add(Constants.CDATA, i + "CDATA test"); // 10 + + store.store(letter); + } + store.commitTransaction(); + } + + { + store.beginTransaction(); + + final Collection coll = store.getObjects(LetterBodyType.class); + assertTrue(coll.size() == maxCnt); + final Iterator it = coll.iterator(); + + // check that we got them all + boolean[] foundAll = new boolean[maxCnt]; + for (int i = 0; i < maxCnt; i++) { + foundAll[i] = false; + } + + while (it.hasNext()) { + LetterBodyType letter = (LetterBodyType) it.next(); + int docIndex = letter.getQuantity().intValue(); + foundAll[docIndex] = true; + final EList list = letter.getMixed(); + checkEntry(docIndex, list, 0, Constants.TEXT, "Amsterdam, The Netherlands", null); + + // salutation + { + final FeatureMap.Entry salEntry = getEntry(list, 1); + assertTrue(salEntry.getValue() instanceof SalutationType); + assertTrue(salEntry.getEStructuralFeature() == MixedPackage.eINSTANCE + .getLetterBodyType_Salutation()); + SalutationType sal = (SalutationType) salEntry.getValue(); + + checkEntry(docIndex, sal.getMixed(), 0, Constants.TEXT, "Dear mr.", null); + checkEntry(docIndex, sal.getMixed(), 1, MixedPackage.eINSTANCE.getSalutationType_Name(), " Taal", + sal.getName()); + checkEntry(docIndex, sal.getMixed(), 2, Constants.TEXT, ",", null); + } + + // 1 salutation + checkEntry(docIndex, list, 2, Constants.TEXT, "Please order the following product for me", null); + checkEntry(docIndex, list, 3, MixedPackage.eINSTANCE.getLetterBodyType_ProductName(), "bicycle", letter + .getProductName()); + checkEntry(docIndex, list, 4, Constants.TEXT, "Description: Bicycle", null); + checkEntry(docIndex, list, 5, Constants.COMMENT, "With two wheels!", null); + + // 6 biginteger + assertTrue("Error in retrieving integer field", + ((BigInteger) getEntry(list, 6).getValue()).intValue() == docIndex); + + checkEntry(docIndex, list, 7, Constants.TEXT, "Unit: pieces", null); + + // 8 Date + { + final FeatureMap.Entry dateEntry = getEntry(list, 8); + assertTrue(dateEntry.getValue() instanceof XMLGregorianCalendar || + dateEntry.getValue() instanceof Date); + assertTrue(dateEntry.getEStructuralFeature() == MixedPackage.eINSTANCE.getLetterBodyType_ShipDate()); + + final Date date; + if (dateEntry.getValue() instanceof XMLGregorianCalendar) { + date = ((XMLGregorianCalendar) dateEntry.getValue()).toGregorianCalendar().getTime(); + } else { + date = (Date) dateEntry.getValue(); + } + cal.set(Calendar.DAY_OF_MONTH, docIndex + 1); + assertTrue(Math.abs(cal.getTimeInMillis() - date.getTime()) < TWO_DAYS); + + // there is an error in emf therefore the xml calendar move the date one day + // back + // therefor the following checks are disabled + /* + * assertEquals(date.getDate(), cal.get(Calendar.DAY_OF_MONTH)); + * assertEquals(date.getMonth(), cal.get(Calendar.MONTH)); + * assertEquals((date.getYear() + 1900), cal.get(Calendar.YEAR)); + */ + } + + checkEntry(docIndex, list, 9, Constants.COMMENT, + "Comment: please ensure that the product is delivered on time.", null); + checkEntry(docIndex, list, 10, Constants.CDATA, "CDATA test", null); + } + + store.commitTransaction(); + + for (int i = 0; i < maxCnt; i++) { + assertTrue("Document with docindex " + i + " was not retrieved", foundAll[i]); + } + } + } + + /** Returns the feature map entry on a specific position */ + private FeatureMap.Entry getEntry(EList list, int index) { + return (FeatureMap.Entry) list.get(index); + } + + /** Checks a certain entry */ + private void checkEntry(int docIndex, EList list, int index, EStructuralFeature feature, Object value, String val2) { + checkEntry(docIndex, getEntry(list, index), feature, value, val2); + } + + /** Checks a certain entry */ + private void checkEntry(int docIndex, FeatureMap.Entry entry, EStructuralFeature feature, Object value, String val2) { + assertTrue("Error, expected/found feature: " + feature.getName() + "/" + + entry.getEStructuralFeature().getName(), entry.getEStructuralFeature() == feature); + assertTrue("Expected String, got: " + value.getClass().getName(), value instanceof String); + final String entryVal = (String) entry.getValue(); + final String expVal = docIndex + (String) value; + assertTrue("Error, expected/found value: " + expVal + "/" + entryVal, entryVal.compareTo(expVal) == 0); + if (val2 != null) // extra check + { + assertTrue("Error, expected/found value: " + val2 + "/" + entryVal, entryVal.compareTo(val2) == 0); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/ModelGroupAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/ModelGroupAction.java new file mode 100644 index 000000000..5bcc3a005 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/ModelGroupAction.java @@ -0,0 +1,44 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: ModelGroupAction.java,v 1.3 2010/04/02 22:42:19 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.schemaconstructs; + +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.modelgroup.ModelgroupPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests for the modelgroup construction. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ + */ +public class ModelGroupAction extends AbstractTestAction { + + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public ModelGroupAction() { + super(ModelgroupPackage.eINSTANCE); + } + + /** Creates simple types and tests against */ + @Override + public void doAction(TestStore store) { + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/NestedGroupAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/NestedGroupAction.java new file mode 100755 index 000000000..fc0fd5914 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/NestedGroupAction.java @@ -0,0 +1,51 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: NestedGroupAction.java,v 1.4 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.schemaconstructs; + +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.nestedgroup.NestedgroupPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.4 $ +*/ +public class NestedGroupAction extends AbstractTestAction +{ + /** + * Constructor for ClassHierarchyParsing. + * @param arg0 + */ + public NestedGroupAction() + { + super(NestedgroupPackage.eINSTANCE); + } + + /** Creates simple types and tests against */ + public void doAction(TestStore store) + { + // test a simple type +// final RestrictionFactory factory = RestrictionFactory.eINSTANCE; + { + { + store.beginTransaction(); + store.commitTransaction(); + } + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/QNameAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/QNameAction.java new file mode 100755 index 000000000..f3940e3d7 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/QNameAction.java @@ -0,0 +1,82 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: QNameAction.java,v 1.3 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.schemaconstructs; + +import javax.xml.namespace.QName; + +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.qname.Mytest; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.qname.QnameFactory; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.qname.QnamePackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Simple test for: qname + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ + */ +public class QNameAction extends AbstractTestAction { + + /** The number of test objects created */ + private static final int NO_TEST_OBJECTS = 5; + + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public QNameAction() { + super(QnamePackage.eINSTANCE); + } + + /** Creates simple types and tests against */ + @Override + public void doAction(TestStore store) { + final QnameFactory factory = QnameFactory.eINSTANCE; + + // store an all type + { + store.beginTransaction(); + Mytest mytest = factory.createMytest(); + mytest.setDescription("test"); + for (int i = 0; i < NO_TEST_OBJECTS; i++) { + QName qName = new QName("http://www.elver.org/" + i, "local" + i, "prefix" + i); + mytest.getNames().add(qName); + } + mytest.setName(new QName("http://www.springsite.com", "name", "e")); + store.store(mytest); + store.commitTransaction(); + } + + { + store.beginTransaction(); + final Mytest mytest = store.getObject(Mytest.class); + assertEquals(mytest.getNames().size(), NO_TEST_OBJECTS); + for (int i = 0; i < NO_TEST_OBJECTS; i++) { + final QName qName = mytest.getNames().get(i); + assertEquals(qName.getNamespaceURI(), "http://www.elver.org/" + i); + assertEquals(qName.getLocalPart(), "local" + i); + assertEquals(qName.getPrefix(), "prefix" + i); + } + assertEquals(mytest.getName().getNamespaceURI(), "http://www.springsite.com"); + assertEquals(mytest.getName().getLocalPart(), "name"); + assertEquals(mytest.getName().getPrefix(), "e"); + store.commitTransaction(); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/RestrictionAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/RestrictionAction.java new file mode 100755 index 000000000..f5d21a3e9 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/RestrictionAction.java @@ -0,0 +1,58 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: RestrictionAction.java,v 1.4 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.schemaconstructs; + +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.restriction.RestrictionPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests for the mixed construction. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.4 $ +*/ +public class RestrictionAction extends AbstractTestAction +{ + /** + * Constructor for ClassHierarchyParsing. + * @param arg0 + */ + public RestrictionAction() + { + super(RestrictionPackage.eINSTANCE); + } + + /** Returns true if hibernate is enabled for a test, false otherwise */ + protected boolean hibernateEnabled() + { + return true; + } + + /** Creates simple types and tests against */ + public void doAction(TestStore store) + { + // test a simple type + //final RestrictionFactory factory = RestrictionFactory.eINSTANCE; + { + { + store.beginTransaction(); + store.commitTransaction(); + } + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/SimpleTypeAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/SimpleTypeAction.java new file mode 100755 index 000000000..81f98143c --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/SimpleTypeAction.java @@ -0,0 +1,434 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * SimpleTypeAction.java,v 1.7 2007/03/06 19:02:42 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.schemaconstructs; + +import java.math.BigDecimal; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.simpletypes.SimpleEnum; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.simpletypes.SimpleList; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.simpletypes.SimpleType; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.simpletypes.SimpleTypeObject; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.simpletypes.SimpletypesFactory; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.simpletypes.SimpletypesPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.HsqldbTestDatabaseAdapter; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests if simple types are stored/retrieved correctly. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.13 $ + */ +public class SimpleTypeAction extends AbstractTestAction { + /** Simple Type Values we test against */ + private static double DOUBLE = 10.95; + + private static float FLOAT = (float) 3458.95; + + private static boolean BOOL = true; + + private static byte BYTE = (byte) 233; + + private static int INT = 5460; + + private static short SHORT = (short) 456; + + private static long LONG = 2789123; + + private static Date DATE = new Date(); + + private static String STRING = "0123456789"; + + private static BigDecimal bigDecimalOne = new BigDecimal("10.456778"); + + private static BigDecimal bigDecimalTwo = new BigDecimal("10.4"); + + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public SimpleTypeAction() { + super(SimpletypesPackage.eINSTANCE); + } + + /** Creates simple types and tests against */ + @Override + public void doAction(TestStore store) { + // test a simple type + final SimpletypesFactory factory = SimpletypesFactory.eINSTANCE; + { + store.beginTransaction(); + + final SimpleType stype = factory.createSimpleType(); + + stype.setCode("This is a test simpletype"); + stype.setBoo(BOOL); + stype.setByt(BYTE); + stype.setDat(DATE); + stype.setDoubl(DOUBLE); + stype.setEnu(SimpleEnum.ENUM1_LITERAL); + stype.setFloat(FLOAT); + stype.setInte(INT); + stype.setLimitedstring(STRING); + stype.setLon(LONG); + stype.setShor(SHORT); + stype.setExtraLimitedString(STRING.substring(0, 5)); + stype.setLimitedDecimal(bigDecimalOne); + store.store(stype); + store.commitTransaction(); + } + // stype.setExtraLimitedString(STRING); + + { + store.beginTransaction(); + SimpleType result = store.getObject(SimpleType.class); + assertEquals(BOOL, result.isBoo()); + assertEquals(BYTE, result.getByt()); + assertTrue(equalDates(store, result.getDat(), DATE)); + assertEquals(DOUBLE, result.getDoubl(), 0.01); + assertTrue(result.getEnu().equals(SimpleEnum.ENUM1_LITERAL)); + assertEquals(FLOAT, result.getFloat(), 0.01); + assertEquals(INT, result.getInte()); + assertTrue(result.getLimitedstring().compareTo(STRING) == 0); + assertEquals(LONG, result.getLon()); + assertEquals(SHORT, result.getShor()); + // hsqldb does not support column length, at least not in in-mem + // mode + if (!(store.getDatabaseAdapter() instanceof HsqldbTestDatabaseAdapter)) { + assertEquals(STRING.substring(0, 5), result.getExtraLimitedString()); + } + assertEquals(bigDecimalTwo.floatValue(), result.getLimitedDecimal().floatValue(), 0.11); + store.deleteObject(result); + store.commitTransaction(); + } + + { + store.beginTransaction(); + + final SimpleTypeObject stype = factory.createSimpleTypeObject(); + + stype.setCode("This is a test simpletype"); + stype.setBoo(new Boolean(BOOL)); + stype.setByt(new Byte(BYTE)); + stype.setDat(DATE); + stype.setDoubl(new Double(DOUBLE)); + stype.setEnu(SimpleEnum.ENUM1_LITERAL); + stype.setFloat(new Float(FLOAT)); + stype.setInte(new Integer(INT)); + stype.setLon(new Long(LONG)); + stype.setShor(new Short(SHORT)); + store.store(stype); + store.commitTransaction(); + } + + { + store.beginTransaction(); + SimpleTypeObject result = store.getObject(SimpleTypeObject.class); + assertEquals(new Boolean(BOOL), result.getBoo()); + assertEquals(new Byte(BYTE), result.getByt()); + assertTrue(equalDates(store, result.getDat(), DATE)); + assertEquals(DOUBLE, result.getDoubl().doubleValue(), 0.01); + assertTrue(result.getEnu().equals(SimpleEnum.ENUM1_LITERAL)); + assertEquals(FLOAT, result.getFloat().floatValue(), 0.01); + assertEquals(new Integer(INT), result.getInte()); + assertEquals(new Long(LONG), result.getLon()); + assertEquals(new Short(SHORT), result.getShor()); + store.deleteObject(result); + store.commitTransaction(); + } + + // now test a list + int length = 5; // not above 30 because is used to set the day of the + // month + Boolean[] bools = new Boolean[length]; + Byte[] bytes = new Byte[length]; + byte[] simpleBytes = new byte[length]; + Integer[] ints = new Integer[length]; + int[] simpleInts = new int[length]; + Short[] shorts = new Short[length]; + Long[] longs = new Long[length]; + Double[] doubles = new Double[length]; + Float[] floats = new Float[length]; + Date[] dates = new Date[length]; + SimpleEnum[] enums = new SimpleEnum[length]; + String[] strings = new String[length]; + Calendar cal = Calendar.getInstance(); + cal.setTime(DATE); + double[] simpleDoubles = new double[length]; + for (int i = 0; i < length; i++) { + bools[i] = new Boolean(isEven(i)); + bytes[i] = new Byte((byte) (BYTE + i)); + ints[i] = new Integer(INT + i); + shorts[i] = new Short((short) (SHORT + i)); + longs[i] = new Long(LONG + i * 100); + doubles[i] = new Double(DOUBLE + i); + floats[i] = new Float(FLOAT + i); + strings[i] = "TEST" + i; + simpleInts[i] = i; + simpleDoubles[i] = 1.156 * i; + simpleBytes[i] = (byte) (BYTE + i); + + cal.set(Calendar.DAY_OF_MONTH, i + 1); + dates[i] = cal.getTime(); + + if (isEven(i)) { + enums[i] = SimpleEnum.ENUM1_LITERAL; + } else { + enums[i] = SimpleEnum.ENUM2_LITERAL; + } + } + + { + store.beginTransaction(); + + final SimpleList stype = factory.createSimpleList(); + + stype.setCode("This is a test simplelisttype"); + copy(stype.getBoo(), bools); + copy(stype.getByt(), bytes); + copy(stype.getShor(), shorts); + copy(stype.getInte(), ints); + copy(stype.getLong(), longs); + copy(stype.getDoubl(), doubles); + copy(stype.getFloa(), floats); + copy(stype.getEnu(), enums); + copy(stype.getDat(), dates); + copy(stype.getLimitedstring(), strings); + copy(stype.getStri(), strings); + stype.setIntArray(simpleInts); + stype.setStringArray(strings); + stype.setDoubleArray(simpleDoubles); + stype.setByteArray(simpleBytes); + store.store(stype); + store.commitTransaction(); + } + { + store.beginTransaction(); + SimpleList result = store.getObject(SimpleList.class); + assertValues(result.getBoo(), bools); + assertValues(result.getByt(), bytes); + assertValues(result.getShor(), shorts); + assertValues(result.getInte(), ints); + assertValues(result.getLong(), longs); + assertValues(result.getDoubl(), doubles); + assertValues(result.getFloa(), floats); + assertValues(result.getIntArray(), simpleInts); + assertValues(result.getDoubleArray(), simpleDoubles); + assertValues(result.getStringArray(), strings); + assertValues(result.getByteArray(), simpleBytes); + assertValues(result.getStri(), strings); + + assertTrue(compare(result.getEnu(), enums)); + assertValues(store, result.getDat(), dates); + assertValues(result.getLimitedstring(), strings); + store.deleteObject(result); + store.commitTransaction(); + } + + if (store.getDatabaseAdapter().getDbUrl().indexOf("hsqldb") == -1) { + store.beginTransaction(); + + final SimpleType stype = factory.createSimpleType(); + + stype.setCode("This is a test simpletype"); + stype.setBoo(BOOL); + stype.setByt(BYTE); + stype.setDat(DATE); + stype.setDoubl(DOUBLE); + stype.setEnu(SimpleEnum.ENUM1_LITERAL); + stype.setFloat(FLOAT); + stype.setInte(INT); + stype.setLimitedstring(STRING); + stype.setLon(LONG); + stype.setShor(SHORT); + stype.setExtraLimitedString(STRING); + stype.setLimitedDecimal(bigDecimalOne); + try { + store.store(stype); + store.commitTransaction(); + // EAV does not do size checking on db level + if (!isEAVTest()) { + fail(); + } + } catch (Exception e) { + // okay, the size limit is checked + } + } + // stype.setExtraLimitedString(STRING); + } + + private boolean compare(List<SimpleEnum> list, SimpleEnum[] arr) { + int i = 0; + for (SimpleEnum se : list) { + if (se.compareTo(arr[i++]) != 0) { + return false; + } + } + return true; + } + + /** Copies the values from an array to the elist */ + private void copy(List list, Object[] objs) { + for (Object element : objs) { + list.add(element); + } + } + + /** Check result */ + private void assertValues(int[] p, int[] s) { + int cnt = 0; + for (int i = 0; i < p.length; i++) { + assertEquals(p[i], s[i]); + cnt++; + } + assertEquals(p.length, s.length); + } + + /** Check result */ + private void assertValues(byte[] p, byte[] s) { + int cnt = 0; + for (int i = 0; i < p.length; i++) { + assertEquals(p[i], s[i]); + cnt++; + } + assertEquals(p.length, s.length); + } + + /** Check result */ + private void assertValues(double[] p, double[] s) { + int cnt = 0; + for (int i = 0; i < p.length; i++) { + assertEquals(p[i], s[i], 0.001); + cnt++; + } + assertEquals(p.length, s.length); + } + + /** Check result */ + private void assertValues(String[] p, String[] s) { + int cnt = 0; + for (int i = 0; i < p.length; i++) { + assertEquals(p[i], s[i]); + cnt++; + } + assertEquals(p.length, s.length); + } + + /** Checks if all the values in the list are equal to the passed array */ + private void assertValues(List list, Boolean[] objs) { + assertEquals(objs.length, list.size()); + + for (int i = 0; i < list.size(); i++) { + assertEquals(objs[i].booleanValue(), ((Boolean) list.get(i)).booleanValue()); + } + } + + /** Checks if all the values in the list are equal to the passed array */ + private void assertValues(List list, Byte[] objs) { + assertEquals(objs.length, list.size()); + + for (int i = 0; i < list.size(); i++) { + assertEquals(objs[i].byteValue(), ((Byte) list.get(i)).byteValue()); + } + } + + /** Checks if all the values in the list are equal to the passed array */ + private void assertValues(List list, Short[] objs) { + assertEquals(objs.length, list.size()); + + for (int i = 0; i < list.size(); i++) { + assertEquals(objs[i].shortValue(), ((Short) list.get(i)).shortValue()); + } + } + + /** Checks if all the values in the list are equal to the passed array */ + private void assertValues(List list, Integer[] objs) { + assertEquals(objs.length, list.size()); + + for (int i = 0; i < list.size(); i++) { + assertEquals(objs[i].intValue(), ((Integer) list.get(i)).intValue()); + } + } + + /** Checks if all the values in the list are equal to the passed array */ + private void assertValues(List list, Long[] objs) { + assertEquals(objs.length, list.size()); + + for (int i = 0; i < list.size(); i++) { + assertEquals(objs[i].longValue(), ((Long) list.get(i)).longValue()); + } + } + + /** Checks if all the values in the list are equal to the passed array */ + private void assertValues(List list, Float[] objs) { + assertEquals(objs.length, list.size()); + + for (int i = 0; i < list.size(); i++) { + assertEquals(objs[i].floatValue(), ((Float) list.get(i)).floatValue(), 0.01); + } + } + + /** Checks if all the values in the list are equal to the passed array */ + private void assertValues(List list, Double[] objs) { + assertEquals(objs.length, list.size()); + + for (int i = 0; i < list.size(); i++) { + assertEquals(objs[i].doubleValue(), ((Double) list.get(i)).doubleValue(), 0.01); + } + } + + /** Checks if all the values in the list are equal to the passed array */ + private void assertValues(TestStore store, List list, Date[] dates) { + assertEquals(dates.length, list.size()); + + for (int i = 0; i < list.size(); i++) { + assertTrue(equalDates(store, (Date) list.get(i), dates[i])); + } + } + + /** Checks if all the values in the list are equal to the passed array */ + private void assertValues(List list, String[] strs) { + assertEquals(strs.length, list.size()); + + for (int i = 0; i < list.size(); i++) { + assertTrue(strs[i].compareTo((String) list.get(i)) == 0); + } + } + + /** returns true if the int is an even number */ + private boolean isEven(int testeven) { + return (testeven % 2 == 0); + } + + /** Compares to dates on day, month, year, hour, minutes and seconds */ + private boolean equalDates(TestStore store, Date date1, Date date2) { + Calendar cal1 = Calendar.getInstance(); + cal1.setTime(date1); + Calendar cal2 = Calendar.getInstance(); + cal2.setTime(date2); + + boolean res = true; + res &= cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR); + res &= cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH); + res &= cal1.get(Calendar.DAY_OF_MONTH) == cal2.get(Calendar.DAY_OF_MONTH); + // disabled this because the database stores dates and not timestamps + // and this + // results in small time differences + // res &= cal1.get(Calendar.HOUR_OF_DAY) == + // cal2.get(Calendar.HOUR_OF_DAY); + // res &= cal1.get(Calendar.MINUTE) == cal2.get(Calendar.MINUTE); + // res &= cal1.get(Calendar.SECOND) == cal2.get(Calendar.SECOND); + return res; + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/SimplefeaturemapAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/SimplefeaturemapAction.java new file mode 100755 index 000000000..052c199d1 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/SimplefeaturemapAction.java @@ -0,0 +1,91 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: SimplefeaturemapAction.java,v 1.4 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.schemaconstructs; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.util.FeatureMap; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.simplefeaturemap.PurchaseOrder; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.simplefeaturemap.SimplefeaturemapFactory; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.simplefeaturemap.SimplefeaturemapPackage; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.simplefeaturemap.Supplier; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests for a simple featuremap (derived features) + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.4 $ +*/ +public class SimplefeaturemapAction extends AbstractTestAction +{ + /** + * Constructor for ClassHierarchyParsing. + * @param arg0 + */ + public SimplefeaturemapAction() + { + super(SimplefeaturemapPackage.eINSTANCE); + } + + /** Creates simple types and tests against */ + public void doAction(TestStore store) + { + // test a simple type + final SimplefeaturemapFactory factory = SimplefeaturemapFactory.eINSTANCE; + { + { + store.beginTransaction(); + + PurchaseOrder pref1 = factory.createPurchaseOrder(); + pref1.setName("preferred1"); + PurchaseOrder stand1 = factory.createPurchaseOrder(); + stand1.setName("standard1"); + PurchaseOrder stand2 = factory.createPurchaseOrder(); + stand2.setName("standard2"); + + Supplier supplier = factory.createSupplier(); + supplier.setName("supplier"); + supplier.getOrders().add(SimplefeaturemapPackage.eINSTANCE.getSupplier_StandardOrders(), stand1); + supplier.getOrders().add(SimplefeaturemapPackage.eINSTANCE.getSupplier_PreferredOrders(), pref1); + supplier.getOrders().add(SimplefeaturemapPackage.eINSTANCE.getSupplier_HardCopyOrderReference(), "ref1"); + supplier.getOrders().add(SimplefeaturemapPackage.eINSTANCE.getSupplier_HardCopyOrderNumber(), new Long(1002)); + supplier.getOrders().add(SimplefeaturemapPackage.eINSTANCE.getSupplier_StandardOrders(), stand2); + +// EList standardList = + supplier.getStandardOrders(); // returns the list of standard orders, there are 2 + EList preferredList = supplier.getPreferredOrders(); // returns the list of preferred orders, there is 1 + EList numberList = supplier.getHardCopyOrderNumber(); // returns the list of hard copy numbers +// EList referenceList = + supplier.getHardCopyOrderReference(); // returns the list hard copy references + + assertEquals(1002, ((Long)numberList.get(0)).longValue()); + assertEquals("preferred1", ((PurchaseOrder)preferredList.get(0)).getName()); + + // Retrieve directly through the main featuremap member, + // this is the same purchaseorder as in the previous step + FeatureMap.Entry entry = (FeatureMap.Entry)supplier.getOrders().get(1); + PurchaseOrder referencePO = (PurchaseOrder)entry.getValue(); + + assertEquals("preferred1", referencePO.getName()); + + store.store(supplier); + store.commitTransaction(); + } + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/SubstitutionAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/SubstitutionAction.java new file mode 100755 index 000000000..258a24b3d --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/SubstitutionAction.java @@ -0,0 +1,203 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: SubstitutionAction.java,v 1.7 2010/03/27 21:14:10 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.schemaconstructs; + +import java.math.BigInteger; +import java.util.Collection; +import java.util.Iterator; + +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.substitution.ComplexNumber; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.substitution.EvenComplexNumberType; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.substitution.MultiNumberType; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.substitution.NumberType; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.substitution.OddComplexNumberType; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.substitution.SubstitutionFactory; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.substitution.SubstitutionPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests for the substitution construction. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.7 $ +*/ +public class SubstitutionAction extends AbstractTestAction +{ + /** + * Constructor for ClassHierarchyParsing. + * @param arg0 + */ + public SubstitutionAction() + { + super(SubstitutionPackage.eINSTANCE); + } + + /** Creates simple types and tests against */ + public void doAction(TestStore store) + { + // test a simple type + final SubstitutionFactory factory = SubstitutionFactory.eINSTANCE; + final SubstitutionPackage pack = SubstitutionPackage.eINSTANCE; + { + // odd complex number + { + store.beginTransaction(); + NumberType complex1 = factory.createNumberType(); + complex1.getMySimpleAbstractGroup().add(pack.getDocumentRoot_Odd(), new BigInteger("3")); + OddComplexNumberType odd = factory.createOddComplexNumberType(); + odd.setUnit("pcs"); + odd.setValue(new BigInteger("1")); + complex1.getMyComplexAbstractGroup().add(pack.getDocumentRoot_OddComplexNumber(), odd); + complex1.setName("o1"); + store.store(complex1); + store.commitTransaction(); + } + + + // even complex number + { + store.beginTransaction(); + NumberType complex1 = factory.createNumberType(); + complex1.getMySimpleAbstractGroup().add(pack.getDocumentRoot_Even(), new BigInteger("4")); + EvenComplexNumberType even = factory.createEvenComplexNumberType(); + even.setUnit("kg"); + even.setValue(new BigInteger("2")); + complex1.getMyComplexAbstractGroup().add(pack.getDocumentRoot_EvenComplexNumber(), even); + complex1.setName("e1"); + store.store(complex1); + store.commitTransaction(); + } + + // retrieve both and check the content + { + store.beginTransaction(); + Collection coll = store.getObjects(NumberType.class); + Iterator it = coll.iterator(); + while (it.hasNext()) + { + NumberType number = (NumberType)it.next(); + if (number.getName().compareTo("o1") == 0) + { + assertEquals((int)3, number.getMySimpleAbstract().intValue()); + OddComplexNumberType odd = (OddComplexNumberType)number.getMyComplexAbstractGroup().getValue(0); + assertEquals("pcs", odd.getUnit()); + assertEquals((int)1, odd.getValue().intValue()); + odd.setValue(new BigInteger("3")); + } + else if (number.getName().compareTo("e1") == 0) + { + assertEquals((int)4, number.getMySimpleAbstract().intValue()); + EvenComplexNumberType even = (EvenComplexNumberType)number.getMyComplexAbstractGroup().getValue(0); + assertEquals("kg", even.getUnit()); + assertEquals((int)2, even.getValue().intValue()); + even.setValue(new BigInteger("4")); + } + else + { + fail("The numbertype with name: " + number.getName() + " was not expected"); + } + } + store.commitTransaction(); + } + + // check the update content + { + store.beginTransaction(); + Collection coll = store.getObjects(NumberType.class); + Iterator it = coll.iterator(); + while (it.hasNext()) + { + NumberType number = (NumberType)it.next(); + if (number.getName().compareTo("o1") == 0) + { + OddComplexNumberType odd = (OddComplexNumberType)number.getMyComplexAbstractGroup().getValue(0); + assertEquals("pcs", odd.getUnit()); + assertEquals((int)3, odd.getValue().intValue()); + } + else if (number.getName().compareTo("e1") == 0) + { + EvenComplexNumberType even = (EvenComplexNumberType)number.getMyComplexAbstractGroup().getValue(0); + assertEquals("kg", even.getUnit()); + assertEquals((int)4, even.getValue().intValue()); + } + else + { + fail("The numbertype with name: " + number.getName() + " was not expected"); + } + } + store.commitTransaction(); + } + + // and now store a multinumber, use the featuremap as well as the elist entry + // after this the multicomplextype consists of: + // 1) even - 2, 2) odd - 3, 3) even - 4, 4) odd - 5 + { + store.beginTransaction(); + MultiNumberType complex = factory.createMultiNumberType(); + + EvenComplexNumberType even = factory.createEvenComplexNumberType(); + even.setUnit("pcs"); + even.setValue(new BigInteger("2")); + complex.getMyComplexAbstractGroup().add(pack.getDocumentRoot_EvenComplexNumber(), even); + + OddComplexNumberType odd = factory.createOddComplexNumberType(); + odd.setUnit("kg"); + odd.setValue(new BigInteger("3")); + complex.getMyComplexAbstractGroup().add(pack.getDocumentRoot_OddComplexNumber(), odd); + + even = factory.createEvenComplexNumberType(); + even.setUnit("pcs"); + even.setValue(new BigInteger("4")); + complex.getMyComplexAbstractGroup().add(pack.getDocumentRoot_EvenComplexNumber(), even); + + odd = factory.createOddComplexNumberType(); + odd.setUnit("kg"); + odd.setValue(new BigInteger("5")); + complex.getMyComplexAbstractGroup().add(pack.getDocumentRoot_OddComplexNumber(), odd); + + complex.setName("m1"); + store.store(complex); + store.commitTransaction(); + } + + { + store.beginTransaction(); + MultiNumberType complex = (MultiNumberType)store.getObject(MultiNumberType.class); + Iterator it = complex.getMyComplexAbstract().iterator(); + int i = 2; + while (it.hasNext()) + { + ComplexNumber number = (ComplexNumber)it.next(); + assertEquals(i++, number.getValue().intValue()); + + if (number.getValue().intValue() % 2 == 0) // even + { + assertTrue(number instanceof EvenComplexNumberType); + assertEquals("pcs", number.getUnit()); + } + else + { + assertTrue(number instanceof OddComplexNumberType); + assertEquals("kg", number.getUnit()); + } + } + store.commitTransaction(); + } + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/SubstitutionzvonAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/SubstitutionzvonAction.java new file mode 100755 index 000000000..59a0b5672 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/SubstitutionzvonAction.java @@ -0,0 +1,64 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: SubstitutionzvonAction.java,v 1.3 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.emf.schemaconstructs; + +import java.math.BigInteger; + +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.substitutionzvon.ComplexOddType; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.substitutionzvon.RootType; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.substitutionzvon.SubstitutionzvonFactory; +import org.eclipse.emf.teneo.samples.emf.schemaconstructs.substitutionzvon.SubstitutionzvonPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests for the mixed construction. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ +*/ +public class SubstitutionzvonAction extends AbstractTestAction +{ + /** + * Constructor for ClassHierarchyParsing. + * @param arg0 + */ + public SubstitutionzvonAction() + { + super(SubstitutionzvonPackage.eINSTANCE); + } + + /** Creates simple types and tests against */ + public void doAction(TestStore store) + { + // test a simple type + final SubstitutionzvonFactory factory = SubstitutionzvonFactory.eINSTANCE; + final SubstitutionzvonPackage pack = SubstitutionzvonPackage.eINSTANCE; + { + { + store.beginTransaction(); + RootType root = factory.createRootType(); + root.getMyAbstractGroup().add(pack.getDocumentRoot_Odd(), new BigInteger("5")); + ComplexOddType complexOdd = factory.createComplexOddType(); + complexOdd.setValue(39); + root.getMyComplexAbstractGroup().add(pack.getDocumentRoot_ComplexOdd(), complexOdd); + store.store(root); + store.commitTransaction(); + } + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/document_root.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/document_root.xml new file mode 100644 index 000000000..effdd1bb5 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/document_root.xml @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="ASCII"?> +<documentroot:test xmlns:documentroot="http://www.eclipse.org/emf/teneo/samples/emf/schemaconstructs/documentroot">test</documentroot:test>
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/AbstractReferenceAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/AbstractReferenceAction.java new file mode 100755 index 000000000..b799be5dc --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/AbstractReferenceAction.java @@ -0,0 +1,116 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: AbstractReferenceAction.java,v 1.6 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import java.io.IOException; +import java.util.Properties; + +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.issues.abstractreference.AbstractreferenceFactory; +import org.eclipse.emf.teneo.samples.issues.abstractreference.AbstractreferencePackage; +import org.eclipse.emf.teneo.samples.issues.abstractreference.Person; +import org.eclipse.emf.teneo.samples.issues.abstractreference.USCity; +import org.eclipse.emf.teneo.samples.issues.abstractreference.USOfficeAddress; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests reference relations between abstract relations. This failed during compute references, the test is therefore very light. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.6 $ + */ +public class AbstractReferenceAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public AbstractReferenceAction() { + super(AbstractreferencePackage.eINSTANCE); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.AbstractTestAction#hibernateEnabled() + */ + protected boolean hibernateEnabled() { + return true; + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true"); + return props; + } + + /** Creates an item, an address and links them to a po. */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + final AbstractreferenceFactory factory = AbstractreferenceFactory.eINSTANCE; + + // create a book, writer and library + try { + { + Resource res = store.getResource(); + res.load(null); + + final USOfficeAddress uoa = factory.createUSOfficeAddress(); + uoa.setName("my uoa"); + uoa.setLocation("my location"); + uoa.setState("state"); + + USCity city = factory.createUSCity(); + city.setName("my city"); + city.setState("mystate"); + uoa.getCountry().add(city); + + res.getContents().add(uoa); + res.save(null); + + Person person = factory.createPerson(); + person.setName("myname"); + person.getAddress().add(uoa); + + res.getContents().add(person); + res.save(null); + } + + { + Resource res = store.getResource(); + res.load(null); + assertEquals(2, res.getContents().size()); + // assert(res.getContents().get(0) instanceof Person); + res.unload(); + } + + { + USOfficeAddress uoa = store.getObject(USOfficeAddress.class); + Object[] eobjs = store.getCrossReferencers(uoa, true); + assertEquals(1, eobjs.length); + } + } catch (IOException e) { + throw new StoreTestException("IOException during save", e); + } + + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/AbstractTopClassAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/AbstractTopClassAction.java new file mode 100755 index 000000000..b2a850a65 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/AbstractTopClassAction.java @@ -0,0 +1,103 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * InheritanceAnnotationAction.java,v 1.6 2007/03/20 23:33:38 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import java.math.BigInteger; +import java.util.Collections; + +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.samples.issues.abstractsuper.AbstractsuperFactory; +import org.eclipse.emf.teneo.samples.issues.abstractsuper.AbstractsuperPackage; +import org.eclipse.emf.teneo.samples.issues.abstractsuper.DistrictUKAddress; +import org.eclipse.emf.teneo.samples.issues.abstractsuper.UKAddress; +import org.eclipse.emf.teneo.samples.issues.abstractsuper.USAddress; +import org.eclipse.emf.teneo.samples.issues.abstractsuper.USState; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests https://bugs.eclipse.org/bugs/show_bug.cgi?id=220106 + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.2 $ + */ +public class AbstractTopClassAction extends AbstractTestAction { + + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public AbstractTopClassAction() { + super(AbstractsuperPackage.eINSTANCE); + } + + /** Creates simple types and tests against */ + @Override + public void doAction(TestStore store) { + // test a simple type + final AbstractsuperFactory factory = AbstractsuperFactory.eINSTANCE; + { + store.beginTransaction(); + + final USAddress usaddress = factory.createUSAddress(); + usaddress.setName("Montgomery"); + usaddress.setCity("Montgomery"); + usaddress.setState(USState.AL); + usaddress.setZip(new BigInteger("36101")); + usaddress.setStreet("Montgomery street"); + store.store(usaddress); + + // test nullable fields + final USAddress emptyaddress = factory.createUSAddress(); + emptyaddress.setName("empty"); + emptyaddress.setCity("empty"); + emptyaddress.setStreet("empty"); + emptyaddress.setState(USState.AL); + emptyaddress.setZip(new BigInteger("1231")); + + store.store(usaddress); + store.store(emptyaddress); + + // create a uk address and a uk district address + final UKAddress ukaddress = factory.createUKAddress(); + ukaddress.setCity("London"); + ukaddress.setStreet("Downingstreet 10"); + ukaddress.setName("Primeminister"); + ukaddress.setPostcode("0000"); + store.store(ukaddress); + + final DistrictUKAddress districtaddress = factory.createDistrictUKAddress(); + districtaddress.setCity("district"); + districtaddress.setDistrict("district1"); + districtaddress.setName("My districtaddress"); + districtaddress.setPostcode("postcode1"); + districtaddress.setStreet("street1"); + store.store(districtaddress); + store.commitTransaction(); + } + + try { + final Resource res = store.getResource(); + res.load(Collections.EMPTY_MAP); + int cntUsAddress = 0; + for (Object o : res.getContents()) { + if (o instanceof USAddress) { + cntUsAddress++; + } else { + fail("Unexcepted class" + o.getClass().getName()); + } + } + assertEquals(2, cntUsAddress); + } catch (Exception e) { + throw new StoreTestException(e.getMessage(), e); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ224991Action.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ224991Action.java new file mode 100755 index 000000000..efbec0df7 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ224991Action.java @@ -0,0 +1,38 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: BZ224991Action.java,v 1.1 2008/04/04 11:50:31 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.samples.issues.bz224991.Bz224991Package; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase for bugzilla 225296 + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.1 $ + */ +public class BZ224991Action extends AbstractTestAction { + public BZ224991Action() { + super(new EPackage[] { Bz224991Package.eINSTANCE }); + } + + @Override + public void doAction(TestStore store) { + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ225296Action.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ225296Action.java new file mode 100755 index 000000000..0bce33961 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ225296Action.java @@ -0,0 +1,38 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: BZ225296Action.java,v 1.1 2008/04/04 11:50:30 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.samples.issues.bz225296.Bz225296Package; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase for bugzilla 225296 + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.1 $ + */ +public class BZ225296Action extends AbstractTestAction { + public BZ225296Action() { + super(new EPackage[] { Bz225296Package.eINSTANCE }); + } + + @Override + public void doAction(TestStore store) { + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ225296Action.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ225296Action.persistence.xml new file mode 100755 index 000000000..cb7e17f30 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ225296Action.persistence.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="utf-8"?> +<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.eclipse.org/emft/teneo http://www.elver.org/xsd/teneo/persistence-mapping-hibernate.xsd"> + + <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/issues/bz225296"> + <eclass name="Block"> + <proxy lazy="true" /> + <table name="ops_block" /> + <property name="id"> + <id /> + <generated-value /> + </property> + <ereference name="vserver"> + <join-column name="vserver_id" /> + </ereference> + </eclass> + + <eclass name="VServer"> + <table name="ops_vserver" /> + <property name="id"> + <id /> + <generated-value /> + </property> + <ereference name="blocks"> + <fetch>SELECT</fetch> + <one-to-many fetch="LAZY" indexed="false" /> + <join-column name="vserver_id" /> + </ereference> + </eclass> + </epackage> + +</persistence-mapping>
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ225296_2Action.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ225296_2Action.java new file mode 100755 index 000000000..0d0599877 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ225296_2Action.java @@ -0,0 +1,38 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: BZ225296_2Action.java,v 1.1 2008/04/06 13:44:01 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.samples.issues.bz225296_2.ops.OpsPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase for bugzilla 225296 + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.1 $ + */ +public class BZ225296_2Action extends AbstractTestAction { + public BZ225296_2Action() { + super(new EPackage[] { OpsPackage.eINSTANCE }); + } + + @Override + public void doAction(TestStore store) { + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ225296_2Action.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ225296_2Action.persistence.xml new file mode 100755 index 000000000..13c2bf6be --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ225296_2Action.persistence.xml @@ -0,0 +1,470 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.eclipse.org/emft/teneo http://www.elver.org/xsd/teneo/persistence-mapping-hibernate.xsd"> + + <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/issues/bz225296_2"> + + <eclass name="Block"> + <proxy lazy="true" /> + <table name="ops_block" /> + <property name="id"> + <id /> + <generated-value /> + </property> + <ereference name="vserver"> + <join-column name="vserver_id" /> + </ereference> + <property name="revision"> + <version /> + <column name="e_version" /> + </property> + <property name="modified"> + <column column-definition="timestamp" insertable="false" + updatable="false" /> + <generated>ALWAYS</generated> + <temporal>TIMESTAMP</temporal> + </property> + </eclass> + + <eclass name="DataCenter"> + <table name="ops_datacenter" /> + <property name="id"> + <id /> + <generated-value /> + </property> + <ereference name="host"> + <fetch>SUBSELECT</fetch> + <one-to-many fetch="LAZY" indexed="false" /> + <join-column name="datacenter_id" /> + </ereference> + <property name="description"> + <lob /> + <column length="64000" /> + </property> + <property name="revision"> + <version /> + <column name="e_version" /> + </property> + <property name="modified"> + <column column-definition="timestamp" insertable="false" + updatable="false" /> + <generated>ALWAYS</generated> + <temporal>TIMESTAMP</temporal> + </property> + </eclass> + + <eclass name="Domain"> + <table name="domain" /> + <property name="id"> + <id /> + <generated-value /> + </property> + <ereference name="systems"> + <fetch>SELECT</fetch> + <many-to-many indexed="false" fetch="LAZY" /> + <join-table name="domain_system"> + <join-column name="domain_id" nullable="false" /> + </join-table> + </ereference> + <property name="revision"> + <version /> + <column name="e_version" /> + </property> + <property name="modified"> + <column column-definition="timestamp" insertable="false" + updatable="false" /> + <generated>ALWAYS</generated> + <temporal>TIMESTAMP</temporal> + </property> + </eclass> + + <eclass name="DomainSystem"> + <table name="domainsystem" /> + <property name="id"> + <id /> + <generated-value /> + </property> + <ereference name="domains"> + <fetch>SELECT</fetch> + <many-to-many indexed="false" fetch="LAZY" mapped-by="systems" /> + <join-table name="domain_system"> + <join-column name="system_id" nullable="false" /> + </join-table> + </ereference> + <ereference name="opsSystem"> + <fetch>SELECT</fetch> + <many-to-many indexed="false" fetch="LAZY" mapped-by="systems" /> + <join-table name="ops_domainsystem_opssystem"> + <join-column name="domainsystem_id" nullable="false" /> + <inverse-join-column name="system_id" nullable="false" /> + </join-table> + </ereference> + <ereference name="interface"> + <join-column name="interface_id" /> + </ereference> + <property name="revision"> + <version /> + <column name="e_version" /> + </property> + <property name="modified"> + <column column-definition="timestamp" insertable="false" + updatable="false" /> + <generated>ALWAYS</generated> + <temporal>TIMESTAMP</temporal> + </property> + </eclass> + + <eclass name="FailoverType"> + <table name="ops_failovertype" /> + <property name="id"> + <id /> + <generated-value /> + </property> + <property name="revision"> + <version /> + <column name="e_version" /> + </property> + <property name="modified"> + <column column-definition="timestamp" insertable="false" + updatable="false" /> + <generated>ALWAYS</generated> + <temporal>TIMESTAMP</temporal> + </property> + </eclass> + + <eclass name="Host"> + <table name="ops_host" /> + <property name="id"> + <id /> + <generated-value /> + </property> + <ereference name="vserver"> + <fetch>SUBSELECT</fetch> + <one-to-many fetch="LAZY" indexed="false" /> + <join-column name="host_id" /> + </ereference> + <ereference name="ip"> + <fetch>SUBSELECT</fetch> + <one-to-many fetch="LAZY" indexed="false" /> + <join-column name="host_id" /> + </ereference> + <ereference name="ownIp"> + <join-column name="ownip_id" /> + </ereference> + <property name="description"> + <lob /> + <column length="64000" /> + </property> + <property name="network"> + <lob /> + <column length="64000" /> + </property> + <property name="providerId"> + <lob /> + <column length="64000" unique="true" /> + </property> + <property name="block"> + <fetch>SUBSELECT</fetch> + <one-to-many fetch="LAZY" indexed="false" /> + <join-column name="host_id" /> + </property> + <property name="revision"> + <version /> + <column name="e_version" /> + </property> + <property name="modified"> + <column column-definition="timestamp" insertable="false" + updatable="false" /> + <generated>ALWAYS</generated> + <temporal>TIMESTAMP</temporal> + </property> + </eclass> + + + + <eclass name="HostBlock"> + <table name="ops_hostblock" /> + <property name="id"> + <id /> + <generated-value /> + </property> + <ereference name="host"> + <join-column name="host_id" /> + </ereference> + <property name="revision"> + <version /> + <column name="e_version" /> + </property> + <property name="modified"> + <column column-definition="timestamp" insertable="false" + updatable="false" /> + <generated>ALWAYS</generated> + <temporal>TIMESTAMP</temporal> + </property> + </eclass> + + <eclass name="Interface"> + <table name="ops_interface" /> + <property name="id"> + <id /> + <generated-value /> + </property> + <ereference name="role"> + <fetch>SELECT</fetch> + <many-to-many indexed="false" fetch="LAZY" mapped-by="interface" /> + <join-table name="ops_role_interface"> + <join-column name="interface_id" nullable="false" /> + </join-table> + </ereference> + <ereference name="domainSystem"> + <fetch>SELECT</fetch> + <one-to-many fetch="LAZY" indexed="false" /> + <join-column name="interface_id" /> + </ereference> + <ereference name="failoverType"> + <join-column name="failovertype_id" /> + </ereference> + <property name="revision"> + <version /> + <column name="e_version" /> + </property> + <property name="modified"> + <column column-definition="timestamp" insertable="false" + updatable="false" /> + <generated>ALWAYS</generated> + <temporal>TIMESTAMP</temporal> + </property> + </eclass> + + <eclass name="IP"> + <table name="ops_ip" /> + <property name="id"> + <id /> + <generated-value /> + </property> + <ereference name="ipName"> + <fetch>SELECT</fetch> + <many-to-many indexed="false" mapped-by="ip" fetch="LAZY" /> + <join-table name="ops_ip_ipname"> + <join-column name="ip_id" nullable="false" /> + </join-table> + </ereference> + <ereference name="vserver"> + <fetch>SELECT</fetch> + <many-to-many indexed="false" fetch="LAZY" mapped-by="ip" /> + <join-table name="ops_vserver_ip"> + <join-column name="ip_id" nullable="false" /> + </join-table> + </ereference> + <ereference name="host"> + <join-column name="host_id" /> + </ereference> + <property name="revision"> + <version /> + <column name="e_version" /> + </property> + <property name="modified"> + <column column-definition="timestamp" insertable="false" + updatable="false" /> + <generated>ALWAYS</generated> + <temporal>TIMESTAMP</temporal> + </property> + </eclass> + + <eclass name="MuninInfo"> + <table name="ops_munininfo" /> + <property name="id"> + <id /> + <generated-value /> + </property> + <property name="pluginName"> + <lob /> + <column length="64000" unique="true" /> + </property> + <ereference name="role"> + <join-column name="role_id" /> + </ereference> + <property name="revision"> + <version /> + <column name="e_version" /> + </property> + <property name="modified"> + <column column-definition="timestamp" insertable="false" + updatable="false" /> + <generated>ALWAYS</generated> + <temporal>TIMESTAMP</temporal> + </property> + </eclass> + + <eclass name="IPName"> + <table name="ops_ipname" /> + <property name="id"> + <id /> + <generated-value /> + </property> + <ereference name="ip"> + <fetch>SELECT</fetch> + <many-to-many indexed="false" fetch="LAZY" /> + <join-table name="ops_ip_ipname"> + <join-column name="ipname_id" nullable="false" /> + </join-table> + </ereference> + <property name="revision"> + <version /> + <column name="e_version" /> + </property> + <property name="modified"> + <column column-definition="timestamp" insertable="false" + updatable="false" /> + <generated>ALWAYS</generated> + <temporal>TIMESTAMP</temporal> + </property> + </eclass> + + <eclass name="Parameter"> + <table name="ops_parameter" /> + <property name="id"> + <id /> + <generated-value /> + </property> + <property name="revision"> + <version /> + <column name="e_version" /> + </property> + <property name="modified"> + <column column-definition="timestamp" insertable="false" + updatable="false" /> + <generated>ALWAYS</generated> + <temporal>TIMESTAMP</temporal> + </property> + </eclass> + + <eclass name="Role"> + <table name="ops_role" /> + <property name="id"> + <id /> + <generated-value /> + </property> + <ereference name="interface"> + <fetch>SELECT</fetch> + <many-to-many indexed="false" fetch="LAZY" /> + <join-table name="ops_role_interface"> + <join-column name="role_id" nullable="false" /> + </join-table> + </ereference> + <ereference name="vserver"> + <fetch>SELECT</fetch> + <one-to-many fetch="LAZY" indexed="false" /> + <join-column name="role_id" /> + </ereference> + <ereference name="requiredInterface"> + <fetch>SELECT</fetch> + <many-to-many indexed="false" fetch="LAZY" /> + <join-table name="ops_role_requredinterface"> + <join-column name="role_id" nullable="false" /> + </join-table> + </ereference> + <ereference name="muninInfo"> + <fetch>SUBSELECT</fetch> + <one-to-many fetch="LAZY" indexed="false" /> + <join-column name="role_id" /> + </ereference> + <property name="revision"> + <version /> + <column name="e_version" /> + </property> + <property name="modified"> + <column column-definition="timestamp" insertable="false" + updatable="false" /> + <generated>ALWAYS</generated> + <temporal>TIMESTAMP</temporal> + </property> + </eclass> + + <eclass name="OpsSystem"> + <table name="ops_opssystem" /> + <property name="id"> + <id /> + <generated-value /> + </property> + <ereference name="ownVserver"> + <fetch>SELECT</fetch> + <one-to-many fetch="LAZY" indexed="false" /> + <join-column name="own_opssystem_id" /> + </ereference> + <ereference name="servingVserver"> + <fetch>SELECT</fetch> + <many-to-many indexed="false" fetch="LAZY" mapped-by="servedSystem" /> + <join-table name="ops_vserver_opssystem"> + <join-column name="opssystem_id" nullable="false" /> + </join-table> + </ereference> + <ereference name="domainSystem"> + <fetch>SELECT</fetch> + <many-to-many indexed="false" fetch="LAZY" mapped-by="opsSystem" /> + <join-table name="ops_domainsystem_opssystem"> + <join-column name="opssystem_id" nullable="false" /> + </join-table> + </ereference> + <property name="revision"> + <version /> + <column name="e_version" /> + </property> + <property name="modified"> + <column column-definition="timestamp" insertable="false" + updatable="false" /> + <generated>ALWAYS</generated> + <temporal>TIMESTAMP</temporal> + </property> + </eclass> + + <eclass name="VServer"> + <table name="ops_vserver" /> + <property name="id"> + <id /> + <generated-value /> + </property> + <ereference name="block"> + <fetch>SELECT</fetch> + <one-to-many fetch="LAZY" indexed="false" /> + <join-column name="vserver_id" /> + </ereference> + <ereference name="servedSystem"> + <fetch>SELECT</fetch> + <many-to-many indexed="false" fetch="LAZY" /> + <join-table name="ops_vserver_opssystem"> + <join-column name="vserver_id" nullable="false" /> + </join-table> + </ereference> + <ereference name="ip"> + <fetch>SELECT</fetch> + <many-to-many indexed="false" fetch="LAZY" /> + <join-table name="ops_vserver_ip"> + <join-column name="vserver_id" nullable="false" /> + </join-table> + </ereference> + <ereference name="role"> + <join-column name="role_id" /> + </ereference> + <ereference name="host"> + <join-column name="host_id" /> + </ereference> + <ereference name="ownSystem"> + <join-column name="own_opssystem_id" /> + </ereference> + <property name="revision"> + <version /> + <column name="e_version" /> + </property> + <property name="modified"> + <column column-definition="timestamp" insertable="false" + updatable="false" /> + <generated>ALWAYS</generated> + <temporal>TIMESTAMP</temporal> + </property> + </eclass> + + + </epackage> +</persistence-mapping> diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ237361Action.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ237361Action.java new file mode 100755 index 000000000..dd0f30627 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ237361Action.java @@ -0,0 +1,64 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: BZ237361Action.java,v 1.2 2008/09/01 13:41:52 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.samples.issues.bz237361.Bz237361Factory; +import org.eclipse.emf.teneo.samples.issues.bz237361.Bz237361Package; +import org.eclipse.emf.teneo.samples.issues.bz237361.Many; +import org.eclipse.emf.teneo.samples.issues.bz237361.One; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase for bugzilla 237361 + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.2 $ + */ +public class BZ237361Action extends AbstractTestAction { + public BZ237361Action() { + super(new EPackage[] { Bz237361Package.eINSTANCE }); + } + + @Override + public void doAction(TestStore store) { + final Bz237361Factory factory = Bz237361Factory.eINSTANCE; + { + store.beginTransaction(); + final One one = factory.createOne(); + final Many many1 = factory.createMany(); + many1.setName("zzz"); + final Many many2 = factory.createMany(); + many2.setName("aaa"); + one.getManies().add(many1); + one.getManies().add(many2); + store.store(one); + store.commitTransaction(); + } + + { + store.beginTransaction(); + final One one = store.getObject(One.class); + final Many m1 = one.getManies().get(0); + assertEquals("zzz", m1.getName()); + final Many m2 = one.getManies().get(1); + assertEquals("aaa", m2.getName()); + store.commitTransaction(); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ237498Action.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ237498Action.java new file mode 100755 index 000000000..e96500d47 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ237498Action.java @@ -0,0 +1,87 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: BZ237498Action.java,v 1.3 2009/03/06 12:31:21 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import java.util.Properties; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.issues.bz237498.Bz237498Factory; +import org.eclipse.emf.teneo.samples.issues.bz237498.Bz237498Package; +import org.eclipse.emf.teneo.samples.issues.bz237498.Many; +import org.eclipse.emf.teneo.samples.issues.bz237498.One; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase for bugzilla 237498 + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ + */ +public class BZ237498Action extends AbstractTestAction { + public BZ237498Action() { + super(new EPackage[] { Bz237498Package.eINSTANCE }); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties + * () + */ + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true"); + return props; + } + + @Override + public void doAction(TestStore store) { + + // don't do anything for now + if (store.getDatabaseAdapter().getDbDriver().indexOf("hsqldb") != -1) { + return; + } + + final Bz237498Factory factory = Bz237498Factory.eINSTANCE; + { + store.beginTransaction(); + final One one = factory.createOne(); + final Many many1 = factory.createMany(); + many1.setName("zzz"); + final Many many2 = factory.createMany(); + many2.setName("aaa"); + one.getManies().add(many1); + one.getManies().add(many2); + store.store(one); + store.commitTransaction(); + } + + { + store.beginTransaction(); + final One one = store.getObject(One.class); + final Many m1 = one.getManies().get(0); + assertEquals("aaa", m1.getName()); + final Many m2 = one.getManies().get(1); + assertEquals("zzz", m2.getName()); + store.commitTransaction(); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ237790Action.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ237790Action.java new file mode 100755 index 000000000..98f4ec449 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ237790Action.java @@ -0,0 +1,79 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: BZ237790Action.java,v 1.1 2008/06/28 23:11:49 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import java.util.Properties; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.issues.bz237790.Bz237790Factory; +import org.eclipse.emf.teneo.samples.issues.bz237790.Bz237790Package; +import org.eclipse.emf.teneo.samples.issues.bz237790.Many; +import org.eclipse.emf.teneo.samples.issues.bz237790.One; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase for bugzilla 237790 + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.1 $ + */ +public class BZ237790Action extends AbstractTestAction { + public BZ237790Action() { + super(new EPackage[] { Bz237790Package.eINSTANCE }); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties() + */ + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.MAP_ALL_LISTS_AS_IDBAG, "true"); + return props; + } + + @Override + public void doAction(TestStore store) { + final Bz237790Factory factory = Bz237790Factory.eINSTANCE; + { + store.beginTransaction(); + final One one = factory.createOne(); + final Many many1 = factory.createMany(); + many1.setName("zzz"); + final Many many2 = factory.createMany(); + many2.setName("aaa"); + one.getManies().add(many1); + one.getManies().add(many2); + store.store(one); + store.commitTransaction(); + } + + { + store.beginTransaction(); + final One one = store.getObject(One.class); + final Many m1 = one.getManies().get(0); + assertEquals("zzz", m1.getName()); + final Many m2 = one.getManies().get(1); + assertEquals("aaa", m2.getName()); + store.commitTransaction(); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ237994Action.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ237994Action.java new file mode 100755 index 000000000..203b8e716 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ237994Action.java @@ -0,0 +1,64 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: BZ237994Action.java,v 1.1 2008/06/29 14:23:08 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.samples.issues.bz237994.Bz237994Factory; +import org.eclipse.emf.teneo.samples.issues.bz237994.Bz237994Package; +import org.eclipse.emf.teneo.samples.issues.bz237994.Many; +import org.eclipse.emf.teneo.samples.issues.bz237994.One; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase for bugzilla 237994 + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.1 $ + */ +public class BZ237994Action extends AbstractTestAction { + public BZ237994Action() { + super(new EPackage[] { Bz237994Package.eINSTANCE }); + } + + @Override + public void doAction(TestStore store) { + final Bz237994Factory factory = Bz237994Factory.eINSTANCE; + { + store.beginTransaction(); + final One one = factory.createOne(); + final Many many1 = factory.createMany(); + many1.setName("zzz"); + final Many many2 = factory.createMany(); + many2.setName("aaa"); + one.getManies().add(many1); + one.getManies().add(many2); + store.store(one); + store.commitTransaction(); + } + + { + store.beginTransaction(); + final One one = store.getObject(One.class); + final Many m1 = one.getManies().get(0); + assertEquals("zzz", m1.getName()); + final Many m2 = one.getManies().get(1); + assertEquals("aaa", m2.getName()); + store.commitTransaction(); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ247785Action.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ247785Action.java new file mode 100755 index 000000000..b57d7373c --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ247785Action.java @@ -0,0 +1,67 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: BZ247785Action.java,v 1.1 2008/09/20 21:20:11 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.samples.issues.bz247785.Bz247785Factory; +import org.eclipse.emf.teneo.samples.issues.bz247785.Bz247785Package; +import org.eclipse.emf.teneo.samples.issues.bz247785.Owner; +import org.eclipse.emf.teneo.samples.issues.bz247785.bz247785Sub.Animal; +import org.eclipse.emf.teneo.samples.issues.bz247785.bz247785Sub.Bz247785SubFactory; +import org.eclipse.emf.teneo.samples.issues.bz247785.bz247785Sub.Cat; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase for bugzilla 247939 + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.1 $ + */ +public class BZ247785Action extends AbstractTestAction { + public BZ247785Action() { + super(new EPackage[] { Bz247785Package.eINSTANCE }); + } + + @Override + public void doAction(TestStore store) { + final Bz247785Factory factory = Bz247785Factory.eINSTANCE; + { + store.beginTransaction(); + final Owner o = factory.createOwner(); + o.setName("n1"); + store.store(o); + for (int i = 0; i < 10; i++) { + final Cat c = Bz247785SubFactory.eINSTANCE.createCat(); + c.setOwner(o); + store.store(c); + } + for (int i = 0; i < 10; i++) { + final Animal a = Bz247785SubFactory.eINSTANCE.createAnimal(); + store.store(a); + } + store.commitTransaction(); + } + { + store.beginTransaction(); + store.checkNumber(Cat.class, 10); + store.checkNumber(Animal.class, 20); + store.checkNumber(Owner.class, 1); + store.commitTransaction(); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ247939Action.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ247939Action.java new file mode 100755 index 000000000..9b701ba09 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ247939Action.java @@ -0,0 +1,66 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: BZ247939Action.java,v 1.2 2008/09/20 21:25:13 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.samples.issues.bz247939.Animal; +import org.eclipse.emf.teneo.samples.issues.bz247939.Bz247939Factory; +import org.eclipse.emf.teneo.samples.issues.bz247939.Bz247939Package; +import org.eclipse.emf.teneo.samples.issues.bz247939.Cat; +import org.eclipse.emf.teneo.samples.issues.bz247939.Owner; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase for bugzilla 247939 + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.2 $ + */ +public class BZ247939Action extends AbstractTestAction { + public BZ247939Action() { + super(new EPackage[] { Bz247939Package.eINSTANCE }); + } + + @Override + public void doAction(TestStore store) { + final Bz247939Factory factory = Bz247939Factory.eINSTANCE; + { + store.beginTransaction(); + final Owner o = factory.createOwner(); + o.setName("n1"); + store.store(o); + for (int i = 0; i < 10; i++) { + final Cat c = factory.createCat(); + c.setOwner(o); + store.store(c); + } + for (int i = 0; i < 10; i++) { + final Animal a = factory.createAnimal(); + store.store(a); + } + store.commitTransaction(); + } + { + store.beginTransaction(); + store.checkNumber(Cat.class, 10); + store.checkNumber(Animal.class, 20); + store.checkNumber(Owner.class, 1); + store.commitTransaction(); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ249246Action.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ249246Action.java new file mode 100755 index 000000000..c744a7ddb --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ249246Action.java @@ -0,0 +1,35 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: BZ249246Action.java,v 1.2 2008/10/12 21:02:11 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import org.eclipse.emf.teneo.samples.issues.bz249246.Bz249246Package; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.2 $ + */ +public class BZ249246Action extends AbstractTestAction { + public BZ249246Action() { + super(Bz249246Package.eINSTANCE); + } + + @Override + public void doAction(TestStore store) { + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ249440Action.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ249440Action.java new file mode 100755 index 000000000..9d5964885 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ249440Action.java @@ -0,0 +1,46 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: BZ249440Action.java,v 1.2 2008/10/12 21:02:11 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.2 $ + */ +public class BZ249440Action extends AbstractTestAction { + public BZ249440Action() { + super(LibraryPackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS, "false"); + props.setProperty(PersistenceOptions.JOIN_COLUMN_NAMING_STRATEGY, "simple"); + return props; + } + + @Override + public void doAction(TestStore store) { + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ253799Action.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ253799Action.java new file mode 100755 index 000000000..3484168b5 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ253799Action.java @@ -0,0 +1,52 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: BZ253799Action.java,v 1.1 2008/11/15 21:37:37 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.samples.issues.bz253799.Bz253799Factory; +import org.eclipse.emf.teneo.samples.issues.bz253799.Bz253799Package; +import org.eclipse.emf.teneo.samples.issues.bz253799.One; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase for bugzilla 253799 + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.1 $ + */ +public class BZ253799Action extends AbstractTestAction { + public BZ253799Action() { + super(new EPackage[] { Bz253799Package.eINSTANCE }); + } + + @Override + public void doAction(TestStore store) { + final Bz253799Factory factory = Bz253799Factory.eINSTANCE; + { + store.beginTransaction(); + final One one = factory.createOne(); + try { + store.store(one); + store.commitTransaction(); + fail(); + } catch (Exception e) { + // successfull + } + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ277546Action.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ277546Action.java new file mode 100644 index 000000000..ba62050d8 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ277546Action.java @@ -0,0 +1,55 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: BZ277546Action.java,v 1.2 2009/05/23 10:51:26 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import java.util.Properties; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.samples.issues.bz277546.Bz277546Factory; +import org.eclipse.emf.teneo.samples.issues.bz277546.Bz277546Package; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase for bugzilla 277546 + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.2 $ + */ +public class BZ277546Action extends AbstractTestAction { + public BZ277546Action() { + super(new EPackage[] { Bz277546Package.eINSTANCE }); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(super.getExtraConfigurationProperties()); + // props.put(PersistenceOptions.XSDDATE_CLASS, "java.util.Date"); + // props.put(PersistenceOptions.USER_XSDDATETIME_TYPE, "timestamp"); + return props; + } + + @Override + public void doAction(TestStore store) { + final Bz277546Factory factory = Bz277546Factory.eINSTANCE; + store.beginTransaction(); + store.store(factory.createDateVersion()); + store.store(factory.createSimpleVersion()); + store.store(factory.createAnotherVersion()); + store.commitTransaction(); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ277570Action.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ277570Action.java new file mode 100644 index 000000000..268352f3e --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ277570Action.java @@ -0,0 +1,79 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: BZ277570Action.java,v 1.3 2009/08/21 15:02:00 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import java.util.Properties; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.issues.adept.Bar; +import org.eclipse.emf.teneo.samples.issues.adept.Biff; +import org.eclipse.emf.teneo.samples.issues.adept.Bz277570Factory; +import org.eclipse.emf.teneo.samples.issues.adept.Bz277570Package; +import org.eclipse.emf.teneo.samples.issues.adept.Foo; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase for bugzilla 277570. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ + */ +public class BZ277570Action extends AbstractTestAction { + public BZ277570Action() { + super(new EPackage[] { Bz277570Package.eINSTANCE }); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(super.getExtraConfigurationProperties()); + props.put(PersistenceOptions.DISABLE_ECONTAINER_MAPPING, "true"); + props.put(PersistenceOptions.ALWAYS_VERSION, "false"); + return props; + } + + @Override + public void doAction(TestStore store) { + final Bz277570Factory factory = Bz277570Factory.eINSTANCE; + store.beginTransaction(); + { + final Foo foo = factory.createFoo(); + foo.setId(1); + store.store(foo); + } + store.commitTransaction(); + + store.refresh(); + + final Foo foo = factory.createFoo(); + foo.setId(1); + final Bar bar = factory.createBar(); + foo.getBars().add(bar); + final Biff biff = factory.createBiff(); + biff.setId(2); + biff.setName("name"); + foo.getBiffs().add(biff); + bar.setBaz(biff); + bar.setId(3); + bar.setName("name"); + + store.beginTransaction(); + store.merge(foo); + store.commitTransaction(); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ302933Action.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ302933Action.java new file mode 100644 index 000000000..1805e2499 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ302933Action.java @@ -0,0 +1,38 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: BZ302933Action.java,v 1.2 2010/03/25 00:32:44 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.samples.issues.bz302933.bz302933_1.Bz302933_1Package; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase for bugzilla 302933 + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.2 $ + */ +public class BZ302933Action extends AbstractTestAction { + public BZ302933Action() { + super(new EPackage[] { Bz302933_1Package.eINSTANCE }); + } + + @Override + public void doAction(TestStore store) { + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BagDuplicateAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BagDuplicateAction.java new file mode 100755 index 000000000..b677c45aa --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BagDuplicateAction.java @@ -0,0 +1,85 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: BagDuplicateAction.java,v 1.4 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.issues.bagduplicate.BagduplicateFactory; +import org.eclipse.emf.teneo.samples.issues.bagduplicate.BagduplicatePackage; +import org.eclipse.emf.teneo.samples.issues.bagduplicate.Person; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests issue with bag + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.4 $ + */ +public class BagDuplicateAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public BagDuplicateAction() { + super(BagduplicatePackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true"); + return props; + } + + /** Creates an item, an address and links them to a po. */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + { + store.beginTransaction(); + Person father = BagduplicateFactory.eINSTANCE.createPerson(); + father.setName("father"); + Person mother = BagduplicateFactory.eINSTANCE.createPerson(); + mother.setName("mother"); + Person child1 = BagduplicateFactory.eINSTANCE.createPerson(); + child1.setName("child1"); + Person child2 = BagduplicateFactory.eINSTANCE.createPerson(); + child2.setName("child2"); + father.getChildren().add(child1); + father.getChildren().add(child2); + mother.getChildren().add(child1); + mother.getChildren().add(child2); + store.store(father); + store.store(mother); + store.commitTransaction(); + } + + { + store.beginTransaction(); + Person father = (Person) store.query(Person.class, "name", "father", 1).get(0); + Person mother = (Person) store.query(Person.class, "name", "mother", 1).get(0); + assertEquals(2, father.getChildren().size()); + assertEquals(2, mother.getChildren().size()); + assertEquals(father.getChildren().get(0), mother.getChildren().get(0)); + assertEquals(father.getChildren().get(1), mother.getChildren().get(1)); + store.commitTransaction(); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/EnumTestAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/EnumTestAction.java new file mode 100755 index 000000000..6425e5e1f --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/EnumTestAction.java @@ -0,0 +1,108 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: EnumTestAction.java,v 1.6 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import java.util.Iterator; +import java.util.List; + +import org.eclipse.emf.teneo.samples.issues.enumtest.EnumtestFactory; +import org.eclipse.emf.teneo.samples.issues.enumtest.EnumtestPackage; +import org.eclipse.emf.teneo.samples.issues.enumtest.Item; +import org.eclipse.emf.teneo.samples.issues.enumtest.ItemType; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests nullable enum and enum as id + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.6 $ + */ +public class EnumTestAction extends AbstractTestAction { + /** + * Constructor. + * + * @param arg0 + */ + public EnumTestAction() { + super(EnumtestPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + public void doAction(TestStore store) { + { + store.beginTransaction(); + Item itemFamily = EnumtestFactory.eINSTANCE.createItem(); + itemFamily.setItemType(ItemType.PRODUCT_FAMILY_LITERAL); + itemFamily.setNullableItemType(null); + store.store(itemFamily); + Item item = EnumtestFactory.eINSTANCE.createItem(); + item.setItemType(ItemType.PRODUCT_LITERAL); + item.setNullableItemType(ItemType.PRODUCT_LITERAL); + store.store(item); + store.commitTransaction(); + } + + { + try { + store.beginTransaction(); + Item itemFamily = EnumtestFactory.eINSTANCE.createItem(); + itemFamily.setItemType(ItemType.PRODUCT_FAMILY_LITERAL); + store.store(itemFamily); + store.commitTransaction(); + fail("Enum primary key does not work"); + } catch (Exception e) { + // correct this should fail + store.rollbackTransaction(); + } + } + + { + store.beginTransaction(); + List<?> list = store.getObjects(Item.class); + assertEquals(2, list.size()); + for (Iterator<?> it = list.iterator(); it.hasNext();) { + Item item = (Item) it.next(); + if (item.getItemType().getValue() == ItemType.PRODUCT_FAMILY) { + assertTrue(item.getNullableItemType() == null); + } else if (item.getItemType().getValue() == ItemType.PRODUCT) { + assertTrue(item.getNullableItemType().getValue() == ItemType.PRODUCT); + } else { + fail("Unknown item"); + } + } + store.commitTransaction(); + } +/* + // do save action with a resource + try { + final Resource rs = store.getResource(); + final Item item1 = EnumtestFactory.eINSTANCE.createItem(); + item1.setItemType(ItemType.PRODUCT_FAMILY_LITERAL); + item1.setNullableItemType(null); + rs.getContents().add(item1); + final Item item2 = EnumtestFactory.eINSTANCE.createItem(); + item2.setItemType(ItemType.PRODUCT_FAMILY_LITERAL); + item2.setNullableItemType(ItemType.PRODUCT_LITERAL); + rs.getContents().add(item2); + rs.save(Collections.EMPTY_MAP); + } catch (IOException e) { + throw new StoreTestException("Exception while saving resource", e); + } +*/ + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/FruitsAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/FruitsAction.java new file mode 100755 index 000000000..0d5fbfb0d --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/FruitsAction.java @@ -0,0 +1,38 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: FruitsAction.java,v 1.2 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +import tc.apple.ApplePackage; +import tc.tree.TreePackage; + +/** + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.2 $ + */ +public class FruitsAction extends AbstractTestAction { + public FruitsAction() { + super(new EPackage[] { TreePackage.eINSTANCE, ApplePackage.eINSTANCE }); + } + + @Override + public void doAction(TestStore store) { + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/GeneralTestAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/GeneralTestAction.java new file mode 100755 index 000000000..1414eea5d --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/GeneralTestAction.java @@ -0,0 +1,143 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: GeneralTestAction.java,v 1.4 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.issues.generaltest.Address; +import org.eclipse.emf.teneo.samples.issues.generaltest.City; +import org.eclipse.emf.teneo.samples.issues.generaltest.Contact; +import org.eclipse.emf.teneo.samples.issues.generaltest.Country; +import org.eclipse.emf.teneo.samples.issues.generaltest.GeneralTestFactory; +import org.eclipse.emf.teneo.samples.issues.generaltest.GeneralTestPackage; +import org.eclipse.emf.teneo.samples.issues.generaltest.State; +import org.eclipse.emf.teneo.samples.issues.generaltest.TC; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * General Test, contains test cases for different issues: - 187984 - 193697 - 193697 - 188973 + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.4 $ $Date: 2008/02/28 07:08:16 $ + */ +public class GeneralTestAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public GeneralTestAction() { + super(GeneralTestPackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "false"); + return props; + } + + /** Doaction */ + @Override + public void doAction(TestStore store) { + // check + if (store.isHibernateTestStore()) { + final Address a = GeneralTestFactory.eINSTANCE.createAddress(); + a.setName("a"); + a.setVolatileString("v1"); + final Contact contact = GeneralTestFactory.eINSTANCE.createContact(); + contact.setName("c"); + a.getContacts().add(contact); + final City c = GeneralTestFactory.eINSTANCE.createCity(); + c.setName("c"); + a.setCity(c); + final Country country = GeneralTestFactory.eINSTANCE.createCountry(); + country.setName("c"); + a.setCountry(country); + final State s = GeneralTestFactory.eINSTANCE.createState(); + s.setName("s"); + a.setState(s); + try { + store.beginTransaction(); + store.store(a); + store.commitTransaction(); + fail("This should fail as 'a' references an object 'country' which is not saved automatically because cascade is set of as a default for mto"); + } catch (Exception e) { + // okay, many-to-one is not cascaded + + // note we can't resave a because in the IdentifierCacheHandler already an id has + // been + // assigned to a and saving this same object again will result in a + // staleobjectexception + } + } + + // do it again but now better + { + final Address a = GeneralTestFactory.eINSTANCE.createAddress(); + a.setName("a"); + a.setVolatileString("v1"); + final Contact contact = GeneralTestFactory.eINSTANCE.createContact(); + contact.setName("c"); + a.getContacts().add(contact); + final City c = GeneralTestFactory.eINSTANCE.createCity(); + c.setName("c"); + a.setCity(c); + final TC tc = GeneralTestFactory.eINSTANCE.createTC(); + tc.setName("tc"); + a.getTc().add(tc); + final Country country = GeneralTestFactory.eINSTANCE.createCountry(); + country.setName("c"); + a.setCountry(country); + final State s = GeneralTestFactory.eINSTANCE.createState(); + s.setName("s"); + a.setState(s); + store.refresh(); + store.beginTransaction(); + store.store(tc); + store.store(country); + store.store(a); + store.commitTransaction(); + } + + // and read the data + { + store.beginTransaction(); + if (store.isHibernateTestStore()) { + // check call 187984 + final City c = store.getObject(City.class); + final Contact contact = store.getObject(Contact.class); + final TC tc = store.getObject(TC.class); + assertNotNull("econtainer should be set", c.eContainer()); + assertNotNull("econtainer should be set", contact.eContainer()); + assertNotNull("econtainer should be set", tc.eContainer()); + assertTrue("contained object should be part of parent container", ((Address) tc.eContainer()).getTc() + .contains(tc)); + } + + // check default transient + final Address a = store.getObject(Address.class); + assertNull("A reference to a transient class should be transient also", a.getState()); + if (store.isHibernateTestStore()) { + assertEquals("v1", a.getVolatileString()); + } + store.commitTransaction(); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/InheritanceAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/InheritanceAction.java new file mode 100755 index 000000000..67bc3b969 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/InheritanceAction.java @@ -0,0 +1,68 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: InheritanceAction.java,v 1.3 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.samples.issues.inheritance.InheritanceFactory; +import org.eclipse.emf.teneo.samples.issues.inheritance.InheritancePackage; +import org.eclipse.emf.teneo.samples.issues.inheritance.SubOne; +import org.eclipse.emf.teneo.samples.issues.inheritance.SubTwo; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests setting resource when a single ref. relation is loaded. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ + */ +public class InheritanceAction extends AbstractTestAction { + + /** + * + * + * @param arg0 + */ + public InheritanceAction() { + super(new EPackage[] { InheritancePackage.eINSTANCE}); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.AbstractTestAction#hibernateEnabled() + */ + protected boolean hibernateEnabled() { + return true; + } + + /** Creates simple types and tests against */ + public void doAction(TestStore store) { + // test a simple type + final InheritanceFactory factory = InheritanceFactory.eINSTANCE; + { + store.beginTransaction(); + SubOne subOne = factory.createSubOne(); + subOne.setName("subOne"); + SubTwo subTwo = factory.createSubTwo(); + subTwo.setName("subTwo"); + store.store(subOne); + store.store(subTwo); + store.commitTransaction(); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/InterfaceTrueAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/InterfaceTrueAction.java new file mode 100755 index 000000000..8521f3fa6 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/InterfaceTrueAction.java @@ -0,0 +1,84 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: InterfaceTrueAction.java,v 1.6 2008/09/17 20:28:02 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import org.eclipse.emf.teneo.samples.issues.interfacetrue.AddressList; +import org.eclipse.emf.teneo.samples.issues.interfacetrue.InterfacetrueFactory; +import org.eclipse.emf.teneo.samples.issues.interfacetrue.InterfacetruePackage; +import org.eclipse.emf.teneo.samples.issues.interfacetrue.USAddress; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests the setting interface="true" on an eclass + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.6 $ + */ +public class InterfaceTrueAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public InterfaceTrueAction() { + super(InterfacetruePackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + { + store.beginTransaction(); + USAddress usAddress = InterfacetrueFactory.eINSTANCE.createUSAddress(); + usAddress.setName("myname"); + usAddress.setState("mystate"); + store.store(usAddress); + AddressList al = InterfacetrueFactory.eINSTANCE.createAddressList(); + al.getAddresses().add(usAddress); + store.store(al); + store.commitTransaction(); + } + + { + store.beginTransaction(); + USAddress usAddress = store.getObject(USAddress.class); + assertTrue("Name is not set", "myname".compareTo(usAddress.getName()) == 0); + assertTrue("State is not set", "mystate".compareTo(usAddress.getState()) == 0); + store.commitTransaction(); + } + + { + store.beginTransaction(); + USAddress usAddress = InterfacetrueFactory.eINSTANCE.createUSAddress(); + usAddress.setName("a2"); + usAddress.setState("s2"); + store.store(usAddress); + AddressList al = store.getObject(AddressList.class); + al.getAddresses().add(usAddress); + store.commitTransaction(); + } + + { + store.beginTransaction(); + AddressList al = store.getObject(AddressList.class); + assertEquals(2, al.getAddresses().size()); + assertTrue(null != al.getAddresses().get(0).getName()); + store.commitTransaction(); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/LargeMapValueAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/LargeMapValueAction.java new file mode 100755 index 000000000..e6d2d6292 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/LargeMapValueAction.java @@ -0,0 +1,72 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: LargeMapValueAction.java,v 1.2 2010/11/12 14:17:00 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.samples.issues.largemapvalue.LargemapvalueFactory; +import org.eclipse.emf.teneo.samples.issues.largemapvalue.LargemapvaluePackage; +import org.eclipse.emf.teneo.samples.issues.largemapvalue.TestElement; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Testcase for emap with large value field. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.2 $ + */ +public class LargeMapValueAction extends AbstractTestAction { + + private String largeString1; + private String largeString2; + + public LargeMapValueAction() { + super(new EPackage[] { LargemapvaluePackage.eINSTANCE }); + largeString1 = createLargeString("teneo", 600000); + largeString2 = createLargeString("emf", 500000); + } + + private String createLargeString(String pattern, int length) { + final StringBuilder sb = new StringBuilder(pattern); + while (sb.length() < length) { + sb.append(sb.toString()); + } + return sb.substring(0, length); + } + + @Override + public void doAction(TestStore store) { + TestElement te = LargemapvalueFactory.eINSTANCE.createTestElement(); + te.setTestProp(largeString1); + te.getTestMap().put("key1", largeString1.intern()); + te.getTestMap().put("key2", largeString2.intern()); + store.beginTransaction(); + store.store(te); + store.commitTransaction(); + + store.beginTransaction(); + te = store.getObject(TestElement.class); + assertEquals(largeString1.length(), te.getTestProp().length()); + assertNotNull(te.getTestMap().get("key1")); + assertNotNull(te.getTestMap().get("key2")); + assertNotSame(te.getTestMap().get("key1"), largeString1); + assertNotSame(te.getTestMap().get("key2"), largeString2); + assertEquals(te.getTestMap().get("key1"), largeString1); + assertEquals(te.getTestMap().get("key2"), largeString2); + store.commitTransaction(); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/MTMSameAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/MTMSameAction.java new file mode 100755 index 000000000..50f02d553 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/MTMSameAction.java @@ -0,0 +1,91 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: MTMSameAction.java,v 1.4 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.emf.teneo.samples.issues.mtmsame.Item; +import org.eclipse.emf.teneo.samples.issues.mtmsame.MtmsameFactory; +import org.eclipse.emf.teneo.samples.issues.mtmsame.MtmsamePackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests an mtm relation to itself. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.4 $ +*/ +public class MTMSameAction extends AbstractTestAction { + /** The number of testitems created */ + private static int NO_ITEMS = 10; + + /** + * Constructor for ClassHierarchyParsing. + * @param arg0 + */ + public MTMSameAction() { + super(MtmsamePackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + final MtmsameFactory factory = MtmsameFactory.eINSTANCE; + { + store.beginTransaction(); + + final ArrayList<Item> myItems = new ArrayList<Item>(); + for (int i = 0; i < NO_ITEMS; i++) { + final Item myitem = factory.createItem(); + myitem.setName("myname_" + i); + myItems.add(myitem); + } + for (int i = 0; i < NO_ITEMS; i++) { + final Item item = myItems.get(i); + for (int j = 0; j < NO_ITEMS; j++) { + item.getYourSide().add(myItems.get(j)); + } + store.store(item); + } + store.commitTransaction(); + } + + { + store.beginTransaction(); + List list = store.getObjects(Item.class); + assertTrue(list.size() == NO_ITEMS); + for (int i = 0; i < list.size(); i++) { + assertEquals(NO_ITEMS, ((Item) list.get(i)).getYourSide().size()); + ((Item) list.get(i)).getYourSide().remove(i); + } + store.commitTransaction(); + } + + { + store.beginTransaction(); + List list = store.getObjects(Item.class); + assertTrue(list.size() == NO_ITEMS); + for (int i = 0; i < list.size(); i++) { + assertEquals(NO_ITEMS - 1, ((Item) list.get(i)).getYourSide().size()); + } + store.commitTransaction(); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/MainAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/MainAction.java new file mode 100755 index 000000000..7f69616f3 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/MainAction.java @@ -0,0 +1,147 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: MainAction.java,v 1.5 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import main.BaseComponent; +import main.BaseGroup; +import main.BaseObject; +import main.ChildObject1; +import main.ChildObject2; +import main.ChildObject3; +import main.ChildObject4; +import main.MainFactory; +import main.MainPackage; +import main.impl.BaseGroupImpl; + +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests issue with inheritance and polymorphic relations. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.5 $ + */ +public class MainAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public MainAction() { + super(MainPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + + BaseGroup mainObjectsGroup = MainFactory.eINSTANCE.createBaseGroup(); + mainObjectsGroup.setName("mainObjectsGroup"); + + // =============== create basic objects ++++++++++++++++++++++ + + // create ChildObject1 + ChildObject1 o1 = MainFactory.eINSTANCE.createChildObject1(); + o1.setGroup(mainObjectsGroup); + o1.setName("o1_1"); + + ChildObject1 o2 = MainFactory.eINSTANCE.createChildObject1(); + o2.setGroup(mainObjectsGroup); + o2.setName("o1_2"); + + ChildObject1 o3 = MainFactory.eINSTANCE.createChildObject1(); + o3.setGroup(mainObjectsGroup); + o3.setName("o1_3"); + + ChildObject1 o4 = MainFactory.eINSTANCE.createChildObject1(); + o4.setGroup(mainObjectsGroup); + o4.setName("o1_4"); + + ChildObject1 o5 = MainFactory.eINSTANCE.createChildObject1(); + o5.setGroup(mainObjectsGroup); + o5.setName("o1_5"); + + // create other ChildObjects + ChildObject2 o11 = MainFactory.eINSTANCE.createChildObject2(); + o11.setGroup(mainObjectsGroup); + o11.setName(o11.getClass().getName()); + o11.setLength(new Integer(13)); + o11.setObject1(o1); + + ChildObject2 o12 = MainFactory.eINSTANCE.createChildObject2(); + o12.setGroup(mainObjectsGroup); + o12.setName(o12.getClass().getName()); + o12.setLength(new Integer(15)); + o12.setObject1(o2); + + ChildObject3 o13 = MainFactory.eINSTANCE.createChildObject3(); + o13.setGroup(mainObjectsGroup); + o13.setName(o13.getClass().getName()); + o13.setWidth(new Integer(6)); + o13.setObject1(o3); + + ChildObject4 o14 = MainFactory.eINSTANCE.createChildObject4(); + o14.setGroup(mainObjectsGroup); + o14.setName(o14.getClass().getName()); + o14.setThickness(new Integer(1)); + o14.setObject1(o4); + + ChildObject4 o15 = MainFactory.eINSTANCE.createChildObject4(); + o15.setGroup(mainObjectsGroup); + o15.setName(o15.getClass().getName()); + o15.setThickness(new Integer(2)); + o15.setObject1(o5); + store.beginTransaction(); + store.store(mainObjectsGroup); + + store.commitTransaction(); + + // Reopen the transaction and query for the objects + store.beginTransaction(); + + List<?> c = store.getObjects(BaseGroupImpl.class); + Iterator<?> it = c.iterator(); + BaseGroup grp = null;// not recursive to limit redondancy display + + // read the TObjectsGroups + while (it.hasNext()) { + grp = (BaseGroup) it.next(); + Collection<?> components = grp.getComponents(); + if (components != null) { + Iterator<?> it2 = components.iterator(); + while (it2.hasNext()) { + BaseComponent cpn = (BaseComponent) it2.next(); + if (cpn instanceof ChildObject1) { + ChildObject1 co1 = (ChildObject1) cpn; + BaseObject bo = co1.getLinkedObject(); + assertTrue(bo.getClass().getName().compareTo(bo.getName()) == 0); + assertTrue(!(bo instanceof ChildObject1)); + } + } + } + } + + // pm.makePersistentAll(c); + // notify end of display + store.commitTransaction(); + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/MultipleInheritanceAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/MultipleInheritanceAction.java new file mode 100755 index 000000000..ac1971902 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/MultipleInheritanceAction.java @@ -0,0 +1,172 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * MultipleInheritanceAction.java,v 1.6 2007/03/29 22:13:54 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import java.io.IOException; +import java.util.Collections; +import java.util.Properties; + +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +import testinheritance.Child; +import testinheritance.Child2; +import testinheritance.NameValuePair; +import testinheritance.ParentOne; +import testinheritance.SomeReference; +import testinheritance.SomeResource; +import testinheritance.TestinheritanceFactory; +import testinheritance.TestinheritancePackage; + +/** + * Tests multiple inheritance. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.13 $ + */ +public class MultipleInheritanceAction extends AbstractTestAction { + /** + * Constructor. + * + * @param arg0 + */ + public MultipleInheritanceAction() { + super(TestinheritancePackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true"); + // as foreign keys are not unique for this test case because of multiple inheritance + // todo: solve this + props.setProperty(PersistenceOptions.SET_FOREIGN_KEY_NAME, "false"); + return props; + } + + /** Test */ + @Override + public void doAction(TestStore store) { + try { + Resource res = null; + try { + res = store.getResource(); + res.load(Collections.EMPTY_MAP); + SomeResource someResource = TestinheritanceFactory.eINSTANCE.createSomeResource(); + someResource.setAnotherProperty(42); + someResource.setProperty("foo"); + NameValuePair nv = TestinheritanceFactory.eINSTANCE.createNameValuePair(); + nv.setName("foo1"); + nv.setValue("bar"); + someResource.getNameValuePairs().add(nv); + res.getContents().add(someResource); + res.save(null); + } finally { + } + SomeResource someResource; + try { + res = store.getResource(); + res.load(Collections.EMPTY_MAP); + someResource = TestinheritanceFactory.eINSTANCE.createSomeResource(); + someResource.setAnotherProperty(13); + someResource.setProperty("baz"); + res.getContents().add(someResource); + res.save(null); + } finally { + } + try { + res = store.getResource(); + res.load(Collections.EMPTY_MAP); + assertNotNull(res.getContents()); + assertEquals(3, res.getContents().size()); + someResource = (SomeResource) res.getContents().get(1); + assertNotNull(someResource); + NameValuePair nv = TestinheritanceFactory.eINSTANCE.createNameValuePair(); + nv.setName("foo1"); + nv.setValue("bar"); + someResource.getNameValuePairs().add(nv); + res.save(null); + } finally { + } + } catch (IOException e) { + throw new StoreTestException("IOException", e); + } + + { + store.beginTransaction(); + ParentOne po = TestinheritanceFactory.eINSTANCE.createParentOne(); + po.setAnotherProperty(5); + store.store(po); + store.commitTransaction(); + } + + // now test mappedsuperclasses + { + store.beginTransaction(); + final Child child = TestinheritanceFactory.eINSTANCE.createChild(); + final SomeReference sr = TestinheritanceFactory.eINSTANCE.createSomeReference(); + sr.setName("sr"); + child.setSomeReference(sr); + child.setAge(10); + child.setName("myName"); + child.setTestId(4); // this is the key! + store.store(child); + store.commitTransaction(); + } + + try { + store.beginTransaction(); + final Child child = TestinheritanceFactory.eINSTANCE.createChild(); + final SomeReference sr = TestinheritanceFactory.eINSTANCE.createSomeReference(); + sr.setName("sr1"); + child.setSomeReference(sr); + child.setAge(11); + child.setName("myName2"); + child.setTestId(4); // this is the key! + store.store(child); + store.commitTransaction(); + fail("PK is not enforced!"); + } catch (Exception e) { + // should fail + store.rollbackTransaction(); + } + + // this child gets the id from the parent, which has a synthetic id + { + store.beginTransaction(); + final Child2 child = TestinheritanceFactory.eINSTANCE.createChild2(); + final SomeReference sr = TestinheritanceFactory.eINSTANCE.createSomeReference(); + sr.setName("sr3"); + store.store(sr); + child.setSomeReference(sr); + child.setAge(10); + child.setAnotherProperty(40); + child.setName("myName"); + child.setTestId(4); // this is not the key! + store.store(child); + store.commitTransaction(); + } + { + store.beginTransaction(); + final Child2 child = TestinheritanceFactory.eINSTANCE.createChild2(); + final SomeReference sr = TestinheritanceFactory.eINSTANCE.createSomeReference(); + sr.setName("sr2"); + store.store(sr); + child.setSomeReference(sr); + child.setAge(11); + child.setAnotherProperty(41); + child.setName("myName2"); + child.setTestId(4); // this is not the key! + store.store(child); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/NavTopAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/NavTopAction.java new file mode 100755 index 000000000..5d62cafa4 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/NavTopAction.java @@ -0,0 +1,46 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: NavTopAction.java,v 1.1 2008/03/19 22:25:33 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.extension.ExtensionManager; +import org.eclipse.emf.teneo.mapping.strategy.EntityNameStrategy; +import org.eclipse.emf.teneo.mapping.strategy.impl.QualifyingEntityNameStrategy; +import org.eclipse.emf.teneo.samples.issues.nav.NavPackage; +import org.eclipse.emf.teneo.samples.issues.top.TopPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.1 $ + */ +public class NavTopAction extends AbstractTestAction { + public NavTopAction() { + super(new EPackage[] { NavPackage.eINSTANCE, TopPackage.eINSTANCE }); + } + + @Override + public void setExtensions(ExtensionManager extensionManager) { + extensionManager.registerExtension(EntityNameStrategy.class.getName(), QualifyingEntityNameStrategy.class + .getName()); + } + + @Override + public void doAction(TestStore store) { + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/ResourceAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/ResourceAction.java new file mode 100755 index 000000000..c81a73d8d --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/ResourceAction.java @@ -0,0 +1,99 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: ResourceAction.java,v 1.7 2008/04/20 10:33:25 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.resource.StoreResource; +import org.eclipse.emf.teneo.samples.issues.resource.Head; +import org.eclipse.emf.teneo.samples.issues.resource.Person; +import org.eclipse.emf.teneo.samples.issues.resource.ResourceFactory; +import org.eclipse.emf.teneo.samples.issues.resource.ResourcePackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests setting resource when a single ref. relation is loaded. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.7 $ + */ +public class ResourceAction extends AbstractTestAction { + + /** + * + * + * @param arg0 + */ + public ResourceAction() { + super(new EPackage[] { ResourcePackage.eINSTANCE }); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.AbstractTestAction#hibernateEnabled() + */ + protected boolean hibernateEnabled() { + return true; + } + + /** Creates simple types and tests against */ + @Override + public void doAction(TestStore store) { + // test a simple type + final ResourceFactory factory = ResourceFactory.eINSTANCE; + { + store.beginTransaction(); + Person person = factory.createPerson(); + person.setName("me"); + Head head = factory.createHead(); + head.setHair("blond"); + person.setHead(head); + store.store(person); + store.store(head); + store.commitTransaction(); + } + + // now use a resource to read! + try { + + final HashMap<String, String> options = new HashMap<String, String>(); + options.put(StoreResource.LOAD_STRATEGY_PARAM, StoreResource.ADD_TO_CONTENTS); + final Resource res = store.getResource("query1=select p from Person p"); + res.load(options); + Iterator<?> it = res.getContents().iterator(); + while (it.hasNext()) { + Object o = it.next(); + if (!(o instanceof Person)) { + continue; + } + Person obj = (Person) o; + assertEquals(obj.eResource(), obj.getHead().eResource()); + assertTrue(obj.eResource() != null); + } + res.unload(); + } catch (IOException e) { + throw new StoreTestException("Exception", e); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/ResourceUnloadAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/ResourceUnloadAction.java new file mode 100755 index 000000000..3d3af42cb --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/ResourceUnloadAction.java @@ -0,0 +1,97 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: ResourceUnloadAction.java,v 1.1 2008/04/16 21:07:53 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import java.io.IOException; + +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.samples.issues.resourceunload.Book; +import org.eclipse.emf.teneo.samples.issues.resourceunload.Library; +import org.eclipse.emf.teneo.samples.issues.resourceunload.ResourceunloadFactory; +import org.eclipse.emf.teneo.samples.issues.resourceunload.ResourceunloadPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests specific unload behavior, see the emft newsgroup for posts with the topic [Teneo] Unload() + * questions + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.1 $ + */ +public class ResourceUnloadAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public ResourceUnloadAction() { + super(ResourceunloadPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + public void doAction(TestStore store) { + final ResourceunloadFactory factory = ResourceunloadFactory.eINSTANCE; + + // create a book, writer and library + try { + { + Resource res = store.getResource(); + res.load(null); + + final Book book = factory.createBook(); + book.setTitle("Fellowship of the Ring"); + + final Library library = factory.createLibrary(); + library.setName("Science Fiction"); + library.getBooks().add(book); + + res.getContents().add(library); + res.save(null); + } + + // walk through the structure starting from the library + { + final String qry = + "query1=select b from " + Book.class.getName() + " as b&query2=select l from " + + Library.class.getName() + " as l"; + Resource res = store.getResource(qry); + res.load(null); + Library lib = null; + for (Object o : res.getContents()) { + if (o instanceof Library) { + lib = (Library) o; + } + } + + assertNotNull(lib); + final Book b = lib.getBooks().get(0); + assertTrue(lib.getBooks().size() > 0); + assertTrue(b.eContainer() == lib); + assertTrue(res.getContents().contains(b)); + res.unload(); + assertTrue(lib.getBooks().size() > 0); + assertTrue(b.eContainer() == lib); + assertTrue(!res.getContents().contains(b)); + } + } catch (IOException e) { + throw new StoreTestException("IOException during save", e); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/SecondarytableInheritanceAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/SecondarytableInheritanceAction.java new file mode 100755 index 000000000..9ee5b357b --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/SecondarytableInheritanceAction.java @@ -0,0 +1,136 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: SecondarytableInheritanceAction.java,v 1.2 2010/02/06 18:25:53 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.List; +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.issues.secondary.Person; +import org.eclipse.emf.teneo.samples.issues.secondary.SecondaryFactory; +import org.eclipse.emf.teneo.samples.issues.secondary.SecondaryPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=235949 + */ +public class SecondarytableInheritanceAction extends AbstractTestAction { + + private static final String ADDRESS = "Amsterdamseweg 123, 4567AZ Amsterdam"; + + private static final long ID = 1; + + private static final byte[] PHOTO = new byte[64 * 1024]; + + private static final String VERIFICATION_QUERY = + "SELECT * FROM GENERIC as A INNER JOIN PERSON_ADDRESS as B ON A.ID = B.ID " + + "INNER JOIN PERSON_PHOTO as C ON A.ID = C.ID"; + + public SecondarytableInheritanceAction() { + super(SecondaryPackage.eINSTANCE); + } + + @Override + public void doAction(TestStore store) { + storePerson(store); + testPerson(store); + testSecondaryTables(store); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties() + */ + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.SQL_CASE_STRATEGY, "uppercase"); + return props; + } + + /** + * Stores a Person in the database. + */ + private void storePerson(TestStore store) { + store.beginTransaction(); + + final Person person = SecondaryFactory.eINSTANCE.createPerson(); + person.setId(ID); + person.setAddress(ADDRESS); + person.setPhoto(PHOTO); + store.store(person); + + store.commitTransaction(); + } + + /** + * Retrieves the previously stored Person from the database and checks its attributes. + */ + private void testPerson(TestStore store) { + store.beginTransaction(); + + final List<?> results = store.query(Person.class, "id", String.valueOf(ID), 1); + assertEquals(1, results.size()); + final Person person = (Person) results.get(0); + assertEquals(ID, person.getId()); + assertEquals(ADDRESS, person.getAddress()); + final byte[] photo = person.getPhoto(); + assertEquals(PHOTO.length, photo.length); + for (int i = 0; i < photo.length; i++) { + assertEquals(PHOTO[i], photo[i]); + } + + store.commitTransaction(); + } + + /** + * Executes a query to verify the existence of the secondary tables. + */ + private void testSecondaryTables(TestStore store) { + final Connection conn = store.getConnection(); + Statement statement = null; + ResultSet resultSet = null; + try { + statement = conn.createStatement(); + resultSet = statement.executeQuery(VERIFICATION_QUERY); + } catch (final SQLException e) { + throw new StoreTestException(e.getMessage(), e); + } finally { + try { + if (resultSet != null) { + resultSet.close(); + } + } catch (final SQLException e) { + } + try { + if (statement != null) { + statement.close(); + } + } catch (final SQLException e) { + } + } + + } + +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/SimplenmAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/SimplenmAction.java new file mode 100755 index 000000000..eb1f535e2 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/SimplenmAction.java @@ -0,0 +1,109 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * SimplenmAction.java,v 1.2 2007/02/01 12:35:37 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import java.util.Iterator; +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.issues.simplenm.Me; +import org.eclipse.emf.teneo.samples.issues.simplenm.SimplenmFactory; +import org.eclipse.emf.teneo.samples.issues.simplenm.SimplenmPackage; +import org.eclipse.emf.teneo.samples.issues.simplenm.You; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests ordering in a nm relation. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.4 $ + */ +public class SimplenmAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public SimplenmAction() { + super(SimplenmPackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true"); + return props; + } + + /** Creates an item, an address and links them to a po. */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + final SimplenmFactory factory = SimplenmFactory.eINSTANCE; + + { + store.beginTransaction(); + + You y1 = factory.createYou(); + y1.setName("y1"); + You y2 = factory.createYou(); + y2.setName("y2"); + You y3 = factory.createYou(); + y3.setName("y3"); + + Me m1 = factory.createMe(); + m1.setName("m1"); + Me m2 = factory.createMe(); + m2.setName("m2"); + Me m3 = factory.createMe(); + m3.setName("m3"); + + y1.getMe().add(m1); + y1.getMe().add(m2); + y1.getMe().add(m3); + + y2.getMe().add(m1); + y2.getMe().add(m2); + y2.getMe().add(m3); + + y3.getMe().add(m1); + y3.getMe().add(m2); + y3.getMe().add(m3); + + store.store(y1); + store.store(y2); + store.store(y3); + + store.commitTransaction(); + } + { + store.beginTransaction(); + final Iterator it = store.getObjects(You.class).iterator(); + while (it.hasNext()) { + You you = (You) it.next(); + assertTrue(((Me) you.getMe().get(0)).getName().compareTo("m1") == 0); + assertTrue(((Me) you.getMe().get(1)).getName().compareTo("m2") == 0); + assertTrue(((Me) you.getMe().get(2)).getName().compareTo("m3") == 0); + } + store.commitTransaction(); + } + { + store.beginTransaction(); + final Iterator it = store.getObjects(Me.class).iterator(); + while (it.hasNext()) { + Me me = (Me) it.next(); + assertTrue(((You) me.getYou().get(0)).getName().compareTo("y1") == 0); + assertTrue(((You) me.getYou().get(1)).getName().compareTo("y2") == 0); + assertTrue(((You) me.getYou().get(2)).getName().compareTo("y3") == 0); + } + store.commitTransaction(); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/SupInterfacesAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/SupInterfacesAction.java new file mode 100755 index 000000000..331ba3a70 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/SupInterfacesAction.java @@ -0,0 +1,308 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: SupInterfacesAction.java,v 1.1 2008/09/15 11:33:40 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.eclipse.emf.teneo.PersistenceOptions; +import org.eclipse.emf.teneo.samples.issues.library.Book; +import org.eclipse.emf.teneo.samples.issues.library.BookCategory; +import org.eclipse.emf.teneo.samples.issues.library.Library; +import org.eclipse.emf.teneo.samples.issues.library.LibraryFactory; +import org.eclipse.emf.teneo.samples.issues.library.LibraryPackage; +import org.eclipse.emf.teneo.samples.issues.library.Writer; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests the library example of emf/xsd. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.1 $ + */ +public class SupInterfacesAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public SupInterfacesAction() { + super(LibraryPackage.eINSTANCE); + } + + @Override + public Properties getExtraConfigurationProperties() { + final Properties props = new Properties(); + props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY, "READ_WRITE"); + props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false"); + props.setProperty(PersistenceOptions.DEFAULT_VARCHAR_LENGTH, "50"); + return props; + } + + /** Creates an item, an address and links them to a po. */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + final LibraryFactory factory = LibraryFactory.eINSTANCE; + +// { +// store.beginTransaction(); +// +// // Create a library. +// Library library = LibraryFactory.eINSTANCE.createLibrary(); +// library.setName("My Library"); +// // Make it persistent. +// store.store(library); +// +// // Create a writer... +// Writer writer = LibraryFactory.eINSTANCE.createWriter(); +// writer.setName("JRR Tolkien"); +// +// // ...and one of his books. +// Book book = LibraryFactory.eINSTANCE.createBook(); +// book.setAuthor(writer); +// book.setPages(305); +// book.setTitle("The Hobbit"); +// book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL); +// +// // Add the Writer and Book to the Library. They are made +// // persistent automatically because the Library is already +// // persistent. +// library.getWriters().add(writer); +// library.getBooks().add(book); +// store.commitTransaction(); +// } + + // create a book, writer and library + { + store.beginTransaction(); + + final Writer writer = factory.createWriter(); + writer.setName("JRR Tolkien"); + + final Book book = factory.createBook(); + + book.setAuthor(writer); + book.setPages(5); + book.setTitle("The Hobbit"); + book.setCategory(BookCategory.SCIENCE_FICTION); + + final Book book2 = factory.createBook(); + book2.setAuthor(writer); + book2.setPages(5); + book2.setTitle("The fellowship of the ring"); + book2.setCategory(BookCategory.SCIENCE_FICTION); + + final Library library = factory.createLibrary(); + library.getBooks().add(book); + library.setName("Science Fiction Library"); + library.getBooks().add(book2); + library.getWriters().add(writer); + store.store(library); + + store.commitTransaction(); + assertEquals(2, writer.getBooks().size()); + } + + // walk through the structure starting from the library + { + store.beginTransaction(); + Library lib = (Library) store.query(Library.class, "name", "Science Fiction Library", 1).get(0); + assertTrue((lib.getWriters().get(0)).getName().compareTo("JRR Tolkien") == 0); + +// final Object[] eobjs = store.getCrossReferencers((EObject)lib.getWriters().get(0), false); + + // these two books should be the same as this book is the first in the writers + // collection + // and in the library collection + Book wBook = (lib.getWriters().get(0)).getBooks().get(0); + Book lBook = lib.getBooks().get(0); + + // check container + assertTrue(lBook.eContainer() == lib); + + assertTrue(wBook.getTitle().compareTo(lBook.getTitle()) == 0); + assertTrue(wBook.getPages() == lBook.getPages()); + assertTrue(wBook.getCategory() instanceof BookCategory); + assertTrue(wBook.getCategory() == BookCategory.SCIENCE_FICTION); + store.commitTransaction(); + } + + // check container relations + if (true) { + store.beginTransaction(); + + final Writer writ = store.getObjects(Writer.class).get(0); + + // store.refresh(writ); + + // test notifications of the elist + // disabled this test as the elist notifications have been disabled + // WriterAdapter writerAdapter = new WriterAdapter(); + // writ.eAdapters().add(writerAdapter); + // assertEquals(2, writ.getBooks().size()); // this should not trigger the adapter to be + // called + // assertEquals(1, writerAdapter.getCountNotifications()); + + checkContainerAfterWriterRetrieve(store, writ); + + Library lib = (Library) store.getCrossReferencers(writ, true)[0]; + checkContainerAfterLibraryRetrieve(store, writ); + checkDetachCopy(store, writ); + + // now set the container of the writer + assertTrue("The container of the writer should be set!", store.setContainer(writ)); + + assertEquals(LibraryPackage.eINSTANCE.getLibrary_Writers().getFeatureID(), writ.eContainingFeature() + .getFeatureID()); + + assertTrue("The container of the writer should be equal to the earlier retrieved Library", lib == writ + .eContainer()); + + final Object[] eobjs = store.getCrossReferencers(writ, false); + assertEquals(3, eobjs.length); + for (final Object obj : eobjs) { + if (obj instanceof Library) { + assertTrue(obj == lib); + } else { + assertTrue(((Book) obj).getAuthor() == writ); + assertTrue(lib.getBooks().contains(obj)); + } + } + + final Book bk = store.getObjects(Book.class).get(0); + assertTrue(bk.eContainer() == lib); + + // check if the containing feature is also set correctly + assertTrue(bk.eContainingFeature() == LibraryPackage.eINSTANCE.getLibrary_Books()); + + assertTrue(lib.getBooks().contains(bk)); + + store.refresh(lib); + + store.commitTransaction(); + } + + dumpPAModel(store); + checkTeneoSQLNameStrategy(); + } + + /** Reads objects in multiple sessions and checks that they are unequal */ + @SuppressWarnings("unchecked") + protected void checkUseCache(TestStore store) { + // read the writers in the cache + store.refresh(); + store.beginTransaction(); + final Writer writer = store.getObject(Writer.class); + assertTrue(writer != null); + store.commitTransaction(); + store.refresh(); + store.beginTransaction(); + final List books1 = new ArrayList(store.getObjects(Book.class)); + store.commitTransaction(); + store.refresh(); + store.beginTransaction(); + final List books2 = new ArrayList(store.getObjects(Book.class)); + assertTrue(books1.size() == books2.size()); + store.commitTransaction(); + for (int i = 0; i < books1.size(); i++) { + final Book bk1 = (Book) books1.get(i); + final Book bk2 = (Book) books2.get(i); + assertEquals(bk1.getTitle(), bk2.getTitle()); + assertTrue(bk1 != bk2); + assertTrue(bk1.getAuthor() != bk2.getAuthor()); + } + } + + // check detachcopy for jpox + protected void checkDetachCopy(TestStore store, Writer writ) { + } + + protected void checkContainerAfterLibraryRetrieve(TestStore store, final Writer writ) { + // TODO specialize for Hibernate/JPOX, was: + // if (store instanceof JPOXTestStore) + // { + // assertTrue("Container of writer is not yet set now, because of lazy loading of container + // relations", + // writ.eContainer() == null); + // } + } + + protected void checkContainerAfterWriterRetrieve(TestStore store, final Writer writ) { + // TODO specialize for Hibernate/JPOX, was: + // if (store instanceof HibernateTestStore) + // { + // assertTrue(writ.eContainer() != null); + // assertTrue(writ.eContainer() instanceof Library); + // } + } + + /** + * @return Returns <code>true</code> the given value indeed encodes a list + */ + protected boolean listValueOfCorrectType(Object value) { + // TODO specialize hibernate/jpox, was + // return (value instanceof PersistableEList || value instanceof + // org.eclipse.emf.teneo.jpox.emf.elist.EListWrapper) + return true; + } + + /** Dump the annotated model to standard output */ + protected void dumpPAModel(TestStore testStore) { + } + + protected void checkTeneoSQLNameStrategy() { + } + +// /** Small adapter test +// private class WriterAdapter extends AdapterImpl { +// /** Counts the number of changes */ +// private int countNotifications = 0; +// +// /** +// * Returns <code>false</code> +// * +// * @param type +// * the type. +// * @return <code>false</code> +// */ +// public boolean isAdapterForType(Object type) { +// return type instanceof Writer; +// } +// +// /** +// * Does nothing; clients may override so that it does something. +// */ +// public void notifyChanged(Notification msg) { +// assertTrue("The new value is of type: " + msg.getNewValue().getClass().getName(), +// listValueOfCorrectType(msg.getNewValue())); +// +// // must be a load event +// assertTrue("Eventtype is not load notification but: " + msg.getEventType(), +// msg.getEventType() == AnnotationUtil.ELIST_LOAD_NOTIFICATION); +// +// countNotifications++; +// } +// +// /** Returns the number of notifications */ +// public int getCountNotifications() { +// return countNotifications; +// } +// } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/TopClassesAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/TopClassesAction.java new file mode 100755 index 000000000..bb4f6d5de --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/TopClassesAction.java @@ -0,0 +1,110 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: TopClassesAction.java,v 1.4 2008/02/28 07:08:16 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import java.io.IOException; + +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.samples.issues.topclasses.M; +import org.eclipse.emf.teneo.samples.issues.topclasses.MList; +import org.eclipse.emf.teneo.samples.issues.topclasses.P; +import org.eclipse.emf.teneo.samples.issues.topclasses.PList; +import org.eclipse.emf.teneo.samples.issues.topclasses.R; +import org.eclipse.emf.teneo.samples.issues.topclasses.TopclassesFactory; +import org.eclipse.emf.teneo.samples.issues.topclasses.TopclassesPackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * Tests if topclasses are computed correctly also in case of an inheritance strategy. Tests if also for n:m relation lazy loading of + * detached objects works for jpox. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.4 $ + */ +public class TopClassesAction extends AbstractTestAction { + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public TopClassesAction() { + super(TopclassesPackage.eINSTANCE); + } + + /** Creates an item, an address and links them to a po. */ + @Override + @SuppressWarnings("unchecked") + public void doAction(TestStore store) { + final TopclassesFactory factory = TopclassesFactory.eINSTANCE; + + // create a book, writer and library + try { + { + Resource res = store.getResource(); + res.load(null); + + // add other case + M m = factory.createM(); + m.setName("m"); + + P p = factory.createP(); + p.setName("p"); + m.getP().add(p); + assertTrue(p.getM().contains(m)); + + MList mlist = factory.createMList(); + mlist.setName("mlist"); + mlist.getM().add(m); + + PList plist = factory.createPList(); + plist.getP().add(p); + plist.setName("plist"); + + R r = factory.createR(); + r.setName("r"); + r.setMlist(mlist); + r.setPlist(plist); + + res.getContents().add(r); + res.save(null); + } + + { + Resource res = store.getResource(); + res.load(null); + assertEquals(1, res.getContents().size()); + R testR = null; + for (int i = 0; i < res.getContents().size(); i++) { + final Object obj = res.getContents().get(i); + if (obj instanceof R) { + testR = (R) obj; + } + } + + M m = (M) testR.getMlist().getM().get(0); + P p = (P) testR.getPlist().getP().get(0); + assertTrue(m.getP().contains(p)); + assertTrue(p.getM().contains(m)); + res.save(null); + } + } catch (IOException e) { + throw new StoreTestException("IOException during save", e); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/UpdateAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/UpdateAction.java new file mode 100755 index 000000000..7dd9586d2 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/UpdateAction.java @@ -0,0 +1,64 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * AgilAction.java,v 1.1 2007/03/28 13:58:33 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.issues; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.samples.issues.update.Child; +import org.eclipse.emf.teneo.samples.issues.update.Parent; +import org.eclipse.emf.teneo.samples.issues.update.UpdateFactory; +import org.eclipse.emf.teneo.samples.issues.update.UpdatePackage; +import org.eclipse.emf.teneo.test.AbstractTestAction; +import org.eclipse.emf.teneo.test.stores.TestStore; + +/** + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.3 $ + */ +public class UpdateAction extends AbstractTestAction { + + /** + * Constructor for ClassHierarchyParsing. + * + * @param arg0 + */ + public UpdateAction() { + super(new EPackage[] { UpdatePackage.eINSTANCE }); + } + + @Override + public void doAction(TestStore store) { + { + final Parent p = UpdateFactory.eINSTANCE.createParent(); + p.setName("p"); + final Child c1 = UpdateFactory.eINSTANCE.createChild(); + c1.setName("c1"); + final Child c2 = UpdateFactory.eINSTANCE.createChild(); + c2.setName("c2"); + p.getChildren().add(c1); + p.getChildren().add(c2); + store.beginTransaction(); + store.store(p); + store.commitTransaction(); + } + + { + final Parent p = UpdateFactory.eINSTANCE.createParent(); + p.setName("p"); + final Child c1 = UpdateFactory.eINSTANCE.createChild(); + c1.setName("c1"); + final Child c2 = UpdateFactory.eINSTANCE.createChild(); + c2.setName("c2"); + p.getChildren().add(c1); + p.getChildren().add(c2); + store.beginTransaction(); + store.store(p); + store.commitTransaction(); + } + } +} diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/AbstractTestStore.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/AbstractTestStore.java new file mode 100755 index 000000000..ce5a2b311 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/AbstractTestStore.java @@ -0,0 +1,148 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * AbstractTestStore.java,v 1.4 2007/03/28 13:58:33 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.stores; + +import java.util.Collection; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; + +/** + * Base abstractteststore + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.8 $ + */ +public abstract class AbstractTestStore implements TestStore { + /** The logger */ + private static Log log = LogFactory.getLog(AbstractTestStore.class); + + /** + * Property defining that the mapping file should be saved one directory higher. This is + * sometimes required if an epackage has subpackages. + */ + public static String STORE_MAPPING_FILE_ONE_DIRECTORY_HIGHER = + AbstractTestStore.class.getName() + ".StoreMappingFileOneDirectoryHigher"; + + /** Used to disable drop */ + protected boolean donotDrop = false; + + /** Test properties, eg. database login */ + private TestDatabaseAdapter testDatabaseAdapter; + + /** Constructor sets the database adapter */ + protected AbstractTestStore(TestDatabaseAdapter tda) { + testDatabaseAdapter = tda; + + // recreate the database + testDatabaseAdapter.dropDatabase(); + testDatabaseAdapter.createDatabase(); + } + + /** Queries for an object */ + public List<?> query(Object query) { + return query(query, -1); + } + + /** + * Return an object of a certain class, there should only be one in the databases + */ + @SuppressWarnings("unchecked") + public <T> T getObject(Class<T> clazz) { + List<?> l = getObjects(clazz); // replace class is called in getObjects + TestCase.assertTrue("There are " + l.size() + + " object(s) of this class in the datastore, 1 was expected, class: " + clazz.getName(), l.size() == 1); + return (T) l.get(0); + } + + /** Test the amount of objects of a certain class in the db */ + public void checkNumber(Class<?> clazz, int count) { + final List<?> list = getObjects(clazz); + TestCase.assertTrue("Expected " + count + " object(s) but there are " + list.size() + + " object(s) of this class in the datastore: " + clazz.getName(), list.size() == count); + } + + /** Is called just before the test */ + public abstract void setUp(); + + /** Can be used to disabled dropping of the store, convenience for testing */ + public void disableDrop() { + donotDrop = true; + } + + /** Store/Makepersistent */ + public void store(Collection<?> objects) { + for (Object o : objects) { + store(o); + } + } + + /** + * Is called just after the test, the dropStore parameter can be used to prevent dropping the + * database when an error + */ + public void tearDown(boolean successfullyCompleted) { + if (transactionActive()) { + if (successfullyCompleted) { + log.error("Transaction active while tearing down store " + toString()); + } + rollbackTransaction(); + } + + if (!successfullyCompleted) { + // TODO do not drop otherwise? + disableDrop(); + } + doTearDown(); + } + + /** Do tear down */ + protected abstract void doTearDown(); + + /** Returns the database adapter */ + public TestDatabaseAdapter getDatabaseAdapter() { + return testDatabaseAdapter; + } + + /** Drops the database */ + public void dropDatabase() { + testDatabaseAdapter.dropDatabase(); + } + + /** Base method to get a resource belonging to the pmf of this test case */ + public Resource getResource() { + return getResource(null); + } + + /** Gets the container list */ + public boolean setContainer(EObject obj) { + return true; + } + + /** Is this a hibernate test store */ + public boolean isHibernateTestStore() { + return false; + } + + /** Is this a jpox test store */ + public boolean isJPOXTestStore() { + return false; + } + + /** Return the mapping xml used */ + public String getMappingXML() { + throw new UnsupportedOperationException(); + } + +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/AbstractTestStoreFactory.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/AbstractTestStoreFactory.java new file mode 100755 index 000000000..60e1b4b55 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/AbstractTestStoreFactory.java @@ -0,0 +1,64 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * Davide Marchignoli + * </copyright> + * + * $Id: AbstractTestStoreFactory.java,v 1.9 2008/05/27 07:42:12 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.stores; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Properties; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.teneo.annotations.pannotation.InheritanceType; +import org.eclipse.emf.teneo.extension.ExtensionManager; +import org.eclipse.emf.teneo.test.AbstractTest; +import org.eclipse.emf.teneo.test.conf.TestConfiguration; + +/** + * Generic part of the store creation. + * + * @author Davide Marchignoli + * @author Martin Taal + * @version $Revision: 1.9 $ + */ +public abstract class AbstractTestStoreFactory { + + /** The logger */ + private static String RUN_BASE_DIR = System.getProperty("user.dir") + File.separatorChar + "run"; + + /** + * Request a store for the given configuration. No other store can be requested until this one + * is tear down. NOTE: dbName must be a key: no equals dbName for difference usedEPackages/cfg + */ + public TestStore get(String dbName, EPackage[] usedEPackages, String mappingFilePath, TestConfiguration cfg, + Properties extraConfigProps, ExtensionManager extensionManager) throws FileNotFoundException { + cfg.getDbAdapter().setDbName(dbName); + return createStoreInstance(cfg.getDbAdapter(), usedEPackages, mappingFilePath, extraConfigProps, cfg + .getMappingStrategy(), cfg.isEjb3(), extensionManager); + } + + /** Ensures that the run directory exists, this directory contains the mapping files */ + protected File getRunTestDir(AbstractTest testCase, TestConfiguration cfg) { + File dir = new File(RUN_BASE_DIR, testCase.getClass().getName()); + dir.mkdirs(); + return dir; + } + + /** Creates the actual specific test store */ + protected abstract TestStore createStoreInstance(TestDatabaseAdapter adapter, EPackage[] epackages, + String mappingFileLocation, Properties props, InheritanceType inheritanceType, boolean ejb3, + ExtensionManager extensionManager); +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/BaseTestDatabaseAdapter.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/BaseTestDatabaseAdapter.java new file mode 100755 index 000000000..5d6271219 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/BaseTestDatabaseAdapter.java @@ -0,0 +1,261 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: BaseTestDatabaseAdapter.java,v 1.4 2008/03/30 15:12:08 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.stores; + +import java.sql.Connection; +import java.sql.Driver; +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.Properties; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.eclipse.emf.teneo.test.StoreTestException; + +/** + * Is a general test database adapter. This adapter hides details related to running the testcass + * with different databases. The database specific actions are relatively simple, drop and create a + * database and possibly specific such as setting lower or uppercase name handling in the database. + * For handling other databases this class can be extended. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.4 $ + */ + +public class BaseTestDatabaseAdapter implements TestDatabaseAdapter { + /** The logger */ + private static Log log = LogFactory.getLog(BaseTestDatabaseAdapter.class); + + /** The database url */ + protected String dbUrl; + + /** The database driver */ + protected String dbDriver; + + /** The database user */ + protected String dbUser; + + /** The database pwd */ + protected String dbPwd; + + /** The database name */ + protected String dbName = null; + + /** The logInfo, is used to display connection information */ + protected String logInfo = "Replace this with a meaningfull message"; + + /** Use optimistic transactions or not */ + protected boolean optimistic; + + /** Initializes the database adapter */ + public void initialize(Properties props) { + dbUrl = props.getProperty("dburl"); + dbDriver = props.getProperty("dbdriver"); + dbUser = props.getProperty("dbuser"); + dbPwd = props.getProperty("dbpassword"); + optimistic = props.getProperty("optimistic") != null && props.getProperty("optimistic").compareTo("true") == 0; + logInfo = + " adapter|dbName|url|user|pwd|driver " + + this.getClass().getName().substring(this.getClass().getName().lastIndexOf(".") + 1) + "|" + + dbName + "|" + dbUrl + "|" + dbUser + "|" + dbPwd + "|" + dbDriver; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.stores.TestDatabaseAdapter#isOptimistic() + */ + public boolean isOptimistic() { + return optimistic; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.stores.TestDatabaseAdapter#getDbDriver() + */ + public String getDbDriver() { + return dbDriver; + } + + /** Returns a log messages which is placed when a testrun starts for this database adapter */ + public String getLogMessage() { + return "Starting run for database: " + logInfo; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.stores.TestDatabaseAdapter#getDbName() + */ + public String getDbName() { + return dbName; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.stores.TestDatabaseAdapter#setDbName(java.lang.String) + */ + public void setDbName(String databaseName) { + dbName = databaseName; + + // set the loginfo + logInfo = + " adapter|dbName|url|user|pwd|driver " + + this.getClass().getName().substring(this.getClass().getName().lastIndexOf(".") + 1) + "|" + + dbName + "|" + dbUrl + "|" + dbUser + "|" + dbPwd + "|" + dbDriver; + + log.debug("Initialized database adapter: " + logInfo); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.stores.TestDatabaseAdapter#getDbPwd() + */ + public String getDbPwd() { + return dbPwd; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.stores.TestDatabaseAdapter#getDbUrl() + */ + public String getDbUrl() { + if (dbUrl.endsWith(":")) { // hsqldb + return dbUrl + dbName; + } else if (dbUrl.endsWith("/")) { + return dbUrl + dbName; + } else { + return dbUrl + "/" + dbName; + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.stores.TestDatabaseAdapter#getDbUser() + */ + public String getDbUser() { + return dbUser; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.stores.TestDatabaseAdapter#createDatabase() + */ + public void createDatabase() { + try { + log.info("Creating database: " + logInfo); + + final Driver driver = (Driver) Class.forName(dbDriver).newInstance(); + Properties info = new Properties(); + info.put("user", dbUser); + info.put("password", dbPwd); + Connection conn = null; + Statement stmt = null; + try { + conn = driver.connect(dbUrl, info); + stmt = conn.createStatement(); + conn.setAutoCommit(true); + stmt.execute("CREATE DATABASE " + dbName + ";"); + } finally { + if (stmt != null) { + stmt.close(); + } + if (conn != null) { + conn.close(); + } + } + } catch (Exception e) { + throw new StoreTestException("Exception while creating database: " + logInfo, e); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.stores.TestDatabaseAdapter#dropDatabase() + */ + public void dropDatabase() { + try { + final Driver driver = (Driver) Class.forName(dbDriver).newInstance(); + Properties info = new Properties(); + info.put("user", dbUser); + info.put("password", dbPwd); + Connection conn = null; + Statement stmt = null; + try { + conn = driver.connect(dbUrl, info); + final ResultSet rs = conn.getMetaData().getCatalogs(); + boolean exists = false; + while (rs.next()) { + final String existingDb = rs.getString(1); + exists |= existingDb.compareToIgnoreCase(dbName) == 0; + } + rs.close(); + + if (exists) { + stmt = conn.createStatement(); + conn.setAutoCommit(true); + log.info("Dropping database: " + logInfo); + stmt.execute("DROP DATABASE " + dbName + ";"); + } else { + log.info("Database does not exist, not dropped, " + logInfo); + } + } finally { + if (stmt != null) { + stmt.close(); + } + if (conn != null) { + conn.close(); + } + } + } catch (Exception e) { + throw new StoreTestException("Exception while dropping database: " + logInfo, e); + } + } + + /** Gets a database connection using the adapters connection info */ + public Connection getConnection() { + try { + final Driver driver = (Driver) Class.forName(dbDriver).newInstance(); + Properties info = new Properties(); + info.put("user", dbUser); + info.put("password", dbPwd); + return driver.connect(getDbUrl(), info); + } catch (Exception e) { + throw new StoreTestException("Exception while creating database: " + logInfo, e); + } + } + + /** Returns true if the passed database exists */ + protected boolean databaseExists(Connection conn) throws Exception { + final String localDbName = getDbName(); + final ResultSet rs = conn.getMetaData().getCatalogs(); + boolean exists = false; + while (rs.next()) { + final String existingDb = rs.getString(1); + exists = exists || existingDb.compareTo(localDbName) == 0; + } + rs.close(); + return exists; + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/HsqldbTestDatabaseAdapter.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/HsqldbTestDatabaseAdapter.java new file mode 100755 index 000000000..3e3f5abd8 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/HsqldbTestDatabaseAdapter.java @@ -0,0 +1,95 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: HsqldbTestDatabaseAdapter.java,v 1.5 2008/05/27 07:42:12 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.stores; + +import java.io.File; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Test database adapter for HSQLDB. Overrides the database create and drop actions because these + * require the database name in the url. + * + * @version $Revision: 1.5 $ + */ + +public class HsqldbTestDatabaseAdapter extends BaseTestDatabaseAdapter { + /** The logger */ + private static Log log = LogFactory.getLog(HsqldbTestDatabaseAdapter.class); + + @Override + public void createDatabase() { + // nothing to do for HSQLDB in memory/file + log.info("Creating database: " + logInfo + " is done automatically at connection time"); + } + + @Override + public void dropDatabase() { + // just delete all files in the hsqldb directory + deleteFile(new File("/tmp/hsqldb")); +// +// +// try { +// final Driver driver = (Driver) Class.forName(dbDriver).newInstance(); +// Properties info = new Properties(); +// info.put("user", dbUser); +// info.put("password", dbPwd); +// Connection conn = null; +// Statement stmt = null; +// try { +// conn = driver.connect(dbUrl, info); +// conn.setAutoCommit(true); +// final ResultSet rs = conn.getMetaData().getSchemas(); +// +// stmt = conn.createStatement(); +// +// while (rs.next()) { +// final String schemaName = rs.getString(1); +// if (!"INFORMATION_SCHEMA".equals(schemaName)) { +// log.info("Dropping schema: " + schemaName); +// stmt.execute("DROP SCHEMA " + schemaName + " CASCADE;"); +// } +// } +// rs.close(); +// } finally { +// if (stmt != null) { +// stmt.close(); +// } +// if (conn != null) { +// conn.close(); +// } +// } +// } catch (Exception e) { +// throw new StoreTestException("Exception while dropping database: " + logInfo, e); +// } + } + + private void deleteFile(File file) { + if (!file.exists()) { + return; + } + if (file.isDirectory()) { + for (File f : file.listFiles()) { + deleteFile(f); + } + } + if (file.getName().contains(getDbName())) { + file.delete(); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/MssqlJDBCTestDatabaseAdapter.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/MssqlJDBCTestDatabaseAdapter.java new file mode 100755 index 000000000..b74fdd077 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/MssqlJDBCTestDatabaseAdapter.java @@ -0,0 +1,37 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: MssqlJDBCTestDatabaseAdapter.java,v 1.4 2008/02/28 07:08:13 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.stores; + + +/** + * Overrides geturl to add specific ms string: ;DatabaseName= + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.4 $ + */ + +public class MssqlJDBCTestDatabaseAdapter extends BaseTestDatabaseAdapter { + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.teneo.test.stores.TestDatabaseAdapter#getDbUrl() + */ + public String getDbUrl() { + return dbUrl + ";DatabaseName=" + dbName + ";SelectMethod=cursor"; + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/PgsqlTestDatabaseAdapter.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/PgsqlTestDatabaseAdapter.java new file mode 100755 index 000000000..68261a779 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/PgsqlTestDatabaseAdapter.java @@ -0,0 +1,189 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * </copyright> + * + * $Id: PgsqlTestDatabaseAdapter.java,v 1.5 2008/07/13 13:13:39 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.stores; + +import java.sql.Connection; +import java.sql.Driver; +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.Properties; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.eclipse.emf.teneo.test.StoreTestException; + +/** + * Test database adapter for postgressql. Overrides the database create and drop actions because + * these require the database name in the url. + * + * The specific issue with the test environment was that at start and cleanup of the test (create + * and drop of the database), postgresql apparently does not release closed connections quick + * enough. Therefore create or drop database failed sometimes. Therefore a very rough workaround has + * been implemented, i.e. the drop/create is retried a number of times before failing. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.5 $ + */ + +public class PgsqlTestDatabaseAdapter extends BaseTestDatabaseAdapter { + /** The logger */ + private static Log log = LogFactory.getLog(PgsqlTestDatabaseAdapter.class); + + /** The number of tries a create database or drop database is run before giving up */ + private static int NO_TRIES = 20; + + /** The amount of milliseconds to wait for postgres to nicely clean up connections */ + // private static long WAIT_TIME = 10000; + /** Sets the dbName */ + @Override + public void setDbName(String databaseName) { + super.setDbName(databaseName.toLowerCase()); + } + + /** Drops the database and creates a new one */ + @Override + public void createDatabase() { + try { + log.info("Creating database: " + logInfo); + + final Driver driver = (Driver) Class.forName(dbDriver).newInstance(); + Properties info = new Properties(); + info.put("user", dbUser); + info.put("password", dbPwd); + Connection conn = null; + Statement stmt = null; + try { + final String useUrl = dbUrl + "template1"; + conn = driver.connect(useUrl, info); + if (!databaseExists(conn)) { + int tries = 0; + while (true) { + try { + tries++; + stmt = conn.createStatement(); + stmt.execute("CREATE DATABASE " + dbName + ";"); + // conn.commit(); + return; + } catch (Exception e) { + Thread.sleep(500); + log.warn("Exception (" + e.getMessage() + ") while creating database (" + getDbName() + + "), num of tries: " + tries + ", the create database gives up at: " + NO_TRIES); + // log.warn("Waiting for " + WAIT_TIME + + // " milli seconds on postgresql to release connections"); + // wait(WAIT_TIME); + if (tries == NO_TRIES) { + throw e; + } + } finally { + if (stmt != null) { + stmt.close(); + } + if (conn != null) { + conn.close(); + } + conn = driver.connect(useUrl, info); + } + } + } + } finally { + if (stmt != null) { + stmt.close(); + } + if (conn != null) { + conn.close(); + } + } + } catch (Exception e) { + throw new StoreTestException("Exception while creating database: " + logInfo, e); + } + } + + /** + * Drops the database, uses the conn.getMetaData().getCatalogs() method to determine if the + * database already exists. This should be supported by the database driver. + */ + @Override + public void dropDatabase() { + try { + final Driver driver = (Driver) Class.forName(dbDriver).newInstance(); + Properties info = new Properties(); + info.put("user", dbUser); + info.put("password", dbPwd); + Connection conn = null; + Statement stmt = null; + try { + final String useUrl = dbUrl + "template1"; + conn = driver.connect(useUrl, info); + + // check if the database exists + stmt = conn.createStatement(); + log.info("Dropping database: " + logInfo); + ResultSet rs = stmt.executeQuery("SELECT datname FROM pg_database"); + boolean exists = false; + while (rs.next()) { + exists |= dbName.compareTo(rs.getString("datname")) == 0; + if (exists) { + break; + } + } + rs.close(); + stmt.close(); + if (exists) { + int tries = 0; + while (true) { + try { + tries++; + stmt = conn.createStatement(); + stmt.execute("DROP DATABASE " + dbName + ";"); + // conn.commit(); + return; + } catch (Exception e) { + Thread.sleep(500); + log.warn("Exception (" + e.getMessage() + ") while creating database (" + getDbName() + + "), num of tries: " + tries + ", the create database gives up at: " + NO_TRIES); + // log.warn("Waiting for " + WAIT_TIME + + // " milli seconds on postgresql to release connections"); + // wait(WAIT_TIME); + if (tries == NO_TRIES) { + throw e; + } + } finally { + if (stmt != null) { + stmt.close(); + } + if (conn != null) { + conn.close(); + } + conn = driver.connect(useUrl, info); + } + } + } + // conn.commit(); + return; + } finally { + if (stmt != null) { + stmt.close(); + } + if (conn != null) { + conn.close(); + } + } + } catch (Exception e) { + throw new StoreTestException("Exception while dropping database: " + logInfo, e); + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/TestDBAdapters.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/TestDBAdapters.java new file mode 100755 index 000000000..d92037973 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/TestDBAdapters.java @@ -0,0 +1,102 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * Davide Marchignoli + * </copyright> + * + * $Id: TestDBAdapters.java,v 1.6 2008/05/27 07:42:12 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.stores; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import org.eclipse.emf.teneo.test.StoreTestException; +import org.eclipse.emf.teneo.test.Utils; + +/** + * Encapsulates multiple database adapters. + * + * @author Davide Marchignoli + * @author Martin Taal + * @version $Revision: 1.6 $ + */ +public class TestDBAdapters { + + /** Map fo adapters by name */ + private Map dbAdapters = new HashMap(); + + /** Add db adapter */ + public void addDBAdapter(String name, BaseTestDatabaseAdapter dbAdapter) { + if (dbAdapters.containsKey(name)) { + throw new IllegalArgumentException("Duplicate db adapter " + name); + } + dbAdapters.put(name, dbAdapter); + } + + /** Add db adapter */ + public void addDBAdapter(String name, Properties initProps) { + String dbAdapterClassName = initProps.getProperty("dbadapter"); + BaseTestDatabaseAdapter testAdapter = null; + if (dbAdapterClassName == null) { + testAdapter = new BaseTestDatabaseAdapter(); + } else { + try { + final Class adapterClass = Class.forName(dbAdapterClassName); + testAdapter = (BaseTestDatabaseAdapter) adapterClass.newInstance(); + } catch (Exception e) { + throw new StoreTestException("Exception when creating TestDatabaseAdapter using classname: " + + dbAdapterClassName + ", db identifier used in property file: " + + initProps.getProperty(Utils.DATABASE_PROP_NAME), e); + } + } + testAdapter.initialize(initProps); + addDBAdapter(name, testAdapter); + } + + /** Add database adapters */ + public void addDBAdapters(Properties props) { + final Map hProps = Utils.hiearchizeProps(props); + for (Iterator i = hProps.keySet().iterator(); i.hasNext();) { + String adapterName = (String) i.next(); + addDBAdapter(adapterName, (Properties) hProps.get(adapterName)); + } + } + + /** Return all db adapters */ + public Collection getAdapters() { + return dbAdapters.values(); + } + + /** Return names of database adapters */ + public Set getAdapterNames() { + return dbAdapters.keySet(); + } + + /** Get one adapter by name */ + public BaseTestDatabaseAdapter get(String adapterName) { + return (BaseTestDatabaseAdapter) dbAdapters.get(adapterName); + } + + /** Add a database adapter */ + public void addDBAdapters(InputStream propertiesStream) throws IOException { + Properties props = new Properties(); + props.load(propertiesStream); + addDBAdapters(props); + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/TestDatabaseAdapter.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/TestDatabaseAdapter.java new file mode 100755 index 000000000..331cbc721 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/TestDatabaseAdapter.java @@ -0,0 +1,78 @@ +/** + * <copyright> + * + * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others + * 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: + * Martin Taal + * Davide Marchignoli + * </copyright> + * + * $Id: TestDatabaseAdapter.java,v 1.5 2008/05/27 07:42:12 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.stores; + +import java.sql.Connection; + +/** + * The test bed encapsulates the environment of a test action. + * + * @author Davide Marchignoli + * @author Martin Taal + * @version $Revision: 1.5 $ + */ +public interface TestDatabaseAdapter { + + public static interface Factory { + public BaseTestDatabaseAdapter[] getConfiguredAdapters(); + } + + /** Returns true if optimistic transactions should be enabled */ + public abstract boolean isOptimistic(); + + /** + * @return Returns the dbDriver. + */ + public abstract String getDbDriver(); + + /** + * @return Returns the dbName. + */ + public abstract String getDbName(); + + /** Sets the dbName */ + public abstract void setDbName(String databaseName); + + /** + * @return Returns the dbPwd. + */ + public abstract String getDbPwd(); + + /** + * @return Returns the dbUrl. + */ + public abstract String getDbUrl(); + + /** + * @return Returns the dbUser. + */ + public abstract String getDbUser(); + + /** Drops the database and creates a new one */ + public abstract void createDatabase(); + + /** Gets a database connection using the adapters connection info */ + public abstract Connection getConnection(); + + /** + * Drops the database, uses the conn.getMetaData().getCatalogs() method to determine if the database already exists. This should be + * supported by the database driver. Assumes that the DBMS does not allow multiple database with names that differ only in case. + */ + public abstract void dropDatabase(); + +}
\ No newline at end of file diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/TestStore.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/TestStore.java new file mode 100755 index 000000000..8b3dcbd66 --- /dev/null +++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/TestStore.java @@ -0,0 +1,154 @@ +/** + * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id: + * TestStore.java,v 1.6 2007/03/20 23:33:38 mtaal Exp $ + */ + +package org.eclipse.emf.teneo.test.stores; + +import java.io.Serializable; +import java.sql.Connection; +import java.util.Collection; +import java.util.Date; +import java.util.List; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.teneo.DataStore; +import org.eclipse.emf.teneo.annotations.pannotation.InheritanceType; + +/** + * The test store encapsulates the datastore actions to different store types + * (ojb, jpox, etc.). In this way different test cases can be reused. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + * @version $Revision: 1.15 $ + */ +public interface TestStore { + + /** Refreshes this store, can for example be used to clear a cache etc. */ + public void refresh(); + + /** Is called just before the test */ + public void setUp(); + + /** Return the datastore */ + public DataStore getDataStore(); + + /** + * Is called just after the test. + */ + public void tearDown(boolean successFullCompletion); + + /** + * Can be used to disabled dropping of the store, convenience for testing + * (for example when an error occured) + */ + public void disableDrop(); + + /** Begin transaction */ + public void beginTransaction(); + + /** Commit transaction */ + public void commitTransaction(); + + /** Rollback transaction */ + public void rollbackTransaction(); + + /** Returns true if the transaction is still active */ + public boolean transactionActive(); + + /** Store/Makepersistent */ + public void store(Collection<?> object); + + /** Store/Makepersistent */ + public void store(Object object); + + /** Merge */ + public Object merge(Object object); + + /** Add an epackage to the list of epackages */ + public void addEPackage(EPackage epackage); + + /** Update the database schema */ + public void updateSchema(); + + /** Test if a delete fails */ + public void checkDeleteFails(Class<?> clazz); + + /** Test if a delete fails */ + public void checkDeleteSucceeds(Class<?> clazz); + + /** + * Return an object of a certain class, there should only be one in the + * databases + */ + public <T> T getObject(Class<T> clazz); + + /** Returns a list of object of a certain class */ + public <T> List<T> getObjects(Class<T> clazz); + + /** Deletes an object */ + public void deleteObject(Object obj); + + /** Query for a class using a field and value pair */ + public List<?> query(Class<?> clazz, String field, String value, + int checkCount); + + /** Query for an object */ + public List<?> query(Object query); + + public Object getObject(String entityName, Serializable id); + + /** Queries for an object and checks the number */ + public List<?> query(Object query, int checkCount); + + /** Test the amount of objects of a certain class in the db */ + public void checkNumber(Class<?> clazz, int count); + + /** Returns the database adapter */ + public TestDatabaseAdapter getDatabaseAdapter(); + + /** Flushes all updates to the underlying datastore */ + public void flush(); + + /** Base method to get a resource belonging to the pmf of this test case */ + public Resource getResource(); + + /** Base method to get a resource belonging to the pmf of this test case */ + public Resource getResource(String extraParam); + + /** Gets the referedto list */ + public Object[] getCrossReferencers(EObject obj, boolean container); + + /** Gets the container list */ + public boolean setContainer(EObject obj); + + /** Refreshes the object from the datastore */ + public void refresh(Object obj); + + /** Check inheritance strategy */ + public boolean isInheritanceStrategy(Class<?> cls, InheritanceType strategy); + + /** Gets a database connection using the adapters connection info */ + public abstract Connection getConnection(); + + /** + * @return the inheritanceType + */ + public InheritanceType getInheritanceType(); + + /** Is this a hibernate test store */ + public boolean isHibernateTestStore(); + + public boolean isEntityManagerStore(); + + /** Get the xmlgregoriancalendar date (hibernate) or normal date (jpox) */ + public Object getDate(Date date); + + /** Return the mapping xml used */ + public String getMappingXML(); +}
\ No newline at end of file |