Search in sources :

Example 71 with RepositoryFileDto

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

the class FileServiceTest method testDoGetTree.

@Test
public void testDoGetTree() {
    String pathId = ":path:to:file:file1.ext";
    int depth = 1;
    String filter = "*|FOLDERS";
    boolean showHidden = true;
    boolean includeAcls = true;
    // Test 1
    doReturn("test").when(fileService).idToPath(anyString());
    RepositoryRequest mockRequest = mock(RepositoryRequest.class);
    doReturn(mockRequest).when(fileService).getRepositoryRequest(anyString(), anyBoolean(), anyInt(), anyString());
    RepositoryFileDto mockChildFile = mock(RepositoryFileDto.class);
    doReturn("test").when(mockChildFile).getId();
    RepositoryFileTreeDto mockChildDto = mock(RepositoryFileTreeDto.class);
    doReturn(mockChildFile).when(mockChildDto).getFile();
    List<RepositoryFileTreeDto> mockChildrenDto = new ArrayList<RepositoryFileTreeDto>();
    mockChildrenDto.add(mockChildDto);
    RepositoryFileTreeDto mockTreeDto = mock(RepositoryFileTreeDto.class);
    doReturn(mockChildrenDto).when(mockTreeDto).getChildren();
    doReturn(mockTreeDto).when(fileService.defaultUnifiedRepositoryWebService).getTreeFromRequest(mockRequest);
    doReturn(true).when(fileService).isShowingTitle(mockRequest);
    Collator mockCollator = mock(Collator.class);
    doReturn(mockCollator).when(fileService).getCollatorInstance();
    doNothing().when(fileService).sortByLocaleTitle(mockCollator, mockTreeDto);
    Map<String, Serializable> fileMeta = new HashMap<String, Serializable>();
    fileMeta.put(IUnifiedRepository.SYSTEM_FOLDER, new Boolean(false));
    doReturn(fileMeta).when(fileService.repository).getFileMetadata(anyString());
    fileService.doGetTree(pathId, depth, filter, showHidden, includeAcls);
    verify(fileService, times(1)).idToPath(anyString());
    verify(mockRequest, times(1)).setIncludeAcls(anyBoolean());
    verify(mockCollator, times(1)).setStrength(Collator.PRIMARY);
    verify(fileService, times(1)).sortByLocaleTitle(mockCollator, mockTreeDto);
    // verify( mockTreeDto ).setChildren( mockChildrenDto );
    // Test 2 - path id is null
    pathId = null;
    fileService.doGetTree(pathId, depth, filter, showHidden, includeAcls);
    verify(fileService, times(1)).getRepositoryRequest(eq(FileUtils.PATH_SEPARATOR), anyBoolean(), anyInt(), anyString());
    // Test 3 - path id is set to the file utils path separator
    pathId = FileUtils.PATH_SEPARATOR;
    fileService.doGetTree(pathId, depth, filter, showHidden, includeAcls);
    verify(fileService, times(2)).getRepositoryRequest(eq(FileUtils.PATH_SEPARATOR), anyBoolean(), anyInt(), anyString());
    // Test 3 - includeSystemFolders is false
    mockRequest.setIncludeSystemFolders(false);
    doReturn(mockTreeDto).when(fileService.defaultUnifiedRepositoryWebService).getTreeFromRequest(mockRequest);
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) Serializable(java.io.Serializable) HashMap(java.util.HashMap) RepositoryFileTreeDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileTreeDto) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Collator(java.text.Collator) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) Test(org.junit.Test)

Example 72 with RepositoryFileDto

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

the class FileServiceTest method mockDoRestoreInHomeDir.

