Skip to content

Commit

Permalink
MONDRIAN: Attempted test case for bug MONDRIAN-756; does not
Browse files Browse the repository at this point in the history
    reproduce the problem, so I am not checking in the fix yet.

[git-p4: depot-paths = "//open/mondrian-release/3.2/": change = 13688]
  • Loading branch information
julianhyde committed Jun 10, 2010
1 parent 1f51cd1 commit f96d0fe
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 49 deletions.
2 changes: 1 addition & 1 deletion demo/SteelWheels.mondrian.xml
Expand Up @@ -38,7 +38,7 @@
</Dimension>
<Dimension type="TimeDimension" foreignKey="TIME_ID" name="Time">
<Hierarchy hasAll="true" allMemberName="All Years" primaryKey="TIME_ID">
<Table name="dim_time">
<Table name="time">
</Table>
<Level name="Years" column="YEAR_ID" type="String" uniqueMembers="true" levelType="TimeYears" hideMemberIf="Never">
</Level>
Expand Down
159 changes: 111 additions & 48 deletions testsrc/main/mondrian/test/SteelWheelsTestCase.java
Expand Up @@ -3,14 +3,19 @@
// 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) 2009-2009 Julian Hyde and others
// Copyright (C) 2009-2010 Julian Hyde and others
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package mondrian.test;

import java.io.InputStream;

import junit.framework.TestCase;

import mondrian.olap.*;
import mondrian.rolap.RolapConnectionProperties;
import mondrian.spi.impl.FilterDynamicSchemaProcessor;

/**
* Unit test against Pentaho's Steel Wheels sample database.
Expand Down Expand Up @@ -45,33 +50,39 @@ public SteelWheelsTestCase() {
* different source for your FoodMart connection.
*/
public TestContext getTestContext() {
return new DelegatingTestContext(
TestContext.instance())
{
public Util.PropertyList getFoodMartConnectionProperties() {
final Util.PropertyList propertyList =
Util.parseConnectString(getDefaultConnectString());
// Assume we are talking to MySQL. Connect to 'sampledata'
// database, using usual credentials ('foodmart').
propertyList.put(
"Jdbc",
Util.replace(
propertyList.get("Jdbc"),
"/foodmart",
"/steelwheels"));
propertyList.put(
"Catalog",
Util.replace(
propertyList.get("Catalog"),
"FoodMart.xml",
"SteelWheels.mondrian.xml"));
return propertyList;
}

public String getDefaultCubeName() {
return "SteelWheelsSales";
}
};
return new SteelWheelsTestContext(TestContext.instance());
}

private static class SteelWheelsTestContext extends DelegatingTestContext
{
private SteelWheelsTestContext(TestContext testContext) {
super(testContext);
}

@Override
public Util.PropertyList getFoodMartConnectionProperties() {
final Util.PropertyList propertyList =
Util.parseConnectString(getDefaultConnectString());
// Assume we are talking to MySQL. Connect to 'sampledata'
// database, using usual credentials ('foodmart').
propertyList.put(
RolapConnectionProperties.Jdbc.name(),
Util.replace(
propertyList.get(RolapConnectionProperties.Jdbc.name()),
"/foodmart",
"/steelwheels"));
propertyList.put(
RolapConnectionProperties.Catalog.name(),
Util.replace(
propertyList.get(RolapConnectionProperties.Catalog.name()),
"FoodMart.xml",
"SteelWheels.mondrian.xml"));
return propertyList;
}

public String getDefaultCubeName() {
return "SteelWheelsSales";
}
}

