|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmondrian.test.TestContext
public class TestContext
TestContext
is a singleton class which contains the information
necessary to run mondrian tests (otherwise we'd have to pass this
information into the constructor of TestCases).
The singleton instance (retrieved via the instance()
method)
contains a connection to the FoodMart database, and runs expressions in the
context of the Sales
cube.
Using the DelegatingTestContext
subclass, you can create derived
classes which use a different connection or a different cube.
Nested Class Summary | |
---|---|
static class |
TestContext.HighCardDynamicSchemaProcessor
Schema processor that flags dimensions as high-cardinality if they appear in the list of values in the MondrianProperties.TestHighCardinalityDimensionList property. |
static class |
TestContext.SafeString
Wrapper around a string that indicates that all line endings have been converted to platform-specific line endings. |
static class |
TestContext.SnoopingSchemaProcessor
|
Field Summary | |
---|---|
protected static java.lang.String |
nl
|
Constructor Summary | |
---|---|
protected |
TestContext()
Creates a TestContext. |
Method Summary | |
---|---|
static java.lang.String |
allHiers()
|
static java.lang.String |
allHiersExcept(java.lang.String... hiers)
Generates a string containing all dimensions except those given. |
void |
assertAxisReturns(java.lang.String expression,
java.lang.String expected)
Executes a query with a given expression on an axis, and asserts that it returns the expected string. |
void |
assertAxisThrows(java.lang.String expression,
java.lang.String pattern)
Executes a query with a given expression on an axis, and asserts that it throws an error which matches a particular pattern. |
static void |
assertEqualsVerbose(java.lang.String expected,
java.lang.String actual)
Checks that an actual string matches an expected string. |
static void |
assertEqualsVerbose(java.lang.String expected,
java.lang.String actual,
boolean java,
java.lang.String message)
Checks that an actual string matches an expected string. |
static void |
assertEqualsVerbose(TestContext.SafeString safeExpected,
java.lang.String actual,
boolean java,
java.lang.String message)
Checks that an actual string matches an expected string. |
void |
assertExprDependsOn(java.lang.String expr,
java.lang.String hierList)
Asserts that an MDX expression depends upon a given list of dimensions. |
void |
assertExprReturns(java.lang.String expression,
java.lang.String expected)
Executes an expression and asserts that it returns a given result. |
void |
assertExprThrows(java.lang.String expression,
java.lang.String pattern)
Executes an expression, and asserts that it gives an error which contains a particular pattern. |
void |
assertMatchesVerbose(java.util.regex.Pattern expected,
java.lang.String actual)
Checks that an actual string matches an expected pattern. |
void |
assertMemberExprDependsOn(java.lang.String expr,
java.lang.String dimList)
Asserts that an MDX member-valued depends upon a given list of dimensions. |
void |
assertQueryReturns(java.lang.String query,
java.lang.String desiredResult)
Executes a query and checks that the result is a given string. |
void |
assertQueryThrows(java.lang.String queryString,
java.lang.String pattern)
Executes a query, and asserts that it throws an exception which contains the given pattern. |
void |
assertSetExprDependsOn(java.lang.String expr,
java.lang.String dimList)
Asserts that an MDX set-valued expression depends upon a given list of dimensions. |
void |
assertSimpleQuery()
Executes a very simple query. |
void |
assertSqlEquals(java.lang.String expectedSql,
java.lang.String actualSql,
int expectedRows)
Checks that expected SQL equals actual SQL. |
(package private) static java.lang.Iterable<Cell> |
cellIter(CellSet cellSet)
Returns an iterator over cells in an olap4j cell set. |
(package private) static java.lang.Iterable<Cell> |
cellIter(Result result)
Returns an iterator over cells in a result. |
static void |
checkThrowable(java.lang.Throwable throwable,
java.lang.String pattern)
|
void |
clearConnection()
|
java.lang.String |
compileExpression(java.lang.String expression,
boolean scalar)
Compiles a scalar expression in the context of the default cube. |
static boolean |
contains(java.lang.String[] a,
java.lang.String s)
|
static TestContext |
create(java.lang.String schema)
Creates a TestContext which contains the given schema text. |
static TestContext |
create(java.lang.String parameterDefs,
java.lang.String cubeDefs,
java.lang.String virtualCubeDefs,
java.lang.String namedSetDefs,
java.lang.String udfDefs,
java.lang.String roleDefs)
Creates a TestContext which is based on a variant of the FoodMart schema, which parameter, cube, named set, and user-defined function definitions added. |
static TestContext |
createSubstitutingCube(java.lang.String cubeName,
java.lang.String dimensionDefs)
Creates a TestContext, adding hierarchy definitions to a cube definition. |
static TestContext |
createSubstitutingCube(java.lang.String cubeName,
java.lang.String dimensionDefs,
java.lang.String memberDefs)
Creates a TestContext, adding hierarchy and calculated member definitions to a cube definition. |
static TestContext |
createSubstitutingCube(java.lang.String cubeName,
java.lang.String dimensionDefs,
java.lang.String memberDefs,
java.lang.String namedSetDefs)
Creates a TestContext, adding hierarchy and calculated member definitions to a cube definition. |
boolean |
databaseIsValid()
Tests whether the database is valid. |
Axis |
executeAxis(java.lang.String expression)
Executes a query with a given expression on an axis, and returns the whole axis. |
Cell |
executeExprRaw(java.lang.String expression)
Executes the expression in the context of the cube indicated by cubeName , and returns the result as a Cell. |
Cell |
executeExprRaw(java.lang.String expression,
java.lang.String cubeName)
Executes the expression in the default cube, and returns the result as a Cell. |
CellSet |
executeOlap4jQuery(java.lang.String queryString)
Executes a query using olap4j. |
Result |
executeQuery(java.lang.String queryString)
Executes a query. |
Member |
executeSingletonAxis(java.lang.String expression)
Executes a set expression which is expected to return 0 or 1 members. |
static TestContext.SafeString |
fold(java.lang.String string)
Replaces line-endings in a string with the platform-dependent equivalent. |
Connection |
getConnection()
Returns the connection to run queries. |
java.lang.String |
getConnectString()
Returns the connect string by which the unit tests can talk to the FoodMart database. |
static java.lang.String |
getDefaultConnectString()
Constructs a connect string by which the unit tests can talk to the FoodMart database. |
java.lang.String |
getDefaultCubeName()
Returns the name of the default cube. |
Dialect |
getDialect()
|
static Dialect |
getFakeDialect()
Creates a dialect without using a connection. |
Connection |
getFoodMartConnection()
Returns a connection to the FoodMart database. |
Connection |
getFoodMartConnection(boolean useSchemaPool)
Returns a connection to the FoodMart database, optionally not from the schema pool. |
Connection |
getFoodMartConnection(java.lang.Class dynProcClass)
Returns a connection to the FoodMart database with a dynamic schema processor and disables use of RolapSchema Pool. |
Connection |
getFoodMartConnection(java.lang.String catalogContent)
Returns a connection to the FoodMart database with an inline schema. |
Connection |
getFoodMartConnection(java.lang.String catalogContent,
java.lang.String role)
Returns a connection to the FoodMart database with an inline schema and a given role. |
Util.PropertyList |
getFoodMartConnectionProperties()
|
static java.lang.String |
getFoodMartSchema(java.lang.String parameterDefs,
java.lang.String cubeDefs,
java.lang.String virtualCubeDefs,
java.lang.String namedSetDefs,
java.lang.String udfDefs,
java.lang.String roleDefs)
Returns a the XML of the foodmart schema with added parameters and cube definitions. |
java.lang.String |
getFoodMartSchemaSubstitutingCube(java.lang.String cubeName,
java.lang.String dimensionDefs,
java.lang.String memberDefs)
Returns a the XML of the foodmart schema, adding dimension definitions to the definition of a given cube. |
java.lang.String |
getFoodMartSchemaSubstitutingCube(java.lang.String cubeName,
java.lang.String dimensionDefs,
java.lang.String memberDefs,
java.lang.String namedSetDefs)
Returns a the XML of the foodmart schema, adding dimension definitions to the definition of a given cube. |
OlapConnection |
getOlap4jConnection()
|
static java.lang.String |
getRawFoodMartSchema()
Returns the definition of the "FoodMart" schema as stored in FoodMart.xml . |
java.util.List<java.lang.Exception> |
getSchemaWarnings()
Creates a FoodMart connection with "Ignore=true" and returns the list of warnings in the schema. |
static java.lang.String |
getStackTrace(java.lang.Throwable e)
Converts a Throwable to a stack trace. |
java.io.PrintWriter |
getWriter()
Returns the output writer. |
static java.lang.String |
hierarchyName(java.lang.String dimension,
java.lang.String hierarchy)
|
static TestContext |
instance()
Retrieves the singleton (instantiating if necessary). |
static java.lang.String |
toString(java.util.List<Position> positions)
Converts a set of positions into a string. |
static java.lang.String |
toString(Result result)
Converts a Result to text in traditional format. |
static java.lang.String |
unfold(java.lang.String string)
Reverses the effect of fold(java.lang.String) ; converts platform-specific line
endings in a string info linefeeds. |
java.lang.String |
upgradeActual(java.lang.String actual)
Massages the actual result of executing a query to handle differences in unique names betweeen old and new behavior. |
java.lang.String |
upgradeQuery(java.lang.String queryString)
Massages an MDX query to handle differences in unique names betweeen old and new behavior. |
TestContext |
withCube(java.lang.String cubeName)
Returns a TestContext similar to this one, but using the given cube as default for tests such as assertExprReturns(String, String) . |
TestContext |
withRole(java.lang.String roleName)
Returns a TestContext similar to this one, but using the given role. |
TestContext |
withScenario()
Returns a test context whose getOlap4jConnection() method always
returns the same connection object, and which has an active
Scenario , thus enabling writeback. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final java.lang.String nl
Constructor Detail |
---|
protected TestContext()
Method Detail |
---|
public static TestContext instance()
public final java.lang.String getConnectString()
In the base class, the result is the same as the static method
getDefaultConnectString()
. If a derived class overrides
getFoodMartConnectionProperties()
, the result of this method
will change also.
public static java.lang.String getDefaultConnectString()
MondrianProperties.TestConnectString
, if it is
set.MondrianProperties.FoodmartJdbcURL
is set, this
overrides the Jdbc
property.catalog
URL is unset or invalid, it assumes that
we are at the root of the source tree, and references
demo/FoodMart.xml
public Connection getConnection()
By default, returns a connection to the FoodMart database.
public void clearConnection()
public Connection getFoodMartConnection()
public final Connection getFoodMartConnection(java.lang.Class dynProcClass)
public Util.PropertyList getFoodMartConnectionProperties()
public Connection getFoodMartConnection(java.lang.String catalogContent)
public Connection getFoodMartConnection(java.lang.String catalogContent, java.lang.String role)
public Connection getFoodMartConnection(boolean useSchemaPool)
useSchemaPool
- If false, use a fresh connection, not one from the
schema poolpublic static java.lang.String getFoodMartSchema(java.lang.String parameterDefs, java.lang.String cubeDefs, java.lang.String virtualCubeDefs, java.lang.String namedSetDefs, java.lang.String udfDefs, java.lang.String roleDefs)
public static java.lang.String getRawFoodMartSchema()
FoodMart.xml
.
public java.lang.String getFoodMartSchemaSubstitutingCube(java.lang.String cubeName, java.lang.String dimensionDefs, java.lang.String memberDefs)
public java.lang.String getFoodMartSchemaSubstitutingCube(java.lang.String cubeName, java.lang.String dimensionDefs, java.lang.String memberDefs, java.lang.String namedSetDefs)
public Result executeQuery(java.lang.String queryString)
queryString
- Query stringpublic CellSet executeOlap4jQuery(java.lang.String queryString) throws java.sql.SQLException
java.sql.SQLException
static java.lang.Iterable<Cell> cellIter(Result result)
static java.lang.Iterable<Cell> cellIter(CellSet cellSet)
public void assertQueryThrows(java.lang.String queryString, java.lang.String pattern)
queryString
- Query stringpattern
- Pattern which exception must matchpublic void assertExprThrows(java.lang.String expression, java.lang.String pattern)
public java.lang.String getDefaultCubeName()
Tests which evaluate scalar expressions, such as
assertExprReturns(String, String)
, generate queries against this
cube.
public Cell executeExprRaw(java.lang.String expression)
cubeName
, and returns the result as a Cell.
expression
- The expression to evaluate
public Cell executeExprRaw(java.lang.String expression, java.lang.String cubeName)
expression
- The expression to evaluatecubeName
- Cube name
public void assertExprReturns(java.lang.String expression, java.lang.String expected)
public void assertAxisReturns(java.lang.String expression, java.lang.String expected)
public java.lang.String upgradeActual(java.lang.String actual)
Even though the new naming is not enabled by default, reference logs should be in terms of the new naming.
actual
- Actual result
MondrianProperties.SsasCompatibleNaming
public java.lang.String upgradeQuery(java.lang.String queryString)
The main difference addressed is with level naming. The problem arises when dimension, hierarchy and level have the same name:
So, upgradeQuery("[Gender]")
returns
"[Gender].[Gender]" for old behavior,
"[Gender].[Gender].[Gender]" for new behavior.
queryString
- Original query
MondrianProperties.SsasCompatibleNaming
public java.lang.String compileExpression(java.lang.String expression, boolean scalar)
expression
- The expression to evaluatescalar
- Whether the expression is scalar
public Member executeSingletonAxis(java.lang.String expression)
expression
- Expression string
public Axis executeAxis(java.lang.String expression)
public void assertAxisThrows(java.lang.String expression, java.lang.String pattern)
public static void checkThrowable(java.lang.Throwable throwable, java.lang.String pattern)
public java.io.PrintWriter getWriter()
public void assertQueryReturns(java.lang.String query, java.lang.String desiredResult)
public void assertSimpleQuery()
This forces the schema to be loaded and performs a basic sanity check. If this is a negative schema test, causes schema validation errors to be thrown.
public static void assertEqualsVerbose(java.lang.String expected, java.lang.String actual)
If they do not, throws a ComparisonFailure
and
prints the difference, including the actual string as an easily pasted
Java string literal.
public static void assertEqualsVerbose(java.lang.String expected, java.lang.String actual, boolean java, java.lang.String message)
If they do not, throws a ComparisonFailure
and prints the
difference, including the actual string as an easily pasted Java string
literal.
expected
- Expected stringactual
- Actual stringjava
- Whether to generate actual string as a Java string literal
if the values are not equalmessage
- Message to display, optionalpublic static void assertEqualsVerbose(TestContext.SafeString safeExpected, java.lang.String actual, boolean java, java.lang.String message)
If they do not, throws a ComparisonFailure
and prints the
difference, including the actual string as an easily pasted Java string
literal.
safeExpected
- Expected string, where all line endings have been
converted into platform-specific line endingsactual
- Actual stringjava
- Whether to generate actual string as a Java string literal
if the values are not equalmessage
- Message to display, optionalpublic void assertMatchesVerbose(java.util.regex.Pattern expected, java.lang.String actual)
ComparisonFailure
and prints the
difference, including the actual string as an easily pasted Java string
literal.
public static java.lang.String getStackTrace(java.lang.Throwable e)
Throwable
to a stack trace.
public static java.lang.String toString(Result result)
Result
to text in traditional format.
For more exotic formats, see
CellSetFormatter
.
result
- Query result
public TestContext withScenario()
getOlap4jConnection()
method always
returns the same connection object, and which has an active
Scenario
, thus enabling writeback.
public static java.lang.String toString(java.util.List<Position> positions)
public static TestContext.SafeString fold(java.lang.String string)
string
- String whose line endings are to be made platform-
dependent. Typically these are constant "expected
value" string expressions where the linefeed is
represented as linefeed "\n", but sometimes this method
will receive strings created dynamically where the line
endings are already appropriate for the platform.
public static java.lang.String unfold(java.lang.String string)
fold(java.lang.String)
; converts platform-specific line
endings in a string info linefeeds.
string
- String where all linefeeds have been converted to
platform-specific (CR+LF on Windows, LF on Unix/Linux)
public Dialect getDialect()
public static Dialect getFakeDialect()
public void assertSqlEquals(java.lang.String expectedSql, java.lang.String actualSql, int expectedRows) throws java.lang.Exception
java.lang.Exception
public void assertSetExprDependsOn(java.lang.String expr, java.lang.String dimList)
public void assertMemberExprDependsOn(java.lang.String expr, java.lang.String dimList)
public void assertExprDependsOn(java.lang.String expr, java.lang.String hierList)
public static TestContext create(java.lang.String parameterDefs, java.lang.String cubeDefs, java.lang.String virtualCubeDefs, java.lang.String namedSetDefs, java.lang.String udfDefs, java.lang.String roleDefs)
parameterDefs
- Parameter definitions. If not null, the string is
is inserted into the schema XML in the appropriate place for
parameter definitions.cubeDefs
- Cube definition(s). If not null, the string is
is inserted into the schema XML in the appropriate place for
cube definitions.virtualCubeDefs
- Definitions of virtual cubes. If not null, the
string is inserted into the schema XML in the appropriate place for
virtual cube definitions.namedSetDefs
- Definitions of named sets. If not null, the string
is inserted into the schema XML in the appropriate place for
named set definitions.udfDefs
- Definitions of user-defined functions. If not null, the
string is inserted into the schema XML in the appropriate place for
UDF definitions.roleDefs
- Definitions of roles
public static TestContext create(java.lang.String schema)
public static TestContext createSubstitutingCube(java.lang.String cubeName, java.lang.String dimensionDefs)
cubeName
- Name of a cube in the schema (cube must exist)dimensionDefs
- String defining dimensions, or null
public static TestContext createSubstitutingCube(java.lang.String cubeName, java.lang.String dimensionDefs, java.lang.String memberDefs)
cubeName
- Name of a cube in the schema (cube must exist)dimensionDefs
- String defining dimensions, or nullmemberDefs
- String defining calculated members, or null
public static TestContext createSubstitutingCube(java.lang.String cubeName, java.lang.String dimensionDefs, java.lang.String memberDefs, java.lang.String namedSetDefs)
cubeName
- Name of a cube in the schema (cube must exist)dimensionDefs
- String defining dimensions, or nullmemberDefs
- String defining calculated members, or nullnamedSetDefs
- String defining named set definitions, or null
public TestContext withRole(java.lang.String roleName)
roleName
- Role name
public TestContext withCube(java.lang.String cubeName)
assertExprReturns(String, String)
.
cubeName
- Cube name
public static java.lang.String allHiersExcept(java.lang.String... hiers)
assertExprDependsOn(String, String)
.
public static boolean contains(java.lang.String[] a, java.lang.String s)
public static java.lang.String allHiers()
public java.util.List<java.lang.Exception> getSchemaWarnings()
public OlapConnection getOlap4jConnection() throws java.sql.SQLException
java.sql.SQLException
public boolean databaseIsValid()
public static java.lang.String hierarchyName(java.lang.String dimension, java.lang.String hierarchy)
|
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |