Skip to content

Commit

Permalink
Tests for compound filters
Browse files Browse the repository at this point in the history
git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@241 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed May 19, 2009
1 parent 4d5decd commit 5b2a39d
Showing 1 changed file with 56 additions and 2 deletions.
58 changes: 56 additions & 2 deletions testsrc/org/olap4j/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class ConnectionTest extends TestCase {
private static final boolean IS_JDK_16 =
System.getProperty("java.version").startsWith("1.6.");

private static final boolean SINGLE_FILTER = true;

/**
* Simple strategy to prevent connection leaks: each test that needs a
* connection assigns it to this field, and {@link #tearDown()} closes it
Expand Down Expand Up @@ -442,8 +444,9 @@ public void testAxes() throws SQLException {
CellSet cellSet =
olapStatement.executeOlapQuery(
"SELECT {[Measures].[Unit Sales]} on 0,\n"
+ "{[Store].Children} on 1\n"
+ "FROM [Sales]");
+ "{[Store].Children} on 1\n"
+ "FROM [Sales]\n"
+ "WHERE ([Time].[1997].[Q1], [Gender].[F])");
List<CellSetAxis> axesList = cellSet.getAxes();
assertEquals(2, axesList.size());
final Member rowsMember =
Expand All @@ -456,6 +459,46 @@ public void testAxes() throws SQLException {
assertTrue(
columnsMember.getUniqueName(),
!(columnsMember instanceof Measure));

// filter axis
final CellSetAxis filterAxis = cellSet.getFilterAxis();
assertEquals(1, filterAxis.getPositionCount());
final List<Position> positions = filterAxis.getPositions();
assertEquals(1, positions.size());
final Position pos0 = positions.get(0);
assertEquals(0, pos0.getOrdinal());
// All members not on other axes are returned on the filter axis.
// REVIEW: Is this desired behavior?
assertEquals(11, pos0.getMembers().size());
assertEquals(
"[Gender].[All Gender].[F]",
pos0.getMembers().get(8).getUniqueName());
}

public void testCompoundSlicer() throws SQLException {
connection = tester.createConnection();
OlapConnection olapConnection =
tester.getWrapper().unwrap(connection, OlapConnection.class);
OlapStatement statement = olapConnection.createStatement();

CellSet cellSet =
statement.executeOlapQuery(
"SELECT {[Measures].[Unit Sales]} on 0,\n"
+ "{[Store].Children} on 1\n"
+ "FROM [Sales]\n"
+ "WHERE [Time].[1997].[Q1] * [Gender].Members");
List<CellSetAxis> axesList = cellSet.getAxes();
assertEquals(2, axesList.size());
final CellSetAxis filterAxis = cellSet.getFilterAxis();
if (SINGLE_FILTER) {
assertEquals(1, filterAxis.getPositionCount());
return;
}
assertEquals(3, filterAxis.getPositionCount());
final List<Position> filterPositions = filterAxis.getPositions();
assertEquals(3, filterPositions.size());
assertEquals(2, filterPositions.get(2).getMembers().size());
assertEquals("F", filterPositions.get(2).getMembers().get(1).getName());
}

public void testInvalidStatement() throws SQLException {
Expand Down Expand Up @@ -765,6 +808,10 @@ private void checkCellSetMetaData(
if (cellSet != null) {
assertEquals(
cellSet.getFilterAxis().getAxisMetaData(), axisMetaData);
assertEquals(
1, cellSet.getFilterAxis().getPositionCount());
assertEquals(
1, cellSet.getFilterAxis().getPositions().size());
}
}

Expand Down Expand Up @@ -1781,6 +1828,13 @@ public void testParentChild() throws ClassNotFoundException, SQLException {
assertEquals(1, parent.getDepth());
assertEquals(member2.getLevel(), parent.getLevel());
assertEquals(member1, parent);
final CellSetAxis filterAxis = cellSet.getFilterAxis();
assertEquals(1, filterAxis.getPositionCount());
final List<Position> positions = filterAxis.getPositions();
assertEquals(1, positions.size());
assertEquals(0, positions.get(0).getOrdinal());
// All members not on other axes are returned on the filter axis.
assertEquals(6, positions.get(0).getMembers().size());
}

/**
Expand Down

0 comments on commit 5b2a39d

Please sign in to comment.