Skip to content

Commit

Permalink
The TCK allows the test suite to be run multiple times in the same pr…
Browse files Browse the repository at this point in the history
…ocess with

different properties. So, TestContext is no longer a singleton; if a test needs
an instance, save it when the TestCase is being constructed (when the correct
TestContext is available in a thread-local).

A Tester's constructor now takes a TestContext (because TestContext is no longer
a singleton).

Obsolete org.olap4j.MondrianTester, and use the MondrianTester in mondrian.jar.

Clarify API: OlapDatabaseMetaData.getDatasources() is sorted.

Fixes to TCK and XMLA driver regarding catalogs and schemas.


git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@375 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Dec 3, 2010
1 parent f2beff8 commit 5291574
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 141 deletions.
3 changes: 2 additions & 1 deletion src/org/olap4j/OlapDatabaseMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ ResultSet getActions(
/**
* Retrives a list of olap4j data sources that are available on the server.
*
* <p>Specification as for XML/A DISCOVER_DATASOURCES schema rowset.
* <p>Specification as for XML/A DISCOVER_DATASOURCES schema rowset. The
* rows are ordered by <code>DATA_SOURCE_NAME</code>.
*
* <ol>
* <li><b>DATA_SOURCE_NAME</b> String => The name of the data source, such
Expand Down
9 changes: 5 additions & 4 deletions src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -840,14 +840,15 @@ public String generateRequest(
}

// If the request requires catalog name, and one wasn't specified in the
// restrictions, use the connection's current catalog.
if (context.olap4jCatalog != null) {
requestCatalogName = context.olap4jCatalog.getName();
// restrictions, use the connection's current schema. (Note: What XMLA
// calls a catalog, JDBC calls a schema.)
if (context.olap4jSchema != null) {
requestCatalogName = context.olap4jSchema.getName();
}
if (requestCatalogName == null
&& metadataRequest.requiresCatalogName())
{
requestCatalogName = context.olap4jConnection.getCatalog();
requestCatalogName = context.olap4jConnection.getSchema().getName();
}

// Add the catalog node only if this request has specified it as a
Expand Down
2 changes: 1 addition & 1 deletion test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# a different database, edit the jdbc.properties file
# in the /simple-jndi folder.

org.olap4j.test.helperClassName=org.olap4j.MondrianTester
org.olap4j.test.helperClassName=mondrian.test.MondrianOlap4jTester
org.olap4j.test.connectUrl=jdbc:mondrian:Datasource=jdbc/SampleData;Catalog=./foodmart/FoodMart.xml;

###############################################################################
Expand Down
5 changes: 3 additions & 2 deletions testsrc/org/olap4j/CellSetFormatterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
* @version $Id$
*/
public class CellSetFormatterTest extends TestCase {
final String query1 =
final TestContext.Tester tester = TestContext.instance().getTester();

static final String query1 =
"select\n"
+ " crossjoin(\n"
+ " {[Time].[1997].[Q1], [Time].[1997].[Q2].[4]},\n"
Expand All @@ -55,7 +57,6 @@ private void assertFormat(
Format format,
String expected) throws SQLException
{
final TestContext.Tester tester = TestContext.instance().getTester();
Connection connection = null;
try {
connection = tester.createConnection();
Expand Down
27 changes: 11 additions & 16 deletions testsrc/org/olap4j/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
* Unit test for olap4j Driver and Connection classes.
*
* <p>The system property "org.olap4j.test.helperClassName" determines the
* name of the helper class. By default, uses {@link MondrianTester}, which
* runs against mondrian; {@link XmlaTester} is also available.
* name of the helper class. By default, uses {@link org.olap4j.XmlaTester},
* use the XMLA driver.
*
* @author jhyde
* @version $Id$
Expand Down Expand Up @@ -1905,28 +1905,23 @@ public void testMetadata() throws Exception {

assertEquals("Food", member.getCaption());

if (tester.getFlavor() != Tester.Flavor.XMLA
&& tester.getFlavor() != Tester.Flavor.REMOTE_XMLA)
{
switch (tester.getFlavor()) {
case XMLA:
case REMOTE_XMLA:
assertEquals("", member.getDescription());
assertEquals(204, member.getOrdinal());
break;
default:
assertNull(member.getDescription());
assertEquals(-1, member.getOrdinal());
assertEquals(1, member.getDepth());
assertEquals(-1, member.getSolveOrder());
assertFalse(member.isHidden());
assertNull(member.getDataMember());
assertFalse(member.isCalculatedInQuery());
} else {
assertEquals("", member.getDescription());
}

switch (tester.getFlavor()) {
case MONDRIAN:
// mondrian does not set ordinals correctly
assertEquals(-1, member.getOrdinal());
break;
default:
assertEquals(204, member.getOrdinal());
break;
}

final NamedList<Property> propertyList = member.getProperties();
assertEquals(25, propertyList.size());
final Property property = propertyList.get("MEMBER_CAPTION");
Expand Down
43 changes: 27 additions & 16 deletions testsrc/org/olap4j/MetadataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,24 +251,31 @@ public void testDatabaseMetaDataGetDatasources() throws SQLException {
switch (tester.getFlavor()) {
case MONDRIAN:
TestContext.assertEqualsVerbose(
"DATA_SOURCE_NAME=xxx,"
"DATA_SOURCE_NAME=FoodMart,"
+ " DATA_SOURCE_DESCRIPTION=null,"
+ " URL=null,"
+ " DATA_SOURCE_INFO=xxx,"
+ " PROVIDER_NAME=null,"
+ " DATA_SOURCE_INFO=FoodMart,"
+ " PROVIDER_NAME=Mondrian,"
+ " PROVIDER_TYPE=MDP,"
+ " AUTHENTICATION_MODE=null\n",
+ " AUTHENTICATION_MODE=Unauthenticated\n",
s);
break;
case REMOTE_XMLA:
// This can be anything, depending on the remote server.
break;
case XMLA:
TestContext.assertEqualsVerbose(
"DATA_SOURCE_NAME=MondrianFoodMart,"
"DATA_SOURCE_NAME=FoodMart,"
+ " DATA_SOURCE_DESCRIPTION=Mondrian FoodMart data source,"
+ " URL=http://localhost:8080/mondrian/xmla,"
+ " DATA_SOURCE_INFO=MondrianFoodMart,"
+ " DATA_SOURCE_INFO=FoodMart,"
+ " PROVIDER_NAME=Mondrian,"
+ " PROVIDER_TYPE=MDP,"
+ " AUTHENTICATION_MODE=Unauthenticated\n"
+ "DATA_SOURCE_NAME=FoodMart2,"
+ " DATA_SOURCE_DESCRIPTION=Mondrian FoodMart data source,"
+ " URL=http://localhost:8080/mondrian/xmla,"
+ " DATA_SOURCE_INFO=FoodMart2,"
+ " PROVIDER_NAME=Mondrian,"
+ " PROVIDER_TYPE=MDP,"
+ " AUTHENTICATION_MODE=Unauthenticated\n",
Expand All @@ -282,16 +289,18 @@ public void testDatabaseMetaDataGetCatalogs() throws SQLException {
olapDatabaseMetaData.getCatalogs(),
CATALOGS_COLUMN_NAMES);
final String expected;
if (tester.getFlavor() == TestContext.Tester.Flavor.XMLA
|| tester.getFlavor() == Tester.Flavor.REMOTE_XMLA)
{
switch (tester.getFlavor()) {
case XMLA:
case REMOTE_XMLA:
// XMLA test uses dummy duplicate catalog to make sure that we
// get all catalogs
expected =
"TABLE_CAT=" + catalogName + "\n"
+ "TABLE_CAT=" + catalogName + "2\n";
} else {
break;
default:
expected = "TABLE_CAT=" + catalogName + "\n";
break;
}
TestContext.assertEqualsVerbose(expected, s);
}
Expand All @@ -301,16 +310,18 @@ public void testDatabaseMetaDataGetSchemas() throws SQLException {
olapDatabaseMetaData.getSchemas(),
SCHEMAS_COLUMN_NAMES);
final String expected;
if (tester.getFlavor() == TestContext.Tester.Flavor.XMLA
|| tester.getFlavor() == Tester.Flavor.REMOTE_XMLA)
{
// XMLA test uses dummy duplicate catalog to make sure that we
// get all catalogs
switch (tester.getFlavor()) {
case XMLA:
case REMOTE_XMLA:
// XMLA test uses dummy duplicate schema to make sure that we
// get all schemas
expected =
"TABLE_SCHEM=FoodMart, TABLE_CAT=" + catalogName + "\n"
+ "TABLE_SCHEM=FoodMart, TABLE_CAT=" + catalogName + "2\n";
} else {
break;
default:
expected = "TABLE_SCHEM=FoodMart, TABLE_CAT=" + catalogName + "\n";
break;
}
TestContext.assertEqualsVerbose(expected, s);
}
Expand Down
73 changes: 0 additions & 73 deletions testsrc/org/olap4j/MondrianTester.java

This file was deleted.

21 changes: 18 additions & 3 deletions testsrc/org/olap4j/RemoteXmlaTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,23 @@ public class RemoteXmlaTester implements Tester {
public static final String DRIVER_URL_PREFIX = "jdbc:xmla:";
public static final String DRIVER_CLASS_NAME =
"org.olap4j.driver.xmla.XmlaOlap4jDriver";

private String url = null;
private String user = null;
private String password = null;
private final TestContext testContext;

public RemoteXmlaTester() {
final Properties properties = TestContext.getTestProperties();
/**
* Creates a RemoteXmlaTester.
*
* <p>The {@link org.olap4j.test.TestContext.Tester} API requires a public
* constructor with a {@link org.olap4j.test.TestContext} parameter.
*
* @param testContext Test context
*/
public RemoteXmlaTester(TestContext testContext) {
this.testContext = testContext;
final Properties properties = testContext.getProperties();
this.url =
properties.getProperty(
TestContext.Property.REMOTE_XMLA_URL.path);
Expand All @@ -51,6 +62,10 @@ public RemoteXmlaTester() {
TestContext.Property.REMOTE_XMLA_PASSWORD.path);
}

public TestContext getTestContext() {
return testContext;
}

public Connection createConnection() throws SQLException {
return this.createConnection(url, null, null);
}
Expand Down Expand Up @@ -94,4 +109,4 @@ public Wrapper getWrapper() {
return TestContext.Wrapper.NONE;
}
}
// End RemoteXmlaTester.java
// End RemoteXmlaTester.java
2 changes: 1 addition & 1 deletion testsrc/org/olap4j/XmlaConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public void testNoNonTrivalCallsOnConnect() throws Exception {
* @throws Exception If the test fails.
*/
public void testNoDoubleQuerySubmission() throws Exception {
if (!TestContext.getTestProperties()
if (!TestContext.instance().getProperties()
.get(TestContext.Property.HELPER_CLASS_NAME.path)
.equals("org.olap4j.XmlaTester"))
{
Expand Down
30 changes: 19 additions & 11 deletions testsrc/org/olap4j/XmlaTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,35 @@
* @version $Id$
*/
public class XmlaTester implements TestContext.Tester {
private final TestContext testContext;
final XmlaOlap4jProxy proxy;
final String cookie;
private Connection connection;

/**
* Creates an XmlaTester
* Creates an XmlaTester.
*
* <p>The {@link org.olap4j.test.TestContext.Tester} API requires a public
* constructor with a {@link org.olap4j.test.TestContext} parameter.
*
* @param testContext Test context
*
* @throws ClassNotFoundException on error
* @throws IllegalAccessException on error
* @throws InstantiationException on error
* @throws NoSuchMethodException on error
* @throws InvocationTargetException on error
*/
public XmlaTester()
public XmlaTester(TestContext testContext)
throws ClassNotFoundException, IllegalAccessException,
InstantiationException, NoSuchMethodException,
InvocationTargetException
{
final Properties properties = TestContext.getTestProperties();
this.testContext = testContext;
final Properties properties = testContext.getProperties();
final String catalogUrl =
properties.getProperty(
TestContext.Property.XMLA_CATALOG_URL.path);
if (catalogUrl == null) {
throw new RuntimeException(
"Property " + TestContext.Property.XMLA_CATALOG_URL.path
+ " must be specified");
}
TestContext.Property.XMLA_CATALOG_URL.path, "http://foo");

// Include the same catalog URL twice with different catalog names. This
// allows us to detect whether operations are restricting to the current
Expand All @@ -61,7 +63,8 @@ public XmlaTester()
catalogNameUrls.put("FoodMart", catalogUrl);
catalogNameUrls.put("FoodMart2", catalogUrl);
String urlString =
properties.getProperty(TestContext.Property.CONNECT_URL.path);
properties.getProperty(
TestContext.Property.CONNECT_URL.path, "jdbc:mondrian:");

final Class<?> clazz = Class.forName(getProxyClassName());
final Constructor<?> constructor =
Expand All @@ -73,6 +76,10 @@ public XmlaTester()
XmlaOlap4jDriver.PROXY_MAP.put(cookie, proxy);
}

public TestContext getTestContext() {
return testContext;
}

public Connection createConnection() throws SQLException {
if (connection != null) {
return connection;
Expand Down Expand Up @@ -114,7 +121,8 @@ public String getDriverClassName() {
}

public String getURL() {
return "jdbc:xmla:Server=http://foo;Catalog=FoodMart;TestProxyCookie=" + cookie;
return "jdbc:xmla:Server=http://foo;Catalog=FoodMart;TestProxyCookie="
+ cookie;
}

public Flavor getFlavor() {
Expand Down
Loading

0 comments on commit 5291574

Please sign in to comment.