Search in sources :

Example 56 with RepositoryFileDto

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

the class FileResourceTest method testSetContentCreator.

@Test
public void testSetContentCreator() throws Exception {
    RepositoryFileDto mockRepositoryFileDto = mock(RepositoryFileDto.class);
    doNothing().when(fileResource.fileService).doSetContentCreator(PATH_ID, mockRepositoryFileDto);
    Response mockOkResponse = mock(Response.class);
    doReturn(mockOkResponse).when(fileResource).buildOkResponse();
    Response testResponse = fileResource.doSetContentCreator(PATH_ID, mockRepositoryFileDto);
    assertEquals(mockOkResponse, testResponse);
    verify(fileResource.fileService, times(1)).doSetContentCreator(PATH_ID, mockRepositoryFileDto);
    verify(fileResource, times(1)).buildOkResponse();
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) Response(javax.ws.rs.core.Response) Test(org.junit.Test)

Example 57 with RepositoryFileDto

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

the class FileResourceTest method testDoGetGeneratedContentForUserError.

@Test
public void testDoGetGeneratedContentForUserError() throws Exception {
    String user = "user";
    Exception mockFileNotFoundException = mock(FileNotFoundException.class);
    doThrow(mockFileNotFoundException).when(fileResource.fileService).doGetGeneratedContent(PATH_ID, user);
    Messages mockMessages = mock(Messages.class);
    doReturn(mockMessages).when(fileResource).getMessagesInstance();
    // Test 1
    List<RepositoryFileDto> testList = fileResource.doGetGeneratedContentForUser(PATH_ID, user);
    assertEquals(0, testList.size());
    // Test 2
    Throwable mockThrowable = mock(RuntimeException.class);
    doThrow(mockThrowable).when(fileResource.fileService).doGetGeneratedContent(PATH_ID, user);
    testList = fileResource.doGetGeneratedContentForUser(PATH_ID, user);
    assertEquals(0, testList.size());
    verify(fileResource.fileService, times(2)).doGetGeneratedContent(PATH_ID, user);
    verify(fileResource, times(1)).getMessagesInstance();
    verify(mockMessages, times(1)).getString("FileResource.GENERATED_CONTENT_FOR_USER_FAILED", PATH_ID, user);
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) Messages(org.pentaho.platform.web.http.messages.Messages) GeneralSecurityException(java.security.GeneralSecurityException) InvalidParameterException(java.security.InvalidParameterException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException) IllegalSelectorException(java.nio.channels.IllegalSelectorException) IOException(java.io.IOException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Test(org.junit.Test)

Example 58 with RepositoryFileDto

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

the class FileResourceTest method testDoGetContentCreatorError.

@Test
public void testDoGetContentCreatorError() throws Exception {
    Throwable mockThrowable = mock(RuntimeException.class);
    doThrow(mockThrowable).when(fileResource.fileService).doGetContentCreator(PATH_ID);
    RepositoryFileDto testDto = fileResource.doGetContentCreator(PATH_ID);
    assertNull(testDto);
    verify(fileResource.fileService, times(1)).doGetContentCreator(PATH_ID);
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) Test(org.junit.Test)

Example 59 with RepositoryFileDto

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

the class FileResourceIT method testDeleteFiles.

@Test
public void testDeleteFiles() {
    loginAsRepositoryAdmin();
    ITenant systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminAuthorityName, authenticatedAuthorityName, "Anonymous");
    userRoleDao.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminAuthorityName });
    ITenant mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminAuthorityName, authenticatedAuthorityName, "Anonymous");
    userRoleDao.createUser(mainTenant_1, "admin", "password", "", new String[] { adminAuthorityName });
    try {
        login("admin", mainTenant_1, new String[] { authenticatedAuthorityName });
        String testFile1Id = "abc.txt";
        String testFile2Id = "def.txt";
        // set object in PentahoSystem
        mp.defineInstance(IUnifiedRepository.class, repo);
        String publicFolderPath = ClientRepositoryPaths.getPublicFolderPath();
        createTestFile(publicFolderPath.replaceAll("/", ":") + ":" + testFile1Id, "abcdefg");
        createTestFile(publicFolderPath.replaceAll("/", ":") + ":" + testFile2Id, "abcdefg");
        createTestFolder(":home:admin");
        RepositoryFile file1 = repo.getFile(publicFolderPath + "/" + testFile1Id);
        RepositoryFile file2 = repo.getFile(publicFolderPath + "/" + testFile2Id);
        WebResource webResource = resource();
        webResource.path("repo/files/delete").entity(file1.getId() + "," + file2.getId()).put();
        RepositoryFileDto[] deletedFiles = webResource.path("repo/files/deleted").accept(APPLICATION_XML).get(RepositoryFileDto[].class);
        assertEquals(2, deletedFiles.length);
        webResource.path("repo/files/deletepermanent").entity(file2.getId()).put();
    } catch (Throwable ex) {
        TestCase.fail();
    } finally {
        cleanupUserAndRoles(mainTenant_1);
        cleanupUserAndRoles(systemTenant);
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) ITenant(org.pentaho.platform.api.mt.ITenant) WebResource(com.sun.jersey.api.client.WebResource) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) JerseyTest(com.sun.jersey.test.framework.JerseyTest) Test(org.junit.Test)

