use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.
the class AnalysisServiceTest method testPutMondrianSchemaNoPublishPermissions.
@Test
public void testPutMondrianSchemaNoPublishPermissions() throws Exception {
analysisService = new AnalysisService() {
@Override
protected void accessValidation() throws PentahoAccessControlException {
throw new PentahoAccessControlException();
}
};
try {
putMondrianSchemaWithSchemaFileName("stubFileName");
fail();
} catch (PentahoAccessControlException e) {
// expected
}
verify(importer, never()).importFile(any());
verify(catalogService, never()).removeCatalog(anyString(), any(IPentahoSession.class));
}
use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.
the class DataSourceWizardServiceTest method testDoGetDSWFilesAsDownloadError.
@Test
public void testDoGetDSWFilesAsDownloadError() throws Exception {
Map<String, InputStream> mockFileData = mock(Map.class);
ModelerWorkspace mockModelerWorkspace = mock(ModelerWorkspace.class);
String dswId = "dswId";
// Test 1
doReturn(false).when(dataSourceWizardService).canManageACL();
try {
Map<String, InputStream> response = dataSourceWizardService.doGetDSWFilesAsDownload("dswId");
fail();
} catch (PentahoAccessControlException pace) {
// expected
}
verify(dataSourceWizardService, times(1)).doGetDSWFilesAsDownload("dswId");
}
use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.
the class DataSourceWizardServiceTest method testRemoveDSWError.
@Test
public void testRemoveDSWError() throws Exception {
Domain mockDomain = mock(Domain.class);
IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
ModelerWorkspace mockModelerWorkspace = mock(ModelerWorkspace.class);
LogicalModel mockLogicalModel = mock(LogicalModel.class);
String mockObject = "not null";
String dswId = "dswId";
// Test 1
ConnectionServiceException cse = new ConnectionServiceException();
doThrow(cse).when(dataSourceWizardService).ensureDataAccessPermissionCheck();
try {
dataSourceWizardService.removeDSW("dswId");
fail();
} catch (PentahoAccessControlException pace) {
// expected
}
// Test 2
DatasourceServiceException mockDatasourceServiceException = mock(DatasourceServiceException.class);
doNothing().when(dataSourceWizardService).ensureDataAccessPermissionCheck();
doReturn(dswId).when(dataSourceWizardService).parseMondrianSchemaNameWrapper(dswId);
doReturn(mockDomain).when(dataSourceWizardService.metadataDomainRepository).getDomain(dswId);
doReturn(mockModelerWorkspace).when(dataSourceWizardService).createModelerWorkspace();
doReturn(null).when(mockModelerWorkspace).getLogicalModel(ModelerPerspective.ANALYSIS);
doReturn(mockLogicalModel).when(mockModelerWorkspace).getLogicalModel(ModelerPerspective.REPORTING);
doReturn(mockObject).when(mockLogicalModel).getProperty("MondrianCatalogRef");
doReturn(mockIPentahoSession).when(dataSourceWizardService).getSession();
doNothing().when(dataSourceWizardService.mondrianCatalogService).removeCatalog("not null", mockIPentahoSession);
doThrow(mockDatasourceServiceException).when(dataSourceWizardService.dswService).deleteLogicalModel(null, null);
dataSourceWizardService.removeDSW("dswId");
verify(dataSourceWizardService, times(2)).removeDSW("dswId");
}
use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.
the class AnalysisResourceTest method testImportAnalysisDatasourceError.
@Test
public void testImportAnalysisDatasourceError() throws Exception {
Response mockResponse = mock(Response.class);
InputStream uploadAnalysis = mock(InputStream.class);
FormDataContentDisposition schemaFileInfo = mock(FormDataContentDisposition.class);
String catalogName = "catalogName";
String origCatalogName = "origCatalogName";
String datasourceName = "datasourceName";
String overwrite = "overwrite";
String xmlaEnabledFlag = "xmlaEnabledFlag";
String parameters = "parameters";
// Test 1
PentahoAccessControlException mockPentahoAccessControlException = mock(PentahoAccessControlException.class);
doThrow(mockPentahoAccessControlException).when(analysisResource.service).putMondrianSchema(uploadAnalysis, schemaFileInfo, catalogName, origCatalogName, datasourceName, false, false, parameters, null);
doReturn(mockResponse).when(analysisResource).buildOkResponse("5");
Response response = analysisResource.importMondrianSchema(uploadAnalysis, schemaFileInfo, catalogName, origCatalogName, datasourceName, overwrite, xmlaEnabledFlag, parameters, null);
assertEquals(mockResponse, response);
// Test 2
PlatformImportException mockPlatformImportException = mock(PlatformImportException.class);
doThrow(mockPlatformImportException).when(analysisResource.service).putMondrianSchema(uploadAnalysis, schemaFileInfo, catalogName, origCatalogName, datasourceName, true, true, parameters, null);
doReturn(mockResponse).when(analysisResource).buildOkResponse("0");
response = analysisResource.importMondrianSchema(uploadAnalysis, schemaFileInfo, catalogName, origCatalogName, datasourceName, overwrite, xmlaEnabledFlag, parameters, null);
assertEquals(mockResponse, response);
// Test 3
RuntimeException mockException = mock(RuntimeException.class);
doThrow(mockException).when(analysisResource.service).putMondrianSchema(uploadAnalysis, schemaFileInfo, catalogName, origCatalogName, datasourceName, true, true, parameters, null);
doReturn(mockResponse).when(analysisResource).buildOkResponse("2");
response = analysisResource.importMondrianSchema(uploadAnalysis, schemaFileInfo, catalogName, origCatalogName, datasourceName, overwrite, xmlaEnabledFlag, parameters, null);
assertEquals(mockResponse, response);
verify(analysisResource, times(3)).importMondrianSchema(uploadAnalysis, schemaFileInfo, catalogName, origCatalogName, datasourceName, overwrite, xmlaEnabledFlag, parameters, null);
}
use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.
the class DataSourceWizardResourceTest method doSetMetadataAcl.
@Test
public void doSetMetadataAcl() throws Exception {
String domainId = "domainId";
Response response = dataSourceWizardResource.doSetDSWAcl(domainId, null);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
//
doThrow(new PentahoAccessControlException()).when(dataSourceWizardResource.service).setDSWAcl(domainId, null);
response = dataSourceWizardResource.doSetDSWAcl(domainId, null);
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
//
doThrow(new FileNotFoundException()).when(dataSourceWizardResource.service).setDSWAcl(domainId, null);
response = dataSourceWizardResource.doSetDSWAcl(domainId, null);
assertEquals(Response.Status.CONFLICT.getStatusCode(), response.getStatus());
}
Aggregations