Skip to content

Commit

Permalink
MONDRIAN: Test case for BISERVER-1574.
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//open/mondrian-release/3.0/": change = 11350]
  • Loading branch information
julianhyde committed Jul 24, 2008
1 parent e41a20c commit 1d1b52c
Showing 1 changed file with 177 additions and 91 deletions.
268 changes: 177 additions & 91 deletions testsrc/main/mondrian/test/AccessControlTest.java
Expand Up @@ -154,18 +154,20 @@ 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)
getRestrictedTestContext().assertAxisReturns("[Store].level.members",
"[Store].[All Stores].[Mexico]" + nl +
"[Store].[All Stores].[USA]");
getRestrictedTestContext().assertAxisReturns(
"[Store].level.members",
fold("[Store].[All Stores].[Mexico]\n" +
"[Store].[All Stores].[USA]"));
}

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)
getRestrictedTestContext().assertAxisReturns("[Store].level.allmembers",
"[Store].[All Stores].[Mexico]" + nl +
"[Store].[All Stores].[USA]");
getRestrictedTestContext().assertAxisReturns(
"[Store].level.allmembers",
fold("[Store].[All Stores].[Mexico]\n" +
"[Store].[All Stores].[USA]"));
}

public void testGrantHierarchy1b() {
Expand All @@ -185,9 +187,10 @@ public void testGrantHierarchy2() {
final TestContext testContext = getRestrictedTestContext();
testContext.assertAxisReturns("[Store].[All Stores].[USA].children", "[Store].[All Stores].[USA].[CA]");
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]");
testContext.assertAxisReturns(
"[Store].[USA].[CA].children",
fold("[Store].[All Stores].[USA].[CA].[Los Angeles]\n" +
"[Store].[All Stores].[USA].[CA].[San Francisco]"));
}

