diff options
author | Eike Stepper | 2008-05-12 09:38:13 +0000 |
---|---|---|
committer | Eike Stepper | 2008-05-12 09:38:13 +0000 |
commit | 00ba22bf1cee6ba0c6fb49dd77c0c54970df748c (patch) | |
tree | 193cfc1ac1be1ca4e0f4dd5b2d55e28f444d0b69 /plugins | |
parent | 4b0a9726955bcca76bba07bc6f30ece1ecf83720 (diff) | |
download | cdo-00ba22bf1cee6ba0c6fb49dd77c0c54970df748c.tar.gz cdo-00ba22bf1cee6ba0c6fb49dd77c0c54970df748c.tar.xz cdo-00ba22bf1cee6ba0c6fb49dd77c0c54970df748c.zip |
Added store test framework
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/store/DBStoreTestLogic.java (renamed from plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/store/DBStoreHorizontalTest.java) | 114 | ||||
-rw-r--r-- | plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/store/HorizontalTest.java | 126 |
2 files changed, 141 insertions, 99 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/store/DBStoreHorizontalTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/store/DBStoreTestLogic.java index df3be6f7ab..bc9cf44b6d 100644 --- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/store/DBStoreHorizontalTest.java +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/store/DBStoreTestLogic.java @@ -10,20 +10,14 @@ **************************************************************************/ package org.eclipse.emf.cdo.tests.store; -import org.eclipse.emf.cdo.internal.server.Transaction; import org.eclipse.emf.cdo.server.IStore; import org.eclipse.emf.cdo.server.internal.db.CDODBSchema; import org.eclipse.emf.cdo.server.internal.db.DBStore; -import org.eclipse.emf.cdo.server.internal.db.HorizontalMappingStrategy; import org.eclipse.emf.cdo.server.internal.db.MappingStrategy; -import org.eclipse.emf.cdo.server.internal.db.ToMany; -import org.eclipse.emf.cdo.server.internal.db.ToOne; import org.eclipse.net4j.db.DBUtil; +import org.eclipse.net4j.db.IDBAdapter; import org.eclipse.net4j.db.IDBConnectionProvider; -import org.eclipse.net4j.db.hsqldb.HSQLDBDataSource; -import org.eclipse.net4j.db.internal.hsqldb.HSQLDBAdapter; -import org.eclipse.net4j.internal.db.DataSourceConnectionProvider; import org.eclipse.net4j.util.ObjectUtil; import org.eclipse.net4j.util.WrappedException; @@ -39,25 +33,23 @@ import java.io.PrintStream; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; -import java.util.HashMap; -import java.util.Map; /** * @author Eike Stepper */ -public class DBStoreHorizontalTest extends TestLogic +public abstract class DBStoreTestLogic extends TestLogic { - private static final String DEFINITION_MODE = ""; + public static final String DEFINITION_MODE = ""; - private HorizontalMappingStrategy mappingStrategy; + protected MappingStrategy mappingStrategy; - private HSQLDBAdapter dbAdapter; + protected IDBAdapter dbAdapter; - private IDBConnectionProvider dbConnectionProvider; + protected IDBConnectionProvider dbConnectionProvider; - private DBStore store; + protected DBStore store; - public DBStoreHorizontalTest() + public DBStoreTestLogic() { } @@ -91,32 +83,13 @@ public class DBStoreHorizontalTest extends TestLogic return store; } - protected IDBConnectionProvider createDBConnectionProvider() - { - HSQLDBDataSource dataSource = new HSQLDBDataSource(); - dataSource.setDatabase("jdbc:hsqldb:mem:storetest"); - dataSource.setUser("sa"); - - return new DataSourceConnectionProvider(dataSource); - } + protected abstract IDBConnectionProvider createDBConnectionProvider(); - protected HSQLDBAdapter createDBAdapter() - { - return new HSQLDBAdapter(); - } - - protected HorizontalMappingStrategy createMappingStrategy() - { - Map<String, String> props = new HashMap<String, String>(); - props.put(MappingStrategy.PROP_TO_MANY_REFERENCE_MAPPING, ToMany.PER_CLASS.toString()); - props.put(MappingStrategy.PROP_TO_ONE_REFERENCE_MAPPING, ToOne.LIKE_ATTRIBUTES.toString()); + protected abstract IDBAdapter createDBAdapter(); - HorizontalMappingStrategy mappingStrategy = new HorizontalMappingStrategy(); - mappingStrategy.setProperties(props); - return mappingStrategy; - } + protected abstract MappingStrategy createMappingStrategy(); - private void defineOrCompare(String fileName) throws IOException + protected void defineOrCompare(String fileName) throws IOException { File file = new File(fileName + ".txt"); if (fileName.equals(DEFINITION_MODE) || "*".equals(DEFINITION_MODE)) @@ -168,19 +141,19 @@ public class DBStoreHorizontalTest extends TestLogic CDODBSchema.INSTANCE.export(dbConnectionProvider, out); } - private void assertRowCount(int expectedRows, String tableName) + protected void assertRowCount(int expectedRows, String tableName) { int actualRowsl = (Integer)query("select count(*) from " + tableName); assertEquals("Rows in " + tableName.toUpperCase(), expectedRows, actualRowsl); } - private void assertFieldValue(Object expectedValue, String sql) + protected void assertFieldValue(Object expectedValue, String sql) { Object actualValue = query(sql); assertEquals("Field in " + sql, expectedValue, actualValue); } - private Object query(String sql) + protected Object query(String sql) { Connection connection = null; Statement statement = null; @@ -209,61 +182,4 @@ public class DBStoreHorizontalTest extends TestLogic DBUtil.close(connection); } } - - @Override - protected void verifyCreateModel1(Transaction transaction) throws Exception - { - defineOrCompare("defs/horizontal/verifyCreateModel1"); - // assertRowCount(1, "cdo_repository"); - // assertRowCount(1, "cdo_packages"); - // assertRowCount(11, "cdo_classes"); - // assertRowCount(8, "cdo_supertypes"); - // assertRowCount(26, "cdo_features"); - } - - @Override - protected void verifyCreateModel2(Transaction transaction) throws Exception - { - defineOrCompare("defs/horizontal/verifyCreateModel2"); - // assertRowCount(1, "cdo_repository"); - // assertRowCount(2, "cdo_packages"); - // assertRowCount(12, "cdo_classes"); - // assertRowCount(9, "cdo_supertypes"); - // assertRowCount(28, "cdo_features"); - } - - @Override - protected void verifyCreateModel3(Transaction transaction) throws Exception - { - defineOrCompare("defs/horizontal/verifyCreateModel3"); - // assertRowCount(1, "cdo_repository"); - // assertRowCount(1, "cdo_packages"); - // assertRowCount(1, "cdo_classes"); - // assertRowCount(0, "cdo_supertypes"); - // assertRowCount(1, "cdo_features"); - } - - @Override - protected void verifyCreateMango(Transaction transaction) throws Exception - { - defineOrCompare("defs/horizontal/verifyCreateMango"); - // assertRowCount(1, "cdo_repository"); - // assertRowCount(1, "cdo_packages"); - // assertRowCount(2, "cdo_classes"); - // assertRowCount(0, "cdo_supertypes"); - // assertRowCount(3, "cdo_features"); - } - - @Override - protected void verifyCommitCompany(Transaction transaction) throws Exception - { - defineOrCompare("defs/horizontal/verifyCommitCompany"); - // assertRowCount(1, "CDOResource"); - // assertFieldValue("/res1", "select path_0 from CDOResource where cdo_id=1 and cdo_version=1"); - // - // assertRowCount(1, "Company"); - // assertFieldValue("Sympedia", "select name from Company where cdo_id=1 and cdo_version=1"); - // assertFieldValue("Homestr. 17", "select street from Company where cdo_id=1 and cdo_version=1"); - // assertFieldValue("Berlin", "select city from Company where cdo_id=1 and cdo_version=1"); - } } diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/store/HorizontalTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/store/HorizontalTest.java new file mode 100644 index 0000000000..39c34412de --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/store/HorizontalTest.java @@ -0,0 +1,126 @@ +/*************************************************************************** + * Copyright (c) 2004 - 2008 Eike Stepper, Germany. + * 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: + * Eike Stepper - initial API and implementation + **************************************************************************/ +package org.eclipse.emf.cdo.tests.store; + +import org.eclipse.emf.cdo.internal.server.Transaction; +import org.eclipse.emf.cdo.server.internal.db.HorizontalMappingStrategy; +import org.eclipse.emf.cdo.server.internal.db.MappingStrategy; +import org.eclipse.emf.cdo.server.internal.db.ToMany; +import org.eclipse.emf.cdo.server.internal.db.ToOne; + +import org.eclipse.net4j.db.IDBConnectionProvider; +import org.eclipse.net4j.db.hsqldb.HSQLDBDataSource; +import org.eclipse.net4j.db.internal.hsqldb.HSQLDBAdapter; +import org.eclipse.net4j.internal.db.DataSourceConnectionProvider; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Eike Stepper + */ +public abstract class HorizontalTest extends DBStoreTestLogic +{ + public HorizontalTest() + { + } + + @Override + protected HorizontalMappingStrategy createMappingStrategy() + { + Map<String, String> props = new HashMap<String, String>(); + props.put(MappingStrategy.PROP_TO_MANY_REFERENCE_MAPPING, ToMany.PER_CLASS.toString()); + props.put(MappingStrategy.PROP_TO_ONE_REFERENCE_MAPPING, ToOne.LIKE_ATTRIBUTES.toString()); + + HorizontalMappingStrategy mappingStrategy = new HorizontalMappingStrategy(); + mappingStrategy.setProperties(props); + return mappingStrategy; + } + + @Override + protected void verifyCreateModel1(Transaction transaction) throws Exception + { + defineOrCompare("defs/horizontal/verifyCreateModel1"); + // assertRowCount(1, "cdo_repository"); + // assertRowCount(1, "cdo_packages"); + // assertRowCount(11, "cdo_classes"); + // assertRowCount(8, "cdo_supertypes"); + // assertRowCount(26, "cdo_features"); + } + + @Override + protected void verifyCreateModel2(Transaction transaction) throws Exception + { + defineOrCompare("defs/horizontal/verifyCreateModel2"); + // assertRowCount(1, "cdo_repository"); + // assertRowCount(2, "cdo_packages"); + // assertRowCount(12, "cdo_classes"); + // assertRowCount(9, "cdo_supertypes"); + // assertRowCount(28, "cdo_features"); + } + + @Override + protected void verifyCreateModel3(Transaction transaction) throws Exception + { + defineOrCompare("defs/horizontal/verifyCreateModel3"); + // assertRowCount(1, "cdo_repository"); + // assertRowCount(1, "cdo_packages"); + // assertRowCount(1, "cdo_classes"); + // assertRowCount(0, "cdo_supertypes"); + // assertRowCount(1, "cdo_features"); + } + + @Override + protected void verifyCreateMango(Transaction transaction) throws Exception + { + defineOrCompare("defs/horizontal/verifyCreateMango"); + // assertRowCount(1, "cdo_repository"); + // assertRowCount(1, "cdo_packages"); + // assertRowCount(2, "cdo_classes"); + // assertRowCount(0, "cdo_supertypes"); + // assertRowCount(3, "cdo_features"); + } + + @Override + protected void verifyCommitCompany(Transaction transaction) throws Exception + { + defineOrCompare("defs/horizontal/verifyCommitCompany"); + // assertRowCount(1, "CDOResource"); + // assertFieldValue("/res1", "select path_0 from CDOResource where cdo_id=1 and cdo_version=1"); + // + // assertRowCount(1, "Company"); + // assertFieldValue("Sympedia", "select name from Company where cdo_id=1 and cdo_version=1"); + // assertFieldValue("Homestr. 17", "select street from Company where cdo_id=1 and cdo_version=1"); + // assertFieldValue("Berlin", "select city from Company where cdo_id=1 and cdo_version=1"); + } + + /** + * @author Eike Stepper + */ + public static final class HSQLDB extends HorizontalTest + { + @Override + protected IDBConnectionProvider createDBConnectionProvider() + { + HSQLDBDataSource dataSource = new HSQLDBDataSource(); + dataSource.setDatabase("jdbc:hsqldb:mem:storetest"); + dataSource.setUser("sa"); + + return new DataSourceConnectionProvider(dataSource); + } + + @Override + protected HSQLDBAdapter createDBAdapter() + { + return new HSQLDBAdapter(); + } + } +} |