Search in sources :

Example 56 with Result

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

the class RolapConnectionTest method testDataSourceOverrideUserPass.

public void testDataSourceOverrideUserPass() throws SQLException, NamingException {
    // use the datasource property to connect to the database
    Util.PropertyList properties = spy(TestContext.instance().getConnectionProperties().clone());
    final Dialect dialect = TestContext.instance().getDialect();
    if (dialect.getDatabaseProduct() == Dialect.DatabaseProduct.ACCESS) {
        // Access doesn't accept user/password, so this test is pointless.
        return;
    }
    final String jdbcUser = properties.get(RolapConnectionProperties.JdbcUser.name());
    final String jdbcPassword = properties.get(RolapConnectionProperties.JdbcPassword.name());
    if (jdbcUser == null || jdbcPassword == null) {
        // Can only run this test if username and password are explicit.
        return;
    }
    // Define a data source with bogus user and password.
    properties.put(RolapConnectionProperties.JdbcUser.name(), "bogususer");
    properties.put(RolapConnectionProperties.JdbcPassword.name(), "boguspassword");
    properties.put(RolapConnectionProperties.PoolNeeded.name(), "false");
    final StringBuilder buf = new StringBuilder();
    final DataSource dataSource = RolapConnection.createDataSource(null, properties, buf);
    final String desc = buf.toString();
    assertTrue(desc, desc.startsWith("Jdbc="));
    assertTrue(desc, desc.indexOf("JdbcUser=bogususer") >= 0);
    verify(properties, atLeastOnce()).get(RolapConnectionProperties.JdbcPassword.name());
    final String jndiName = "jndiDataSource";
    THREAD_INITIAL_CONTEXT.set(new InitialContext() {

        public Object lookup(String str) {
            return str.equals(jndiName) ? dataSource : null;
        }
    });
    // Create a property list that we will use for the actual mondrian
    // connection. Replace the original JDBC info with the data source we
    // just created.
    final Util.PropertyList properties2 = new Util.PropertyList();
    for (Pair<String, String> entry : properties) {
        properties2.put(entry.getKey(), entry.getValue());
    }
    properties2.remove(RolapConnectionProperties.Jdbc.name());
    properties2.put(RolapConnectionProperties.DataSource.name(), jndiName);
    // With JdbcUser and JdbcPassword credentials in the mondrian connect
    // string, the data source's "user" and "password" properties are
    // overridden and the connection succeeds.
    properties2.put(RolapConnectionProperties.JdbcUser.name(), jdbcUser);
    properties2.put(RolapConnectionProperties.JdbcPassword.name(), jdbcPassword);
    mondrian.olap.Connection connection = null;
    try {
        connection = DriverManager.getConnection(properties2, null);
        Query query = connection.parseQuery("select from [Sales]");
        final Result result = connection.execute(query);
        assertNotNull(result);
    } finally {
        if (connection != null) {
            connection.close();
            connection = null;
        }
    }
    // If we don't specify JdbcUser and JdbcPassword in the mondrian
    // connection properties, mondrian uses the data source's
    // bogus credentials, and the connection fails.
    properties2.remove(RolapConnectionProperties.JdbcUser.name());
    properties2.remove(RolapConnectionProperties.JdbcPassword.name());
    for (String poolNeeded : Arrays.asList("false", "true")) {
        // Important to test with & without pooling. Connection pools
        // typically do not let you change user, so it's important that
        // mondrian handles these right.
        properties2.put(RolapConnectionProperties.PoolNeeded.name(), poolNeeded);
        try {
            connection = DriverManager.getConnection(properties2, null);
            fail("Expected exception");
        } catch (MondrianException e) {
            final String s = TestContext.getStackTrace(e);
            assertTrue(s, s.indexOf("Error while creating SQL connection: " + "DataSource=jndiDataSource") >= 0);
            switch(dialect.getDatabaseProduct()) {
                case DERBY:
                    assertTrue(s, s.indexOf("Caused by: java.sql.SQLException: " + "Schema 'BOGUSUSER' does not exist") >= 0);
                    break;
                case ORACLE:
                    assertTrue(s, s.indexOf("Caused by: java.sql.SQLException: ORA-01017: " + "invalid username/password; logon denied") >= 0);
                    break;
                case MYSQL:
                case MARIADB:
                    assertTrue(s, s.indexOf("Caused by: java.sql.SQLException: Access denied " + "for user 'bogususer'") >= 0);
                    break;
                case POSTGRESQL:
                    assertTrue(s, s.indexOf("Caused by: org.postgresql.util.PSQLException: " + "FATAL: password authentication failed for " + "user \"bogususer\"") >= 0);
                    break;
            }
        } finally {
            if (connection != null) {
                connection.close();
                connection = null;
            }
        }
    }
}
Also used : Query(mondrian.olap.Query) Util(mondrian.olap.Util) InitialContext(javax.naming.InitialContext) DataSource(javax.sql.DataSource) Result(mondrian.olap.Result) Dialect(mondrian.spi.Dialect) MondrianException(mondrian.olap.MondrianException)