public void testGrantHierarchy3() {
Expand Down Expand Up @@ -215,7 +218,7 @@ public void testGrantHierarchy5() {
final TestContext testContext = getRestrictedTestContext();
testContext.assertAxisThrows("[Store].[All Stores]", "not found");
testContext.assertAxisReturns(
"[Store].members",
"[Store].members",
// note:
// no: [All Stores] -- above top level
// no: [Canada] -- not explicitly allowed
Expand All @@ -227,31 +230,31 @@ public void testGrantHierarchy5() {
// no: [OR], [WA]
// yes: [San Francisco] -- explicitly allowed
// no: [San Diego]
"[Store].[All Stores].[Mexico]" + nl +
"[Store].[All Stores].[Mexico].[Guerrero]" + nl +
"[Store].[All Stores].[Mexico].[Guerrero].[Acapulco]" + nl +
"[Store].[All Stores].[Mexico].[Guerrero].[Acapulco].[Store 1]" + nl +
"[Store].[All Stores].[Mexico].[Jalisco]" + nl +
"[Store].[All Stores].[Mexico].[Jalisco].[Guadalajara]" + nl +
"[Store].[All Stores].[Mexico].[Jalisco].[Guadalajara].[Store 5]" + nl +
"[Store].[All Stores].[Mexico].[Veracruz]" + nl +
"[Store].[All Stores].[Mexico].[Veracruz].[Orizaba]" + nl +
"[Store].[All Stores].[Mexico].[Veracruz].[Orizaba].[Store 10]" + nl +
"[Store].[All Stores].[Mexico].[Yucatan]" + nl +
"[Store].[All Stores].[Mexico].[Yucatan].[Merida]" + nl +
"[Store].[All Stores].[Mexico].[Yucatan].[Merida].[Store 8]" + nl +
"[Store].[All Stores].[Mexico].[Zacatecas]" + nl +
"[Store].[All Stores].[Mexico].[Zacatecas].[Camacho]" + nl +
"[Store].[All Stores].[Mexico].[Zacatecas].[Camacho].[Store 4]" + nl +
"[Store].[All Stores].[Mexico].[Zacatecas].[Hidalgo]" + nl +
"[Store].[All Stores].[Mexico].[Zacatecas].[Hidalgo].[Store 12]" + nl +
"[Store].[All Stores].[Mexico].[Zacatecas].[Hidalgo].[Store 18]" + nl +
"[Store].[All Stores].[USA]" + nl +
"[Store].[All Stores].[USA].[CA]" + nl +
"[Store].[All Stores].[USA].[CA].[Los Angeles]" + nl +
"[Store].[All Stores].[USA].[CA].[Los Angeles].[Store 7]" + nl +
"[Store].[All Stores].[USA].[CA].[San Francisco]" + nl +
"[Store].[All Stores].[USA].[CA].[San Francisco].[Store 14]");
fold("[Store].[All Stores].[Mexico]\n" +
"[Store].[All Stores].[Mexico].[Guerrero]\n" +
"[Store].[All Stores].[Mexico].[Guerrero].[Acapulco]\n" +
"[Store].[All Stores].[Mexico].[Guerrero].[Acapulco].[Store 1]\n" +
"[Store].[All Stores].[Mexico].[Jalisco]\n" +
"[Store].[All Stores].[Mexico].[Jalisco].[Guadalajara]\n" +
"[Store].[All Stores].[Mexico].[Jalisco].[Guadalajara].[Store 5]\n" +
"[Store].[All Stores].[Mexico].[Veracruz]\n" +
"[Store].[All Stores].[Mexico].[Veracruz].[Orizaba]\n" +
"[Store].[All Stores].[Mexico].[Veracruz].[Orizaba].[Store 10]\n" +
"[Store].[All Stores].[Mexico].[Yucatan]\n" +
"[Store].[All Stores].[Mexico].[Yucatan].[Merida]\n" +
"[Store].[All Stores].[Mexico].[Yucatan].[Merida].[Store 8]\n" +
"[Store].[All Stores].[Mexico].[Zacatecas]\n" +
"[Store].[All Stores].[Mexico].[Zacatecas].[Camacho]\n" +
"[Store].[All Stores].[Mexico].[Zacatecas].[Camacho].[Store 4]\n" +
"[Store].[All Stores].[Mexico].[Zacatecas].[Hidalgo]\n" +
"[Store].[All Stores].[Mexico].[Zacatecas].[Hidalgo].[Store 12]\n" +
"[Store].[All Stores].[Mexico].[Zacatecas].[Hidalgo].[Store 18]\n" +
"[Store].[All Stores].[USA]\n" +
"[Store].[All Stores].[USA].[CA]\n" +
"[Store].[All Stores].[USA].[CA].[Los Angeles]\n" +
"[Store].[All Stores].[USA].[CA].[Los Angeles].[Store 7]\n" +
"[Store].[All Stores].[USA].[CA].[San Francisco]\n" +
"[Store].[All Stores].[USA].[CA].[San Francisco].[Store 14]"));
}

public void testGrantHierarchy6() {
Expand Down Expand Up @@ -301,39 +304,39 @@ public void testGrantHierarchy9() {
// where ([Marital Status].[S], [Store].[SF LA])
final TestContext tc = new RestrictedTestContext();
tc.assertQueryReturns(
"with member [Measures].[California Unit Sales] as " +
" 'Aggregate({[Store].[USA].[CA].children}, [Measures].[Unit Sales])'" + nl +
"select {[Measures].[California Unit Sales]} on columns," + nl +
" {[Gender].children} on rows" + nl +
"from Sales" + nl +
"with member [Measures].[California Unit Sales] as " +
" 'Aggregate({[Store].[USA].[CA].children}, [Measures].[Unit Sales])'\n" +
"select {[Measures].[California Unit Sales]} on columns,\n" +
" {[Gender].children} on rows\n" +
"from Sales\n" +
"where ([Marital Status].[S])",
"Axis #0:" + nl +
"{[Marital Status].[All Marital Status].[S]}" + nl +
"Axis #1:" + nl +
"{[Measures].[California Unit Sales]}" + nl +
"Axis #2:" + nl +
"{[Gender].[All Gender].[F]}" + nl +
"{[Gender].[All Gender].[M]}" + nl +
"Row #0: 6,636" + nl +
"Row #1: 7,329" + nl);
fold("Axis #0:\n" +
"{[Marital Status].[All Marital Status].[S]}\n" +
"Axis #1:\n" +
"{[Measures].[California Unit Sales]}\n" +
"Axis #2:\n" +
"{[Gender].[All Gender].[F]}\n" +
"{[Gender].[All Gender].[M]}\n" +
"Row #0: 6,636\n" +
"Row #1: 7,329\n"));
}

public void testGrantHierarchyA() {
final TestContext tc = new RestrictedTestContext();
// assert: totals for USA include missing cells
tc.assertQueryReturns(
"select {[Unit Sales]} on columns," + nl +
"{[Store].[USA], [Store].[USA].children} on rows" + nl +
"select {[Unit Sales]} on columns,\n" +
"{[Store].[USA], [Store].[USA].children} on rows\n" +
"from [Sales]",
"Axis #0:" + nl +
"{}" + nl +
"Axis #1:" + nl +
"{[Measures].[Unit Sales]}" + nl +
"Axis #2:" + nl +
"{[Store].[All Stores].[USA]}" + nl +
"{[Store].[All Stores].[USA].[CA]}" + nl +
"Row #0: 266,773" + nl +
"Row #1: 74,748" + nl);
fold("Axis #0:\n" +
"{}\n" +
"Axis #1:\n" +
"{[Measures].[Unit Sales]}\n" +
"Axis #2:\n" +
"{[Store].[All Stores].[USA]}\n" +
"{[Store].[All Stores].[USA].[CA]}\n" +
"Row #0: 266,773\n" +
"Row #1: 74,748\n"));
}

