Search in sources :

Example 31 with RepositoryFileAclDto

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

the class MetadataServiceTest method testGetMetadataDatasourceAcl.

@Test
public void testGetMetadataDatasourceAcl() throws Exception {
    String domainId = DOMAIN_ID;
    final RepositoryFileAcl acl = new RepositoryFileAcl.Builder("owner").build();
    doReturn(true).when(metadataService).canManageACL();
    when(metadataService.aclAwarePentahoMetadataDomainRepositoryImporter.getAclFor(domainId)).thenReturn(acl);
    final Map<String, InputStream> domainFilesData = mock(Map.class);
    when(domainFilesData.isEmpty()).thenReturn(false);
    when(((PentahoMetadataDomainRepository) metadataService.metadataDomainRepository).getDomainFilesData(domainId)).thenReturn(domainFilesData);
    final RepositoryFileAclDto aclDto = metadataService.getMetadataAcl(domainId);
    verify(metadataService.aclAwarePentahoMetadataDomainRepositoryImporter).getAclFor(eq(domainId));
    assertEquals(acl, new RepositoryFileAclAdapter().unmarshal(aclDto));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StringInputStream(org.apache.tools.ant.filters.StringInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) PentahoMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.PentahoMetadataDomainRepository) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) RepositoryFileAclAdapter(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAdapter) Test(org.junit.Test)

Example 32 with RepositoryFileAclDto

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

the class MetadataServiceTest method testImportMetadataDatasourceLocaleFileStreams.

@Test
public void testImportMetadataDatasourceLocaleFileStreams() throws Exception {
    String domainId = DOMAIN_ID;
    InputStream metadataFile = mock(InputStream.class);
    boolean overwrite = true;
    InputStream mockLocalFileStream = mock(InputStream.class);
    List<InputStream> localeFiles = new ArrayList<>();
    localeFiles.add(mockLocalFileStream);
    List<String> localeFilesInfo = new ArrayList<>();
    localeFilesInfo.add("fileName");
    FileResource mockFileResource = mock(FileResource.class);
    Response mockResponse = mock(Response.class);
    IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
    IPlatformImporter mockIPlatformImporter = mock(IPlatformImporter.class);
    IPlatformImportBundle mockIPlatformImportBundle = mock(IPlatformImportBundle.class);
    RepositoryFileImportBundle.Builder mockRepositoryFileImportBundleBuilder = mock(RepositoryFileImportBundle.Builder.class);
    RepositoryFileImportBundle mockRepositoryFileImportBundle = mock(RepositoryFileImportBundle.class);
    ByteArrayInputStream mockByteArrayInputStream = mock(ByteArrayInputStream.class);
    doNothing().when(metadataService).accessValidation();
    doReturn(metadataFile).when(metadataService).validateFileSize(any(InputStream.class), anyString());
    doReturn(mockFileResource).when(metadataService).createNewFileResource();
    doReturn(mockResponse).when(mockFileResource).doGetReservedChars();
    doReturn(null).when(mockResponse).getEntity();
    doReturn("\t\n/").when(metadataService).objectToString(null);
    doReturn(mockRepositoryFileImportBundleBuilder).when(metadataService).createNewRepositoryFileImportBundleBuilder(metadataFile, false, domainId, null);
    doReturn(mockByteArrayInputStream).when(metadataService).createNewByteArrayInputStream(any(byte[].class));
    // doReturn( mockRepositoryFileImportBundle ).when( metadataService ).createNewRepositoryFileImportBundle(
    // mockByteArrayInputStream, "fileName", domainId );
    doReturn(mockRepositoryFileImportBundle).when(mockRepositoryFileImportBundleBuilder).build();
    doReturn(mockIPlatformImporter).when(metadataService).getImporter();
    doNothing().when(mockIPlatformImporter).importFile(mockIPlatformImportBundle);
    doReturn(mockIPentahoSession).when(metadataService).getSession();
    doNothing().when(metadataService).publish(mockIPentahoSession);
    final RepositoryFileAclDto acl = new RepositoryFileAclDto();
    acl.setOwner("owner");
    acl.setOwnerType(RepositoryFileSid.Type.USER.ordinal());
    metadataService.importMetadataDatasource(domainId, metadataFile, overwrite, localeFiles, localeFilesInfo, acl);
    verify(metadataService, times(1)).importMetadataDatasource(domainId, metadataFile, overwrite, localeFiles, localeFilesInfo, acl);
    verify(metadataService.getImporter()).importFile(argThat(new ArgumentMatcher<IPlatformImportBundle>() {

        @Override
        public boolean matches(Object argument) {
            IPlatformImportBundle bundle = (IPlatformImportBundle) argument;
            return new RepositoryFileAclAdapter().unmarshal(acl).equals(bundle.getAcl());
        }
    }));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StringInputStream(org.apache.tools.ant.filters.StringInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) ArrayList(java.util.ArrayList) FileResource(org.pentaho.platform.web.http.api.resources.FileResource) Matchers.anyString(org.mockito.Matchers.anyString) Response(javax.ws.rs.core.Response) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) ByteArrayInputStream(java.io.ByteArrayInputStream) ArgumentMatcher(org.mockito.ArgumentMatcher) RepositoryFileImportBundle(org.pentaho.platform.plugin.services.importer.RepositoryFileImportBundle) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) RepositoryFileAclAdapter(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAdapter) Test(org.junit.Test)

