diff options
Diffstat (limited to 'tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations')
51 files changed, 5040 insertions, 0 deletions
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> |