public void mockDoRestoreInHomeDir(FileService fileService) {
    IUnifiedRepository iUnifiedRepository = mock(IUnifiedRepository.class);
    List<RepositoryFileDto> homeFolderFiles = getMockedRepositoryFileDtoList(new String[] { FILE_1, FILE_3 });
    when(fileService.doGetChildren(eq(PATH_USER_HOME_FOLDER), anyString(), anyBoolean(), anyBoolean())).thenReturn(homeFolderFiles);
    when(fileService.getRepository()).thenReturn(iUnifiedRepository);
    when(fileService.doRestoreFilesInHomeDir(eq(PARAMS), anyInt())).thenCallRealMethod();
    RepositoryFile mockRepoFile1 = getMockedRepoFile(FILE_1);
    RepositoryFile mockRepoFile2 = getMockedRepoFile(FILE_2);
    when(iUnifiedRepository.getFileById(eq(FILE_1))).thenReturn(mockRepoFile1);
    when(iUnifiedRepository.getFileById(eq(FILE_2))).thenReturn(mockRepoFile2);
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 73 with RepositoryFileDto

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

the class FileServiceTest method testDoGetGeneratedContentForUser.

@Test
public void testDoGetGeneratedContentForUser() {
    String pathId = "test.prpt", user = "admin", userFolder = "public/admin";
    RepositoryFileDto fileDetailsMock = mock(RepositoryFileDto.class);
    RepositoryFile workspaceFolder = mock(RepositoryFile.class);
    doReturn(userFolder).when(workspaceFolder).getId();
    SessionResource sessionResource = mock(SessionResource.class);
    List<RepositoryFile> children = new ArrayList<RepositoryFile>();
    RepositoryFile mockedChild = mock(RepositoryFile.class);
    doReturn(false).when(mockedChild).isFolder();
    children.add(mockedChild);
    Map<String, Serializable> mockedFileMetadata = mock(Map.class);
    doReturn(pathId).when(mockedFileMetadata).get(PentahoJcrConstants.PHO_CONTENTCREATOR);
    when(fileService.repository.getFileMetadata(mockedChild.getId())).thenReturn(mockedFileMetadata);
    doReturn(pathId).when(fileDetailsMock).getId();
    doReturn(userFolder).when(sessionResource).doGetUserDir(user);
    doReturn(workspaceFolder).when(fileService.repository).getFile(userFolder);
    doReturn(sessionResource).when(fileService).getSessionResource();
    doReturn(children).when(fileService.repository).getChildren(userFolder);
    RepositoryFileDto mockedRepositoryFileDto = mock(RepositoryFileDto.class);
    doReturn(mockedRepositoryFileDto).when(fileService).toFileDto(mockedChild, null, false);
    try {
        doReturn(fileDetailsMock).when(fileService).doGetProperties(pathId);
        List<RepositoryFileDto> list = fileService.doGetGeneratedContent(pathId, user);
        assertEquals(list.size(), 1);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail();
    } catch (Throwable t) {
        fail();
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) Serializable(java.io.Serializable) SessionResource(org.pentaho.platform.web.http.api.resources.SessionResource) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 74 with RepositoryFileDto

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

the class FileServiceTest method testDoGetFileLocalesFileNotFoundException.

@Test
public void testDoGetFileLocalesFileNotFoundException() {
    String param = "file1";
    RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
    doReturn(param).when(repositoryFileDto).getId();
    doReturn(null).when(fileService.defaultUnifiedRepositoryWebService).getFile("/" + param);
    try {
        fileService.doGetFileLocales(param);
        fail();
    } catch (FileNotFoundException e) {
        verify(fileService.getRepository(), times(0)).getAvailableLocalesForFileById(repositoryFileDto.getId());
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) FileNotFoundException(java.io.FileNotFoundException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 75 with RepositoryFileDto

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

the class FileResourceIT method testFileCreator.

@Test
public void testFileCreator() {
    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 });
        // set object in PentahoSystem
        mp.defineInstance(IUnifiedRepository.class, repo);
        WebResource webResource = resource();
        String publicFolderPath = ClientRepositoryPaths.getPublicFolderPath();
        createTestFile(publicFolderPath.replaceAll("/", ":") + ":" + "file1.txt", "abcdefg");
        RepositoryFile file1 = repo.getFile(publicFolderPath + "/" + "file1.txt");
        RepositoryFileDto file2 = new RepositoryFileDto();
        file2.setId(file1.getId().toString());
        webResource.path("repo/files/public:file1.txt/creator").entity(file2).put();
    } catch (Throwable ex) {
        TestCase.fail();
    } finally {
        cleanupUserAndRoles(mainTenant_1);
        cleanupUserAndRoles(systemTenant);
        logout();
    }
}
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)

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