Skip to content

Commit

Permalink
Create TCK so that mondrian can run olap4j tests from its own suite.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
julianhyde committed Nov 23, 2010
1 parent 6fdb574 commit 2cac149
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 44 deletions.
15 changes: 14 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ${src.dir}/org/olap4j/mdx/parser/impl/DefaultMdxParserSym.java" />

<!-- Override to create a proper release. -->
<target name="dist"
depends="clean,version-properties,jar,javadoc,javadoc-pdf,javadoc-with-ydoc,jar-jdk14,source.zip"
depends="clean,version-properties,jar,tck-jar,javadoc,javadoc-pdf,javadoc-with-ydoc,jar-jdk14,source.zip"
description="Creates a distribution">
<zip zipfile="${dist.dir}/${zip.filename}">
<zipfileset dir="${basedir}/doc" prefix="${ivy.artifact.id}-${project.revision}/doc"
Expand Down Expand Up @@ -98,6 +98,19 @@ VERSION.txt" />
</zip>
</target>

<target name="tck-jar" depends="jar"
description="Jars up the Test Compatibility Kit (TCK) after a compile">
<zip destfile="${dist.dir}/olap4j-tck-${project.revision}.jar">
<zipfileset dir="${testclasses.dir}" prefix="" includes="**/*"
excludes="jndi.properties" />
<zipfileset dir="${basedir}" prefix=""
includes="
LICENSE.html,
README.txt,
VERSION.txt" />
</zip>
</target>

<target name="compileJdk16">
<exec osfamily="unix" executable="${basedir}/buildJdk16.sh">
<arg line="compile"/>
Expand Down
2 changes: 1 addition & 1 deletion ivy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<dependency org="hsqldb" name="hsqldb" rev="1.8.0.7"
transitive="false" conf="test->default" />

<dependency org="pentaho" name="mondrian" rev="3.2.1.13916"
<dependency org="pentaho" name="mondrian" rev="3.2.1.13929"
transitive="false" changing="true" conf="test->default" />

<dependency org="eigenbase" name="eigenbase-xom" rev="1.3.0.11999"
Expand Down
17 changes: 4 additions & 13 deletions testsrc/org/olap4j/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,9 @@ public void testInvalidStatement() throws SQLException {
switch (tester.getFlavor()) {
case XMLA:
case REMOTE_XMLA:
assertTrue(e.getMessage().indexOf(
"XMLA MDX parse failed") >= 0);
assertTrue(
e.getMessage(),
e.getMessage().indexOf("XMLA MDX parse failed") >= 0);
break;
default:
assertTrue(
Expand Down Expand Up @@ -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();
Expand Down
26 changes: 2 additions & 24 deletions testsrc/org/olap4j/OlapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Schema> schemas = catalog.getSchemas();
if (schemas.size() == 0) {
return null;
Expand Down Expand Up @@ -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<Schema> schemas = catalog.getSchemas();

if (schemas.size() == 0) {
Expand Down
84 changes: 79 additions & 5 deletions testsrc/org/olap4j/test/TestContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<TestContext> THREAD_INSTANCE =
new ThreadLocal<TestContext>();

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);
}
}

/**
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 2cac149

Please sign in to comment.