public void _testSharedObjectsInGrantMappingsBug() {
Expand Down Expand Up @@ -541,6 +544,35 @@ private void rollupPolicyBottom(
testContext.assertExprReturns("([Customers].[USA].[CA])", v1);
testContext.assertExprReturns("([Customers].[USA].[CA], [Gender].[F])", v2);
testContext.assertExprReturns("([Customers].[USA])", v3);

checkQuery(testContext, "select [Customers].Children on 0, [Gender].Members on 1 from [Sales]");
}

/**
* Calls various {@link SchemaReader} methods on the members returned in
* a result set.
*
* @param testContext Test context
* @param mdx MDX query
*/
private void checkQuery(TestContext testContext, String mdx) {
Result result = testContext.executeQuery(mdx);
final SchemaReader schemaReader =
testContext.getConnection().getSchemaReader();
for (Axis axis : result.getAxes()) {
for (Position position : axis.getPositions()) {
for (Member member : position) {
final Member accessControlledParent =
schemaReader.getMemberParent(member);
if (member.getParentMember() == null) {
assertNull(accessControlledParent);
}
final Member[] accessControlledChildren =
schemaReader.getMemberChildren(member);
assertNotNull(accessControlledChildren);
}
}
}
}

/**
Expand Down Expand Up @@ -621,7 +653,8 @@ public void testRollupPolicySimultaneous() {
private void rollupPolicySimultaneous(
Role.RollupPolicy policy,
String v1,
String v2, String v3)
String v2,
String v3)
{
TestContext testContext =
TestContext.create(
Expand Down Expand Up @@ -807,6 +840,7 @@ public void testUnionRole() {
"Row #0: 3,583\n" +
"Row #0: 3,583\n" +
"Row #0: 124,366\n"));
checkQuery(testContext.withRole("Role1,Role2"), mdx);
}

/**
Expand Down Expand Up @@ -839,21 +873,22 @@ public void testNonEmptyAccess() {
"{[Gender].[All Gender], [Product].[All Products].[Drink]}\n" +
"Row #0: 24,597\n");

testContext.assertQueryReturns(
final String mdx =
"select {[Measures].[Unit Sales]} ON COLUMNS, " +
" Crossjoin({[Gender].[All Gender]}, " +
"[Product].[All Products].Children) ON ROWS " +
"from [Sales]",
expected);
"from [Sales]";
testContext.assertQueryReturns(mdx, expected);
checkQuery(testContext, mdx);

// with bug 1888821, non empty crossjoin did not return the correct
// list
testContext.assertQueryReturns(
"select {[Measures].[Unit Sales]} ON COLUMNS, " +
"NON EMPTY Crossjoin({[Gender].[All Gender]}, " +
"[Product].[All Products].Children) ON ROWS " +
"from [Sales]",
expected);
final String mdx2 = "select {[Measures].[Unit Sales]} ON COLUMNS, " +
"NON EMPTY Crossjoin({[Gender].[All Gender]}, " +
"[Product].[All Products].Children) ON ROWS " +
"from [Sales]";
testContext.assertQueryReturns(mdx2, expected);
checkQuery(testContext, mdx2);
}

public void testNonEmptyAccessLevelMembers() {
Expand Down Expand Up @@ -882,21 +917,21 @@ public void testNonEmptyAccessLevelMembers() {
"{[Gender].[All Gender], [Product].[All Products].[Drink]}\n" +
"Row #0: 24,597\n");

testContext.assertQueryReturns(
"select {[Measures].[Unit Sales]} ON COLUMNS, " +
" Crossjoin({[Gender].[All Gender]}, " +
"[Product].[Product Family].Members) ON ROWS " +
"from [Sales]",
expected);
final String mdx = "select {[Measures].[Unit Sales]} ON COLUMNS, " +
" Crossjoin({[Gender].[All Gender]}, " +
"[Product].[Product Family].Members) ON ROWS " +
"from [Sales]";
testContext.assertQueryReturns(mdx, expected);
checkQuery(testContext, mdx);

// with bug 1888821, <Level>.members inside non empty crossjoin did not
// return the correct list
testContext.assertQueryReturns(
"select {[Measures].[Unit Sales]} ON COLUMNS, " +
"NON EMPTY Crossjoin({[Gender].[All Gender]}, " +
"[Product].[Product Family].Members) ON ROWS " +
"from [Sales]",
expected);
final String mdx2 = "select {[Measures].[Unit Sales]} ON COLUMNS, " +
"NON EMPTY Crossjoin({[Gender].[All Gender]}, " +
"[Product].[Product Family].Members) ON ROWS " +
"from [Sales]";
testContext.assertQueryReturns(mdx2, expected);
checkQuery(testContext, mdx2);
}

/**
Expand All @@ -914,7 +949,9 @@ public void testGoodman() {

// Note that total for [Store].[All Stores] and [Store].[USA] is sum
// of visible children [Store].[CA] and [Store].[OR].[Portland].
goodmanContext(Role.RollupPolicy.PARTIAL).assertQueryReturns(
final TestContext testContext =
goodmanContext(Role.RollupPolicy.PARTIAL);
testContext.assertQueryReturns(
query,
fold("Axis #0:\n" +
"{[Time].[1997]}\n" +
Expand Down Expand Up @@ -992,6 +1029,7 @@ public void testGoodman() {
"Row #6: 25,635\n" +
"Row #7: 2,117\n" +
"Row #8: \n"));
checkQuery(testContext, query);
}

private static TestContext goodmanContext(final Role.RollupPolicy policy) {
Expand Down Expand Up @@ -1056,30 +1094,78 @@ public void testPartialRollupParentChildHierarchy() {
+ " </SchemaGrant>\n"
+ "</Role>").
withRole("Buggy Role");

final String mdx = "select\n"
+ " {[Measures].[Number of Employees]} on columns,\n"
+ " {[Store]} on rows\n"
+ "from HR";
testContext.assertQueryReturns(
"select\n"
+ " {[Measures].[Number of Employees]} on columns,\n"
+ " {[Store]} on rows\n"
+ "from HR",
mdx,
fold("Axis #0:\n" +
"{}\n" +
"Axis #1:\n" +
"{[Measures].[Number of Employees]}\n" +
"Axis #2:\n" +
"{[Store].[All Stores]}\n" +
"Row #0: 1\n"));
checkQuery(testContext, mdx);

final String mdx2 = "select\n"
+ " {[Measures].[Number of Employees]} on columns,\n"
+ " {[Employees]} on rows\n"
+ "from HR";
testContext.assertQueryReturns(
"select\n"
+ " {[Measures].[Number of Employees]} on columns,\n"
+ " {[Employees]} on rows\n"
+ "from HR",
mdx2,
fold("Axis #0:\n" +
"{}\n" +
"Axis #1:\n" +
"{[Measures].[Number of Employees]}\n" +
"Axis #2:\n" +
"{[Employees].[All Employees]}\n" +
"Row #0: 1\n"));
checkQuery(testContext, mdx2);
}

/**
* Test case for
* <a href="http://jira.pentaho.com/browse/BISERVER-1574">BISERVER-1574,
* "Cube role rollupPolicy='partial' failure"</a>. The problem was a
* NullPointerException in
* {@link SchemaReader#getMemberParent(mondrian.olap.Member)} when called
* on a members returned in a result set. JPivot calls that method but
* Mondrian normally does not.
*/
public void testBugBiserver1574() {
final TestContext testContext =
TestContext.create(
null, null, null, null, null,
"<Role name=\"role1\">\n"
+ " <SchemaGrant access=\"none\">\n"
+ " <CubeGrant cube=\"Warehouse\" access=\"all\">\n"
+ " <HierarchyGrant hierarchy=\"[Store Size in SQFT]\" access=\"custom\" rollupPolicy=\"partial\">\n"
+ " <MemberGrant member=\"[Store Size in SQFT].[20319]\" access=\"all\"/>\n"
+ " <MemberGrant member=\"[Store Size in SQFT].[21215]\" access=\"none\"/>\n"
+ " </HierarchyGrant>\n"
+ " <HierarchyGrant hierarchy=\"[Store Type]\" access=\"custom\" rollupPolicy=\"partial\">\n"
+ " <MemberGrant member=\"[Store Type].[Supermarket]\" access=\"all\"/>\n"
+ " </HierarchyGrant>\n"
+ " </CubeGrant>\n"
+ " </SchemaGrant>\n"
+ "</Role>").withRole("role1");
final String mdx =
"select {([Measures].[Store Invoice], [Store Size in SQFT].[All Store Size in SQFTs])} ON COLUMNS,\n"
+ " {[Warehouse].[All Warehouses]} ON ROWS\n"
+ "from [Warehouse]";
checkQuery(testContext, mdx);
testContext.assertQueryReturns(
mdx,
fold("Axis #0:\n" +
"{}\n" +
"Axis #1:\n" +
"{[Measures].[Store Invoice], [Store Size in SQFT].[All Store Size in SQFTs]}\n" +
"Axis #2:\n" +
"{[Warehouse].[All Warehouses]}\n" +
"Row #0: 4,042.96\n"));
}
}

Expand Down

0 comments on commit 1d1b52c

Please sign in to comment.