Search in sources :

Example 6 with MondrianServer

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

the class MondrianServerTest method testEmbedded.

/**
 * Tests an embedded server.
 */
public void testEmbedded() {
    TestContext testContext = TestContext.instance();
    final MondrianServer server = MondrianServer.forConnection(testContext.getConnection());
    final int id = server.getId();
    assertNotNull(id);
    server.shutdown();
}
Also used : MondrianServer(mondrian.olap.MondrianServer) XmlaTestContext(mondrian.xmla.test.XmlaTestContext)

Example 7 with MondrianServer

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

the class XmlaExtraTest method testGetDataSourceDoesntLeakPassword.

/**
 * This test makes sure that the value of
 * {@link RolapConnectionProperties#JdbcPassword} isn't leaked through
 * the XmlaExtra interface.
 */
public void testGetDataSourceDoesntLeakPassword() throws Exception {
    final List<Map<String, Object>> expectedList = new ArrayList<Map<String, Object>>();
    final Map<String, Object> expectedMap = new HashMap<String, Object>();
    expectedMap.put("DataSourceInfo", "Provider=Mondrian;Jdbc=foo;JdbcPassword=bar;JdbcUser=bacon");
    expectedList.add(expectedMap);
    final MondrianServer server = mock(MondrianServer.class);
    final RolapConnection rConn = mock(RolapConnection.class);
    final MondrianOlap4jConnection conn = mock(MondrianOlap4jConnection.class);
    final MondrianOlap4jExtra extra = mock(MondrianOlap4jExtra.class);
    doReturn(expectedList).when(server).getDatabases(rConn);
    doReturn(server).when(rConn).getServer();
    doReturn(rConn).when(conn).getMondrianConnection();
    doCallRealMethod().when(extra).getDataSources(conn);
    for (Map<String, Object> ds : extra.getDataSources(conn)) {
        final PropertyList props = Util.parseConnectString(String.valueOf(ds.get("DataSourceInfo")));
        assertNull(props.get(RolapConnectionProperties.Jdbc.name()));
        assertNull(props.get(RolapConnectionProperties.JdbcUser.name()));
        assertNull(props.get(RolapConnectionProperties.JdbcPassword.name()));
    }
}
Also used : RolapConnection(mondrian.rolap.RolapConnection) MondrianServer(mondrian.olap.MondrianServer) PropertyList(mondrian.olap.Util.PropertyList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with MondrianServer

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

the class FileRepositoryTest method testDiscoverDatasourceLegacyNameMatch.

public void testDiscoverDatasourceLegacyNameMatch() throws Exception {
    final String contentStub = "<?xml version=\"1.0\"" + " encoding=\"UTF-8\"?>\n" + "<DataSources>\n" + "<DataSource>\n" + "<DataSourceName>Pentaho Mondrian</DataSourceName>\n" + "<DataSourceDescription>Pentaho BI Platform Datasources</DataSourceDescription>\n" + "<URL>/pentaho/Xmla</URL>\n" + "<DataSourceInfo>Provider=mondrian;Jdbc=SomethingAwfulWhichPeopleCantSee</DataSourceInfo>\n" + "<ProviderName>PentahoXMLA</ProviderName>\n" + "<ProviderType>MDP</ProviderType>\n" + "<AuthenticationMode>Unauthenticated</AuthenticationMode>\n" + "<Catalogs>\n" + "<Catalog name=\"SampleData\">\n" + "<DataSourceInfo>Jdbc=example.com;EnableXmla=false;Provider=mondrian;Datasource=\"SampleData\";overwrite=\"true\"</DataSourceInfo>\n" + "<Definition>mondrian:/SampleData</Definition>\n" + "</Catalog>\n" + "</Catalogs>\n" + "</DataSource>\n" + "</DataSources>\n";
    // Mocks.
    FileRepository fileRepositoryMock = mock(FileRepository.class);
    RepositoryContentFinder repositoryContentFinderMock = mock(RepositoryContentFinder.class);
    // Return the content we want from the RCF.
    doReturn(repositoryContentFinderMock).when(fileRepositoryMock).getRepositoryContentFinder();
    doReturn(contentStub).when(repositoryContentFinderMock).getContent();
    // Calling getServerInfo's actual implementation
    doCallRealMethod().when(fileRepositoryMock).getServerInfo();
    // Give it a try.
    final FileRepository.ServerInfo serverInfo = fileRepositoryMock.getServerInfo();
    // Some sanity checks.
    FileRepository.DatabaseInfo databaseInfo = serverInfo.getDatasourceMap().get("Pentaho Mondrian");
    assertNotNull("Database not found by name", databaseInfo);
    // Moar mocks.
    final Properties mockProps = mock(Properties.class);
    final MondrianServer mockServer = mock(MondrianServer.class);
    final String databaseName = "Pentaho Mondrian";
    final String dsInfo = "Provider=mondrian";
    final String catalogName = "SampleData";
    final String roleName = null;
    final CatalogInfo cInfo = databaseInfo.catalogMap.get("SampleData");
    final OlapConnection oc = mock(OlapConnection.class);
    // Make sure to short circuit the connection creation internal call...
    doReturn(oc).when(fileRepositoryMock).getConnection(cInfo, mockServer, roleName, mockProps);
    // We'll try to call into this method with the DS name.
    doCallRealMethod().when(fileRepositoryMock).getConnection(mockServer, databaseName, catalogName, roleName, mockProps);
    // OK make the call.
    OlapConnection ocPrime = fileRepositoryMock.getConnection(mockServer, databaseName, catalogName, roleName, mockProps);
    // Check we got a proper output.
    assertTrue(ocPrime == oc);
    // Make sure the protected call was made
    verify(fileRepositoryMock, times(1)).getConnection(cInfo, mockServer, roleName, mockProps);
    // *** Now do the same w/ the DS Info name instead. Legacy mode.
    // We'll try to call into this method with the DSInfo instead of the
    // name of the database.
    doCallRealMethod().when(fileRepositoryMock).getConnection(mockServer, dsInfo, catalogName, roleName, mockProps);
    // Make the call.
    ocPrime = fileRepositoryMock.getConnection(mockServer, dsInfo, catalogName, roleName, mockProps);
    // Check we got a proper output.
    assertTrue(ocPrime == oc);
    // Make sure the protected call was made. 2 calls by now.
    verify(fileRepositoryMock, times(2)).getConnection(cInfo, mockServer, roleName, mockProps);
}
Also used : MondrianServer(mondrian.olap.MondrianServer) OlapConnection(org.olap4j.OlapConnection) CatalogInfo(mondrian.server.FileRepository.CatalogInfo) Properties(java.util.Properties)

Aggregations

MondrianServer (mondrian.olap.MondrianServer)8 OlapConnection (org.olap4j.OlapConnection)4 XmlaTestContext (mondrian.xmla.test.XmlaTestContext)3 Properties (java.util.Properties)2 UrlRepositoryContentFinder (mondrian.server.UrlRepositoryContentFinder)2 Catalog (org.olap4j.metadata.Catalog)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Connection (mondrian.olap.Connection)1 MondrianException (mondrian.olap.MondrianException)1 PropertyList (mondrian.olap.Util.PropertyList)1 RolapConnection (mondrian.rolap.RolapConnection)1 FileRepository (mondrian.server.FileRepository)1 CatalogInfo (mondrian.server.FileRepository.CatalogInfo)1 StringRepositoryContentFinder (mondrian.server.StringRepositoryContentFinder)1 XmlaException (mondrian.xmla.XmlaException)1