Skip to content

Commit

Permalink
Add unit test for construction of an MDX statement via language objec…
Browse files Browse the repository at this point in the history
…t model.

git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@36 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
jsichi committed Nov 5, 2007
1 parent f689ac9 commit b066d25
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 10 deletions.
1 change: 0 additions & 1 deletion doc/tasks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Testing
* Test methods in OlapResultAxisMetaData (see ConnectionTest.testOlapResultAxisMetaData)
* Test cell and dimension properties (in ConnectionTest, see "todo: submit a query with cell and dimension properties, and make sure the properties appear in the result set")
* Test scrolling (in ConnectionTest, see "todo: submit a query where you ask for different scrolling")
* Test building parse tree (in ConnectionTest see "build parse tree (todo) ")
* Test axis name uniqueness (in ConnectionTest, see "test that get error if axes do not have unique names (todo)")

Not in scope for olap4j 0.9
Expand Down
92 changes: 83 additions & 9 deletions testsrc/org/olap4j/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
import org.olap4j.metadata.Cube;
import org.olap4j.metadata.Dimension;
import org.olap4j.metadata.Schema;
import org.olap4j.mdx.SelectNode;
import org.olap4j.mdx.ParseTreeWriter;
import org.olap4j.mdx.*;
import org.olap4j.mdx.parser.MdxParser;
import org.olap4j.test.TestContext;
import org.olap4j.type.Type;
import org.olap4j.type.*;
import org.olap4j.driver.xmla.XmlaOlap4jDriver;
import org.xml.sax.SAXException;
import mondrian.tui.XmlaSupport;
Expand Down Expand Up @@ -648,7 +647,12 @@ public void testParsing() throws SQLException {
"where [Time].[1997].[Q4]");

// unparse
checkUnparsedMdx(select);

// test that get error if axes do not have unique names (todo)
}

private void checkUnparsedMdx(SelectNode select) {
StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
ParseTreeWriter parseTreeWriter = new ParseTreeWriter(pw);
Expand All @@ -665,17 +669,84 @@ public void testParsing() throws SQLException {
"WHERE [Time].[1997].[Q4]"),
mdx);

// build parse tree (todo)

// test that get error if axes do not have unique names (todo)
}

/**
* Tests creation of an MDX query from a parse tree. Build the parse tree
* programmatically.
*/
public void testUnparsing() {

// Note that the select statement constructed here is equivalent
// to the one in testParsing.
SelectNode select = new SelectNode(
null,
new ArrayList<ParseTreeNode>(),
new ArrayList<AxisNode>(),
new IdentifierNode(new IdentifierNode.Segment("sales")),
new AxisNode(
null,
false,
null,
Axis.SLICER,
new ArrayList<IdentifierNode>()),
new ArrayList<IdentifierNode>());
select.getWithList().add(
new WithMemberNode(
null,
new IdentifierNode(
new IdentifierNode.Segment("Measures"),
new IdentifierNode.Segment("Foo")),
new IdentifierNode(
new IdentifierNode.Segment("Measures"),
new IdentifierNode.Segment("Bar")),
Arrays.asList(
new PropertyValueNode [] {
new PropertyValueNode(
null,
"FORMAT_STRING",
LiteralNode.createString(
null,
"xxx"))
})));
select.getAxisList().add(
new AxisNode(
null,
false,
new CallNode(
null,
"{}",
Syntax.Braces,
Arrays.asList(
new ParseTreeNode [] {
new IdentifierNode(
new IdentifierNode.Segment("Gender"))
})),
Axis.COLUMNS,
new ArrayList<IdentifierNode>()));
select.getAxisList().add(
new AxisNode(
null,
false,
new CallNode(
null,
"{}",
Syntax.Braces,
new CallNode(
null,
"Children",
Syntax.Property,
new IdentifierNode(
new IdentifierNode.Segment("Store"))
)),
Axis.ROWS,
new ArrayList<IdentifierNode>()));
select.getSlicerAxis().setExpression(
new IdentifierNode(
new IdentifierNode.Segment("Time"),
new IdentifierNode.Segment("1997"),
new IdentifierNode.Segment("Q4")));

checkUnparsedMdx(select);
}

/**
Expand Down Expand Up @@ -758,6 +829,9 @@ public boolean isMondrian() {
}

public static String getDefaultConnectString() {
if (false) {
return "jdbc:mondrian:Jdbc='jdbc:derby:/home/jvs/open/mondrian/demo/derby/foodmart';JdbcUser=sa;JdbcPassword=sa;Catalog='file:///home/jvs/open/mondrian/demo/FoodMart.xml';JdbcDrivers=org.apache.derby.jdbc.EmbeddedDriver;";
}
if (true) {
return "jdbc:mondrian:Jdbc='jdbc:odbc:MondrianFoodMart';Catalog='file://c:/open/mondrian/demo/FoodMart.xml';JdbcDrivers=sun.jdbc.odbc.JdbcOdbcDriver;";
} else {
Expand All @@ -768,8 +842,8 @@ public static String getDefaultConnectString() {
public static final String DRIVER_CLASS_NAME = "mondrian.olap4j.MondrianOlap4jDriver";

public static final String DRIVER_URL_PREFIX = "jdbc:mondrian:";
private static final String USER = "user";
private static final String PASSWORD = "password";
private static final String USER = "sa";
private static final String PASSWORD = "sa";
}

/**
Expand Down

0 comments on commit b066d25

Please sign in to comment.