Search in sources :

Example 1 with CatalogInfo

use of mondrian.server.FileRepository.CatalogInfo 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

Properties (java.util.Properties)1 MondrianServer (mondrian.olap.MondrianServer)1 CatalogInfo (mondrian.server.FileRepository.CatalogInfo)1 OlapConnection (org.olap4j.OlapConnection)1