Skip to content

Commit

Permalink
MONDRIAN: Reorganize test infrastructure (move more methods onto Test…
Browse files Browse the repository at this point in the history
…Context), and add a testcsae for bug 1250080 "bug with hierarchy with no all member when in query".

[git-p4: depot-paths = "//open/mondrian/": change = 4069]
  • Loading branch information
julianhyde committed Sep 9, 2005
1 parent 6a0bccf commit bb703ad
Show file tree
Hide file tree
Showing 10 changed files with 661 additions and 511 deletions.
527 changes: 260 additions & 267 deletions testsrc/main/mondrian/olap/fun/FunctionTest.java

Large diffs are not rendered by default.

62 changes: 39 additions & 23 deletions testsrc/main/mondrian/test/AccessControlTest.java
Expand Up @@ -29,7 +29,8 @@ public AccessControlTest(String name) {
}

public void testGrantDimensionNone() {
Connection connection = getConnection(true);
final Connection connection = getConnection(true);
TestContext testContext = getTestContext(connection);
Role role = connection.getRole().makeMutableClone();
Schema schema = connection.getSchema();
Cube salesCube = schema.lookupCube("Sales", true);
Expand All @@ -40,7 +41,7 @@ public void testGrantDimensionNone() {
role.grant(genderDimension, Access.NONE);
role.makeImmutable();
connection.setRole(role);
assertAxisThrows(connection, "[Gender].children", "MDX object '[Gender]' not found in cube 'Sales'");
testContext.assertAxisThrows("[Gender].children", "MDX object '[Gender]' not found in cube 'Sales'");
}

public void testRoleMemberAccess() {
Expand Down Expand Up @@ -73,7 +74,7 @@ public void testGrantHierarchy1a() {
// assert: can access Mexico (explicitly granted)
// assert: can not access Canada (explicitly denied)
// assert: can access USA (rule 3 - parent of allowed member San Francisco)
assertAxisReturns(getRestrictedConnection(), "[Store].level.members",
getRestrictedTestContext().assertAxisReturns("[Store].level.members",
"[Store].[All Stores].[Mexico]" + nl +
"[Store].[All Stores].[USA]");
}
Expand All @@ -82,42 +83,55 @@ public void testGrantHierarchy1aAllMembers() {
// assert: can access Mexico (explicitly granted)
// assert: can not access Canada (explicitly denied)
// assert: can access USA (rule 3 - parent of allowed member San Francisco)
assertAxisReturns(getRestrictedConnection(), "[Store].level.allmembers",
getRestrictedTestContext().assertAxisReturns("[Store].level.allmembers",
"[Store].[All Stores].[Mexico]" + nl +
"[Store].[All Stores].[USA]");
}

public void testGrantHierarchy1b() {
// can access Mexico (explicitly granted) which is the first accessible one
assertAxisReturns(getRestrictedConnection(), "[Store].defaultMember",
getRestrictedTestContext().assertAxisReturns("[Store].defaultMember",
"[Store].[All Stores].[Mexico]");
}

public void testGrantHierarchy1c() {
// can access Mexico (explicitly granted) which is the first accessible one
assertAxisReturns(getRestrictedConnection(), "[Customers].defaultMember",
getRestrictedTestContext().assertAxisReturns("[Customers].defaultMember",
"[Customers].[All Customers].[Canada].[BC]");
}
public void testGrantHierarchy2() {
// assert: can access California (parent of allowed member)
final Connection restrictedConnection = getRestrictedConnection();
assertAxisReturns(restrictedConnection, "[Store].[USA].children", "[Store].[All Stores].[USA].[CA]");
assertAxisReturns(restrictedConnection, "[Store].[USA].[CA].children",
final TestContext testContext = getRestrictedTestContext();
testContext.assertAxisReturns("[Store].[USA].children", "[Store].[All Stores].[USA].[CA]");
testContext.assertAxisReturns("[Store].[USA].[CA].children",
"[Store].[All Stores].[USA].[CA].[Los Angeles]" + nl +
"[Store].[All Stores].[USA].[CA].[San Francisco]");
}
public void testGrantHierarchy3() {
// assert: can not access Washington (child of denied member)
assertAxisThrows(getRestrictedConnection(), "[Store].[USA].[WA]", "not found");
final TestContext testContext = getRestrictedTestContext();
testContext.assertAxisThrows("[Store].[USA].[WA]", "not found");
}

private TestContext getRestrictedTestContext() {
return new DelegatingTestContext(getTestContext()) {
public Connection getConnection() {
return getRestrictedConnection();
}
};
}

public void testGrantHierarchy4() {
// assert: can not access Oregon (rule 1 - order matters)
assertAxisThrows(getRestrictedConnection(), "[Store].[USA].[OR].children", "not found");
final TestContext testContext = getRestrictedTestContext();
testContext.assertAxisThrows("[Store].[USA].[OR].children", "not found");
}
public void testGrantHierarchy5() {
// assert: can not access All (above top level)
assertAxisThrows(getRestrictedConnection(), "[Store].[All Stores]", "not found");
assertAxisReturns(getRestrictedConnection(), "[Store].members",
final TestContext testContext = getRestrictedTestContext();
testContext.assertAxisThrows("[Store].[All Stores]", "not found");
testContext.assertAxisReturns(
"[Store].members",
// note:
// no: [All Stores] -- above top level
// no: [Canada] -- not explicitly allowed
Expand Down Expand Up @@ -160,28 +174,30 @@ public void testGrantHierarchy5() {
}
public void testGrantHierarchy6() {
// assert: parent if at top level is null
assertAxisReturns(getRestrictedConnection(), "[Customers].[USA].[CA].parent", "");
getRestrictedTestContext().assertAxisReturns("[Customers].[USA].[CA].parent", "");
}
public void testGrantHierarchy7() {
// assert: members above top level do not exist
assertAxisThrows(getRestrictedConnection(), "[Customers].[Canada].children",
final TestContext testContext = getRestrictedTestContext();
testContext.assertAxisThrows(
"[Customers].[Canada].children",
"MDX object '[Customers].[Canada]' not found in cube 'Sales'");
}
public void testGrantHierarchy8() {
// assert: can not access Catherine Abel in San Francisco (below bottom level)
final Connection restrictedConnection = getRestrictedConnection();
assertAxisThrows(restrictedConnection, "[Customers].[USA].[CA].[San Francisco].[Catherine Abel]", "not found");
assertAxisReturns(restrictedConnection, "[Customers].[USA].[CA].[San Francisco].children", "");
Axis axis = executeAxis2(restrictedConnection, "[Customers].members");
final TestContext testContext = getRestrictedTestContext();
testContext.assertAxisThrows("[Customers].[USA].[CA].[San Francisco].[Catherine Abel]", "not found");
testContext.assertAxisReturns("[Customers].[USA].[CA].[San Francisco].children", "");
Axis axis = testContext.executeAxis("[Customers].members");
Assert.assertEquals(122, axis.positions.length); // 13 states, 109 cities
}

public void testGrantHierarchy8AllMembers() {
// assert: can not access Catherine Abel in San Francisco (below bottom level)
final Connection restrictedConnection = getRestrictedConnection();
assertAxisThrows(restrictedConnection, "[Customers].[USA].[CA].[San Francisco].[Catherine Abel]", "not found");
assertAxisReturns(restrictedConnection, "[Customers].[USA].[CA].[San Francisco].children", "");
Axis axis = executeAxis2(restrictedConnection, "[Customers].allmembers");
final TestContext testContext = getRestrictedTestContext();
testContext.assertAxisThrows("[Customers].[USA].[CA].[San Francisco].[Catherine Abel]", "not found");
testContext.assertAxisReturns("[Customers].[USA].[CA].[San Francisco].children", "");
Axis axis = testContext.executeAxis("[Customers].allmembers");
Assert.assertEquals(122, axis.positions.length); // 13 states, 109 cities
}

Expand Down
119 changes: 94 additions & 25 deletions testsrc/main/mondrian/test/BasicQueryTest.java
Expand Up @@ -18,12 +18,13 @@
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.regex.Pattern;
import java.io.PrintWriter;

import junit.framework.Assert;

/**
* <code>BasicQueryTest</code> is a test case which tests simple queries against
* the FoodMart database.
* <code>BasicQueryTest</code> is a test case which tests simple queries
* against the FoodMart database.
*
* @author jhyde
* @since Feb 14, 2003
Expand Down Expand Up @@ -413,35 +414,35 @@ public BasicQueryTest(String name) {
};

public void testSample0() {
assertQueryReturns(sampleQueries[0]);
assertQueryReturns(sampleQueries[0].query, sampleQueries[0].result);
}

public void testSample1() {
assertQueryReturns(sampleQueries[1]);
assertQueryReturns(sampleQueries[1].query, sampleQueries[1].result);
}

public void testSample2() {
assertQueryReturns(sampleQueries[2]);
assertQueryReturns(sampleQueries[2].query, sampleQueries[2].result);
}

public void testSample3() {
assertQueryReturns(sampleQueries[3]);
assertQueryReturns(sampleQueries[3].query, sampleQueries[3].result);
}

public void testSample4() {
assertQueryReturns(sampleQueries[4]);
assertQueryReturns(sampleQueries[4].query, sampleQueries[4].result);
}

public void testSample5() {
assertQueryReturns(sampleQueries[5]);
assertQueryReturns(sampleQueries[5].query, sampleQueries[5].result);
}

public void testSample6() {
assertQueryReturns(sampleQueries[6]);
assertQueryReturns(sampleQueries[6].query, sampleQueries[6].result);
}

public void testSample7() {
assertQueryReturns(sampleQueries[7]);
assertQueryReturns(sampleQueries[7].query, sampleQueries[7].result);
}

/**
Expand Down Expand Up @@ -1284,8 +1285,8 @@ public void _testMembersFunction() {
}

public void _testProduct2() {
final Axis axis = executeAxis2("Sales", "{[Product2].members}");
System.out.println(toString(axis.positions));
final Axis axis = getTestContext().executeAxis("{[Product2].members}");
System.out.println(TestContext.toString(axis.positions));
}

public static final QueryAndResult[] taglibQueries = {
Expand Down Expand Up @@ -2063,27 +2064,27 @@ public void _testProduct2() {
};

public void testTaglib0() {
assertQueryReturns(taglibQueries[0]);
assertQueryReturns(taglibQueries[0].query, taglibQueries[0].result);
}

public void testTaglib1() {
assertQueryReturns(taglibQueries[1]);
assertQueryReturns(taglibQueries[1].query, taglibQueries[1].result);
}

public void testTaglib2() {
assertQueryReturns(taglibQueries[2]);
assertQueryReturns(taglibQueries[2].query, taglibQueries[2].result);
}

public void testTaglib3() {
assertQueryReturns(taglibQueries[3]);
assertQueryReturns(taglibQueries[3].query, taglibQueries[3].result);
}

public void testTaglib4() {
assertQueryReturns(taglibQueries[4]);
assertQueryReturns(taglibQueries[4].query, taglibQueries[4].result);
}

public void testTaglib5() {
assertQueryReturns(taglibQueries[5]);
assertQueryReturns(taglibQueries[5].query, taglibQueries[5].result);
}

public void testCellValue() {
Expand Down Expand Up @@ -2636,11 +2637,11 @@ public void testCatalogHierarchyBasedOnView() {
" <Level name=\"Gender\" column=\"gender\" uniqueMembers=\"true\"/>" + nl +
" </Hierarchy>" + nl +
"</Dimension>");
final Axis axis = executeAxis2("Sales", "[Gender2].members");
final Axis axis = getTestContext().executeAxis("[Gender2].members");
assertEquals("[Gender2].[All Gender]" + nl +
"[Gender2].[All Gender].[F]" + nl +
"[Gender2].[All Gender].[M]",
toString(axis.positions));
TestContext.toString(axis.positions));
}

/**
Expand Down Expand Up @@ -4123,7 +4124,8 @@ public void run(int i) {
for (int j = 0; j < iterationCount; j++) {
int queryIndex = (i * 2 + j) % queries.length;
try {
assertQueryReturns(queries[queryIndex]);
QueryAndResult query = queries[queryIndex];
assertQueryReturns(query.query, query.result);
if (flush && i == 0) {
CachePool.instance().flush();
}
Expand Down Expand Up @@ -4352,10 +4354,10 @@ public void _testCubeWhichUsesSameSharedDimTwice() {
schema.createDimension(
salesCube,
"<DimensionUsage name=\"Other Store\" source=\"Store\" foreignKey=\"unit_sales\" />");
Axis axis = executeAxis2("Sales", "[Other Store].members");
Axis axis = getTestContext().executeAxis("[Other Store].members");
assertEquals(63, axis.positions.length);

axis = executeAxis2("Sales", "[Store].members");
axis = getTestContext().executeAxis("[Store].members");
assertEquals(63, axis.positions.length);

final String q1 = "select {[Measures].[Unit Sales]} on columns," + nl +
Expand Down Expand Up @@ -4520,7 +4522,7 @@ public void testAllMemberCaption() {
" </Hierarchy>" + nl +
"</Dimension>");
String mdx = "select {[Gender3].[All Gender]} on columns from Sales";
Result result = TestContext.instance().executeFoodMart(mdx);
Result result = TestContext.instance().executeQuery(mdx);
Axis axis0 = result.getAxes()[0];
Position pos0 = axis0.positions[0];
Member allGender = pos0.members[0];
Expand All @@ -4542,14 +4544,81 @@ public void testAllLevelName() {
" </Hierarchy>" + nl +
"</Dimension>");
String mdx = "select {[Gender4].[All Gender]} on columns from Sales";
Result result = TestContext.instance().executeFoodMart(mdx);
Result result = TestContext.instance().executeQuery(mdx);
Axis axis0 = result.getAxes()[0];
Position pos0 = axis0.positions[0];
Member allGender = pos0.members[0];
String caption = allGender.getLevel().getName();
Assert.assertEquals(caption, "GenderLevel");
}

/**
* Bug 1250080 caused a dimension with no 'all' member to be constrained
* twice.
*/
public void testDimWithoutAll() {
RolapConnection conn = (RolapConnection) getConnection();
Schema schema = getConnection().getSchema();
final Cube cube = schema.createCube(fold(new String[] {
"<Cube name=\"Sales_DimWithoutAll\">",
" <Table name=\"sales_fact_1997\"/>",
" <Dimension name=\"Product\" foreignKey=\"product_id\">",
" <Hierarchy hasAll=\"false\" primaryKey=\"product_id\" primaryKeyTable=\"product\">",
" <Join leftKey=\"product_class_id\" rightKey=\"product_class_id\">",
" <Table name=\"product\"/>",
" <Table name=\"product_class\"/>",
" </Join>",
" <Level name=\"Product Family\" table=\"product_class\" column=\"product_family\"",
" uniqueMembers=\"true\"/>",
" <Level name=\"Product Department\" table=\"product_class\" column=\"product_department\"",
" uniqueMembers=\"false\"/>",
" <Level name=\"Product Category\" table=\"product_class\" column=\"product_category\"",
" uniqueMembers=\"false\"/>",
" <Level name=\"Product Subcategory\" table=\"product_class\" column=\"product_subcategory\"",
" uniqueMembers=\"false\"/>",
" <Level name=\"Brand Name\" table=\"product\" column=\"brand_name\" uniqueMembers=\"false\"/>",
" <Level name=\"Product Name\" table=\"product\" column=\"product_name\"",
" uniqueMembers=\"true\"/>",
" </Hierarchy>",
" </Dimension>",
" <Dimension name=\"Gender\" foreignKey=\"customer_id\">",
" <Hierarchy hasAll=\"false\" primaryKey=\"customer_id\">",
" <Table name=\"customer\"/>",
" <Level name=\"Gender\" column=\"gender\" uniqueMembers=\"true\"/>",
" </Hierarchy>",
" </Dimension>" +
" <Measure name=\"Unit Sales\" column=\"unit_sales\" aggregator=\"sum\"",
" formatString=\"Standard\" visible=\"false\"/>",
" <Measure name=\"Store Cost\" column=\"store_cost\" aggregator=\"sum\"",
" formatString=\"#,###.00\"/>",
"</Cube>"}));
// Create a test context which evaluates expressions against the
// "Sales_DimWithoutAll" cube, not the "Sales" cube.
TestContext testContext = new DelegatingTestContext(getTestContext()) {
public String getDefaultCubeName() {
return "Sales_DimWithoutAll";
}
};
// the default member of the Gender dimension is the first member
testContext.assertExprReturns("[Gender].CurrentMember.Name", "F");
testContext.assertExprReturns("[Product].CurrentMember.Name", "Drink");
// There is no all member.
testContext.assertExprThrows("([Gender].[All Gender], [Measures].[Unit Sales])",
"MDX object '[Gender].[All Gender]' not found in cube 'Sales_DimWithoutAll'");
testContext.assertExprThrows("([Gender].[All Genders], [Measures].[Unit Sales])",
"MDX object '[Gender].[All Genders]' not found in cube 'Sales_DimWithoutAll'");
// evaluated in the default context: [Product].[Drink], [Gender].[F]
testContext.assertExprReturns("[Measures].[Unit Sales]", "12,202");
// evaluated in the same context: [Product].[Drink], [Gender].[F]
testContext.assertExprReturns("([Gender].[F], [Measures].[Unit Sales])", "12,202");
// evaluated at in the context: [Product].[Drink], [Gender].[M]
testContext.assertExprReturns("([Gender].[M], [Measures].[Unit Sales])", "12,395");
// evaluated at in the context: [Product].[Food].[Canned Foods], [Gender].[F]
testContext.assertExprReturns("([Product].[Food].[Canned Foods], [Measures].[Unit Sales])", "9,407");
testContext.assertExprReturns("([Product].[Food].[Dairy], [Measures].[Unit Sales])", "6,513");
testContext.assertExprReturns("([Product].[Drink].[Dairy], [Measures].[Unit Sales])", "1,987");
}

/**
* It is illegal for a query to have the same dimension on more than
* one axis.
Expand Down
2 changes: 1 addition & 1 deletion testsrc/main/mondrian/test/CompatibilityTest.java
Expand Up @@ -190,7 +190,7 @@ public void testHierarchyNames() {
}

private void checkAxis(String result, String expression) {
Assert.assertEquals(result, executeAxis(expression).toString());
Assert.assertEquals(result, executeSingletonAxis(expression).toString());
}

}

0 comments on commit bb703ad

Please sign in to comment.