From 1521c92490497e2b7f3eac292af6041600c55a31 Mon Sep 17 00:00:00 2001 From: Luc Boudreau Date: Thu, 22 Jul 2010 19:45:26 +0000 Subject: [PATCH] Added a new tester flavor to allow remote xmla servers to be tested against the olap4j test suite. The remote server must expose the Foodmart test database. git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@327 c6a108a4-781c-0410-a6c6-c2d559e19af0 --- test.properties | 8 +- testsrc/org/olap4j/ConnectionTest.java | 58 +++++++++++--- testsrc/org/olap4j/MetadataTest.java | 18 ++++- testsrc/org/olap4j/OlapTest.java | 2 + testsrc/org/olap4j/RemoteXmlaTester.java | 97 ++++++++++++++++++++++++ testsrc/org/olap4j/test/TestContext.java | 21 ++++- 6 files changed, 190 insertions(+), 14 deletions(-) create mode 100644 testsrc/org/olap4j/RemoteXmlaTester.java diff --git a/test.properties b/test.properties index a364393..2cdd681 100644 --- a/test.properties +++ b/test.properties @@ -23,7 +23,6 @@ org.olap4j.test.connectUrl=jdbc:mondrian:Datasource=jdbc/SampleData;Catalog=./foodmart/FoodMart.xml; - # This activates the Mondrian in-process tester. org.olap4j.test.helperClassName=org.olap4j.MondrianTester @@ -32,4 +31,11 @@ org.olap4j.test.helperClassName=org.olap4j.MondrianTester #org.olap4j.test.helperClassName=org.olap4j.XmlaTester #org.olap4j.XmlaTester.CatalogUrl=file:foodmart/FoodMart.xml +# These options are used to test against a remote XML/A server. +# The server must have the FoodMart schema installed. +#org.olap4j.test.helperClassName=org.olap4j.RemoteXmlaTester +#org.olap4j.RemoteXmlaTester.JdbcUrl=jdbc:xmla:Server=http://localhost:8080/mondrian/xmla +#org.olap4j.RemoteXmlaTester.Username=joe +#org.olap4j.RemoteXmlaTester.Password=password + # End test.properties diff --git a/testsrc/org/olap4j/ConnectionTest.java b/testsrc/org/olap4j/ConnectionTest.java index 7751bbc..8c2c011 100644 --- a/testsrc/org/olap4j/ConnectionTest.java +++ b/testsrc/org/olap4j/ConnectionTest.java @@ -101,6 +101,7 @@ public void testDriver() throws ClassNotFoundException, SQLException { new Properties()); switch (tester.getFlavor()) { case XMLA: + case REMOTE_XMLA: break; default: assertTrue(driverPropertyInfos.length > 0); @@ -238,6 +239,18 @@ public void testConnection() throws ClassNotFoundException, SQLException { case XMLA: // in-process XMLA test does not support username/password break; + + case REMOTE_XMLA: + // connect using username/password + connection = tester.createConnectionWithUserPassword(); + assertNotNull(connection); + + // connect with URL only + connection = DriverManager.getConnection(tester.getURL()); + assertNotNull(connection); + + connection.close(); + break; } assertTrue(connection.isClosed()); } @@ -324,7 +337,9 @@ public void testConnectionUnwrap() throws SQLException { } public void testXmlaCatalogParameter() throws Exception { - if (tester.getFlavor() == TestContext.Tester.Flavor.XMLA) { + if (tester.getFlavor() == TestContext.Tester.Flavor.XMLA + || tester.getFlavor() != Tester.Flavor.XMLA) + { // We won't use the tester itself since we want to test // creating a connection with and without a Catalog parameter. Properties info = new Properties(); @@ -529,6 +544,7 @@ public void testCompoundSlicer() throws SQLException { assertEquals(1, filterAxis.getPositionCount()); break; case XMLA: + case REMOTE_XMLA: assertEquals(3, filterAxis.getPositionCount()); final List filterPositions = filterAxis.getPositions(); assertEquals(3, filterPositions.size()); @@ -583,6 +599,7 @@ public void testInvalidStatement() throws SQLException { } catch (OlapException e) { switch (tester.getFlavor()) { case XMLA: + case REMOTE_XMLA: assertTrue(e.getMessage().indexOf( "XMLA MDX parse failed") >= 0); break; @@ -625,6 +642,7 @@ public void testPreparedStatement() throws SQLException { // XMLA driver does not support parameters yet. switch (tester.getFlavor()) { case XMLA: + case REMOTE_XMLA: assertEquals(0, paramCount); return; } @@ -1022,8 +1040,10 @@ public void testCell() throws Exception { // access method 1 Cell cell = cellSet.getCell(5); assertEquals(5, cell.getOrdinal()); - if (tester.getFlavor() != TestContext.Tester.Flavor.XMLA) { // FIXME - assertEquals(12935.16, cell.getValue()); + if (tester.getFlavor() != TestContext.Tester.Flavor.XMLA // FIXME + || tester.getFlavor() != TestContext.Tester.Flavor.REMOTE_XMLA) + { + assertEquals(12935.16, cell.getValue()); } assertEquals(12935.16, cell.getDoubleValue()); assertEquals("12,935.16", cell.getFormattedValue()); @@ -1050,6 +1070,7 @@ public void testCell() throws Exception { switch (tester.getFlavor()) { case XMLA: + case REMOTE_XMLA: // TODO: implement drill-through in XMLA driver break; default: @@ -1149,6 +1170,7 @@ public void testCell() throws Exception { cell = cellSet.getCell(0); switch (tester.getFlavor()) { case XMLA: + case REMOTE_XMLA: // FIXME: mondrian's XMLA provider doesn't indicate that a cell is // an error break; @@ -1250,7 +1272,9 @@ public void testParsing() throws SQLException { "select {[Gender]} on columns, {[Store].Children} on columns\n" + "from [sales]"); - if (tester.getFlavor() == TestContext.Tester.Flavor.XMLA) { + if (tester.getFlavor() == TestContext.Tester.Flavor.XMLA + || tester.getFlavor() != Tester.Flavor.XMLA) + { // This test requires validator support. return; } @@ -1504,6 +1528,7 @@ public void testCubeLookupMembers() throws Exception { String expected; switch (tester.getFlavor()) { case XMLA: + case REMOTE_XMLA: // TODO: Fix mondrian's XMLA driver to return members ordered by // level then by ordinal as per XMLA spec expected = @@ -1558,6 +1583,7 @@ public void testCubeLookupMembers() throws Exception { "Time", "1997", "Q2"); switch (tester.getFlavor()) { case XMLA: + case REMOTE_XMLA: // TODO: fix mondrian's XMLA driver to return members ordered by // level then ordinal expected = @@ -1629,6 +1655,9 @@ public void testMetadata() throws Exception { // We engineered the XMLA test environment to have two catalogs. switch (tester.getFlavor()) { + case REMOTE_XMLA: + assertEquals(1, olapConnection.getCatalogs().size()); + break; case XMLA: assertEquals(2, olapConnection.getCatalogs().size()); break; @@ -1745,6 +1774,7 @@ public void testMetadata() throws Exception { namedSet.getDescription(Locale.getDefault()); switch (tester.getFlavor()) { case XMLA: + case REMOTE_XMLA: // FIXME: implement getExpression in XMLA driver break; default: @@ -1784,7 +1814,9 @@ public void testMetadata() throws Exception { assertEquals("Food", member.getCaption(null)); - if (tester.getFlavor() != Tester.Flavor.XMLA) { + if (tester.getFlavor() != Tester.Flavor.XMLA + && tester.getFlavor() != Tester.Flavor.REMOTE_XMLA) + { assertNull(member.getDescription(null)); assertEquals(1, member.getDepth()); assertEquals(-1, member.getSolveOrder()); @@ -2022,7 +2054,9 @@ public void testParentChild() throws ClassNotFoundException, SQLException { * @throws Throwable on error */ public void testCubeType() throws Throwable { - if (tester.getFlavor() == TestContext.Tester.Flavor.XMLA) { + if (tester.getFlavor() == TestContext.Tester.Flavor.XMLA + || tester.getFlavor() == TestContext.Tester.Flavor.REMOTE_XMLA) + { // This test requires validator support. return; } @@ -2089,7 +2123,9 @@ public void testCubeType() throws Throwable { * @throws Throwable on error */ public void testAxisType() throws Throwable { - if (tester.getFlavor() == TestContext.Tester.Flavor.XMLA) { + if (tester.getFlavor() == TestContext.Tester.Flavor.XMLA + || tester.getFlavor() == TestContext.Tester.Flavor.REMOTE_XMLA) + { // This test requires validator support. return; } @@ -2182,7 +2218,9 @@ public void testAxisType() throws Throwable { } public void testParseQueryWithNoFilter() throws Exception { - if (tester.getFlavor() == TestContext.Tester.Flavor.XMLA) { + if (tester.getFlavor() == TestContext.Tester.Flavor.XMLA + || tester.getFlavor() != Tester.Flavor.REMOTE_XMLA) + { // This test requires validator support. return; } @@ -2224,7 +2262,9 @@ public void testParseQueryWithNoFilter() throws Exception { } public void testValidateError() throws Exception { - if (tester.getFlavor() == TestContext.Tester.Flavor.XMLA) { + if (tester.getFlavor() == TestContext.Tester.Flavor.XMLA + || tester.getFlavor() != Tester.Flavor.XMLA) + { // This test requires validator support. return; } diff --git a/testsrc/org/olap4j/MetadataTest.java b/testsrc/org/olap4j/MetadataTest.java index 80752e9..7db49d0 100644 --- a/testsrc/org/olap4j/MetadataTest.java +++ b/testsrc/org/olap4j/MetadataTest.java @@ -12,6 +12,7 @@ import org.olap4j.impl.Olap4jUtil; import org.olap4j.metadata.*; import org.olap4j.test.TestContext; +import org.olap4j.test.TestContext.Tester; import java.sql.*; import java.util.*; @@ -179,6 +180,7 @@ public void testDatabaseMetaData() throws SQLException { DatabaseMetaData databaseMetaData = connection.getMetaData(); switch (tester.getFlavor()) { case XMLA: + case REMOTE_XMLA: // FIXME: implement getDatabaseXxxVersion in XMLA driver break; default: @@ -218,6 +220,7 @@ public void testDatabaseMetaData() throws SQLException { olapDatabaseMetaData.getDriverName())); switch (tester.getFlavor()) { case XMLA: + case REMOTE_XMLA: // FIXME: implement getDatabaseXxxVersion in XMLA driver break; default: @@ -257,6 +260,9 @@ public void testDatabaseMetaDataGetDatasources() throws SQLException { + " AUTHENTICATION_MODE=null\n", s); break; + case REMOTE_XMLA: + // This can be anything, depending on the remote server. + break; case XMLA: TestContext.assertEqualsVerbose( "DATA_SOURCE_NAME=MondrianFoodMart," @@ -276,7 +282,9 @@ public void testDatabaseMetaDataGetCatalogs() throws SQLException { olapDatabaseMetaData.getCatalogs(), CATALOGS_COLUMN_NAMES); final String expected; - if (tester.getFlavor() == TestContext.Tester.Flavor.XMLA) { + 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 expected = @@ -293,7 +301,9 @@ public void testDatabaseMetaDataGetSchemas() throws SQLException { olapDatabaseMetaData.getSchemas(), SCHEMAS_COLUMN_NAMES); final String expected; - if (tester.getFlavor() == TestContext.Tester.Flavor.XMLA) { + 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 expected = @@ -383,7 +393,9 @@ public void testDatabaseMetaDataGetCubes() throws SQLException { + ", SCHEMA_NAME=FoodMart, CUBE_NAME=Sales, ", s); final int lineCount2 = linecount(s); - if (tester.getFlavor() == TestContext.Tester.Flavor.XMLA) { + if (tester.getFlavor() == TestContext.Tester.Flavor.XMLA + || tester.getFlavor() != Tester.Flavor.REMOTE_XMLA) + { assertEquals(lineCount * 2, lineCount2); } diff --git a/testsrc/org/olap4j/OlapTest.java b/testsrc/org/olap4j/OlapTest.java index 7db00c3..ec08bb5 100644 --- a/testsrc/org/olap4j/OlapTest.java +++ b/testsrc/org/olap4j/OlapTest.java @@ -57,6 +57,7 @@ public Cube getFoodmartCube(String cubeName) { catalogName = "LOCALDB"; break; case XMLA: + case REMOTE_XMLA: default: catalogName = "FoodMart"; break; @@ -126,6 +127,7 @@ public void testModel() { catalogName = "LOCALDB"; break; case XMLA: + case REMOTE_XMLA: default: catalogName = "FoodMart"; break; diff --git a/testsrc/org/olap4j/RemoteXmlaTester.java b/testsrc/org/olap4j/RemoteXmlaTester.java new file mode 100644 index 0000000..d886855 --- /dev/null +++ b/testsrc/org/olap4j/RemoteXmlaTester.java @@ -0,0 +1,97 @@ +/* +// This software is subject to the terms of the Eclipse Public License v1.0 +// Agreement, available at the following URL: +// http://www.eclipse.org/legal/epl-v10.html. +// Copyright (C) 2007-2010 Julian Hyde +// All Rights Reserved. +// You must accept the terms of that agreement to use this software. +*/ +package org.olap4j; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Properties; + +import org.olap4j.test.TestContext; +import org.olap4j.test.TestContext.Tester; +import org.olap4j.test.TestContext.Wrapper; + +/** + * Implementation of {@link org.olap4j.test.TestContext.Tester} which speaks + * to remote XML/A servers. + * + * @author Luc Boudreau + * @version $Id:$ + */ +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; + + public RemoteXmlaTester() { + final Properties properties = TestContext.getTestProperties(); + this.url = + properties.getProperty( + TestContext.Property.REMOTE_XMLA_URL.path); + if (url == null) { + throw new RuntimeException( + "Property " + TestContext.Property.REMOTE_XMLA_URL + + " must be specified"); + } + this.user = + properties.getProperty( + TestContext.Property.REMOTE_XMLA_USERNAME.path); + this.password = + properties.getProperty( + TestContext.Property.REMOTE_XMLA_PASSWORD.path); + } + + public Connection createConnection() throws SQLException { + return this.createConnection(url, null, null); + } + + public Connection createConnectionWithUserPassword() throws SQLException { + return this.createConnection(url, user, password); + } + + private Connection createConnection( + String url, String user, String password) + { + try { + Class.forName(DRIVER_CLASS_NAME); + return DriverManager.getConnection(url, user, password); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public String getDriverClassName() { + return DRIVER_CLASS_NAME; + } + + public String getDriverUrlPrefix() { + return DRIVER_URL_PREFIX; + } + + public Flavor getFlavor() { + return Flavor.REMOTE_XMLA; + } + + public String getURL() { + return this.url; + } + + public void setUrl(String url) { + this.url = url; + } + + public Wrapper getWrapper() { + return TestContext.Wrapper.NONE; + } +} +// End RemoteXmlaTester.java \ No newline at end of file diff --git a/testsrc/org/olap4j/test/TestContext.java b/testsrc/org/olap4j/test/TestContext.java index a9e8b15..41a082a 100644 --- a/testsrc/org/olap4j/test/TestContext.java +++ b/testsrc/org/olap4j/test/TestContext.java @@ -520,7 +520,8 @@ public interface Tester { enum Flavor { MONDRIAN, - XMLA + XMLA, + REMOTE_XMLA } } @@ -596,6 +597,24 @@ public enum Property { */ XMLA_CATALOG_URL("org.olap4j.XmlaTester.CatalogUrl"), + /** + * Test property related to the remote XMLA tester. + * Must be a valid XMLA driver URL. + */ + REMOTE_XMLA_URL("org.olap4j.RemoteXmlaTester.JdbcUrl"), + + /** + * Test property related to the remote XMLA tester. + * User name to use. + */ + REMOTE_XMLA_USERNAME("org.olap4j.RemoteXmlaTester.Username"), + + /** + * Test property related to the remote XMLA tester. + * Password to use. + */ + REMOTE_XMLA_PASSWORD("org.olap4j.RemoteXmlaTester.Password"), + /** * Test property that indicates the wrapper to place around the * connection. Valid values are defined by the {@link Wrapper}