Search in sources :

Example 51 with RepositoryFileAclDto

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

the class FileServiceIT method testDoGetFileAcl.

@Test
public void testDoGetFileAcl() {
    RepositoryFileDto file = mock(RepositoryFileDto.class);
    RepositoryFileAclDto fileAcl = mock(RepositoryFileAclDto.class);
    when(fileAcl.isEntriesInheriting()).thenReturn(false);
    when(fileService.defaultUnifiedRepositoryWebService.getFile(nullable(String.class))).thenReturn(file);
    when(fileService.defaultUnifiedRepositoryWebService.getAcl(nullable(String.class))).thenReturn(fileAcl);
    doNothing().when(fileService).addAdminRole(fileAcl);
    String pathId = "/usr/dir/file.txt";
    fileService.doGetFileAcl(pathId);
    verify(fileService).addAdminRole(fileAcl);
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) RepositoryFileAclDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 52 with RepositoryFileAclDto

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

the class FileServiceIT method testSetFileAclsException.

@Test
public void testSetFileAclsException() throws Exception {
    String pathId = "/usr/folder/file.txt";
    RepositoryFileAclDto acl = mock(RepositoryFileAclDto.class);
    try {
        fileService.setFileAcls(pathId, acl);
        fail();
    } catch (FileNotFoundException e) {
    // expected exception
    }
}
Also used : RepositoryFileAclDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 53 with RepositoryFileAclDto

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

the class RepositoryFileAclAdapter method unmarshal.

@Override
public RepositoryFileAcl unmarshal(final RepositoryFileAclDto v) {
    RepositoryFileAcl.Builder builder = null;
    if (v.getOwnerType() != -1) {
        if (v.getId() != null) {
            builder = new RepositoryFileAcl.Builder(v.getId(), v.getOwner(), RepositoryFileSid.Type.values()[v.getOwnerType()]);
        } else {
            builder = new RepositoryFileAcl.Builder(v.getTenantPath(), v.getOwner(), RepositoryFileSid.Type.values()[v.getOwnerType()]);
        }
    } else {
        builder = new RepositoryFileAcl.Builder((Serializable) v.getId(), null);
    }
    builder.entriesInheriting(v.isEntriesInheriting());
    for (RepositoryFileAclAceDto fileAclAceDto : v.getAces()) {
        builder.ace(RepositoryFileAclAceAdapter.toAce(fileAclAceDto));
    }
    return builder.build();
}
Also used : Serializable(java.io.Serializable) RepositoryFileAclAceDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Example 54 with RepositoryFileAclDto

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

the class FileResourceTest method usersOrRolesExist_RecipientUserExists.

@Test
public void usersOrRolesExist_RecipientUserExists() {
    RepositoryFileAclDto acl = new RepositoryFileAclDto();
    acl.setOwner(ACL_OWNER);
    RepositoryFileAclAceDto recipient = mock(RepositoryFileAclAceDto.class);
    doReturn(USERNAME).when(recipient).getRecipient();
    acl.setAces(Arrays.asList(new RepositoryFileAclAceDto[] { recipient }), false);
    assertTrue(fileResource.validateUsersAndRoles(acl));
}
Also used : RepositoryFileAclAceDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto) RepositoryFileAclDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto) Test(org.junit.Test)

Example 55 with RepositoryFileAclDto

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

the class FileResourceTest method testSetFileAclsError.

@Test
public void testSetFileAclsError() throws Exception {
    RepositoryFileAclDto repository = mock(RepositoryFileAclDto.class);
    doReturn(mock(Messages.class)).when(fileResource).getMessagesInstance();
    doReturn(true).when(fileResource).validateUsersAndRoles(any());
    doThrow(mock(RuntimeException.class)).when(fileResource.fileService).setFileAcls(PATH_ID, repository);
    assertEquals(INTERNAL_SERVER_ERROR.getStatusCode(), fileResource.setFileAcls(PATH_ID, repository).getStatus());
}
Also used : Messages(org.pentaho.platform.web.http.messages.Messages) RepositoryFileAclDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto) 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