/**
Expand All @@ -84,12 +95,15 @@ public void testMeasures() {
}
testContext.assertAxisReturns(
"Measures.Members",
"[Measures].[Quantity]\n" + "[Measures].[Sales]");
"[Measures].[Quantity]\n"
+ "[Measures].[Sales]\n"
+ "[Measures].[Fact Count]");
}

/**
* Test case for Infobright issue where [Markets].[All Markets].[Japan]
* was not found but [Markets].[All Markets].[JAPAN] was OK.
* (We've since dropped 'All Xxx' from member unique names.)
*/
public void testMarkets() {
TestContext testContext = getTestContext();
Expand All @@ -101,19 +115,19 @@ public void testMarkets() {
"Axis #0:\n"
+ "{}\n"
+ "Axis #1:\n"
+ "{[Markets].[All Markets].[Japan]}\n"
+ "{[Markets].[Japan]}\n"
+ "Row #0: 4,923\n");

testContext.assertQueryReturns(
"select [Markets].Children on 0 from [SteelWheelsSales]",
"Axis #0:\n"
+ "{}\n"
+ "Axis #1:\n"
+ "{[Markets].[All Markets].[#null]}\n"
+ "{[Markets].[All Markets].[APAC]}\n"
+ "{[Markets].[All Markets].[EMEA]}\n"
+ "{[Markets].[All Markets].[Japan]}\n"
+ "{[Markets].[All Markets].[NA]}\n"
+ "{[Markets].[#null]}\n"
+ "{[Markets].[APAC]}\n"
+ "{[Markets].[EMEA]}\n"
+ "{[Markets].[Japan]}\n"
+ "{[Markets].[NA]}\n"
+ "Row #0: \n"
+ "Row #0: 12,878\n"
+ "Row #0: 49,578\n"
Expand All @@ -125,14 +139,14 @@ public void testMarkets() {
"Axis #0:\n"
+ "{}\n"
+ "Axis #1:\n"
+ "{[Markets].[All Markets].[EMEA].[UK].[Isle of Wight].[Cowes]}\n"
+ "{[Markets].[All Markets].[Japan]}\n"
+ "{[Markets].[All Markets].[Japan].[Hong Kong]}\n"
+ "{[Markets].[All Markets].[Japan].[Hong Kong].[#null]}\n"
+ "{[Markets].[All Markets].[Japan].[Hong Kong].[#null].[Central Hong Kong]}\n"
+ "{[Markets].[All Markets].[Japan].[Japan]}\n"
+ "{[Markets].[All Markets].[Japan].[Japan].[Osaka]}\n"
+ "{[Markets].[All Markets].[Japan].[Japan].[Osaka].[Osaka]}\n"
+ "{[Markets].[EMEA].[UK].[Isle of Wight].[Cowes]}\n"
+ "{[Markets].[Japan]}\n"
+ "{[Markets].[Japan].[Hong Kong]}\n"
+ "{[Markets].[Japan].[Hong Kong].[#null]}\n"
+ "{[Markets].[Japan].[Hong Kong].[#null].[Central Hong Kong]}\n"
+ "{[Markets].[Japan].[Japan]}\n"
+ "{[Markets].[Japan].[Japan].[Osaka]}\n"
+ "{[Markets].[Japan].[Japan].[Osaka].[Osaka]}\n"
+ "Row #0: 895\n"
+ "Row #0: 4,923\n"
+ "Row #0: 596\n"
Expand All @@ -147,17 +161,66 @@ public void testMarkets() {
"Axis #0:\n"
+ "{}\n"
+ "Axis #1:\n"
+ "{[Markets].[All Markets].[#null]}\n"
+ "{[Markets].[All Markets].[APAC]}\n"
+ "{[Markets].[All Markets].[EMEA]}\n"
+ "{[Markets].[All Markets].[Japan]}\n"
+ "{[Markets].[All Markets].[NA]}\n"
+ "{[Markets].[#null]}\n"
+ "{[Markets].[APAC]}\n"
+ "{[Markets].[EMEA]}\n"
+ "{[Markets].[Japan]}\n"
+ "{[Markets].[NA]}\n"
+ "Row #0: \n"
+ "Row #0: 12,878\n"
+ "Row #0: 49,578\n"
+ "Row #0: 4,923\n"
+ "Row #0: 37,952\n");
}

/**
* Test case for bug <a href="http://jira.pentaho.com/browse/MONDRIAN-756">
* MONDRIAN-756, "Error in RolapResult.replaceNonAllMembers leads to
* NPE"</a>.
*/
public void testBugMondrian756() {
TestContext testContext =
new SteelWheelsTestContext(TestContext.instance()) {
@Override
public Util.PropertyList getFoodMartConnectionProperties() {
Util.PropertyList propertyList =
super.getFoodMartConnectionProperties();
propertyList.put(
RolapConnectionProperties.DynamicSchemaProcessor.name(),
Mondrian756SchemaProcessor.class.getName());
return propertyList;
}
};
if (!testContext.databaseIsValid()) {
return;
}
testContext.assertQueryReturns(
"select NON EMPTY {[Measures].[Quantity]} ON COLUMNS,\n"
+ "NON EMPTY {[Markets].[APAC]} ON ROWS\n"
+ "from [SteelWheelsSales]\n"
+ "where [Time].[2004]",
"Axis #0:\n"
+ "{[Time].[2004]}\n"
+ "Axis #1:\n"
+ "{[Measures].[Quantity]}\n"
+ "Axis #2:\n"
+ "{[Markets].[APAC]}\n"
+ "Row #0: 5,938\n");
}

public static class Mondrian756SchemaProcessor
extends FilterDynamicSchemaProcessor
{
@Override
public String filter(
String schemaUrl,
Util.PropertyList connectInfo,
InputStream stream) throws Exception
{
String schema = super.filter(schemaUrl, connectInfo, stream);
return Util.replace(schema, " hasAll=\"true\"", " hasAll=\"false\"");
}
}
}

// End SteelWheelsTestCase.java

0 comments on commit f96d0fe

Please sign in to comment.