Search in sources :

Example 6 with Connection

use of mondrian.olap.Connection in project mondrian by pentaho.

the class SchemaVersionTest method testSchema4withVersion.

public void testSchema4withVersion() {
    TestContext testContext = TestContext.instance().withSchema(SCHEMA_4_HEADER + SCHEMA_4_BODY);
    Util.PropertyList connectInfo = testContext.getConnectionProperties();
    try {
        Connection conn = DriverManager.getConnection(connectInfo, null);
        conn.close();
        Assert.fail("No exception thrown for version 4 schema.");
    } catch (MondrianException e) {
        assertTrue(e.getMessage().contains("Schema version"));
    }
}
Also used : Connection(mondrian.olap.Connection) Util(mondrian.olap.Util) MondrianException(mondrian.olap.MondrianException)

Example 7 with Connection

use of mondrian.olap.Connection in project mondrian by pentaho.

the class SchemaVersionTest method testSchema3withVersion.

public void testSchema3withVersion() {
    TestContext testContext = TestContext.instance().withSchema(SCHEMA_3_VHEADER + SCHEMA_3_BODY);
    Util.PropertyList connectInfo = testContext.getConnectionProperties();
    Connection conn = DriverManager.getConnection(connectInfo, null);
    assertNotNull(conn);
    conn.close();
}
Also used : Connection(mondrian.olap.Connection) Util(mondrian.olap.Util)

Example 8 with Connection

use of mondrian.olap.Connection in project mondrian by pentaho.

the class TestContext method assertAxisThrows.

/**
 * Executes a query with a given expression on an axis, and asserts that it
 * throws an error which matches a particular pattern. The expression is
 * evaulated against the default cube.
 */
public void assertAxisThrows(String expression, String pattern) {
    Throwable throwable = null;
    Connection connection = getConnection();
    try {
        final String cubeName = getDefaultCubeName();
        final String queryString = "select {" + expression + "} on columns from " + cubeName;
        Query query = connection.parseQuery(queryString);
        connection.execute(query);
    } catch (Throwable e) {
        throwable = e;
    }
    checkThrowable(throwable, pattern);
}
Also used : Connection(mondrian.olap.Connection)

Example 9 with Connection

use of mondrian.olap.Connection in project mondrian by pentaho.

the class TestContext method assertExprDependsOn.

/**
 * Asserts that an MDX expression depends upon a given list of dimensions.
 */
public void assertExprDependsOn(String expr, String hierList) {
    // Construct a query, and mine it for a parsed expression.
    // Use a fresh connection, because some tests define their own dims.
    final Connection connection = getConnection();
    final String queryString = "WITH MEMBER [Measures].[Foo] AS " + Util.singleQuoteString(expr) + " SELECT FROM [Sales]";
    final Query query = connection.parseQuery(queryString);
    query.resolve();
    final Formula formula = query.getFormulas()[0];
    final Exp expression = formula.getExpression();
    // Build a list of the dimensions which the expression depends upon,
    // and check that it is as expected.
    checkDependsOn(query, expression, hierList, true);
}
Also used : Connection(mondrian.olap.Connection)

Example 10 with Connection

use of mondrian.olap.Connection in project mondrian by pentaho.

the class TestContext method assertParameterizedExprReturns.

/**
 * Asserts that an expression, with a given set of parameter bindings,
 * returns a given result.
 *
 * @param expr Scalar MDX expression
 * @param expected Expected result
 * @param paramValues Array of parameter names and values
 */
public void assertParameterizedExprReturns(String expr, String expected, Object... paramValues) {
    Connection connection = getConnection();
    String queryString = generateExpression(expr);
    Query query = connection.parseQuery(queryString);
    assert paramValues.length % 2 == 0;
    for (int i = 0; i < paramValues.length; ) {
        final String paramName = (String) paramValues[i++];
        final Object value = paramValues[i++];
        query.setParameter(paramName, value);
    }
    final Result result = connection.execute(query);
    final Cell cell = result.getCell(new int[] { 0 });
    if (expected == null) {
        // null values are formatted as empty string
        expected = "";
    }
    assertEqualsVerbose(expected, cell.getFormattedValue());
}
Also used : Connection(mondrian.olap.Connection) Cell(mondrian.olap.Cell)

Aggregations

Connection (mondrian.olap.Connection)38 RolapConnection (mondrian.rolap.RolapConnection)8 Util (mondrian.olap.Util)5 MondrianException (mondrian.olap.MondrianException)4 Result (mondrian.olap.Result)4 Member (mondrian.olap.Member)3 Query (mondrian.olap.Query)3 MDXConnection (org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection)3 MemberExpr (mondrian.mdx.MemberExpr)2 Cube (mondrian.olap.Cube)2 QueryAxis (mondrian.olap.QueryAxis)2 TestMember (mondrian.olap.fun.TestMember)2 Execution (mondrian.server.Execution)2 FoodMartTestCase (mondrian.test.FoodMartTestCase)2 TestContext (mondrian.test.TestContext)2 OlapConnection (org.olap4j.OlapConnection)2 IMondrianCatalogService (org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService)2 MondrianCatalog (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog)2 SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1