Search in sources :

Example 41 with PentahoAccessControlException

use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.

the class MetadataResourceTest method testDoRemoveMetadataError.

@Test
public void testDoRemoveMetadataError() throws Exception {
    Response mockResponse = mock(Response.class);
    PentahoAccessControlException mockPentahoAccessControlException = mock(PentahoAccessControlException.class);
    doThrow(mockPentahoAccessControlException).when(metadataResource.service).removeMetadata("metadataId");
    doReturn(mockResponse).when(metadataResource).buildUnauthorizedResponse();
    try {
        Response response = metadataResource.deleteMetadata("metadataId");
        fail("Should have had a WebApplicationException");
    } catch (WebApplicationException e) {
        // Good
        assertEquals(401, e.getResponse().getStatus());
    }
    verify(metadataResource, times(1)).deleteMetadata("metadataId");
}
Also used : Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) Test(org.junit.Test)

Example 42 with PentahoAccessControlException

use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.

the class MetadataResourceTest method doGetMetadataAcl.

@Test
public void doGetMetadataAcl() throws Exception {
    String domainId = "domainId";
    doReturn(new HashMap<String, InputStream>() {

        {
            put("test", null);
        }
    }).when(metadataResource).getDomainFilesData(domainId);
    doReturn(new RepositoryFileAclDto()).when(metadataResource.service).getMetadataAcl(domainId);
    // no exception thrown
    metadataResource.doGetMetadataAcl(domainId);
    // 
    doThrow(new PentahoAccessControlException()).when(metadataResource.service).getMetadataAcl(domainId);
    try {
        metadataResource.doGetMetadataAcl(domainId);
        fail();
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), e.getResponse().getStatus());
    }
    // 
    doThrow(new FileNotFoundException()).when(metadataResource.service).getMetadataAcl(domainId);
    try {
        metadataResource.doGetMetadataAcl(domainId);
        fail();
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.CONFLICT.getStatusCode(), e.getResponse().getStatus());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) InputStream(java.io.InputStream) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) FileNotFoundException(java.io.FileNotFoundException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) Test(org.junit.Test)

Example 43 with PentahoAccessControlException

use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.

the class DataSourceWizardServiceTest method testPublishDswError.

@Test
public void testPublishDswError() throws Exception {
    String domainId = "domainId";
    InputStream metadataFile = mock(InputStream.class);
    boolean overwrite = true;
    boolean checkConnection = false;
    XmiParser mockXmiParser = mock(XmiParser.class);
    Domain mockDomain = mock(Domain.class);
    InputStream mockInputStream = mock(InputStream.class);
    IPlatformImportBundle mockMetadataBundle = mock(IPlatformImportBundle.class);
    IPlatformImportBundle mockMondrianBundle = mock(IPlatformImportBundle.class);
    IPlatformImporter mockIPlatformImporter = mock(IPlatformImporter.class);
    IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
    String mockObject = "not null";
    String dswId = "dswId";
    // Test 1
    doReturn(false).when(dataSourceWizardService).hasManageAccessCheck();
    try {
        dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
        fail();
    } catch (PentahoAccessControlException e) {
    // expected
    }
    // Test 2
    doReturn(true).when(dataSourceWizardService).hasManageAccessCheck();
    doReturn(false).when(dataSourceWizardService).endsWith(anyString(), anyString());
    try {
        dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
        fail();
    } catch (IllegalArgumentException e) {
    // expected
    }
    // Test 3
    doReturn(true).when(dataSourceWizardService).endsWith(anyString(), anyString());
    try {
        dataSourceWizardService.publishDsw(domainId, null, overwrite, checkConnection, null);
        fail();
    } catch (IllegalArgumentException e) {
    // expected
    }
    // Test 4
    List<String> mockList = new ArrayList<String>();
    mockList.add("string1");
    doReturn(mockList).when(dataSourceWizardService).getOverwrittenDomains(domainId);
    try {
        dataSourceWizardService.publishDsw(domainId, metadataFile, false, checkConnection, null);
        fail();
    } catch (Exception e) {
    // expected
    }
    // Test 5
    doReturn(mockXmiParser).when(dataSourceWizardService).createXmiParser();
    RuntimeException mockException = mock(RuntimeException.class);
    doThrow(mockException).when(mockXmiParser).parseXmi(metadataFile);
    try {
        dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
        fail();
    } catch (Exception e) {
    // expected
    }
    // Test 6
    doReturn(mockDomain).when(mockXmiParser).parseXmi(metadataFile);
    doReturn(null).when(dataSourceWizardService).getMondrianDatasourceWrapper(mockDomain);
    try {
        dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, true, null);
        fail();
    } catch (Exception e) {
    // expected
    }
    verify(dataSourceWizardService, times(3)).publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
    verify(dataSourceWizardService, times(1)).publishDsw(domainId, null, overwrite, checkConnection, null);
    verify(dataSourceWizardService, times(1)).publishDsw(domainId, metadataFile, false, checkConnection, null);
    verify(dataSourceWizardService, times(1)).publishDsw(domainId, metadataFile, overwrite, true, null);
}
Also used : InputStream(java.io.InputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) XmiParser(org.pentaho.metadata.util.XmiParser) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) Domain(org.pentaho.metadata.model.Domain) Test(org.junit.Test)

Example 44 with PentahoAccessControlException

use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.

the class MetadataServiceTest method testImportMetadataDatasourceNoPublishPermission.

@Test
public void testImportMetadataDatasourceNoPublishPermission() throws Exception {
    String domainId = DOMAIN_ID;
    InputStream metadataFile = mock(InputStream.class);
    FormDataContentDisposition metadataFileInfo = mock(FormDataContentDisposition.class);
    doThrow(new PentahoAccessControlException()).when(metadataService).accessValidation();
    try {
        metadataService.importMetadataDatasource(domainId, metadataFile, metadataFileInfo, true, Collections.emptyList(), Collections.emptyList(), null);
        fail();
    } catch (PentahoAccessControlException e) {
    // expected
    }
    verify(metadataService, never()).getImporter();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StringInputStream(org.apache.tools.ant.filters.StringInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Matchers.anyString(org.mockito.Matchers.anyString) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) Test(org.junit.Test)

Example 45 with PentahoAccessControlException

use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.

the class MetadataServiceTest method testRemoveMetadataError.

@Test
public void testRemoveMetadataError() throws Exception {
    ConnectionServiceException cse = new ConnectionServiceException();
    doThrow(cse).when(metadataService).ensureDataAccessPermissionCheck();
    try {
        metadataService.removeMetadata("metadataId");
        fail();
    } catch (PentahoAccessControlException e) {
    // expected
    }
    verify(metadataService, times(1)).removeMetadata("metadataId");
}
Also used : ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) 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