diff --git a/testsrc/org/olap4j/OlapTest.java b/testsrc/org/olap4j/OlapTest.java index 6823b54..1b1da90 100644 --- a/testsrc/org/olap4j/OlapTest.java +++ b/testsrc/org/olap4j/OlapTest.java @@ -747,6 +747,99 @@ public void testSelectionContext() throws Exception { s); } + public void testComplexSelectionContext() throws Exception { + Cube cube = getFoodmartCube("Sales"); + if (cube == null) { + fail("Could not find Sales cube"); + } + Query query = new Query("my query", cube); + + // create selections + QueryDimension productDimension = query.getDimension("Product"); + + + productDimension.include( + Selection.Operator.MEMBER, "Product", "All Products"); + productDimension.include( + Selection.Operator.CHILDREN, "Product", "All Products"); + QueryDimension timeDimension = query.getDimension("Time"); + Selection selection = timeDimension.include( + Selection.Operator.CHILDREN, "Time", "Year", "1997"); + selection.addContext( + productDimension.createSelection( + "Product", "All Products")); + + QueryDimension measuresDimension = query.getDimension("Measures"); + measuresDimension.include("Measures", "Store Sales"); + + query.getAxis(Axis.ROWS).addDimension(productDimension); + query.getAxis(Axis.ROWS).addDimension(timeDimension); + + query.getAxis(Axis.COLUMNS).addDimension(measuresDimension); + + query.validate(); + + assertEquals( + Axis.ROWS, + productDimension.getAxis().getLocation()); + assertEquals( + Axis.ROWS, + timeDimension.getAxis().getLocation()); + assertEquals( + Axis.COLUMNS, + measuresDimension.getAxis().getLocation()); + + SelectNode mdx = query.getSelect(); + String mdxString = mdx.toString(); + TestContext.assertEqualsVerbose( + "SELECT\n" + + "{[Measures].[Store Sales]} ON COLUMNS,\n" + + "Hierarchize(Union(CrossJoin({[Product].[All Products]}, [Time].[1997].Children), CrossJoin([Product].[All Products].Children, [Time].[1997].Children))) ON ROWS\n" + + "FROM [Sales]", + mdxString); + + CellSet results = query.execute(); + String s = TestContext.toString(results); + TestContext.assertEqualsVerbose( + "Axis #0:\n" + + "{}\n" + + "Axis #1:\n" + + "{[Measures].[Store Sales]}\n" + + "Axis #2:\n" + + "{[Product].[All Products], [Time].[1997].[Q1]}\n" + + "{[Product].[All Products], [Time].[1997].[Q2]}\n" + + "{[Product].[All Products], [Time].[1997].[Q3]}\n" + + "{[Product].[All Products], [Time].[1997].[Q4]}\n" + + "{[Product].[Drink], [Time].[1997].[Q1]}\n" + + "{[Product].[Drink], [Time].[1997].[Q2]}\n" + + "{[Product].[Drink], [Time].[1997].[Q3]}\n" + + "{[Product].[Drink], [Time].[1997].[Q4]}\n" + + "{[Product].[Food], [Time].[1997].[Q1]}\n" + + "{[Product].[Food], [Time].[1997].[Q2]}\n" + + "{[Product].[Food], [Time].[1997].[Q3]}\n" + + "{[Product].[Food], [Time].[1997].[Q4]}\n" + + "{[Product].[Non-Consumable], [Time].[1997].[Q1]}\n" + + "{[Product].[Non-Consumable], [Time].[1997].[Q2]}\n" + + "{[Product].[Non-Consumable], [Time].[1997].[Q3]}\n" + + "{[Product].[Non-Consumable], [Time].[1997].[Q4]}\n" + + "Row #0: 139,628.35\n" + + "Row #1: 132,666.27\n" + + "Row #2: 140,271.89\n" + + "Row #3: 152,671.62\n" + + "Row #4: 11,585.80\n" + + "Row #5: 11,914.58\n" + + "Row #6: 11,994.00\n" + + "Row #7: 13,341.83\n" + + "Row #8: 101,261.32\n" + + "Row #9: 95,436.00\n" + + "Row #10: 101,807.60\n" + + "Row #11: 110,530.67\n" + + "Row #12: 26,781.23\n" + + "Row #13: 25,315.69\n" + + "Row #14: 26,470.29\n" + + "Row #15: 28,799.12\n", + s); + } public void testSortAxis() { try { Cube cube = getFoodmartCube("Sales");