Skip to content

Commit

Permalink
Added a test to make sure that there are no inherent links between a …
Browse files Browse the repository at this point in the history
…query model object and it's generated MDX object trees.

git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@259 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
lucboudreau committed Jul 7, 2009
1 parent ec7511e commit 9e039d4
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions testsrc/org/olap4j/OlapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.olap4j.metadata.*;
import org.olap4j.query.*;
import org.olap4j.query.QueryDimension.SortOrder;
import org.olap4j.query.Selection.Operator;
import org.olap4j.test.TestContext;

import java.sql.Connection;
Expand Down Expand Up @@ -609,6 +610,77 @@ public void testDimensionsOrder() {
}
}

/**
* This test makes sure that the generated MDX model is not affected
* by subsequent operations performed on the source query model.
*/
public void testQueryVersusParseTreeIndependence() {
try {
Cube cube = getFoodmartCube("Sales");
if (cube == null) {
fail("Could not find Sales cube");
}

// Setup a base query.
Query query = new Query("my query", cube);

QueryDimension productDimension = query.getDimension("Product");
productDimension.select(
Selection.Operator.INCLUDE_CHILDREN, "Product", "Drink");

QueryDimension measuresDimension = query.getDimension("Measures");
measuresDimension.select("Measures", "Store Sales");

query.getAxis(Axis.ROWS).addDimension(productDimension);
query.getAxis(Axis.COLUMNS).addDimension(measuresDimension);

query.validate();

assertEquals(
Axis.ROWS,
productDimension.getAxis().getLocation());
assertEquals(
Axis.COLUMNS,
measuresDimension.getAxis().getLocation());

// These variables are important. We will evaluate those
// to decide if there are links between the MDX and the Query
SelectNode originalMdx = query.getSelect();
String originalMdxString = originalMdx.toString();

TestContext.assertEqualsVerbose(
"SELECT\n"
+ "{[Measures].[Store Sales]} ON COLUMNS,\n"
+ "{{[Product].[All Products].[Drink], [Product].[All Products].[Drink].Children}} ON ROWS\n"
+ "FROM [Sales]",
originalMdxString);

// change selections
measuresDimension.select(
Selection.Operator.SIBLINGS, "Measures", "Customer Count");
productDimension.select(
Selection.Operator.SIBLINGS,
"Product", "All Products", "Drink", "Alcoholic Beverages");

// Add something to crossjoin with
query.getAxis(Axis.COLUMNS).addDimension(
query.getDimension("Gender"));
query.getDimension("Gender").select(Operator.CHILDREN, "Gender",
"All Gender");

query.getAxis(Axis.UNUSED).addDimension(
query.getDimension("Product"));

query.validate();

// Check if the MDX object tree is still the same
assertEquals(originalMdxString, originalMdx.toString());
} catch (Exception e) {
e.printStackTrace();
fail();
}
}

public static void listHierarchies(Dimension dimension) {
// Get a list of hierarchy objects and dump their names
for (Hierarchy hierarchy : dimension.getHierarchies()) {
Expand Down

0 comments on commit 9e039d4

Please sign in to comment.