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());
}
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());
}
}
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());
}
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());
}
}
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");
}
}
Aggregations