Search in sources :

Example 1 with IOlapServiceException

use of org.pentaho.platform.plugin.action.olap.IOlapServiceException in project pentaho-platform by pentaho.

the class OlapServiceImplTest method testRemoveOlap4jCatalogsWithoutPermission.

/**
 * Validates getting a list of remote catalogs.
 */
@Test
public void testRemoveOlap4jCatalogsWithoutPermission() throws Exception {
    stubGetChildren(repository, olapFolderPath, "myServer");
    // Stub /etc/olap-servers/myServer
    final String testServerPath = olapFolderPath + RepositoryFile.SEPARATOR + "myServer";
    stubGetFolder(repository, testServerPath);
    stubGetChildren(repository, testServerPath, "metadata");
    // Stub /etc/olap-servers/myServer/metadata
    final String metadataPath = testServerPath + RepositoryFile.SEPARATOR + "metadata";
    stubGetFile(repository, metadataPath);
    stubGetData(repository, metadataPath + RepositoryFile.SEPARATOR + "myServer", "server", pathPropertyPair("/server/name", "myServer"), pathPropertyPair("/server/user", "myUser"), pathPropertyPair("/server/password", "myPassword"), pathPropertyPair("/server/URL", "myUrl"), pathPropertyPair("/server/className", "someClass"));
    // Get a list of catalogs.
    final List<String> catalogs = olapService.getCatalogNames(session);
    assertEquals(1, catalogs.size());
    assertEquals("myServer", catalogs.get(0));
    verify(repository).getChildren(eq(makeIdObject(olapFolderPath)));
    // Stub the security
    accessMock = new DefaultAccessImpl() {

        public boolean hasAccess(String path, EnumSet<RepositoryFilePermission> perms, IPentahoSession session) {
            if (perms.contains(RepositoryFilePermission.DELETE) && path.equals("myServer")) {
                return false;
            }
            return true;
        }
    };
    // Try to delete it. We expect it to fail.
    try {
        olapService.removeCatalog("myServer", session);
        fail();
    } catch (IOlapServiceException e) {
        assertEquals(IOlapServiceException.Reason.ACCESS_DENIED, e.getReason());
        assertTrue(e.getMessage().contains("OlapServiceImpl.ERROR_0003"));
    }
    // Make sure we didn't invoke the delete method.
    verify(repository, never()).deleteFile((RepositoryFile) anyObject(), anyString());
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) RepositoryFilePermission(org.pentaho.platform.api.repository2.unified.RepositoryFilePermission) IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 2 with IOlapServiceException

use of org.pentaho.platform.plugin.action.olap.IOlapServiceException in project pentaho-platform by pentaho.

the class OlapServiceImplTest method testGetOlap4jCatalogs.

/**
 * Validates getting a list of remote catalogs.
 */
@Test
public void testGetOlap4jCatalogs() throws Exception {
    stubGetChildren(repository, olapFolderPath, "myServer");
    // Stub /etc/olap-servers/myServer
    final String testServerPath = olapFolderPath + RepositoryFile.SEPARATOR + "myServer";
    stubGetFolder(repository, testServerPath);
    stubGetChildren(repository, testServerPath, "metadata");
    // Stub /etc/olap-servers/myServer/metadata
    final String metadataPath = testServerPath + RepositoryFile.SEPARATOR + "metadata";
    stubGetFile(repository, metadataPath);
    stubGetData(repository, metadataPath + RepositoryFile.SEPARATOR + "myServer", "server", pathPropertyPair("/server/name", "myServer"), pathPropertyPair("/server/user", "myUser"), pathPropertyPair("/server/password", "myPassword"), pathPropertyPair("/server/URL", "myUrl"), pathPropertyPair("/server/className", "someClass"));
    // Get a list of catalogs.
    final List<String> catalogs = olapService.getCatalogNames(session);
    assertEquals(1, catalogs.size());
    assertEquals("myServer", catalogs.get(0));
    verify(repository).getChildren(eq(makeIdObject(olapFolderPath)));
    // Now check for non-existent catalogs
    try {
        olapService.getConnection("someName", session);
        fail();
    } catch (IOlapServiceException e) {
        assertEquals(IOlapServiceException.Reason.GENERAL, e.getReason());
        assertEquals("MondrianCatalogHelper.ERROR_0015 - Catalog someName not found", e.getMessage());
    }
}
Also used : IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 3 with IOlapServiceException

use of org.pentaho.platform.plugin.action.olap.IOlapServiceException in project pentaho-platform by pentaho.

the class OlapServiceImplTest method testImportHostedOverwriteFlag.

/**
 * Verifies that we can create locally hosted mondrian instances.
 */
