Skip to content

Commit

Permalink
MONDRIAN: Make sure every test calls its parent's setUp() and tearDow…
Browse files Browse the repository at this point in the history
…n().

    Add facilities to PropertySaver to restore logging levels.
    SchemaTest.testUnknownUsages now ensures it has sufficient logging level to succeed.
    Now throw sensible error if VirtualCubeMeasure references an unknown cube; add test case.

[git-p4: depot-paths = "//open/mondrian-release/3.2/": change = 13478]
  • Loading branch information
julianhyde committed Mar 15, 2010
1 parent 026be72 commit cc12536
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 63 deletions.
6 changes: 5 additions & 1 deletion src/main/mondrian/rolap/RolapCube.java
Expand Up @@ -4,7 +4,7 @@
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2001-2002 Kana Software, Inc.
// Copyright (C) 2001-2009 Julian Hyde and others
// Copyright (C) 2001-2010 Julian Hyde and others
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
Expand Down Expand Up @@ -471,6 +471,10 @@ static CellFormatter getCellFormatter(
{
// Lookup a measure in an existing cube.
RolapCube cube = schema.lookupCube(xmlMeasure.cubeName);
if (cube == null) {
throw Util.newError(
"Cube '" + xmlMeasure.cubeName + "' not found");
}
List<Member> cubeMeasures = cube.getMeasures();
boolean found = false;
for (Member cubeMeasure : cubeMeasures) {
Expand Down
4 changes: 0 additions & 4 deletions testsrc/main/mondrian/olap/fun/NativizeSetFunDefTest.java
Expand Up @@ -21,8 +21,6 @@
* @since Oct 14, 2009
*/
public class NativizeSetFunDefTest extends BatchTestCase {
private final PropertySaver propSaver = new PropertySaver();

public void setUp() throws Exception {
super.setUp();
propSaver.set(
Expand All @@ -33,8 +31,6 @@ public void setUp() throws Exception {

public void tearDown() throws Exception {
super.tearDown();
// revert any properties that have been set during this test
propSaver.reset();
}

public void testLevelHierarchyHighCardinality() {
Expand Down
Expand Up @@ -23,10 +23,6 @@
* @version $Id$
*/
public class NonEmptyPropertyForAllAxisTest extends FoodMartTestCase {
protected void tearDown() throws Exception {
propSaver.reset();
}

public void testNonEmptyForAllAxesWithPropertySet() {
propSaver.set(
MondrianProperties.instance().EnableNonEmptyOnAllAxis, true);
Expand Down
20 changes: 5 additions & 15 deletions testsrc/main/mondrian/rolap/NonEmptyTest.java
Expand Up @@ -2337,17 +2337,8 @@ public boolean requiresLayout() {
return false;
}
};
Logger rolapUtilLogger = Logger.getLogger(RolapUtil.class);
final org.apache.log4j.Level prevLevel = rolapUtilLogger.getLevel();
final boolean needToResetLevel;
if (prevLevel == null
|| !prevLevel.isGreaterOrEqual(org.apache.log4j.Level.WARN))
{
rolapUtilLogger.setLevel(org.apache.log4j.Level.WARN);
needToResetLevel = true;
} else {
needToResetLevel = false;
}
final Logger rolapUtilLogger = Logger.getLogger(RolapUtil.class);
propSaver.setAtLeast(rolapUtilLogger, org.apache.log4j.Level.WARN);
rolapUtilLogger.addAppender(alertListener);
String expectedMessage =
"Unable to use native SQL evaluation for 'NonEmptyCrossJoin'";
Expand All @@ -2362,6 +2353,7 @@ public boolean requiresLayout() {
// Expected
} finally {
propSaver.reset();
propSaver.setAtLeast(rolapUtilLogger, org.apache.log4j.Level.WARN);
}

// should have gotten one ERROR
Expand All @@ -2378,6 +2370,7 @@ public boolean requiresLayout() {
checkNotNative(3, mdx);
} finally {
propSaver.reset();
propSaver.setAtLeast(rolapUtilLogger, org.apache.log4j.Level.WARN);
}

// should have gotten one WARN
Expand All @@ -2396,6 +2389,7 @@ public boolean requiresLayout() {
checkNotNative(3, mdx);
} finally {
propSaver.reset();
propSaver.setAtLeast(rolapUtilLogger, org.apache.log4j.Level.WARN);
}

// should have gotten no WARN
Expand All @@ -2407,10 +2401,6 @@ public boolean requiresLayout() {
// no biggie if we don't get here for some reason; just being
// half-heartedly clean
rolapUtilLogger.removeAppender(alertListener);

if (needToResetLevel) {
rolapUtilLogger.setLevel(prevLevel);
}
}

private int countFilteredEvents(
Expand Down
28 changes: 25 additions & 3 deletions testsrc/main/mondrian/rolap/VirtualCubeTest.java
Expand Up @@ -3,7 +3,7 @@
// 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) 2003-2009 Julian Hyde
// Copyright (C) 2003-2010 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand All @@ -26,6 +26,7 @@
public class VirtualCubeTest extends BatchTestCase {
public VirtualCubeTest() {
}

public VirtualCubeTest(String name) {
super(name);
}
Expand Down Expand Up @@ -127,6 +128,24 @@ public void testDefaultMeasureInVCForCaseSensitivity() {
}
}

public void testVirtualCubeMeasureInvalidCubeName() {
TestContext testContext = TestContext.create(
null,
null,
"<VirtualCube name=\"Sales vs Warehouse\">\n"
+ "<VirtualCubeDimension name=\"Product\"/>\n"
+ "<VirtualCubeMeasure cubeName=\"Warehouse\" "
+ "name=\"[Measures].[Warehouse Sales]\"/>\n"
+ "<VirtualCubeMeasure cubeName=\"Bad cube\" "
+ "name=\"[Measures].[Unit Sales]\"/>\n"
+ "</VirtualCube>",
null,
null,
null);
testContext.assertQueryThrows(
"select from [Sales vs Warehouse]",
"Cube 'Bad cube' not found");
}

public void testWithTimeDimension() {
TestContext testContext = TestContext.create(
Expand Down Expand Up @@ -220,6 +239,9 @@ public void testNonDefaultAllMember2() {
/**
* Creates a TestContext containing a cube
* "Warehouse (Default USA) and Sales".
*
* @return test context with a cube where the default member in the
* Warehouse dimension is USA
*/
private TestContext createContextWithNonDefaultAllMember() {
return TestContext.create(
Expand Down Expand Up @@ -311,8 +333,8 @@ private void assertVisibility(
Member measure = columnPositions.get(ordinal).get(0);
assertEquals(expectedName, measure.getName());
assertEquals(
Boolean.valueOf(expectedVisibility), measure.getPropertyValue(
Property.VISIBLE.name));
expectedVisibility,
measure.getPropertyValue(Property.VISIBLE.name));
}

/**
Expand Down
20 changes: 6 additions & 14 deletions testsrc/main/mondrian/rolap/aggmatcher/AggGenTest.java
Expand Up @@ -3,34 +3,26 @@
// 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) 2005-2009 Julian Hyde and others
// Copyright (C) 2005-2010 Julian Hyde and others
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package mondrian.rolap.aggmatcher;

import javax.sql.DataSource;
import java.io.StringWriter;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.log4j.Appender;
import org.apache.log4j.*;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;
import org.apache.log4j.WriterAppender;

import mondrian.olap.MondrianProperties;
import mondrian.olap.Query;
import mondrian.olap.Util;
import mondrian.olap.*;
import mondrian.rolap.RolapConnection;
import mondrian.test.FoodMartTestCase;

import javax.sql.DataSource;


/**
* Test if lookup columns are there after loading them in
Expand All @@ -53,7 +45,7 @@ public AggGenTest(String name) {
StringWriter writer = new StringWriter();
Appender myAppender = new WriterAppender(new SimpleLayout(), writer);
logger.addAppender(myAppender);
logger.setLevel(Level.DEBUG);
propSaver.setAtLeast(logger, Level.DEBUG);

final String trueValue = "true";

Expand Down
Expand Up @@ -3,7 +3,7 @@
// 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) 2001-2009 Julian Hyde and others
// Copyright (C) 2001-2010 Julian Hyde and others
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
Expand All @@ -22,15 +22,16 @@
* @version $Id$
* @since Dec 12, 2007
*/
public class IgnoreMeasureForNonJoiningDimensionInAggregationTest extends
FoodMartTestCase
public class IgnoreMeasureForNonJoiningDimensionInAggregationTest
extends FoodMartTestCase
{

// TODO: use propSaver to restore property values
boolean originalNonEmptyFlag;
boolean originalEliminateUnrelatedDimensions;
private final MondrianProperties prop = MondrianProperties.instance();

protected void setUp() throws Exception {
super.setUp();
originalNonEmptyFlag = prop.EnableNonEmptyOnAllAxis.get();
originalEliminateUnrelatedDimensions =
prop.IgnoreMeasureForNonJoiningDimension.get();
Expand All @@ -42,6 +43,7 @@ protected void tearDown() throws Exception {
prop.EnableNonEmptyOnAllAxis.set(originalNonEmptyFlag);
prop.IgnoreMeasureForNonJoiningDimension.set(
originalEliminateUnrelatedDimensions);
super.tearDown();
}

public void testNoTotalsForCompdMeasureWithComponentsHavingNonJoiningDims()
Expand Down
26 changes: 15 additions & 11 deletions testsrc/main/mondrian/test/IgnoreUnrelatedDimensionsTest.java
Expand Up @@ -3,7 +3,7 @@
// 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) 2001-2009 Julian Hyde and others
// Copyright (C) 2001-2010 Julian Hyde and others
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
Expand All @@ -14,24 +14,21 @@
import mondrian.olap.MondrianProperties;

/**
* <code>IgnoreUnrelatedDimensionsTest</code> Test case to
* Test case to
* push unrelatedDimensions to top level when ignoreUnrelatedDimensions property
* is set to true on a base cube usage.
*
* @author ajoglekar
* @since Dec 03, 2007
* @version $Id$
*/
public class IgnoreUnrelatedDimensionsTest extends FoodMartTestCase {

// TODO: use propSaver to restore property values
boolean originalNonEmptyFlag;
private final MondrianProperties prop = MondrianProperties.instance();

protected void setUp() throws Exception {
originalNonEmptyFlag = prop.EnableNonEmptyOnAllAxis.get();
prop.EnableNonEmptyOnAllAxis.set(true);
}

private String cubeSales3 =
private static final String cubeSales3 =
"<Cube name=\"Sales 3\">\n"
+ " <Table name=\"sales_fact_1997\"/>\n"
+ " <DimensionUsage name=\"Time\" source=\"Time\" foreignKey=\"time_id\"/>\n"
Expand All @@ -47,7 +44,8 @@ protected void setUp() throws Exception {
+ " <CalculatedMemberProperty name=\"MEMBER_ORDINAL\" value=\"2\"/>\n"
+ " </Measure>\n"
+ "</Cube>";
private String cubeWarehouseAndSales3 =

private static final String cubeWarehouseAndSales3 =
"<VirtualCube name=\"Warehouse and Sales 3\" defaultMeasure=\"Store Invoice\">\n"
+ " <CubeUsages>\n"
+ " <CubeUsage cubeName=\"Sales 3\" ignoreUnrelatedDimensions=\"true\"/>\n"
Expand All @@ -61,12 +59,19 @@ protected void setUp() throws Exception {
+ " <VirtualCubeMeasure cubeName=\"Warehouse\" name=\"[Measures].[Warehouse Sales]\"/>\n"
+ "</VirtualCube>";

protected void setUp() throws Exception {
super.setUp();
originalNonEmptyFlag = prop.EnableNonEmptyOnAllAxis.get();
prop.EnableNonEmptyOnAllAxis.set(true);
}

protected void tearDown() throws Exception {
prop.EnableNonEmptyOnAllAxis.set(originalNonEmptyFlag);
super.tearDown();
}

public TestContext getTestContext() {
final TestContext testContext = TestContext.create(
return TestContext.create(
null,
null,
"<VirtualCube name=\"Warehouse and Sales2\" defaultMeasure=\"Store Sales\">\n"
Expand Down Expand Up @@ -106,7 +111,6 @@ public TestContext getTestContext() {
null,
null,
null);
return testContext;
}

public void testTotalingOnCrossJoinOfJoiningAndNonJoiningDimensions() {
Expand Down

0 comments on commit cc12536

Please sign in to comment.