Search in sources :

Example 56 with RepositoryFileDto

use of org.pentaho.platform.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 57 with RepositoryFileDto

use of org.pentaho.platform.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 58 with RepositoryFileDto

use of org.pentaho.platform.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 59 with RepositoryFileDto

use of org.pentaho.platform.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 60 with RepositoryFileDto

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

the class FileResourceTest method testDoGetRootProperties.

@Test
public void testDoGetRootProperties() {
    RepositoryFileDto mockRepositoryFileDto = mock(RepositoryFileDto.class);
    doReturn(mockRepositoryFileDto).when(fileResource.fileService).doGetRootProperties();
    RepositoryFileDto testRepositoryFileDto = fileResource.doGetRootProperties();
    assertEquals(mockRepositoryFileDto, testRepositoryFileDto);
    verify(fileResource.fileService, times(1)).doGetRootProperties();
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) Test(org.junit.Test)

Aggregations

RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)66 Test (org.junit.Test)42 Matchers.anyString (org.mockito.Matchers.anyString)26 FileNotFoundException (java.io.FileNotFoundException)23 ArrayList (java.util.ArrayList)20 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)18 Serializable (java.io.Serializable)15 GeneralSecurityException (java.security.GeneralSecurityException)11 StringKeyStringValueDto (org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto)9 IllegalSelectorException (java.nio.channels.IllegalSelectorException)8 InvalidParameterException (java.security.InvalidParameterException)8 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)8 UnifiedRepositoryAccessDeniedException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException)8 IOException (java.io.IOException)7 IRepositoryFileData (org.pentaho.platform.api.repository2.unified.IRepositoryFileData)6 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)6 RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)6 Properties (java.util.Properties)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 RepositoryFileAclAceDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAceDto)4