Skip to content

Commit

Permalink
MONDRIAN: adds clearview Solve Order test; enhances ClearViewBase and…
Browse files Browse the repository at this point in the history
… generateDiffRepositoryJUnit.xsl to support creating calculatedMember; replaces the double-checking pattern for syncrhonization in TestContext

[git-p4: depot-paths = "//open/mondrian/": change = 9100]
  • Loading branch information
Khanh Vu committed Apr 13, 2007
1 parent b36c970 commit 8e4164f
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 12 deletions.
1 change: 1 addition & 0 deletions build.xml
Expand Up @@ -554,6 +554,7 @@ in {mondrian.foodmart.jdbcURL}.">
<property name="path" value="${testsrc.dir}/main/mondrian/test/clearview/"/>
<genJUnit path="${path}" packagename="mondrian.test.clearview" testname="CVBasicTest"/>
<genJUnit path="${path}" packagename="mondrian.test.clearview" testname="MetricFilterTest"/>
<genJUnit path="${path}" packagename="mondrian.test.clearview" testname="MiscTest"/>
<genJUnit path="${path}" packagename="mondrian.test.clearview" testname="PredicateFilterTest"/>
<genJUnit path="${path}" packagename="mondrian.test.clearview" testname="SummaryTest"/>
<genJUnit path="${path}" packagename="mondrian.test.clearview" testname="SummaryMetricPercentTest"/>
Expand Down
3 changes: 2 additions & 1 deletion testsrc/main/mondrian/test/Main.java
Expand Up @@ -174,6 +174,7 @@ public static Test suite() throws Exception {
suite.addTest(CVBasicTest.suite());
suite.addTest(GrandTotalTest.suite());
suite.addTest(MetricFilterTest.suite());
suite.addTest(MiscTest.suite());
suite.addTest(PredicateFilterTest.suite());
suite.addTest(SubTotalTest.suite());
suite.addTest(SummaryMetricPercentTest.suite());
Expand Down Expand Up @@ -232,7 +233,7 @@ public static Test suite() throws Exception {
if (testNonEmpty)
suite.addTestSuite(NonEmptyTest.class);
else
logger.warn("skipping NonEmptyTests");
logger.warn("skipping NonEmptyTests");
}
if (testName != null && !testName.equals("")) {
// Filter the suite, so that only tests whose names match
Expand Down
8 changes: 2 additions & 6 deletions testsrc/main/mondrian/test/TestContext.java
Expand Up @@ -93,13 +93,9 @@ public class TestContext {
/**
* Retrieves the singleton (instantiating if necessary).
*/
public static TestContext instance() {
public static synchronized TestContext instance() {
if (instance == null) {
synchronized (TestContext.class) {
if (instance == null) {
instance = new TestContext();
}
}
instance = new TestContext();
}
return instance;
}
Expand Down
18 changes: 18 additions & 0 deletions testsrc/main/mondrian/test/clearview/ClearViewBase.java
Expand Up @@ -85,11 +85,29 @@ public static TestSuite constructSuite(
protected void runTest() throws Exception {
DiffRepository diffRepos = getDiffRepos();
TestContext testContext = getTestContext();

// add calculated member to a cube if specified in the xml file
String cubeName = diffRepos.expand(null, "${modifiedCubeName}").trim();
if (! (cubeName.equals("")
|| cubeName.equals("${modifiedCubeName}")))
{
String calculatedMembers = diffRepos.expand(
null, "${calculatedMembers}");
if (! (calculatedMembers.equals("")
|| calculatedMembers.equals("${calculatedMembers}")))
{
testContext = testContext.createSubstitutingCube(
cubeName,
null,
calculatedMembers);
}
}
String mdx = diffRepos.expand(null, "${mdx}");
String result = Util.nl + testContext.toString(
testContext.executeQuery(mdx));
diffRepos.assertEquals("result", "${result}", result);
}

}

// End ClearViewBase.java
52 changes: 52 additions & 0 deletions testsrc/main/mondrian/test/clearview/MiscTest.java
@@ -0,0 +1,52 @@
/*
// $Id$
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2007 Julian Hyde and others
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
*/
package mondrian.test.clearview;

import junit.framework.*;

import mondrian.test.*;

/**
* <code>MiscTest</code> is a test suite which tests miscellaneous
* complex queries against the FoodMart database. MDX queries and their
* expected results are maintained separately in MiscTest.ref.xml file.
* If you would prefer to see them as inlined Java string literals, run
* ant target "generateDiffRepositoryJUnit" and then use
* file MiscTestJUnit.java which will be generated in this directory.
*
* @author Khanh Vu
* @version $Id$
*/
public class MiscTest extends ClearViewBase {

public MiscTest() {
super();
}

public MiscTest(String name) {
super(name);
}

protected DiffRepository getDiffRepos() {
return getDiffReposStatic();
}

private static DiffRepository getDiffReposStatic() {
return DiffRepository.lookup(MiscTest.class);
}

public static TestSuite suite() {
return constructSuite(getDiffReposStatic(), MiscTest.class);
}

}

// End MiscTest.java
127 changes: 127 additions & 0 deletions testsrc/main/mondrian/test/clearview/MiscTest.ref.xml
@@ -0,0 +1,127 @@
<?xml version="1.0" ?>
<Root>
<TestCase name="testSolveOrder">
<Resource name="description">
<![CDATA[
Tests that solve order is correctly generated such that max is applied on top of rank on top of ratio measure.
]]>
</Resource>
<Resource name="modifiedCubeName">
<![CDATA[
Sales
]]>
</Resource>
<Resource name="calculatedMembers">
<![CDATA[
<CalculatedMember
name='Sales as % of Cost'
dimension='Measures'
formula='([Measures].[Store Sales] - [Measures].[Store Cost])/[Measures].[Store Cost]'>
<CalculatedMemberProperty name='FORMAT_STRING' value='####0.0%'/>
</CalculatedMember>
]]>
</Resource>
<Resource name="mdx">
<![CDATA[
With
Set [*NATIVE_CJ_SET] as 'Filter([*BASE_MEMBERS_Product], Not IsEmpty ([Measures].[Sales as % of Cost]))'
Set [*SM_RSUM_SET_0] as 'Generate([*NATIVE_CJ_SET], {([Product].CurrentMember)})'
Set [*BASE_MEMBERS_Measures] as '{[Measures].[Sales as % of Cost],[Measures].[*SUMMARY_METRIC_0]}'
Set [*BASE_MEMBERS_Product] as '[Product].[Product Department].Members'
Set [*NATIVE_MEMBERS_Product] as 'Generate([*NATIVE_CJ_SET], {[Product].CurrentMember})'
Member [Measures].[*SUMMARY_METRIC_0] as 'Rank(([Product].CurrentMember),[*SM_RSUM_SET_0],[Measures].[Sales as % of Cost])', SOLVE_ORDER=50
Member [Product].[*CTX_MEMBER_SEL~SUM] as 'Sum({[Product].[All Products]})', SOLVE_ORDER=-100
Member [Product].[*CTX_MEMBER_SEL~MAX] as 'Max([*NATIVE_MEMBERS_Product])', SOLVE_ORDER=100
Select
[*BASE_MEMBERS_Measures] on columns,
Non Empty Union({[Product].[*CTX_MEMBER_SEL~MAX]},Union({[Product].[*CTX_MEMBER_SEL~SUM]},Generate([*NATIVE_CJ_SET], {([Product].CurrentMember)}))) on rows
From [Sales]
]]>
</Resource>
<Resource name="result">
<![CDATA[
Axis #0:
{}
Axis #1:
{[Measures].[Sales as % of Cost]}
{[Measures].[*SUMMARY_METRIC_0]}
Axis #2:
{[Product].[*CTX_MEMBER_SEL~MAX]}
{[Product].[*CTX_MEMBER_SEL~SUM]}
{[Product].[All Products].[Drink].[Alcoholic Beverages]}
{[Product].[All Products].[Drink].[Beverages]}
{[Product].[All Products].[Drink].[Dairy]}
{[Product].[All Products].[Food].[Baked Goods]}
{[Product].[All Products].[Food].[Baking Goods]}
{[Product].[All Products].[Food].[Breakfast Foods]}
{[Product].[All Products].[Food].[Canned Foods]}
{[Product].[All Products].[Food].[Canned Products]}
{[Product].[All Products].[Food].[Dairy]}
{[Product].[All Products].[Food].[Deli]}
{[Product].[All Products].[Food].[Eggs]}
{[Product].[All Products].[Food].[Frozen Foods]}
{[Product].[All Products].[Food].[Meat]}
{[Product].[All Products].[Food].[Produce]}
{[Product].[All Products].[Food].[Seafood]}
{[Product].[All Products].[Food].[Snack Foods]}
{[Product].[All Products].[Food].[Snacks]}
{[Product].[All Products].[Food].[Starchy Foods]}
{[Product].[All Products].[Non-Consumable].[Carousel]}
{[Product].[All Products].[Non-Consumable].[Checkout]}
{[Product].[All Products].[Non-Consumable].[Health and Hygiene]}
{[Product].[All Products].[Non-Consumable].[Household]}
{[Product].[All Products].[Non-Consumable].[Periodicals]}
Row #0: 151.8%
Row #0: 23
Row #1: 150.5%
Row #1: 12
Row #2: 151.6%
Row #2: 5
Row #3: 150.7%
Row #3: 9
Row #4: 149.3%
Row #4: 22
Row #5: 150.7%
Row #5: 8
Row #6: 151.6%
Row #6: 4
Row #7: 151.8%
Row #7: 1
Row #8: 150.2%
Row #8: 16
Row #9: 151.6%
Row #9: 3
Row #10: 149.5%
Row #10: 21
Row #11: 150.5%
Row #11: 14
Row #12: 149.7%
Row #12: 19
Row #13: 150.6%
Row #13: 10
Row #14: 150.4%
Row #14: 15
Row #15: 150.5%
Row #15: 12
Row #16: 150.5%
Row #16: 13
Row #17: 150.7%
Row #17: 7
Row #18: 149.7%
Row #18: 20
Row #19: 149.8%
Row #19: 18
Row #20: 151.7%
Row #20: 2
Row #21: 147.1%
Row #21: 23
Row #22: 151.1%
Row #22: 6
Row #23: 150.2%
Row #23: 17
Row #24: 150.6%
Row #24: 11
]]>
</Resource>
</TestCase>
</Root>
23 changes: 18 additions & 5 deletions testsrc/xsl/generateDiffRepositoryJUnit.xsl
Expand Up @@ -28,6 +28,7 @@
package <xsl:value-of select="$packagename"/>;

import mondrian.test.*;
import mondrian.olap.*;

/**
* Wraps DiffRepository-based tests with JUnit test methods so
Expand All @@ -43,6 +44,7 @@ public class <xsl:value-of select="$classname"/> extends FoodMartTestCase
super(testName);
}
<xsl:apply-templates select="node()" />

}
</xsl:template>

Expand Down Expand Up @@ -82,16 +84,29 @@ public class <xsl:value-of select="$classname"/> extends FoodMartTestCase
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="TestCase">
<xsl:param name="modifiedCubeName" select="Resource[@name='modifiedCubeName']"/>
<xsl:param name="calculatedMembers" select="Resource[@name='calculatedMembers']"/>
public void <xsl:value-of select="@name"/>()
throws Exception
{
assertQueryReturns(
{
TestContext testContext = getTestContext();
<xsl:if test="not(normalize-space(string($modifiedCubeName)) = '')" >
<xsl:if test="not(normalize-space(string($calculatedMembers)) = '')" >
testContext = testContext.createSubstitutingCube(
&quot;<xsl:value-of select="normalize-space(Resource[@name='modifiedCubeName'])"/>&quot;,
null,
&quot;<xsl:call-template name="genTxt">
<xsl:with-param name="text" select="Resource[@name='calculatedMembers']"/>
</xsl:call-template>&quot;);
</xsl:if>
</xsl:if>
testContext.assertQueryReturns(
&quot;<xsl:call-template name="genTxt">
<xsl:with-param name="text" select="Resource[@name='mdx']"/>
</xsl:call-template>&quot;,
Expand All @@ -101,6 +116,4 @@ public class <xsl:value-of select="$classname"/> extends FoodMartTestCase
</xsl:call-template>&quot;));
}
</xsl:template>

}
</xsl:stylesheet>

0 comments on commit 8e4164f

Please sign in to comment.