Example 60 with RepositoryFileDto

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

the class RepositoryFileAdapter method toFile.

public static RepositoryFile toFile(final RepositoryFileDto v) {
    if (v == null) {
        return null;
    }
    RepositoryFile.Builder builder = null;
    if (v.getId() != null) {
        builder = new RepositoryFile.Builder(v.getId(), v.getName());
    } else {
        builder = new RepositoryFile.Builder(v.getName());
    }
    if (v.getOwnerType() != -1) {
        new RepositoryFileSid(v.getOwner(), RepositoryFileSid.Type.values()[v.getOwnerType()]);
    }
    if (v.getLocalePropertiesMapEntries() != null) {
        for (LocaleMapDto localeMapDto : v.getLocalePropertiesMapEntries()) {
            String locale = localeMapDto.getLocale();
            Properties localeProperties = new Properties();
            if (localeMapDto.getProperties() != null) {
                for (StringKeyStringValueDto keyValueDto : localeMapDto.getProperties()) {
                    localeProperties.put(keyValueDto.getKey(), keyValueDto.getValue());
                }
            }
            builder.localeProperties(locale, localeProperties);
        }
    }
    return builder.path(v.getPath()).createdDate(unmarshalDate(v.getCreatedDate())).creatorId(v.getCreatorId()).description(v.getDescription()).folder(v.isFolder()).fileSize(v.getFileSize()).lastModificationDate(unmarshalDate(v.getLastModifiedDate())).locale(v.getLocale()).lockDate(unmarshalDate(v.getLockDate())).locked(v.isLocked()).lockMessage(v.getLockMessage()).lockOwner(v.getLockOwner()).title(v.getTitle()).versioned(v.isVersioned()).versionId(v.getVersionId()).originalParentFolderPath(v.getOriginalParentFolderPath()).deletedDate(unmarshalDate(v.getDeletedDate())).hidden(v.isHidden()).schedulable(!v.isNotSchedulable()).aclNode(v.isAclNode()).build();
}
Also used : StringKeyStringValueDto(org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto) RepositoryFileSid(org.pentaho.platform.api.repository2.unified.RepositoryFileSid) LocaleMapDto(org.pentaho.platform.api.repository2.unified.webservices.LocaleMapDto) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Properties(java.util.Properties)

Aggregations

Test (org.junit.Test)77 RepositoryFileDto (org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto)77 FileNotFoundException (java.io.FileNotFoundException)35 ArrayList (java.util.ArrayList)34 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)29 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)27 Serializable (java.io.Serializable)26 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)26 Matchers.anyString (org.mockito.Matchers.anyString)25 GeneralSecurityException (java.security.GeneralSecurityException)14 StringKeyStringValueDto (org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto)11 IllegalSelectorException (java.nio.channels.IllegalSelectorException)9 InvalidParameterException (java.security.InvalidParameterException)9 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)9 Properties (java.util.Properties)8 UnifiedRepositoryAccessDeniedException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException)8 DefaultUnifiedRepositoryWebService (org.pentaho.platform.repository2.unified.webservices.DefaultUnifiedRepositoryWebService)8 IOException (java.io.IOException)7 IRepositoryFileData (org.pentaho.platform.api.repository2.unified.IRepositoryFileData)7 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)7