Example 57 with Result

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

the class RolapResultTest method testD1.

public void testD1() throws Exception {
    if (!isApplicable()) {
        return;
    }
    String mdx = "select " + " filter({[D1].[a],[D1].[b],[D1].[c]}, " + "    [Measures].[Value] > 0) " + " ON COLUMNS, " + " {[D2].[x],[D2].[y],[D2].[z]} " + " ON ROWS " + "from FT1";
    // getCubeTestContext().assertQueryReturns(mdx, RESULTS);
    Result result = getTestContext().executeQuery(mdx);
    String resultString = TestContext.toString(result);
    // System.out.println(resultString);
    /*
 This is what is produced
Axis #0:
{}
Axis #1:
Axis #2:
{[D2].[x]}
{[D2].[y]}
{[D2].[z]}
*/
    assertEquals(resultString, RESULTS);
}
Also used : Result(mondrian.olap.Result)

Example 58 with Result

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

the class TopCountWithTwoParamsVersusHeadTest method assertResultsAreEqual.

private void assertResultsAreEqual(String testCase, String topCountQuery) {
    if (!topCountQuery.contains("TOPCOUNT")) {
        throw new IllegalArgumentException("'TOPCOUNT' was not found. Please ensure you are using upper case:\n\t\t" + topCountQuery);
    }
    String headQuery = topCountQuery.replace("TOPCOUNT", "HEAD");
    TestContext ctx = getTestContext();
    Result topCountResult = ctx.executeQuery(topCountQuery);
    ctx.flushSchemaCache();
    Result headResult = ctx.executeQuery(headQuery);
    assertEquals(String.format("[%s]: TOPCOUNT() and HEAD() results of the query differ. The query:\n\t\t%s", testCase, topCountQuery), TestContext.toString(topCountResult), TestContext.toString(headResult));
}
Also used : TestContext(mondrian.test.TestContext) Result(mondrian.olap.Result)

Example 59 with Result

use of mondrian.olap.Result in project pentaho-platform by pentaho.

the class MDXMetaDataTest method testGetColumnCount.

@Test
@SuppressWarnings("rawtypes")
public void testGetColumnCount() {
    List positions = mockPositions(COLUMN_SIZE, ROW_SIZE);
    Axis axColumn = mockAxis(positions);
    Axis axRow = mockAxis(positions);
    Axis[] axes = new Axis[] { axColumn, axRow };
    Result nativeResultSet = mock(Result.class);
    when(nativeResultSet.getAxes()).thenReturn(axes);
    MDXMetaData metadata = new MDXMetaData(nativeResultSet);
    int columnCount = metadata.getColumnCount();
    assertEquals(positions.size(), columnCount);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Axis(mondrian.olap.Axis) Result(mondrian.olap.Result) Test(org.junit.Test)

Example 60 with Result

use of mondrian.olap.Result in project pentaho-platform by pentaho.

the class MDXMetaDataTest method testGetZeroColumnCount.

@Test
public void testGetZeroColumnCount() {
    Result nativeResultSet = mock(Result.class);
    when(nativeResultSet.getAxes()).thenReturn(new Axis[0]);
    MDXMetaData metadata = new MDXMetaData(nativeResultSet);
    int columnCount = metadata.getColumnCount();
    assertEquals(0, columnCount);
    when(nativeResultSet.getAxes()).thenReturn(new Axis[] { null });
    metadata = new MDXMetaData(nativeResultSet);
    columnCount = metadata.getColumnCount();
    assertEquals(0, columnCount);
    Axis axColumn = mockAxis(null);
    when(nativeResultSet.getAxes()).thenReturn(new Axis[] { axColumn });
    metadata = new MDXMetaData(nativeResultSet);
    columnCount = metadata.getColumnCount();
    assertEquals(0, columnCount);
}
Also used : Axis(mondrian.olap.Axis) Result(mondrian.olap.Result) Test(org.junit.Test)

Aggregations

Result (mondrian.olap.Result)113 Axis (mondrian.olap.Axis)24 Member (mondrian.olap.Member)10 Test (org.junit.Test)10 Cell (mondrian.olap.Cell)9 Connection (mondrian.olap.Connection)9 Query (mondrian.olap.Query)9 Position (mondrian.olap.Position)8 TestContext (mondrian.test.TestContext)7 ArrayList (java.util.ArrayList)5 MondrianProperties (mondrian.olap.MondrianProperties)5 OlapElement (mondrian.olap.OlapElement)5 RolapCell (mondrian.rolap.RolapCell)5 NonEmptyResult (mondrian.rolap.RolapConnection.NonEmptyResult)5 Execution (mondrian.server.Execution)5 Dialect (mondrian.spi.Dialect)5 OlapConnection (org.olap4j.OlapConnection)5 List (java.util.List)4 ResultBase (mondrian.olap.ResultBase)4 Evaluator (mondrian.olap.Evaluator)3