You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2012/12/06 18:42:17 UTC
[19/52] [partial] ISIS-188: moving framework/ subdirs up to parent
http://git-wip-us.apache.org/repos/asf/isis/blob/255ef514/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/Data.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/Data.java b/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/Data.java
new file mode 100644
index 0000000..1708cde
--- /dev/null
+++ b/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/Data.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.runtimes.dflt.objectstores.sql.common;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.isis.applib.value.Color;
+import org.apache.isis.applib.value.Date;
+import org.apache.isis.applib.value.DateTime;
+import org.apache.isis.applib.value.Image;
+import org.apache.isis.applib.value.Money;
+import org.apache.isis.applib.value.Password;
+import org.apache.isis.applib.value.Percentage;
+import org.apache.isis.applib.value.Time;
+import org.apache.isis.applib.value.TimeStamp;
+
+public class Data {
+
+ // private static final TimeZone GMTm2_TIME_ZONE;
+
+ // Helper values
+ static final java.sql.Date sqlDate;
+ static final java.sql.Date sqlDate20100305;
+
+ static {
+ /*
+ *
+ * // For testing -ve offset timezone local regions. GMTm2_TIME_ZONE = TimeZone.getTimeZone("GMT-0200");
+ * //GMTm2_TIME_ZONE = TimeZone.getTimeZone("UTC"); TimeZone.setDefault(GMTm2_TIME_ZONE);
+ */
+
+ /*
+ * TimeZone timeZone = TimeZone.getTimeZone("Etc/UTC"); if (timeZone == null) { timeZone =
+ * TimeZone.getTimeZone("UTC"); } UTC_TIME_ZONE = timeZone;
+ */
+
+ /*
+ * There is still an issue assigning a java.sql.Date variable from a calendar. final Calendar cal =
+ * Calendar.getInstance(); cal.setTimeZone(UTC_TIME_ZONE); cal.clear(); cal.set(Calendar.YEAR, 2011);
+ * cal.set(Calendar.MONTH, 4-1); cal.set(Calendar.DAY_OF_MONTH, 8);
+ */
+ // 2011-4-8 = 1,270,684,800,000
+ final Date date20100308 = new Date(2010, 4, 8);
+ sqlDate = new java.sql.Date(date20100308.getMillisSinceEpoch());
+
+ sqlDate20100305 = new java.sql.Date(new Date(2010, 3, 5).getMillisSinceEpoch());
+ }
+
+ static final Date applibDate = new Date(2010, 3, 5); // 2010-03-05 =
+ // 1,267,747,200,000
+ static final DateTime dateTime = new DateTime(2010, 3, 5, 1, 23); // 1,267,752,180,000
+ static final TimeStamp timeStamp = new TimeStamp(dateTime.millisSinceEpoch());
+ static final Time time = new Time(14, 56); // 53,760,000
+
+ static final Color color = Color.WHITE;
+ static final Image image = new Image(new int[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } });
+ static final Password password = new Password("password");
+ static final Percentage percentage = new Percentage(42);
+ static final Money money = new Money(99.99, "ZAR");
+
+ // Standard values
+ static final int intMaxValue = Integer.MAX_VALUE;
+ static final short shortMaxValue = Short.MAX_VALUE;
+ static final long longMaxValue = Long.MAX_VALUE;
+ static final double doubleMaxValue = 1e308;// Double.MAX_VALUE;
+ static final float floatMaxValue = (float) 1e37;// Float.MAX_VALUE;
+
+ static final int intMinValue = Integer.MIN_VALUE;
+ static final short shortMinValue = Short.MIN_VALUE;
+ static final long longMinValue = Long.MIN_VALUE;
+ static final double doubleMinValue = 1e-307;// Double.MIN_VALUE;
+ static final float floatMinValue = (float) 1e-37;// Float.MIN_VALUE;
+
+ // Collection mapper tests
+ static final List<String> stringList1 = Arrays.asList("Baking", "Bakery", "Canned", "Dairy");
+ static final List<String> stringList2 = Arrays.asList("Fridge", "Deli", "Fresh Produce", "Frozen", "Household",
+ "Other..");
+
+ public static List<String> getTableNames() {
+ return Arrays.asList("sqldataclass", "simpleclass", "simpleclasstwo", "primitivevaluedentity");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/255ef514/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestCommonBase.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestCommonBase.java b/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestCommonBase.java
new file mode 100755
index 0000000..723d06c
--- /dev/null
+++ b/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestCommonBase.java
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.runtimes.dflt.objectstores.sql.common;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+import org.apache.isis.runtimes.dflt.objectstores.sql.common.SqlIntegrationTestFixtures.State;
+import org.apache.isis.tck.dom.poly.ReferencingPolyTypesEntity;
+import org.apache.isis.tck.dom.sqlos.SqlDomainObjectRepository;
+import org.apache.isis.tck.dom.sqlos.data.SqlDataClass;
+
+/**
+ * @author Kevin kevin@kmz.co.za
+ *
+ * This common test class is used by all sql objectstore tests to manage the Isis framework.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class SqlIntegrationTestCommonBase {
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+ protected SqlIntegrationTestFixtures getSqlIntegrationTestFixtures() {
+ return SqlIntegrationTestFixtures.getInstance();
+ }
+
+ protected SqlDomainObjectRepository factory;
+ protected SqlDataClass sqlDataClass;
+ protected ReferencingPolyTypesEntity referencingPolyTypesEntity;
+
+ public Properties getProperties() {
+ try {
+ final Properties properties = new Properties();
+ properties.load(new FileInputStream("src/test/config/" + getPropertiesFilename()));
+ return properties;
+ } catch (final FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+ public abstract String getPropertiesFilename();
+
+ protected void setFixtureInitializationStateIfNot(State state, String persistenceMechanism) {
+ if (!persistenceMechanismIs(persistenceMechanism)) {
+ setFixtureInitializationState(state);
+ }
+ }
+
+ protected void setFixtureInitializationState(final State state, final String persistenceMechanism) {
+ if (persistenceMechanismIs(persistenceMechanism)) {
+ setFixtureInitializationState(state);
+ }
+ }
+
+ protected void setFixtureInitializationState(final State state) {
+ getSqlIntegrationTestFixtures().setState(state);
+ }
+
+ protected boolean persistenceMechanismIs(final String persistenceMechanism) {
+ return getProperties().getProperty("isis.persistor").equals(persistenceMechanism);
+ }
+
+ /**
+ * This method can be used to do any DB specific actions the first time the test framework is setup. e.g. In the XML
+ * test, it must delete all XML files in the data store directory.
+ */
+ public void resetPersistenceStoreDirectlyIfRequired() {
+ }
+
+ protected void testSetup() {
+ resetPersistenceStoreDirectlyIfRequired();
+ getSqlIntegrationTestFixtures().setState(State.INITIALIZE);
+ }
+
+ // //////////////////////////////////////////////////////////////////////////////
+ // before, after
+ // //////////////////////////////////////////////////////////////////////////////
+
+ @Before
+ public void setUpSystem() throws Exception {
+ Logger.getRootLogger().setLevel(Level.INFO);
+
+ if (!getSqlIntegrationTestFixtures().getState().isInitialize()) {
+ return;
+ }
+
+ final Properties properties = getProperties();
+ if (properties == null) {
+ getSqlIntegrationTestFixtures().initSystem("src/test/config", getPropertiesFilename());
+ } else {
+ getSqlIntegrationTestFixtures().initSystem(properties);
+ }
+
+ final String sqlSetupString = getSqlSetupString();
+ if (sqlSetupString != null) {
+ getSqlIntegrationTestFixtures().sqlExecute(sqlSetupString);
+ }
+ }
+
+ /**
+ * optional hook
+ */
+ protected String getSqlSetupString() {
+ return null;
+ }
+
+ @Before
+ public void setUpFactory() throws Exception {
+ factory = getSqlIntegrationTestFixtures().getSqlDataClassFactory();
+
+ // may have been setup by previous test
+ sqlDataClass = getSqlIntegrationTestFixtures().getSqlDataClass();
+ referencingPolyTypesEntity = getSqlIntegrationTestFixtures().getPolyTestClass();
+ }
+
+ // //////////////////////////////////////////////////////////////////////////////
+ // after
+ // //////////////////////////////////////////////////////////////////////////////
+
+ @After
+ public void tearDown() throws Exception {
+ if (!getSqlIntegrationTestFixtures().getState().isInitialize()) {
+ return;
+ }
+ final String sqlTeardownString = getSqlTeardownString();
+ if (sqlTeardownString != null) {
+ try {
+ getSqlIntegrationTestFixtures().sqlExecute(sqlTeardownString);
+ } catch (final SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ getSqlIntegrationTestFixtures().shutDown();
+ }
+
+ /**
+ * optional hook
+ */
+ protected String getSqlTeardownString() {
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/255ef514/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestData.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestData.java b/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestData.java
new file mode 100644
index 0000000..471fc10
--- /dev/null
+++ b/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestData.java
@@ -0,0 +1,601 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.runtimes.dflt.objectstores.sql.common;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.Test;
+
+import org.apache.isis.applib.value.Color;
+import org.apache.isis.applib.value.Date;
+import org.apache.isis.applib.value.DateTime;
+import org.apache.isis.applib.value.Money;
+import org.apache.isis.applib.value.Password;
+import org.apache.isis.applib.value.Percentage;
+import org.apache.isis.applib.value.Time;
+import org.apache.isis.applib.value.TimeStamp;
+import org.apache.isis.runtimes.dflt.objectstores.sql.common.SqlIntegrationTestFixtures.State;
+import org.apache.isis.tck.dom.scalars.PrimitiveValuedEntity;
+import org.apache.isis.tck.dom.sqlos.SqlDomainObjectRepository;
+import org.apache.isis.tck.dom.sqlos.data.SimpleClass;
+import org.apache.isis.tck.dom.sqlos.data.SimpleClassTwo;
+import org.apache.isis.tck.dom.sqlos.data.SqlDataClass;
+
+/**
+ * @author Kevin kevin@kmz.co.za
+ *
+ * This common class is used by the datatype tests (values, objects, collections) to ensure proper creation and
+ * reloading of domain objects.
+ *
+ * There are two "tests", with the framework re-initialised each time (to flush any objectstore memory of any
+ * created domain objects).
+ *
+ * The Singleton class {@link SqlIntegrationTestFixtures} is used to preserve values between tests.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class SqlIntegrationTestData extends SqlIntegrationTestCommonBase {
+
+ private static final Logger LOG = Logger.getLogger(SqlIntegrationTestData.class);
+
+ private static List<SimpleClass> simpleClassList1 = new ArrayList<SimpleClass>();
+ private static List<SimpleClass> simpleClassList2 = new ArrayList<SimpleClass>();
+
+ private static SimpleClassTwo simpleClassTwoA;
+ private static SimpleClassTwo simpleClassTwoB;
+
+ private static PrimitiveValuedEntity pve1;
+ private static PrimitiveValuedEntity pve2;
+
+ @Test
+ /**
+ * Uses factory methods within the Isis framework to create the test data,
+ * thus exercising the "create data" portion of the object store.
+ *
+ * The Isis framework will be again be re-created in the next test unless the
+ * object store is "in-memory" (this is required since "in-memory" has to be
+ * left alone for created data to still be present in the next test).
+ */
+ public void testSetupStore() throws Exception {
+ testSetup();
+ setUpFactory();
+ testCreate();
+ }
+
+ protected void testCreate() throws Exception {
+
+ sqlDataClass = factory.newDataClass();
+
+ sqlDataClass.setString("Test String");
+ sqlDataClass.setDate(Data.applibDate);
+ sqlDataClass.setSqlDate(Data.sqlDate);
+ sqlDataClass.setMoney(Data.money);
+ sqlDataClass.setDateTime(Data.dateTime);
+ sqlDataClass.setTimeStamp(Data.timeStamp);
+ sqlDataClass.setTime(Data.time);
+ sqlDataClass.setColor(Data.color);
+ sqlDataClass.setImage(Data.image);
+ sqlDataClass.setPassword(Data.password);
+ sqlDataClass.setPercentage(Data.percentage);
+
+ // Setup SimpleClassTwo
+ simpleClassTwoA = factory.newSimpleClassTwo();
+ simpleClassTwoA.setText("A");
+ simpleClassTwoA.setIntValue(999);
+ simpleClassTwoA.setBooleanValue(true);
+
+ simpleClassTwoB = factory.newSimpleClassTwo();
+ simpleClassTwoB.setText("B");
+
+ sqlDataClass.setSimpleClassTwo(simpleClassTwoA);
+
+ // NumericClasses
+ // standard min types
+ pve2 = factory.newPrimitiveValuedEntity();
+ LOG.log(Level.INFO, "Bits to represent Double: " + Double.SIZE);
+ pve2.setIntProperty(Data.intMinValue);
+ pve2.setShortProperty(Data.shortMinValue);
+ pve2.setLongProperty(Data.longMinValue);
+ pve2.setDoubleProperty(Data.doubleMinValue);
+ pve2.setFloatProperty(Data.floatMinValue);
+ pve2.setCharProperty((char) (32)); // temporary work around: See ISIS-269
+
+ sqlDataClass.setPrimitiveValuedEntityMin(pve2);
+
+ // standard max types
+ pve1 = factory.newPrimitiveValuedEntity();
+ pve1.setIntProperty(Data.intMaxValue);
+ pve1.setShortProperty(Data.shortMaxValue);
+ pve1.setLongProperty(Data.longMaxValue);
+ pve1.setDoubleProperty(Data.doubleMaxValue);
+ pve1.setFloatProperty(Data.floatMaxValue);
+ pve1.setCharProperty((char) (255));
+
+ sqlDataClass.setPrimitiveValuedEntityMax(pve1);
+
+ // Initialise collection1
+ boolean bMustAdd = false;
+ if (simpleClassList1.size() == 0) {
+ bMustAdd = true;
+ }
+ for (final String string : Data.stringList1) {
+ final SimpleClass simpleClass = factory.newSimpleClass();
+ simpleClass.setString(string);
+ simpleClass.setSimpleClassTwoA(simpleClassTwoA);
+ sqlDataClass.addToSimpleClasses1(simpleClass);
+ if (bMustAdd) {
+ simpleClassList1.add(simpleClass);
+ }
+ }
+
+ // Initialise collection2
+ for (final String string : Data.stringList2) {
+ final SimpleClass simpleClass = factory.newSimpleClass();
+ simpleClass.setString(string);
+ simpleClass.setSimpleClassTwoA(simpleClassTwoB);
+ sqlDataClass.addToSimpleClasses2(simpleClass);
+ if (bMustAdd) {
+ simpleClassList2.add(simpleClass);
+ }
+ }
+ factory.save(sqlDataClass);
+
+ setFixtureInitializationState(State.DONT_INITIALIZE, "in-memory");
+ }
+
+ @Test
+ /**
+ * The actual "tests". Unless the test is using the "in-memory" object store
+ * the Isis framework is re-created, thus ensuring that no domain objects are
+ * left over from the previous "create" step, forcing the objects to be created
+ * via the object store.
+ *
+ * Exercises the "restore data" portion of the object store.
+ *
+ * Confirms that values and objects (single and collections) are loaded as expected.
+ * Especially, it confirms that dates, times, etc, do not suffer from differences in
+ * time zones between the database and the Isis framework.
+ */
+ public void testTestAll() throws Exception {
+ testLoad();
+
+ setUpFactory();
+
+ testString();
+ setStringToDifferentValue();
+ testSimpleClassCollection1Lazy();
+
+ testMoney();
+ testColor();
+ testPassword();
+ testPercentage();
+ testStandardValueTypesMaxima();
+ testStandardValueTypesMinima();
+
+ testSingleReferenceLazy();
+ testSimpleClassTwoReferenceLazy();
+
+ testSimpleClassCollection1();
+ testSimpleClassCollection2();
+
+ testSingleReferenceResolve();
+ testSimpleClassTwoReferenceResolve();
+ testSimpleClassTwo();
+ testUpdate1();
+ testUpdate2();
+ testUpdateCollectionIsDirty();
+ testFindByMatchString();
+ testFindByMatchEntity();
+
+ testApplibDate();
+ testSqlDate();
+ testTime();
+ testTimeStamp();
+ testDateTimezoneIssue();
+ testDateTime();
+
+ // Must be here so that the Isis framework is initialised for the next test package.
+ setFixtureInitializationState(State.INITIALIZE);
+ }
+
+ private void testLoad() throws Exception {
+ final List<SqlDataClass> dataClasses = factory.allDataClasses();
+ assertEquals(1, dataClasses.size());
+ final SqlDataClass sqlDataClass = dataClasses.get(0);
+ getSqlIntegrationTestFixtures().setSqlDataClass(sqlDataClass);
+
+ setFixtureInitializationState(State.DONT_INITIALIZE);
+ }
+
+ private void testString() {
+ assertEquals("Test String", sqlDataClass.getString());
+ }
+
+ private void setStringToDifferentValue() {
+ sqlDataClass.setString("String 2");
+ }
+
+ private void testSimpleClassCollection1Lazy() {
+ final List<SimpleClass> collection = sqlDataClass.simpleClasses1;
+
+ assertEquals("collection size is not equal!", collection.size(), simpleClassList1.size());
+ }
+
+ /**
+ * Test {@link SqlDataClass} {@link Date} field.
+ *
+ * @throws Exception
+ */
+ private void testApplibDate() {
+
+ LOG.log(Level.INFO, "Test: testDate() '2010-3-5' = 1267747200000");
+
+ // 2010-3-5 = 1267747200000
+ LOG.log(Level.INFO, "applibDate.dateValue() as String: " + Data.applibDate);
+ LOG.log(Level.INFO, "applibDate.dateValue() as Long: " + Data.applibDate.getMillisSinceEpoch());
+
+ // 2010-3-5 = 1267747200000
+ LOG.log(Level.INFO, "sqlDataClass.getDate() as String: " + sqlDataClass.getDate());
+ LOG.log(Level.INFO, "sqlDataClass.getDate().getTime() as Long: " + sqlDataClass.getDate().getMillisSinceEpoch());
+
+ if (!Data.applibDate.isEqualTo(sqlDataClass.getDate())) {
+ fail("Applib date: Test '2010-3-5', expected " + Data.applibDate.toString() + ", but got "
+ + sqlDataClass.getDate().toString() + ". Check log for more info.");
+ // LOG.log(Level.INFO, "Applib date: Test '2011-3-5', expected " +
+ // applibDate.toString() + ", but got "
+ // +
+ // sqlDataClass.getDate().toString()+". Check log for more info.");
+ } else {
+ // LOG.log(Level.INFO,
+ // "SQL applib.value.date: test passed! Woohoo!");
+ }
+
+ }
+
+ /**
+ * Test {@link SqlDataClass} {@link java.sql.Date} field.
+ *
+ * @throws Exception
+ */
+ private void testSqlDate() {
+
+ LOG.log(Level.INFO, "Test: testSqlDate() '2011-4-8' == 1302220800000");
+
+ // 2011-4-8 = 1302220800000
+ LOG.log(Level.INFO, "sqlDate.toString() as String:" + Data.sqlDate); // shows
+ // as
+ // 2011-04-07
+ LOG.log(Level.INFO, "sqlDate.getTime() as Long:" + Data.sqlDate.getTime());
+
+ // 2011-4-8 = 1302220800000
+ LOG.log(Level.INFO, "sqlDataClass.getSqlDate() as String:" + sqlDataClass.getSqlDate()); // shows
+ // as
+ // 2011-04-07
+ LOG.log(Level.INFO, "sqlDataClass.getSqlDate().getTime() as Long:" + sqlDataClass.getSqlDate().getTime());
+
+ if (Data.sqlDate.compareTo(sqlDataClass.getSqlDate()) != 0) {
+ fail("SQL date: Test '2011-4-8', expected " + Data.sqlDate.toString() + ", but got "
+ + sqlDataClass.getSqlDate().toString() + ". Check log for more info.");
+ // LOG.log(Level.INFO, "SQL date: Test '2011-4-8', expected " +
+ // sqlDate.toString() + ", and got "
+ // + sqlDataClass.getSqlDate().toString()
+ // +". Check log for more info.");
+ } else {
+ // LOG.log(Level.INFO, "SQL date: test passed! Woohoo!");
+ }
+
+ }/**/
+
+ private void testDateTimezoneIssue() {
+ /*
+ * At the moment, applib Date and java.sql.Date are restored from ValueSemanticsProviderAbstractTemporal with an
+ * explicit hourly offset that comes from the timezone. I.e. in South Africa, with TZ +2h00, they have an
+ * implicit time of 02h00 (2AM). This can potentially seriously screw up GMT-X dates, which, I suspect, will
+ * actually be set to the dat BEFORE.
+ *
+ * This test is a simple test to confirm that date/time before and after checks work as expected.
+ */
+
+ DateTime dateTime = sqlDataClass.getDateTime(); // new DateTime(2010, 3, 5, 1, 23);
+ Date date = sqlDataClass.getDate(); // new Date(2010, 3, 5);
+
+ // java.sql.Date sqlDate = sqlDataClass.getSqlDate(); // "2010-03-05"
+ // assertTrue("dateTime's value (" + dateTime.dateValue() + ") should be after java.sql.date's (" + sqlDate +
+ // ")",
+ // dateTime.dateValue().after(sqlDate));
+
+ assertTrue("dateTime's value (" + dateTime.dateValue() + ") should be after date's (" + date + ")", dateTime
+ .dateValue().after(date.dateValue()));
+
+ }
+
+ /**
+ * Test {@link Money} type.
+ */
+ private void testMoney() {
+ assertEquals(Data.money, sqlDataClass.getMoney());
+ }
+
+ /**
+ * Test {@link DateTime} type.
+ */
+ private void testDateTime() {
+
+ LOG.log(Level.INFO, "Test: testDateTime()");
+ LOG.log(Level.INFO, "sqlDataClass.getDateTime() as String:" + sqlDataClass.getDateTime());
+ LOG.log(Level.INFO, "dateTime.toString() as String:" + Data.dateTime);
+
+ LOG.log(Level.INFO, "sqlDataClass.getDateTime().getTime() as Long:"
+ + sqlDataClass.getDateTime().millisSinceEpoch());
+ LOG.log(Level.INFO, "dateTime.getTime() as Long:" + Data.dateTime.millisSinceEpoch());
+
+ if (!Data.dateTime.equals(sqlDataClass.getDateTime())) {
+ fail("DateTime " + Data.dateTime.toString() + " is not expected " + sqlDataClass.getDateTime().toString());
+ }
+ }
+
+ /**
+ * Test {@link TimeStamp} type.
+ */
+ private void testTimeStamp() {
+ assertTrue(
+ "TimeStamp " + sqlDataClass.getTimeStamp().toString() + " does not equal expected "
+ + Data.timeStamp.toString(), Data.timeStamp.isEqualTo(sqlDataClass.getTimeStamp()));
+ }
+
+ /**
+ * Test {@link Time} type.
+ */
+ /**/
+ private void testTime() {
+ assertNotNull("sqlDataClass is null", sqlDataClass);
+ assertNotNull("getTime() is null", sqlDataClass.getTime());
+ assertTrue("Time 14h56: expected " + Data.time.toString() + ", but got " + sqlDataClass.getTime().toString(),
+ Data.time.isEqualTo(sqlDataClass.getTime()));
+ }
+
+ /**
+ * Test {@link Color} type.
+ */
+ private void testColor() {
+ assertEquals(Data.color, sqlDataClass.getColor());
+ }
+
+ /**
+ * Test {@link Image} type.
+ */
+ // TODO: Images are not equal...
+ /*
+ * public void testImage(){ SqlDataClass sqlDataClass = SqlIntegrationTestSingleton.getPerson(); Image image2 =
+ * sqlDataClass.getImage(); assertEqual(image, image2); }
+ *
+ * private void assertEqual(Image image2, Image image3) { assertEquals(image2.getHeight(), image3.getHeight());
+ * assertEquals(image2.getWidth(), image3.getWidth()); boolean same = true; int i=0,j=0; int p1=0, p2=0; String
+ * error = ""; int [][] i1 = image2.getImage(), i2 = image3.getImage(); for(i = 0; same &&
+ * i<image2.getHeight();i++){ int [] r1 = i1[i], r2 = i2[i]; for (j = 0; same && j < image2.getWidth(); j++){ if
+ * (r1[j] != r2[j]){ same = false; p1 = r1[j]; p2 = r2[j]; error = "Images differ at i = "+i+", j = "+j+", "+p1+
+ * " is not "+p2+"!"; break; } } } assertTrue(error, same); }
+ */
+
+ /**
+ * Test {@link Password} type.
+ */
+ private void testPassword() {
+ assertEquals(Data.password, sqlDataClass.getPassword());
+ }
+
+ /**
+ * Test {@link Percentage} type.
+ */
+ private void testPercentage() {
+ assertEquals(Data.percentage, sqlDataClass.getPercentage());
+ }
+
+ private void testStandardValueTypesMaxima() {
+ final PrimitiveValuedEntity pveMax = sqlDataClass.getPrimitiveValuedEntityMax();
+
+ assertEquals(Data.shortMaxValue, pveMax.getShortProperty());
+ assertEquals(Data.intMaxValue, pveMax.getIntProperty());
+ assertEquals(Data.longMaxValue, pveMax.getLongProperty());
+ assertEquals(Data.doubleMaxValue, pveMax.getDoubleProperty(), 0.00001f); // fails
+ // in
+ assertEquals(Data.floatMaxValue, pveMax.getFloatProperty(), 0.00001f);
+ }
+
+ private void testStandardValueTypesMinima() {
+ final PrimitiveValuedEntity pveMin = sqlDataClass.getPrimitiveValuedEntityMin();
+
+ assertEquals(Data.shortMinValue, pveMin.getShortProperty());
+ assertEquals(Data.intMinValue, pveMin.getIntProperty());
+ assertEquals(Data.longMinValue, pveMin.getLongProperty());
+ assertEquals(Data.doubleMinValue, pveMin.getDoubleProperty(), 0.00001f); // fails
+ // in
+ // MySQL
+ // =
+ // infinity
+ assertEquals(Data.floatMinValue, pveMin.getFloatProperty(), 0.00001f);
+ }
+
+ /**
+ * Test {@link StringCollection} type.
+ */
+ /*
+ * public void testStringCollection(){ SqlDataClass sqlDataClass = SqlIntegrationTestSingleton.getPerson();
+ * List<String> collection = sqlDataClass.getStringCollection(); int i = 0; for (String string : collection) {
+ * assertEquals(SqlIntegrationTestCommon.stringList.get(i++), string); } }
+ */
+
+ private void testSingleReferenceLazy() {
+ final SimpleClassTwo a = sqlDataClass.getSimpleClassTwo();
+ if (!persistenceMechanismIs("in-memory")) {
+ assertEquals(null, a.text); // must check direct value, as
+ // framework can auto-resolve, if you use getText()
+ }
+ }
+
+ /**
+ * Test a collection of {@link SimpleClass} type.
+ */
+ private void testSimpleClassCollection1() {
+ final List<SimpleClass> collection = sqlDataClass.getSimpleClasses1();
+
+ assertEquals("collection size is not equal!", simpleClassList1.size(), collection.size());
+
+ int i = 0;
+ for (final SimpleClass simpleClass : simpleClassList1) {
+ assertEquals(simpleClass.getString(), collection.get(i++).getString());
+ }
+ }
+
+ /**
+ * Test another collection of {@link SimpleClass} type.
+ */
+ private void testSimpleClassCollection2() {
+ final List<SimpleClass> collection = sqlDataClass.getSimpleClasses2();
+
+ assertEquals("collection size is not equal!", simpleClassList2.size(), collection.size());
+
+ int i = 0;
+ for (final SimpleClass simpleClass : simpleClassList2) {
+ assertEquals(simpleClass.getString(), collection.get(i++).getString());
+ }
+ }
+
+ private void testSimpleClassTwoReferenceLazy() {
+ final List<SimpleClass> collection = sqlDataClass.getSimpleClasses1();
+ if (getProperties().getProperty("isis.persistor") != "in-memory") {
+ for (final SimpleClass simpleClass : collection) {
+ final SimpleClassTwo a = simpleClass.getSimpleClassTwoA();
+ assertEquals(null, a.text); // must check direct value, as
+ // framework can auto-resolve, if
+ // you use getText()
+ }
+ }
+ }
+
+ private void testSingleReferenceResolve() {
+ final SimpleClassTwo a = sqlDataClass.getSimpleClassTwo();
+ factory.resolve(a);
+ assertEquals(simpleClassTwoA.getText(), a.getText());
+ }
+
+ private void testSimpleClassTwoReferenceResolve() {
+ final List<SimpleClass> collection = sqlDataClass.getSimpleClasses1();
+ for (final SimpleClass simpleClass : collection) {
+ final SimpleClassTwo a = simpleClass.getSimpleClassTwoA();
+ factory.resolve(a);
+ assertEquals(simpleClassTwoA.getText(), a.getText());
+ assertEquals(simpleClassTwoA.getIntValue(), a.getIntValue());
+ assertEquals(simpleClassTwoA.getBooleanValue(), a.getBooleanValue());
+ }
+ }
+
+ private void testSimpleClassTwo() {
+ final SqlDomainObjectRepository factory = getSqlIntegrationTestFixtures().getSqlDataClassFactory();
+ final List<SimpleClassTwo> classes = factory.allSimpleClassTwos();
+ assertEquals(2, classes.size());
+ for (final SimpleClassTwo simpleClass : classes) {
+ // assertEquals(simpleClassTwoA.getText(), simpleClass.getText());
+ assertTrue("AB".contains(simpleClass.getText()));
+ }
+ }
+
+ private void testUpdate1() {
+ final List<SimpleClassTwo> classes = factory.allSimpleClassTwos();
+ assertEquals(2, classes.size());
+
+ final SimpleClassTwo simpleClass = classes.get(0);
+ simpleClass.setText("XXX");
+ simpleClass.setBooleanValue(false);
+ simpleClassTwoA.setBooleanValue(false);
+
+ setFixtureInitializationStateIfNot(State.INITIALIZE, "in-memory");
+ }
+
+ private void testUpdate2() {
+ final List<SimpleClassTwo> classes = factory.allSimpleClassTwos();
+ assertEquals(2, classes.size());
+
+ final SimpleClassTwo simpleClass = classes.get(0);
+ assertEquals("XXX", simpleClass.getText());
+ assertEquals(simpleClassTwoA.getBooleanValue(), simpleClass.getBooleanValue());
+
+ setFixtureInitializationState(State.DONT_INITIALIZE);
+ }
+
+ private void testUpdateCollectionIsDirty() {
+
+ final List<SqlDataClass> sqlDataClasses = factory.allDataClasses();
+ final SqlDataClass sqlDataClass = sqlDataClasses.get(0);
+
+ final List<SimpleClass> collection = sqlDataClass.getSimpleClasses1();
+ final SimpleClass simpleClass1 = collection.get(0);
+ // simpleClass1.setString(stringList1.get(3));
+
+ collection.remove(simpleClass1);
+
+ // REVIEW: I'm very doubtful about this...
+ // what exactly is meant by updating an internal collection?
+ if (!persistenceMechanismIs("xml")) {
+ factory.update(collection);
+ }
+
+ factory.update(sqlDataClass);
+ }
+
+ private void testFindByMatchString() {
+ final SimpleClass simpleClassMatch = new SimpleClass();
+ simpleClassMatch.setString(Data.stringList1.get(1));
+
+ final List<SimpleClass> classes = factory.allSimpleClassesThatMatch(simpleClassMatch);
+ assertEquals(1, classes.size());
+
+ }
+
+ private void testFindByMatchEntity() {
+ final List<SimpleClassTwo> classTwos = factory.allSimpleClassTwos();
+
+ final SimpleClass simpleClassMatch = new SimpleClass();
+ simpleClassMatch.setSimpleClassTwoA(classTwos.get(0));
+
+ final List<SimpleClass> classes = factory.allSimpleClassesThatMatch(simpleClassMatch);
+
+ // TODO: Why is this hack required?
+ if (!getProperties().getProperty("isis.persistor").equals("in-memory")) {
+ assertEquals(Data.stringList1.size(), classes.size());
+ } else {
+ assertEquals(Data.stringList1.size() + 2, classes.size());
+ }
+ }
+
+ private void reinitializeFixtures() {
+ setFixtureInitializationState(State.INITIALIZE);
+ SqlIntegrationTestFixtures.recreate();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/255ef514/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestFixtures.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestFixtures.java b/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestFixtures.java
new file mode 100644
index 0000000..3feb90e
--- /dev/null
+++ b/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestFixtures.java
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ *
+ */
+package org.apache.isis.runtimes.dflt.objectstores.sql.common;
+
+import java.io.FileInputStream;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.commons.config.IsisConfigurationDefault;
+import org.apache.isis.core.commons.exceptions.IsisException;
+import org.apache.isis.runtimes.dflt.objectstores.sql.SqlObjectStore;
+import org.apache.isis.runtimes.dflt.runtime.installerregistry.installerapi.PersistenceMechanismInstallerAbstract;
+import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
+import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures.Fixtures.Initialization;
+import org.apache.isis.tck.dom.poly.ReferencingPolyTypesEntity;
+import org.apache.isis.tck.dom.scalars.PrimitiveValuedEntity;
+import org.apache.isis.tck.dom.sqlos.SqlDomainObjectRepository;
+import org.apache.isis.tck.dom.sqlos.data.SimpleClass;
+import org.apache.isis.tck.dom.sqlos.data.SimpleClassTwo;
+import org.apache.isis.tck.dom.sqlos.data.SqlDataClass;
+
+/**
+ * @author Kevin
+ *
+ */
+public class SqlIntegrationTestFixtures {
+
+ static SqlIntegrationTestFixtures instance;
+
+ public static SqlIntegrationTestFixtures getInstance() {
+ if (instance == null) {
+ instance = new SqlIntegrationTestFixtures();
+ }
+ return instance;
+ }
+
+ public static void recreate() {
+ instance = new SqlIntegrationTestFixtures();
+ }
+
+ public enum State {
+ INITIALIZE,
+ DONT_INITIALIZE;
+
+ public boolean isInitialize() { return this == INITIALIZE; }
+ }
+
+ private State state = State.INITIALIZE;
+ public State getState() {
+ return state;
+ }
+ public void setState(final State state) {
+ this.state = state;
+ }
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ ///////////////////////////////////////////////////////////////////////////
+
+
+ private IsisSystemWithFixtures system;
+
+
+ // JDBC
+ private Connection conn = null;
+ private Statement stmt = null;
+
+ public void initSystem(final String propertiesDirectory, final String propertiesFileName) throws Exception {
+
+ final Properties properties = new Properties();
+ properties.load(new FileInputStream(propertiesDirectory + "/" + propertiesFileName));
+
+ initSystem(properties);
+ }
+
+ public void initSystem(final Properties properties) throws Exception {
+ final IsisConfigurationDefault configuration = new IsisConfigurationDefault();
+ configuration.add(properties);
+
+ sqlDomainObjectRepository = new SqlDomainObjectRepository();
+ if (system != null) {
+ system.tearDownSystem();
+ }
+
+ final PersistenceMechanismInstallerAbstract persistorInstaller = Utils.createPersistorInstaller(configuration);
+ system = IsisSystemWithFixtures.builder().with(configuration).withServices(sqlDomainObjectRepository).with(Initialization.NO_INIT).with(persistorInstaller).build();
+
+ system.setUpSystem();
+
+ registerDriverAndConnect(configuration);
+ }
+
+
+ public void shutDown() throws Exception {
+ if (system != null) {
+ system.tearDownSystem();
+ }
+ }
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ ///////////////////////////////////////////////////////////////////////////
+
+
+ @SuppressWarnings("unchecked")
+ private void registerDriverAndConnect(final IsisConfiguration isisConfiguration) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
+ final String jdbcClassName = isisConfiguration.getString(SqlObjectStore.BASE_NAME + ".jdbc.driver");
+ if (jdbcClassName == null) {
+ conn = null;
+ stmt = null;
+ return;
+ }
+ final Class<Driver> driverClass = (Class<Driver>) Class.forName(jdbcClassName);
+ final Driver driver = driverClass.newInstance();
+ DriverManager.registerDriver(driver);
+
+ // jdbc - connect to DB and drop tables.
+ conn = DriverManager.getConnection(isisConfiguration.getString(SqlObjectStore.BASE_NAME + ".jdbc.connection"), isisConfiguration.getString(SqlObjectStore.BASE_NAME + ".jdbc.user"), isisConfiguration.getString(SqlObjectStore.BASE_NAME + ".jdbc.password"));
+ stmt = conn.createStatement();
+
+
+ // doesn't seem to be used...
+
+ // dropTable(SqlObjectStore.getTableName());
+ }
+
+ public void dropTable(final String tableName) {
+ if (stmt == null) {
+ if (tableName.equalsIgnoreCase("sqldataclass")) {
+ final List<SqlDataClass> list = sqlDomainObjectRepository.allDataClasses();
+ for (final SqlDataClass sqlDataClass : list) {
+ sqlDomainObjectRepository.delete(sqlDataClass);
+ }
+ return;
+ }
+ if (tableName.equalsIgnoreCase("simpleclass")) {
+ final List<SimpleClass> list = sqlDomainObjectRepository.allSimpleClasses();
+ for (final SimpleClass sqlClass : list) {
+ sqlDomainObjectRepository.delete(sqlClass);
+ }
+ return;
+ }
+ if (tableName.equalsIgnoreCase("simpleclasstwo")) {
+ final List<SimpleClassTwo> list = sqlDomainObjectRepository.allSimpleClassTwos();
+ for (final SimpleClassTwo sqlClass : list) {
+ sqlDomainObjectRepository.delete(sqlClass);
+ }
+ return;
+ }
+ if (tableName.equalsIgnoreCase("primitivevaluedentity")) {
+ final List<PrimitiveValuedEntity> list = sqlDomainObjectRepository.allPrimitiveValueEntities();
+ for (final PrimitiveValuedEntity pve : list) {
+ sqlDomainObjectRepository.delete(pve);
+ }
+ return;
+ }
+ throw new IsisException("Unknown table: " + tableName);
+ }
+
+ try {
+ String tableIdentifier = Utils.tableIdentifierFor(tableName);
+ stmt.executeUpdate("DROP TABLE " + tableIdentifier);
+ } catch (final SQLException e) {
+ // this can happen, not a problem.
+ // e.printStackTrace();
+ }
+ }
+
+ public void sqlExecute(final String sqlString) throws SQLException {
+ if (stmt != null) {
+ stmt.executeUpdate(sqlString);
+ }
+ }
+
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ ///////////////////////////////////////////////////////////////////////////
+
+ private SqlDomainObjectRepository sqlDomainObjectRepository = null;
+
+ private SqlDataClass sqlDataClass;
+ private ReferencingPolyTypesEntity referencingPolyTypesEntity;
+
+
+ public SqlDomainObjectRepository getSqlDataClassFactory() {
+ return sqlDomainObjectRepository;
+ }
+
+
+
+ public SqlDataClass getSqlDataClass() {
+ return sqlDataClass;
+ }
+ public void setSqlDataClass(SqlDataClass sqlDataClass) {
+ this.sqlDataClass = sqlDataClass;
+ }
+
+
+
+ public ReferencingPolyTypesEntity getPolyTestClass() {
+ return referencingPolyTypesEntity;
+ }
+ public void setPolyTestClass(final ReferencingPolyTypesEntity referencingPolyTypesEntity) {
+ this.referencingPolyTypesEntity = referencingPolyTypesEntity;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/255ef514/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/Utils.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/Utils.java b/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/Utils.java
new file mode 100644
index 0000000..c005cf5
--- /dev/null
+++ b/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/Utils.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.runtimes.dflt.objectstores.sql.common;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.runtimes.dflt.objectstores.dflt.InMemoryPersistenceMechanismInstaller;
+import org.apache.isis.runtimes.dflt.objectstores.sql.Sql;
+import org.apache.isis.runtimes.dflt.objectstores.sql.SqlObjectStore;
+import org.apache.isis.runtimes.dflt.objectstores.sql.SqlPersistorInstaller;
+import org.apache.isis.runtimes.dflt.objectstores.xml.XmlPersistenceMechanismInstaller;
+import org.apache.isis.runtimes.dflt.runtime.installerregistry.installerapi.PersistenceMechanismInstallerAbstract;
+
+public class Utils {
+
+ static PersistenceMechanismInstallerAbstract createPersistorInstaller(final IsisConfiguration configuration) {
+
+ final String jdbcDriver = configuration.getString(SqlObjectStore.BASE_NAME + ".jdbc.driver");
+ if (jdbcDriver != null) {
+ return new SqlPersistorInstaller();
+ }
+
+ final String persistor = configuration.getString("isis.persistor");
+ if (persistor.equals(InMemoryPersistenceMechanismInstaller.NAME)) {
+ return new InMemoryPersistenceMechanismInstaller();
+ }
+ if (persistor.equals(XmlPersistenceMechanismInstaller.NAME)) {
+ return new XmlPersistenceMechanismInstaller();
+ }
+ if (persistor.equals(SqlPersistorInstaller.NAME)) {
+ return new SqlPersistorInstaller();
+ }
+ return new InMemoryPersistenceMechanismInstaller();
+ }
+
+ static String tableIdentifierFor(final String tableName) {
+ if (tableName.substring(0, 4).toUpperCase().equals("ISIS")) {
+ return Sql.tableIdentifier(tableName);
+ } else {
+ return Sql.tableIdentifier("isis_" + tableName);
+ }
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/255ef514/component/objectstore/sql/sql-tests-common/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/main/resources/log4j.properties b/component/objectstore/sql/sql-tests-common/src/main/resources/log4j.properties
new file mode 100644
index 0000000..b36337f
--- /dev/null
+++ b/component/objectstore/sql/sql-tests-common/src/main/resources/log4j.properties
@@ -0,0 +1,39 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# apache's log4j is used to provide system logging.
+log4j.rootCategory=DEBUG, File
+log4j.rootCategory=INFO, Console
+
+
+# The console appender
+log4j.appender.Console=org.apache.log4j.ConsoleAppender
+log4j.appender.Console.target=System.out
+log4j.appender.Console.layout=org.apache.log4j.PatternLayout
+log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} [%-20c{1} %-10t %-5p] %m%n
+
+
+log4j.appender.File=org.apache.log4j.RollingFileAppender
+log4j.appender.File.file=isis.log
+log4j.appender.File.append=false
+#log4j.appender.File.maxFileSize=500KB
+#log4j.appender.File.maxBackupIndex=1
+log4j.appender.File.layout=org.apache.log4j.PatternLayout
+log4j.appender.File.layout.ConversionPattern=%d [%-20c{1} %-10t %-5p] %m%n
+
+
+
+
http://git-wip-us.apache.org/repos/asf/isis/blob/255ef514/component/objectstore/sql/sql-tests-common/src/site/apt/index.apt
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/site/apt/index.apt b/component/objectstore/sql/sql-tests-common/src/site/apt/index.apt
new file mode 100644
index 0000000..025703e
--- /dev/null
+++ b/component/objectstore/sql/sql-tests-common/src/site/apt/index.apt
@@ -0,0 +1,28 @@
+~~ Licensed to the Apache Software Foundation (ASF) under one
+~~ or more contributor license agreements. See the NOTICE file
+~~ distributed with this work for additional information
+~~ regarding copyright ownership. The ASF licenses this file
+~~ to you under the Apache License, Version 2.0 (the
+~~ "License"); you may not use this file except in compliance
+~~ with the License. You may obtain a copy of the License at
+~~
+~~ http://www.apache.org/licenses/LICENSE-2.0
+~~
+~~ Unless required by applicable law or agreed to in writing,
+~~ software distributed under the License is distributed on an
+~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+~~ KIND, either express or implied. See the License for the
+~~ specific language governing permissions and limitations
+~~ under the License.
+
+
+
+SQL ObjectStore Integration Tests
+
+ This module holds the integration tests for the {{{../index.html}SQL ObjectStore}}.
+
+Further Info
+
+ See this module's {{{./apidocs/index.html}Javadoc}} and {{{../docbkx/html/guide/isis-sql-objectstore.html}User Guide}} for more information.
+
+
http://git-wip-us.apache.org/repos/asf/isis/blob/255ef514/component/objectstore/sql/sql-tests-common/src/site/apt/jottings.apt
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/site/apt/jottings.apt b/component/objectstore/sql/sql-tests-common/src/site/apt/jottings.apt
new file mode 100644
index 0000000..c5d1200
--- /dev/null
+++ b/component/objectstore/sql/sql-tests-common/src/site/apt/jottings.apt
@@ -0,0 +1,24 @@
+~~ Licensed to the Apache Software Foundation (ASF) under one
+~~ or more contributor license agreements. See the NOTICE file
+~~ distributed with this work for additional information
+~~ regarding copyright ownership. The ASF licenses this file
+~~ to you under the Apache License, Version 2.0 (the
+~~ "License"); you may not use this file except in compliance
+~~ with the License. You may obtain a copy of the License at
+~~
+~~ http://www.apache.org/licenses/LICENSE-2.0
+~~
+~~ Unless required by applicable law or agreed to in writing,
+~~ software distributed under the License is distributed on an
+~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+~~ KIND, either express or implied. See the License for the
+~~ specific language governing permissions and limitations
+~~ under the License.
+
+
+
+Jottings
+
+ This page is to capture any random jottings relating to this module prior
+ to being moved into formal documentation.
+
http://git-wip-us.apache.org/repos/asf/isis/blob/255ef514/component/objectstore/sql/sql-tests-common/src/site/site.xml
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/site/site.xml b/component/objectstore/sql/sql-tests-common/src/site/site.xml
new file mode 100644
index 0000000..9aa405b
--- /dev/null
+++ b/component/objectstore/sql/sql-tests-common/src/site/site.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project>
+
+ <body>
+ <breadcrumbs>
+ <item name="Tests" href="index.html"/>
+ </breadcrumbs>
+
+ <menu name="SQL Objectstore Tests">
+ <item name="About" href="index.html" />
+ </menu>
+
+ <menu name="SQL OS Modules">
+ <item name="Implementation" href="../sql-impl/index.html" />
+ <item name="Tests" href="../sql-tests-common/index.html" />
+ <item name="Integration Tests" href="../sql-tests-served/index.html" />
+ </menu>
+
+ <menu name="Maven Reports" ref="reports" />
+ </body>
+</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/255ef514/component/objectstore/sql/sql-tests-common/src/test/config/hsql-poly.properties
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/test/config/hsql-poly.properties b/component/objectstore/sql/sql-tests-common/src/test/config/hsql-poly.properties
new file mode 100644
index 0000000..1966071
--- /dev/null
+++ b/component/objectstore/sql/sql-tests-common/src/test/config/hsql-poly.properties
@@ -0,0 +1,26 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+isis.persistor=sql
+
+isis.persistor.sql.jdbc.driver=org.hsqldb.jdbcDriver
+isis.persistor.sql.jdbc.connection=jdbc:hsqldb:file:hsql-db/polytests
+isis.persistor.sql.jdbc.user=sa
+isis.persistor.sql.jdbc.password=
+
+# testing
+isis.logging.objectstore=on
+isis.persistor.sql.default.command.beginTransaction=
http://git-wip-us.apache.org/repos/asf/isis/blob/255ef514/component/objectstore/sql/sql-tests-common/src/test/config/hsql.properties
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/test/config/hsql.properties b/component/objectstore/sql/sql-tests-common/src/test/config/hsql.properties
new file mode 100644
index 0000000..9e4a262
--- /dev/null
+++ b/component/objectstore/sql/sql-tests-common/src/test/config/hsql.properties
@@ -0,0 +1,29 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+isis.persistor=sql
+
+isis.persistor.sql.jdbc.driver=org.hsqldb.jdbcDriver
+isis.persistor.sql.jdbc.connection=jdbc:hsqldb:file:hsql-db/tests
+isis.persistor.sql.jdbc.user=sa
+isis.persistor.sql.jdbc.password=
+
+# testing
+isis.persistor.sql.datatypes.string=VARCHAR(70)
+isis.persistor.sql.default.password.seed=gfkhgdf76453fhgj#$
+isis.persistor.sql.default.command.beginTransaction=
+
+
http://git-wip-us.apache.org/repos/asf/isis/blob/255ef514/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/HsqlTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/HsqlTest.java b/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/HsqlTest.java
new file mode 100644
index 0000000..be4be4b
--- /dev/null
+++ b/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/HsqlTest.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.runtimes.dflt.objectstores.sql;
+
+import org.apache.isis.core.testsupport.files.Files;
+import org.apache.isis.core.testsupport.files.Files.Recursion;
+import org.apache.isis.runtimes.dflt.objectstores.sql.common.Data;
+import org.apache.isis.runtimes.dflt.objectstores.sql.common.SqlIntegrationTestData;
+import org.apache.isis.runtimes.dflt.objectstores.sql.common.SqlIntegrationTestFixtures;
+
+/**
+ * @author Kevin kevin@kmz.co.za
+ *
+ * This test implementation uses the HyperSQL database engine to perform "serverless" tests of data creation and
+ * reloading.
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class HsqlTest extends SqlIntegrationTestData {
+
+ @Override
+ public void resetPersistenceStoreDirectlyIfRequired() {
+ Files.deleteFilesWithPrefix("hsql-db", "tests", Recursion.DONT_RECURSE);
+ }
+
+ @Override
+ protected void testCreate() throws Exception {
+ final SqlIntegrationTestFixtures sqlIntegrationTestFixtures = getSqlIntegrationTestFixtures();
+ for (final String tableName : Data.getTableNames()) {
+ sqlIntegrationTestFixtures.dropTable(tableName);
+ }
+ super.testCreate();
+ }
+
+ @Override
+ protected String getSqlSetupString() {
+ return "COMMIT;";
+ }
+
+ @Override
+ public String getPropertiesFilename() {
+ return "hsql.properties";
+ }
+
+ @Override
+ public String getSqlTeardownString() {
+ return "SHUTDOWN;";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/255ef514/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/PolymorphismTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/PolymorphismTest.java b/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/PolymorphismTest.java
new file mode 100755
index 0000000..795ff49
--- /dev/null
+++ b/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/PolymorphismTest.java
@@ -0,0 +1,349 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.runtimes.dflt.objectstores.sql;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.junit.Test;
+
+import org.apache.isis.core.testsupport.files.Files;
+import org.apache.isis.core.testsupport.files.Files.Recursion;
+import org.apache.isis.runtimes.dflt.objectstores.sql.common.SqlIntegrationTestCommonBase;
+import org.apache.isis.runtimes.dflt.objectstores.sql.common.SqlIntegrationTestFixtures;
+import org.apache.isis.runtimes.dflt.objectstores.sql.common.SqlIntegrationTestFixtures.State;
+import org.apache.isis.tck.dom.poly.Empty;
+import org.apache.isis.tck.dom.poly.EmptyEntityWithOwnProperty;
+import org.apache.isis.tck.dom.poly.ReferencingPolyTypesEntity;
+import org.apache.isis.tck.dom.poly.SelfReferencingEntity;
+import org.apache.isis.tck.dom.poly.StringBaseEntity;
+import org.apache.isis.tck.dom.poly.StringBaseEntitySub;
+import org.apache.isis.tck.dom.poly.StringBaseEntitySubThree;
+import org.apache.isis.tck.dom.poly.StringBaseEntitySubTwo;
+import org.apache.isis.tck.dom.poly.Stringable;
+import org.apache.isis.tck.dom.poly.StringableEntityWithOwnDerivedProperty;
+import org.apache.isis.tck.dom.poly.StringableEntityWithOwnProperties;
+import org.apache.isis.tck.dom.poly.StringableEntityWithOwnProperty;
+
+/**
+ * @author Kevin kevin@kmz.co.za
+ *
+ * This test implementation uses the HyperSQL database engine to perform "serverless" tests of polymorphic class
+ * object creation and reloading.
+ *
+ * The sql object store thus allows your domain objects to have properties referenced via interface or
+ * superclass. Both single reference properties and property collections are supported.
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+
+public class PolymorphismTest extends SqlIntegrationTestCommonBase {
+
+ private static final String IMPL_A_STRING = "Impl A String";
+ private static final String IMPL_B_STRING = "Impl B String";
+ private static final String CHILD_1 = "Child 1";
+
+ private static StringableEntityWithOwnProperty polyIntImpA;
+ private static StringableEntityWithOwnProperties polyIntImpB;
+
+ @Override
+ public String getPropertiesFilename() {
+ return "hsql-poly.properties";
+ }
+
+ @Override
+ public void resetPersistenceStoreDirectlyIfRequired() {
+ Files.deleteFilesWithPrefix("hsql-db", "poly", Recursion.DONT_RECURSE);
+ getSqlIntegrationTestFixtures();
+ }
+
+ @Override
+ public String getSqlTeardownString() {
+ return "SHUTDOWN;";
+ }
+
+ // Order is important. The next three "tests" must be executed in the correct sequential order.
+ @Test
+ /**
+ * Sets up the database connection and tells the test framework to create an instance of the
+ * Isis framework for the next "test".
+ */
+ public void test1SetupStoreAndDatabaseConnection() throws Exception {
+ testSetup();
+ }
+
+ @Test
+ /**
+ * Uses the database connection to drop database tables related to these tests.
+ * This forces (and exercises the ability of) the object store to re-create the tables.
+ *
+ * Also uses factory methods within the Isis framework to create the test data,
+ * thus exercising the "create data" portion of the object store.
+ *
+ * The Isis framework will be again be re-created in the next test unless the
+ * object store is "in-memory" (this is required since "in-memory" has to be
+ * left alone for created data to still be present in the next test).
+ */
+ public void test2SetupDataWithDatabaseConnection() throws Exception {
+ final SqlIntegrationTestFixtures sqlIntegrationTestFixtures = getSqlIntegrationTestFixtures();
+ sqlIntegrationTestFixtures.dropTable("ISIS_SELFREFERENCINGENTITY");
+ sqlIntegrationTestFixtures.dropTable("ISIS_STRINGABLEENTITYWITHOWNPROPERTY");
+ sqlIntegrationTestFixtures.dropTable("ISIS_STRINGABLEENTITYWITHOWNPROPERTIES");
+ sqlIntegrationTestFixtures.dropTable("ISIS_STRINGBASEENTITYSUB");
+ sqlIntegrationTestFixtures.dropTable("ISIS_STRINGBASEENTITYSUBTWO");
+ sqlIntegrationTestFixtures.dropTable("ISIS_STRINGBASEENTITYSUBTHREE");
+ sqlIntegrationTestFixtures.dropTable("ISIS_REFERENCINGPOLYTYPESENTITY");
+ sqlIntegrationTestFixtures.dropTable("ISIS_STRINGBASEENTITY");
+ sqlIntegrationTestFixtures.dropTable("ISIS_STRINGABLE");
+
+ final ReferencingPolyTypesEntity referencingPolyTypesEntity = factory.newPolyTestClass();
+ referencingPolyTypesEntity.setString("polyTestClassString");
+
+ // Setup self-referencing collection
+ final SelfReferencingEntity polySelfRefClassParent = factory.newPolySelfRefClass();
+ polySelfRefClassParent.setString("Parent");
+
+ final SelfReferencingEntity polySelfRefClassChild1 = factory.newPolySelfRefClass();
+ polySelfRefClassChild1.setString(CHILD_1);
+ polySelfRefClassParent.addToPolySelfRefClasses(polySelfRefClassChild1);
+
+ final SelfReferencingEntity polySelfRefClassChild2 = factory.newPolySelfRefClass();
+ polySelfRefClassChild2.setString("Child 2");
+ polySelfRefClassParent.addToPolySelfRefClasses(polySelfRefClassChild2);
+ factory.save(polySelfRefClassChild2);
+
+ final SelfReferencingEntity polySelfRefClassChild3 = factory.newPolySelfRefClass();
+ polySelfRefClassChild3.setString("Child 1 of Child 1");
+ polySelfRefClassChild1.addToPolySelfRefClasses(polySelfRefClassChild3);
+
+ factory.save(polySelfRefClassChild3);
+ factory.save(polySelfRefClassChild1);
+
+ factory.save(polySelfRefClassParent);
+ referencingPolyTypesEntity.setPolySelfRefClass(polySelfRefClassParent);
+
+ // polyTestClass.setPolyTestInterface(polyTestClass);
+
+ polyIntImpA = factory.newPolyInterfaceImplA();
+ polyIntImpA.setString(IMPL_A_STRING);
+ polyIntImpA.setSpecial("special");
+ factory.save(polyIntImpA);
+
+ referencingPolyTypesEntity.setPolyInterfaceType(polyIntImpA);
+ referencingPolyTypesEntity.getPolyInterfaces().add(polyIntImpA);
+
+ // setup the polyTestClass
+ final StringBaseEntitySub stringBaseEntitySub = factory.newPolySubClassOne();
+ stringBaseEntitySub.setStringBase("PolySubClassOne 1");
+ stringBaseEntitySub.setStringClassOne("Class 1");
+
+ final StringBaseEntitySubTwo stringBaseEntitySubTwo = factory.newPolySubClassTwo();
+ stringBaseEntitySubTwo.setStringBase("PolySubClassTwo 1");
+ stringBaseEntitySubTwo.setStringClassTwo("Class 2");
+
+ final StringBaseEntitySubThree stringBaseEntitySubThree = factory.newPolySubClassThree();
+ stringBaseEntitySubThree.setStringBase("PolySubClassThree 1");
+ stringBaseEntitySubThree.setStringClassThree("Another String");
+ stringBaseEntitySubThree.setStringClassTwo("Class 3");
+
+ referencingPolyTypesEntity.getPolyBaseClasses().add(stringBaseEntitySub);
+ referencingPolyTypesEntity.getPolyBaseClasses().add(stringBaseEntitySubTwo);
+ referencingPolyTypesEntity.getPolyBaseClasses().add(stringBaseEntitySubThree);
+
+ factory.save(stringBaseEntitySub);
+ factory.save(stringBaseEntitySubTwo);
+ factory.save(stringBaseEntitySubThree);
+
+ // store it and step the state engine
+ factory.save(referencingPolyTypesEntity);
+
+ setFixtureInitializationState(State.DONT_INITIALIZE, "in-memory");
+ }
+
+ @Test
+ /**
+ * The actual "tests". Unless the test is using the "in-memory" object store
+ * the Isis framework is re-created, thus ensuring that no domain objects are
+ * left over from the previous "create" step, forcing the objects to be created
+ * via the object store.
+ *
+ * Exercises the "restore data" portion of the object store.
+ *
+ * Confirms that polymorphic classes are loaded as expected (via interface,
+ * via super-class, etc.)
+ */
+ public void test3All() throws Exception {
+ load();
+
+ setUpFactory();
+
+ polymorphicLoad();
+ interfaceLoad();
+ loadSelfReferencingCollection();
+ interfaceLoadProperty();
+ interfaceLoadCollection();
+ interfaceEditSave();
+ interfaceEditLoad();
+ allInterfacesInstancesLoaded();
+ interfacesLoadedByQuery();
+ interfacesLoadedByQuerySpecial();
+ findByMatchPartialEntity();
+ cannotFindByMatchWithWrongValue();
+
+ // Must be here so that the Isis framework is initialised for the next test package.
+ setFixtureInitializationState(State.INITIALIZE);
+ }
+
+ private void load() {
+ final List<ReferencingPolyTypesEntity> dataClasses = factory.allPolyTestClasses();
+ assertEquals(1, dataClasses.size());
+ final ReferencingPolyTypesEntity referencingPolyTypesEntity = dataClasses.get(0);
+
+ getSqlIntegrationTestFixtures().setPolyTestClass(referencingPolyTypesEntity);
+
+ setFixtureInitializationState(State.DONT_INITIALIZE);
+ }
+
+ private void polymorphicLoad() {
+ final List<StringBaseEntity> polyBaseClasses = referencingPolyTypesEntity.getPolyBaseClasses();
+ assertEquals(3, polyBaseClasses.size());
+
+ StringBaseEntity polyClassBase = polyBaseClasses.get(0);
+ assertTrue(polyClassBase instanceof StringBaseEntitySub);
+ assertEquals("PolySubClassOne 1", polyClassBase.getStringBase());
+ final StringBaseEntitySub stringBaseEntitySub = (StringBaseEntitySub) polyClassBase;
+ assertEquals("Class 1", stringBaseEntitySub.getStringClassOne());
+
+ polyClassBase = polyBaseClasses.get(1);
+ assertTrue(polyClassBase instanceof StringBaseEntitySubTwo);
+ final StringBaseEntitySubTwo stringBaseEntitySubTwo = (StringBaseEntitySubTwo) polyClassBase;
+ assertEquals("Class 2", stringBaseEntitySubTwo.getStringClassTwo());
+
+ polyClassBase = polyBaseClasses.get(2);
+ assertTrue(polyClassBase instanceof StringBaseEntitySubThree);
+ final StringBaseEntitySubThree stringBaseEntitySubThree = (StringBaseEntitySubThree) polyClassBase;
+ assertEquals("Class 3", stringBaseEntitySubThree.getStringClassTwo());
+ assertEquals("Another String", stringBaseEntitySubThree.getStringClassThree());
+ }
+
+ private void interfaceLoad() {
+ final Stringable loaded = referencingPolyTypesEntity.getPolyInterfaceType();
+ factory.resolve(loaded);
+ assertEquals(polyIntImpA.getString(), loaded.getString());
+ }
+
+ private void loadSelfReferencingCollection() {
+ final SelfReferencingEntity polySelfRefParent = referencingPolyTypesEntity.getPolySelfRefClass();
+ final List<SelfReferencingEntity> list = polySelfRefParent.getPolySelfRefClasses();
+ assertEquals(2, list.size());
+
+ SelfReferencingEntity polySelfRefChild1 = null;
+ for (final SelfReferencingEntity selfReferencingEntity : list) {
+ if (selfReferencingEntity.getString().equals(CHILD_1)) {
+ polySelfRefChild1 = selfReferencingEntity;
+ }
+ }
+ assertNotNull(polySelfRefChild1);
+
+ assertEquals(CHILD_1, polySelfRefChild1.title());
+
+ List<SelfReferencingEntity> list2 = polySelfRefChild1.getPolySelfRefClasses();
+ factory.resolve(polySelfRefChild1);
+ list2 = polySelfRefChild1.getPolySelfRefClasses();
+ assertEquals(1, list2.size());
+ }
+
+ private void interfaceLoadProperty() {
+ final Stringable loaded = referencingPolyTypesEntity.getPolyInterfaceType();
+ assertEquals(polyIntImpA.getString(), loaded.getString());
+ }
+
+ private void interfaceLoadCollection() {
+ final List<Stringable> list = referencingPolyTypesEntity.getPolyInterfaces();
+
+ assertEquals(1, list.size());
+ final Stringable loaded = list.get(0);
+
+ assertEquals(polyIntImpA.getString(), loaded.getString());
+ }
+
+ private void interfaceEditSave() {
+ polyIntImpB = factory.newPolyInterfaceImplB();
+ polyIntImpB.setString(IMPL_B_STRING);
+ polyIntImpB.setSpecial("special");
+ polyIntImpB.setInteger(1);
+
+ factory.save(polyIntImpB);
+
+ referencingPolyTypesEntity.setPolyInterfaceType(polyIntImpB);
+
+ setFixtureInitializationState(State.INITIALIZE);
+ }
+
+ private void interfaceEditLoad() {
+ load(); // reload data
+
+ final Stringable loaded = referencingPolyTypesEntity.getPolyInterfaceType();
+ assertEquals(polyIntImpB.getString(), loaded.getString());
+ }
+
+ private void allInterfacesInstancesLoaded() {
+ final List<Stringable> list = factory.allPolyInterfaces();
+ assertEquals(2, list.size());
+ }
+
+ private void interfacesLoadedByQuery() {
+ // PolyInterface query = polyIntImpA;
+
+ final StringableEntityWithOwnDerivedProperty query = new StringableEntityWithOwnDerivedProperty();
+ query.setString(IMPL_A_STRING);
+
+ final List<Stringable> list = factory.queryPolyInterfaces(query);
+ assertEquals(1, list.size());
+ }
+
+ private void interfacesLoadedByQuerySpecial() {
+
+ final StringableEntityWithOwnDerivedProperty query = new StringableEntityWithOwnDerivedProperty();
+
+ final List<Stringable> list = factory.queryPolyInterfaces(query);
+ assertEquals(2, list.size());
+ }
+
+ private void findByMatchPartialEntity() {
+ final Empty match = new EmptyEntityWithOwnProperty();
+ final List<Empty> matches = factory.allEmptyInterfacesThatMatch(match);
+ assertEquals(1, matches.size());
+
+ final Empty empty = matches.get(0);
+ final StringableEntityWithOwnProperties imp = (StringableEntityWithOwnProperties) empty;
+ assertEquals(IMPL_B_STRING, imp.getString());
+ }
+
+ private void cannotFindByMatchWithWrongValue() {
+ final StringableEntityWithOwnProperties match = new StringableEntityWithOwnProperties();
+ match.setInteger(0);
+ final List<Empty> matches = factory.allEmptyInterfacesThatMatch(match);
+ assertEquals(0, matches.size());
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/255ef514/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/crosscheck/InMemoryPersistenceTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/crosscheck/InMemoryPersistenceTest.java b/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/crosscheck/InMemoryPersistenceTest.java
new file mode 100644
index 0000000..af28e24
--- /dev/null
+++ b/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/crosscheck/InMemoryPersistenceTest.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ *
+ */
+package org.apache.isis.runtimes.dflt.objectstores.sql.crosscheck;
+
+import java.util.Properties;
+
+import org.apache.isis.runtimes.dflt.objectstores.sql.common.SqlIntegrationTestData;
+import org.apache.isis.runtimes.dflt.objectstores.sql.common.SqlIntegrationTestFixtures;
+import org.apache.isis.runtimes.dflt.objectstores.sql.common.SqlIntegrationTestFixtures.State;
+
+public class InMemoryPersistenceTest extends SqlIntegrationTestData {
+
+ @Override
+ public Properties getProperties() {
+ final Properties properties = new Properties();
+ properties.put("isis.persistor", "in-memory");
+ properties.put("isis.logging.objectstore", "off");
+ return properties;
+ }
+
+ @Override
+ protected void testSetup() {
+ resetPersistenceStoreDirectlyIfRequired();
+ SqlIntegrationTestFixtures.recreate();
+ try {
+ SqlIntegrationTestFixtures.getInstance().initSystem(getProperties());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ getSqlIntegrationTestFixtures().setState(State.INITIALIZE);
+ }
+
+ @Override
+ public String getPropertiesFilename() {
+ return "inmemory.properties";
+ }
+
+ @Override
+ public String getSqlTeardownString() {
+ return "SHUTDOWN;";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/255ef514/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/crosscheck/XmlPersistenceTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/crosscheck/XmlPersistenceTest.java b/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/crosscheck/XmlPersistenceTest.java
new file mode 100644
index 0000000..23e24a7
--- /dev/null
+++ b/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/crosscheck/XmlPersistenceTest.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ *
+ */
+package org.apache.isis.runtimes.dflt.objectstores.sql.crosscheck;
+
+import java.util.Properties;
+
+import org.apache.isis.core.testsupport.files.Files;
+import org.apache.isis.core.testsupport.files.Files.Recursion;
+import org.apache.isis.runtimes.dflt.objectstores.sql.common.SqlIntegrationTestData;
+import org.apache.isis.runtimes.dflt.objectstores.sql.common.SqlIntegrationTestFixtures;
+import org.apache.isis.runtimes.dflt.objectstores.sql.common.SqlIntegrationTestFixtures.State;
+
+public class XmlPersistenceTest extends SqlIntegrationTestData {
+
+ @Override
+ public void resetPersistenceStoreDirectlyIfRequired() {
+ Files.deleteFiles("xml/objects", ".xml", Recursion.DO_RECURSE);
+ }
+
+ @Override
+ protected void testSetup() {
+ resetPersistenceStoreDirectlyIfRequired();
+ SqlIntegrationTestFixtures.recreate();
+ try {
+ SqlIntegrationTestFixtures.getInstance().initSystem(getProperties());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ getSqlIntegrationTestFixtures().setState(State.INITIALIZE);
+ }
+
+ @Override
+ public Properties getProperties() {
+ final Properties properties = new Properties();
+ properties.put("isis.persistor", "xml");
+ properties.put("isis.logging.objectstore", "off");
+ return properties;
+ }
+
+ @Override
+ public String getPropertiesFilename() {
+ return "xml.properties";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/255ef514/component/objectstore/sql/sql-tests-served/NOTICE
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-served/NOTICE b/component/objectstore/sql/sql-tests-served/NOTICE
new file mode 100644
index 0000000..d391f54
--- /dev/null
+++ b/component/objectstore/sql/sql-tests-served/NOTICE
@@ -0,0 +1,7 @@
+Apache Isis
+Copyright 2010-2011 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+