Search in sources :

Example 1 with SessionResource

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

the class FileServiceTest method testSearchGeneratedContentFileNotFound.

@Test
public void testSearchGeneratedContentFileNotFound() {
    String lineageId = "test.prpt", pathId = "test.prpt", userFolder = "public/admin";
    SessionResource sessionResource = mock(SessionResource.class);
    doReturn(userFolder).when(sessionResource).doGetCurrentUserDir();
    doReturn(sessionResource).when(fileService).getSessionResource();
    try {
        doReturn(null).when(fileService).doGetProperties(pathId);
        fileService.searchGeneratedContent(userFolder, lineageId, QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID);
        fail();
    } catch (FileNotFoundException e) {
    }
}
Also used : SessionResource(org.pentaho.platform.web.http.api.resources.SessionResource) FileNotFoundException(java.io.FileNotFoundException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 2 with SessionResource

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

the class FileServiceTest method testDoGetGeneratedContentFileNotFound.

@Test
public void testDoGetGeneratedContentFileNotFound() {
    String pathId = "test.prpt", userFolder = "public/admin";
    SessionResource sessionResource = mock(SessionResource.class);
    doReturn(userFolder).when(sessionResource).doGetCurrentUserDir();
    doReturn(sessionResource).when(fileService).getSessionResource();
    try {
        doReturn(null).when(fileService).doGetProperties(pathId);
        fileService.doGetGeneratedContent(pathId);
        fail();
    } catch (FileNotFoundException e) {
    }
}
Also used : SessionResource(org.pentaho.platform.web.http.api.resources.SessionResource) FileNotFoundException(java.io.FileNotFoundException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 3 with SessionResource

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

the class FileServiceTest method testDoGetGeneratedContentForUserFileNotFound.

@Test
public void testDoGetGeneratedContentForUserFileNotFound() {
    String pathId = "test.prpt", user = "admin", userFolder = "public/admin";
    SessionResource sessionResource = mock(SessionResource.class);
    doReturn(userFolder).when(sessionResource).doGetUserDir(user);
    doReturn(sessionResource).when(fileService).getSessionResource();
    try {
        doReturn(null).when(fileService).doGetProperties(pathId);
        fileService.doGetGeneratedContent(pathId, user);
        fail();
    } catch (FileNotFoundException e) {
    }
}
Also used : SessionResource(org.pentaho.platform.web.http.api.resources.SessionResource) FileNotFoundException(java.io.FileNotFoundException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 4 with SessionResource

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

the class FileServiceTest method testSearchGeneratedContent.

@Test
public void testSearchGeneratedContent() {
    String lineageId = "test.prpt", pathId = "test.prpt", 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(lineageId).when(mockedFileMetadata).get(QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID);
    when(fileService.repository.getFileMetadata(mockedChild.getId())).thenReturn(mockedFileMetadata);
    doReturn(pathId).when(fileDetailsMock).getId();
    doReturn(userFolder).when(sessionResource).doGetCurrentUserDir();
    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.searchGeneratedContent(userFolder, lineageId, QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID);
        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 5 with SessionResource

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

the class FileServiceTest method testDoGetGeneratedContent.

@Test
public void testDoGetGeneratedContent() {
    String pathId = "test.prpt", 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).doGetCurrentUserDir();
    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);
        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)

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