Search in sources :

Example 36 with RepositoryFileAclDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto in project data-access by pentaho.

the class DataSourceWizardResourceTest method doGetAnalysisAcl.

@Test
public void doGetAnalysisAcl() throws Exception {
    String domainId = "domainId";
    doReturn(new RepositoryFileAclDto()).when(dataSourceWizardResource.service).getDSWAcl(domainId);
    // no exception thrown
    dataSourceWizardResource.doGetDSWAcl(domainId);
    // 
    doThrow(new PentahoAccessControlException()).when(dataSourceWizardResource.service).getDSWAcl(domainId);
    try {
        dataSourceWizardResource.doGetDSWAcl(domainId);
        fail();
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), e.getResponse().getStatus());
    }
    // 
    doThrow(new FileNotFoundException()).when(dataSourceWizardResource.service).getDSWAcl(domainId);
    try {
        dataSourceWizardResource.doGetDSWAcl(domainId);
        fail();
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.CONFLICT.getStatusCode(), e.getResponse().getStatus());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) FileNotFoundException(java.io.FileNotFoundException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) Test(org.junit.Test)

Example 37 with RepositoryFileAclDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto 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 38 with RepositoryFileAclDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto in project data-access by pentaho.

the class AnalysisServiceTest method testSetAnalysisDatasourceAcl.

@Test
public void testSetAnalysisDatasourceAcl() throws Exception {
    allAccess();
    final String catalogName = "catalogName";
    final RepositoryFileAclDto aclDto = new RepositoryFileAclDto();
    aclDto.setOwner("owner");
    aclDto.setOwnerType(RepositoryFileSid.Type.USER.ordinal());
    final MondrianCatalog mondrianCatalog = mock(MondrianCatalog.class);
    when(catalogService.getCatalog(eq(catalogName), any(IPentahoSession.class))).thenReturn(mondrianCatalog);
    analysisService.setAnalysisDatasourceAcl(catalogName, aclDto);
    verify(catalogService).setAclFor(eq(catalogName), eq(new RepositoryFileAclAdapter().unmarshal(aclDto)));
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) RepositoryFileAclAdapter(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAdapter) Test(org.junit.Test)

Example 39 with RepositoryFileAclDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto in project data-access by pentaho.

the class AnalysisServiceTest method testGetAnalysisDatasourceAcl.

@Test
public void testGetAnalysisDatasourceAcl() throws Exception {
    allAccess();
    final String catalogName = "SampleData";
    final RepositoryFileAcl expectedAcl = new RepositoryFileAcl.Builder("owner").build();
    when(catalogService.getAclFor(catalogName)).thenReturn(expectedAcl);
    final MondrianCatalog mondrianCatalog = mock(MondrianCatalog.class);
    when(catalogService.getCatalog(eq(catalogName), any(IPentahoSession.class))).thenReturn(mondrianCatalog);
    final RepositoryFileAclDto actualAcl = analysisService.getAnalysisDatasourceAcl(catalogName);
    assertEquals(expectedAcl, new RepositoryFileAclAdapter().unmarshal(actualAcl));
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) RepositoryFileAclAdapter(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAdapter) Test(org.junit.Test)

Example 40 with RepositoryFileAclDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto in project data-access by pentaho.

the class DataSourceWizardServiceTest method testGetDSWAcl.

@Test
public void testGetDSWAcl() throws Exception {
    String domainId = "domainId";
    final RepositoryFileAcl acl = new RepositoryFileAcl.Builder("owner").build();
    doReturn(true).when(dataSourceWizardService).canManageACL();
    when(dataSourceWizardService.aclAwarePentahoMetadataDomainRepositoryImporter.getAclFor(domainId)).thenReturn(acl);
    final IUnifiedRepository repository = mock(IUnifiedRepository.class);
    final RepositoryFile repositoryFile = mock(RepositoryFile.class);
    when(repository.getFileById(anyString())).thenReturn(repositoryFile);
    doReturn(new HashMap<String, InputStream>()).when(dataSourceWizardService).doGetDSWFilesAsDownload(domainId);
    final RepositoryFileAclDto aclDto = dataSourceWizardService.getDSWAcl(domainId);
    verify(dataSourceWizardService.aclAwarePentahoMetadataDomainRepositoryImporter).getAclFor(eq(domainId));
    assertEquals(acl, new RepositoryFileAclAdapter().unmarshal(aclDto));
}
Also used : InputStream(java.io.InputStream) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) RepositoryFileAclAdapter(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAdapter) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)41 RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)26 RepositoryFileAclDto (org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto)20 Matchers.anyString (org.mockito.Matchers.anyString)16 InputStream (java.io.InputStream)14 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)13 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)11 RepositoryFileAclAceDto (org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto)11 FileInputStream (java.io.FileInputStream)9 IPlatformImportBundle (org.pentaho.platform.api.repository2.unified.IPlatformImportBundle)9 RepositoryFileDto (org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto)9 ArrayList (java.util.ArrayList)8 RepositoryFileAclAdapter (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAdapter)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 FileNotFoundException (java.io.FileNotFoundException)7 Serializable (java.io.Serializable)7 GeneralSecurityException (java.security.GeneralSecurityException)6 IPlatformImporter (org.pentaho.platform.plugin.services.importer.IPlatformImporter)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 ClientResponse (com.sun.jersey.api.client.ClientResponse)4