Skip to content

Commit

Permalink
Added a new tester flavor to allow remote xmla servers to be tested a…
Browse files Browse the repository at this point in the history
…gainst 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
  • Loading branch information
lucboudreau committed Jul 22, 2010
1 parent c4079d7 commit 1521c92
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 14 deletions.
8 changes: 7 additions & 1 deletion test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
58 changes: 49 additions & 9 deletions testsrc/org/olap4j/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<Position> filterPositions = filterAxis.getPositions();
assertEquals(3, filterPositions.size());
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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());
Expand All @@ -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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
18 changes: 15 additions & 3 deletions testsrc/org/olap4j/MetadataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,"
Expand All @@ -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 =
Expand All @@ -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 =
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions testsrc/org/olap4j/OlapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public Cube getFoodmartCube(String cubeName) {
catalogName = "LOCALDB";
break;
case XMLA:
case REMOTE_XMLA:
default:
catalogName = "FoodMart";
break;
Expand Down Expand Up @@ -126,6 +127,7 @@ public void testModel() {
catalogName = "LOCALDB";
break;
case XMLA:
case REMOTE_XMLA:
default:
catalogName = "FoodMart";
break;
Expand Down
97 changes: 97 additions & 0 deletions testsrc/org/olap4j/RemoteXmlaTester.java
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 1521c92

Please sign in to comment.