@Test
public void testImportHostedOverwriteFlag() throws Exception {
    final String testFolderPath = mondrianFolderPath + RepositoryFile.SEPARATOR + "myHostedServer";
    // Stub the hosted server
    stubGetChildren(repository, mondrianFolderPath, "myHostedServer");
    final String testServerPath = mondrianFolderPath + RepositoryFile.SEPARATOR + "myHostedServer";
    stubGetFolder(repository, testServerPath);
    stubGetChildren(repository, testServerPath, "metadata");
    final String metadataPath = testServerPath + RepositoryFile.SEPARATOR + "metadata";
    stubGetFile(repository, metadataPath);
    stubGetFile(repository, testFolderPath + RepositoryFile.SEPARATOR + "schema.xml");
    stubGetData(repository, metadataPath, "catalog", pathPropertyPair("/catalog/definition", "mondrian:/SteelWheels"), pathPropertyPair("/catalog/datasourceInfo", "Provider=mondrian;DataSource=SteelWheels;"));
    final InputStream is = this.getClass().getResourceAsStream("/solution/security/steelwheels.mondrian.xml");
    // Try to save it without the overwrite flag. We expect it to fail.
    try {
        olapService.addHostedCatalog("myHostedServer", "Provider=mondrian;DataSource=SampleData", is, false, session);
        fail();
    } catch (IOlapServiceException e) {
        assertEquals(IOlapServiceException.Reason.ALREADY_EXISTS, e.getReason());
        assertTrue(e.getMessage().contains("OlapServiceImpl.ERROR_0004"));
    }
    // Make sure we didn't invoke the update or write methods.
    verify(repository, never()).updateFile((RepositoryFile) anyObject(), (IRepositoryFileData) anyObject(), anyString());
    verify(repository, never()).createFile((RepositoryFile) anyObject(), (RepositoryFile) anyObject(), (IRepositoryFileData) anyObject(), anyString());
    // Now do it again.
    olapService.addHostedCatalog("myHostedServer", "Provider=mondrian;DataSource=SampleData", is, true, session);
    verify(repository).updateFile(argThat(isLikeFile(makeFileObject(metadataPath))), argThat(hasData(pathPropertyPair("/catalog/definition", "mondrian:/" + "myHostedServer"), pathPropertyPair("/catalog/datasourceInfo", "Provider=mondrian;DataSource=SampleData"))), anyString());
    verify(repository).updateFile(argThat(isLikeFile(makeFileObject(testFolderPath + RepositoryFile.SEPARATOR + "schema.xml"))), any(IRepositoryFileData.class), anyString());
}
Also used : IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) InputStream(java.io.InputStream) IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 4 with IOlapServiceException

use of org.pentaho.platform.plugin.action.olap.IOlapServiceException in project pentaho-platform by pentaho.

the class OlapServiceImplTest method testRemoveOlap4jCatalogs.

/**
 * Validates getting a list of remote catalogs.
 */
@Test
public void testRemoveOlap4jCatalogs() throws Exception {
    stubGetChildren(repository, olapFolderPath, "myServer");
    // Stub /etc/olap-servers/myServer
    final String testServerPath = olapFolderPath + RepositoryFile.SEPARATOR + "myServer";
    stubGetFolder(repository, testServerPath);
    stubGetChildren(repository, testServerPath, "metadata");
    // Stub /etc/olap-servers/myServer/metadata
    final String metadataPath = testServerPath + RepositoryFile.SEPARATOR + "metadata";
    stubGetFile(repository, metadataPath);
    stubGetData(repository, metadataPath + RepositoryFile.SEPARATOR + "myServer", "server", pathPropertyPair("/server/name", "myServer"), pathPropertyPair("/server/user", "myUser"), pathPropertyPair("/server/password", "myPassword"), pathPropertyPair("/server/URL", "myUrl"), pathPropertyPair("/server/className", "someClass"));
    // Get a list of catalogs.
    final List<String> catalogs = olapService.getCatalogNames(session);
    assertEquals(1, catalogs.size());
    assertEquals("myServer", catalogs.get(0));
    verify(repository).getChildren(eq(makeIdObject(olapFolderPath)));
    // Now delete it.
    olapService.removeCatalog("myServer", session);
    // Check if the repo was modified.
    verify(repository).deleteFile(eq(makeIdObject(testServerPath)), eq(true), anyString());
    // Now check for non-existent catalogs
    try {
        olapService.removeCatalog("someName", session);
        fail();
    } catch (IOlapServiceException e) {
        assertEquals(IOlapServiceException.Reason.GENERAL, e.getReason());
        assertEquals("MondrianCatalogHelper.ERROR_0015 - Catalog someName not found", e.getMessage());
    }
}
Also used : IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 5 with IOlapServiceException

use of org.pentaho.platform.plugin.action.olap.IOlapServiceException in project pentaho-platform by pentaho.

the class SystemRefreshResourceTest method flushMondrianSchemaCacheError.

@Test
public void flushMondrianSchemaCacheError() {
    when(SystemUtils.canAdminister()).thenReturn(true);
    doThrow(IOlapServiceException.class).when(olapService).flush(session, "schemaX");
    try {
        Response response = resource.flushMondrianSchemaCache("schemaX");
        fail();
    } catch (IOlapServiceException e) {
        verify(olapService, times(1)).flush(session, "schemaX");
    }
}
Also used : Response(javax.ws.rs.core.Response) IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

IOlapServiceException (org.pentaho.platform.plugin.action.olap.IOlapServiceException)17 Test (org.junit.Test)8 SQLException (java.sql.SQLException)6 Matchers.anyString (org.mockito.Matchers.anyString)6 Properties (java.util.Properties)5 RolapConnectionProperties (mondrian.rolap.RolapConnectionProperties)5 FileSystemException (org.apache.commons.vfs2.FileSystemException)5 OlapException (org.olap4j.OlapException)5 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)5 Lock (java.util.concurrent.locks.Lock)4 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)4 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)4 RolapConnection (mondrian.rolap.RolapConnection)4 OlapConnection (org.olap4j.OlapConnection)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 RepositoryFilePermission (org.pentaho.platform.api.repository2.unified.RepositoryFilePermission)3 InputStream (java.io.InputStream)2 Connection (java.sql.Connection)2 Callable (java.util.concurrent.Callable)2 IOlapConnectionFilter (org.pentaho.platform.plugin.action.olap.IOlapConnectionFilter)2