Example 33 with RepositoryFileAclDto

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

the class MetadataServiceTest method testGetMetadataDatasourceAclNoAcl.

@Test
public void testGetMetadataDatasourceAclNoAcl() throws Exception {
    String domainId = DOMAIN_ID;
    doReturn(true).when(metadataService).canManageACL();
    when(metadataService.aclAwarePentahoMetadataDomainRepositoryImporter.getAclFor(domainId)).thenReturn(null);
    final Map<String, InputStream> domainFilesData = mock(Map.class);
    when(domainFilesData.isEmpty()).thenReturn(false);
    when(((PentahoMetadataDomainRepository) metadataService.metadataDomainRepository).getDomainFilesData(domainId)).thenReturn(domainFilesData);
    final RepositoryFileAclDto aclDto = metadataService.getMetadataAcl(domainId);
    verify(metadataService.aclAwarePentahoMetadataDomainRepositoryImporter).getAclFor(eq(domainId));
    assertNull(aclDto);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StringInputStream(org.apache.tools.ant.filters.StringInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) PentahoMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.PentahoMetadataDomainRepository) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 34 with RepositoryFileAclDto

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

the class MetadataServiceTest method testGetMetadataDatasourceAclNoDS.

@Test(expected = FileNotFoundException.class)
public void testGetMetadataDatasourceAclNoDS() throws Exception {
    String domainId = DOMAIN_ID;
    doReturn(true).when(metadataService).canManageACL();
    when(metadataService.aclAwarePentahoMetadataDomainRepositoryImporter.getAclFor(domainId)).thenReturn(null);
    final RepositoryFileAclDto aclDto = metadataService.getMetadataAcl(domainId);
    verify(metadataService.aclAwarePentahoMetadataDomainRepositoryImporter).getAclFor(eq(domainId));
    assertNull(aclDto);
}
Also used : RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)31 Test (org.junit.Test)28 Matchers.anyString (org.mockito.Matchers.anyString)16 InputStream (java.io.InputStream)12 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)9 FileInputStream (java.io.FileInputStream)8 RepositoryFileAclAdapter (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAdapter)8 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)8 RepositoryFileAclAceDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAceDto)7 FileNotFoundException (java.io.FileNotFoundException)6 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 GeneralSecurityException (java.security.GeneralSecurityException)5 ArrayList (java.util.ArrayList)5 StringInputStream (org.apache.tools.ant.filters.StringInputStream)5 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 WebResource (com.sun.jersey.api.client.WebResource)4 FormDataBodyPart (com.sun.jersey.multipart.FormDataBodyPart)4 JerseyTest (com.sun.jersey.test.framework.JerseyTest)4 Response (javax.ws.rs.core.Response)4