From 2cac1496aa6cb2cce5a6ebefae193920cf47e632 Mon Sep 17 00:00:00 2001 From: Julian Hyde Date: Tue, 23 Nov 2010 20:27:57 +0000 Subject: [PATCH] Create TCK so that mondrian can run olap4j tests from its own suite. Upgrade to latest mondrian (catalog name has changed). git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@371 c6a108a4-781c-0410-a6c6-c2d559e19af0 --- build.xml | 15 ++++- ivy.xml | 2 +- testsrc/org/olap4j/ConnectionTest.java | 17 ++--- testsrc/org/olap4j/OlapTest.java | 26 +------- testsrc/org/olap4j/test/TestContext.java | 84 ++++++++++++++++++++++-- 5 files changed, 100 insertions(+), 44 deletions(-) diff --git a/build.xml b/build.xml index 9cad265..c7d1ed7 100644 --- a/build.xml +++ b/build.xml @@ -47,7 +47,7 @@ ${src.dir}/org/olap4j/mdx/parser/impl/DefaultMdxParserSym.java" /> + + + + + + + diff --git a/ivy.xml b/ivy.xml index b08ed3a..5ec39aa 100644 --- a/ivy.xml +++ b/ivy.xml @@ -76,7 +76,7 @@ - = 0); + assertTrue( + e.getMessage(), + e.getMessage().indexOf("XMLA MDX parse failed") >= 0); break; default: assertTrue( @@ -2580,17 +2581,7 @@ private void buildQuery( boolean useCubeObject) throws OlapException { - final String catalogName; - switch (tester.getFlavor()) { - case MONDRIAN: - catalogName = "LOCALDB"; - break; - case XMLA: - default: - catalogName = "FoodMart"; - break; - } - Catalog catalog = olapConnection.getCatalogs().get(catalogName); + Catalog catalog = olapConnection.getCatalogs().get("FoodMart"); Schema schema = catalog.getSchemas().get("FoodMart"); Cube cube = schema.getCubes().get("Sales"); SelectNode query = new SelectNode(); diff --git a/testsrc/org/olap4j/OlapTest.java b/testsrc/org/olap4j/OlapTest.java index 6c84238..09a36d9 100644 --- a/testsrc/org/olap4j/OlapTest.java +++ b/testsrc/org/olap4j/OlapTest.java @@ -54,18 +54,7 @@ public Cube getFoodmartCube(String cubeName) { connection = tester.createConnection(); OlapConnection olapConnection = tester.getWrapper().unwrap(connection, OlapConnection.class); - final String catalogName; - switch (tester.getFlavor()) { - case MONDRIAN: - catalogName = "LOCALDB"; - break; - case XMLA: - case REMOTE_XMLA: - default: - catalogName = "FoodMart"; - break; - } - Catalog catalog = olapConnection.getCatalogs().get(catalogName); + Catalog catalog = olapConnection.getCatalogs().get("FoodMart"); NamedList schemas = catalog.getSchemas(); if (schemas.size() == 0) { return null; @@ -124,18 +113,7 @@ public void testModel() { // Get a list of the schemas available from this connection and dump // their names. - final String catalogName; - switch (tester.getFlavor()) { - case MONDRIAN: - catalogName = "LOCALDB"; - break; - case XMLA: - case REMOTE_XMLA: - default: - catalogName = "FoodMart"; - break; - } - Catalog catalog = olapConnection.getCatalogs().get(catalogName); + Catalog catalog = olapConnection.getCatalogs().get("FoodMart"); NamedList schemas = catalog.getSchemas(); if (schemas.size() == 0) { diff --git a/testsrc/org/olap4j/test/TestContext.java b/testsrc/org/olap4j/test/TestContext.java index 6f0c1c0..362bc80 100644 --- a/testsrc/org/olap4j/test/TestContext.java +++ b/testsrc/org/olap4j/test/TestContext.java @@ -14,14 +14,13 @@ import java.util.regex.Pattern; import java.sql.*; +import junit.framework.*; import org.olap4j.*; import org.olap4j.impl.Olap4jUtil; import org.olap4j.mdx.*; import org.olap4j.layout.TraditionalCellSetFormatter; import org.apache.commons.dbcp.*; -import junit.framework.ComparisonFailure; -import junit.framework.Assert; /** * Context for olap4j tests. @@ -45,13 +44,62 @@ public class TestContext { Pattern.compile("\r\n|\r|\n"); private static final Pattern TabPattern = Pattern.compile("\t"); public static Properties testProperties; + private static final ThreadLocal THREAD_INSTANCE = + new ThreadLocal(); - private final Tester tester = createTester(); + /** + * The following classes are part of the TCK. Each driver should call them. + */ + public static final Class[] TCK_CLASSES = { + org.olap4j.ConnectionTest.class, + org.olap4j.CellSetFormatterTest.class, + org.olap4j.MetadataTest.class, + org.olap4j.mdx.MdxTest.class, + org.olap4j.transform.TransformTest.class, + org.olap4j.XmlaConnectionTest.class, + org.olap4j.OlapTreeTest.class, + org.olap4j.OlapTest.class, + }; + + /** + * The following tests do not depend upon the driver implementation. + * They should be executed once, in olap4j's test suite, not for each + * provider's test suite. + */ + public static final Class[] NON_TCK_CLASSES = { + org.olap4j.impl.ConnectStringParserTest.class, + org.olap4j.impl.Olap4jUtilTest.class, + org.olap4j.impl.Base64Test.class, + org.olap4j.test.ParserTest.class, + org.olap4j.test.ArrayMapTest.class, + org.olap4j.driver.xmla.cache.XmlaShaEncoderTest.class, + org.olap4j.driver.xmla.proxy.XmlaCookieManagerTest.class, + org.olap4j.driver.xmla.proxy.XmlaCachedProxyTest.class, + }; + + private final Tester tester; /** * Intentionally private: use {@link #instance()}. */ private TestContext() { + tester = createTester(getTestProperties()); + } + + private TestContext(Tester tester) { + this.tester = tester; + } + + /** + * Adds all of the test classes in the TCK (Test Compatibility Kit) + * to a given junit test suite. + * + * @param suite Suite to which to add tests + */ + private static void addTck(TestSuite suite) { + for (Class tckClass : TCK_CLASSES) { + suite.addTestSuite(tckClass); + } } /** @@ -124,6 +172,10 @@ public static String toString(CellSet cellSet) { * @return default TestContext */ public static TestContext instance() { + final TestContext i = THREAD_INSTANCE.get(); + if (i != null) { + return i; + } return INSTANCE; } @@ -264,10 +316,10 @@ public static String quotePattern(String s) * Factory method for the {@link Tester} * object which determines which driver to test. * + * @param testProperties Properties that define the properties of the tester * @return a new Tester */ - private static Tester createTester() { - Properties testProperties = getTestProperties(); + private static Tester createTester(Properties testProperties) { String helperClassName = testProperties.getProperty(Property.HELPER_CLASS_NAME.path); if (helperClassName == null) { @@ -325,6 +377,28 @@ public Wrapper getWrapper() { return tester; } + /** + * Creates a test suite that executes the olap4j TCK with the given + * set of properties. The properties are the same as those you can put in + * {@code "test.properties"}. + * + * @param properties Properties + * @param name Name of test suite + * @return Test suite that executes the TCK + */ + public static TestSuite createTckSuite(Properties properties, String name) { + TestContext testContext = new TestContext(createTester(properties)); + THREAD_INSTANCE.set(testContext); + try { + final TestSuite suite = new TestSuite(); + suite.setName(name); + addTck(suite); + return suite; + } finally { + THREAD_INSTANCE.remove(); + } + } + /** * Enumeration of valid values for the * {@link org.olap4j.test.TestContext.Property#WRAPPER} property.