Search in sources :

Example 6 with SessionResource

use of org.pentaho.platform.web.http.api.resources.SessionResource 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 7 with SessionResource

use of org.pentaho.platform.web.http.api.resources.SessionResource in project pentaho-platform by pentaho.

the class SchedulerServiceTest method testDoGetGeneratedContentForSchedule.

@Test
public void testDoGetGeneratedContentForSchedule() throws Exception {
    String lineageId = "test.prpt";
    FileService mockFileService = mock(FileService.class);
    doReturn(mockFileService).when(schedulerService).getFileService();
    SessionResource mockSessionResource = mock(SessionResource.class);
    doReturn(mockSessionResource).when(schedulerService).getSessionResource();
    String currentUserDir = "currentUserDir";
    doReturn(currentUserDir).when(mockSessionResource).doGetCurrentUserDir();
    List<RepositoryFileDto> mockList = mock(List.class);
    doReturn(mockList).when(mockFileService).searchGeneratedContent(currentUserDir, lineageId, QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID);
    List<RepositoryFileDto> list = schedulerService.doGetGeneratedContentForSchedule(lineageId);
    assertEquals(mockList, list);
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) SessionResource(org.pentaho.platform.web.http.api.resources.SessionResource) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 Matchers.anyString (org.mockito.Matchers.anyString)7 SessionResource (org.pentaho.platform.web.http.api.resources.SessionResource)7 FileNotFoundException (java.io.FileNotFoundException)6 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)4 Serializable (java.io.Serializable)3 ArrayList (java.util.ArrayList)3 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3