Search in sources :

Example 6 with PentahoAccessControlException

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));
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) Test(org.junit.Test)

Example 7 with PentahoAccessControlException

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");
}
Also used : InputStream(java.io.InputStream) Matchers.anyString(org.mockito.Matchers.anyString) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) Test(org.junit.Test)

Example 8 with PentahoAccessControlException

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");
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Matchers.anyString(org.mockito.Matchers.anyString) Domain(org.pentaho.metadata.model.Domain) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) Test(org.junit.Test)

Example 9 with PentahoAccessControlException

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);
}
Also used : Response(javax.ws.rs.core.Response) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) InputStream(java.io.InputStream) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) Test(org.junit.Test)

Example 10 with PentahoAccessControlException

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());
}
Also used : Response(javax.ws.rs.core.Response) FileNotFoundException(java.io.FileNotFoundException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) Test(org.junit.Test)

Aggregations

PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)48 Test (org.junit.Test)28 InputStream (java.io.InputStream)13 Response (javax.ws.rs.core.Response)13 FileNotFoundException (java.io.FileNotFoundException)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)6 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)6 PlatformInitializationException (org.pentaho.platform.engine.core.system.boot.PlatformInitializationException)6 PlatformImportException (org.pentaho.platform.plugin.services.importer.PlatformImportException)6 DataAccessException (org.springframework.dao.DataAccessException)6 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)6 Domain (org.pentaho.metadata.model.Domain)5 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)5 FileInputStream (java.io.FileInputStream)4 Consumes (javax.ws.rs.Consumes)4 Facet (org.codehaus.enunciate.Facet)4 Matchers.anyString (org.mockito.Matchers.anyString)4 ModelerWorkspace (org.pentaho.agilebi.modeler.ModelerWorkspace)4 FormDataContentDisposition (com.sun.jersey.core.header.FormDataContentDisposition)3