Search in sources :

Example 61 with RepositoryFileDto

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

the class FileResourceTest method testDoGetProperties.

@Test
public void testDoGetProperties() throws Exception {
    RepositoryFileDto mockRepositoryFileDto = mock(RepositoryFileDto.class);
    doReturn(mockRepositoryFileDto).when(fileResource.fileService).doGetProperties(PATH_ID);
    RepositoryFileDto testDto = fileResource.doGetProperties(PATH_ID);
    assertEquals(mockRepositoryFileDto, testDto);
    verify(fileResource.fileService, times(1)).doGetProperties(PATH_ID);
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) Test(org.junit.Test)

Example 62 with RepositoryFileDto

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

the class FileResourceTest method testDoGetGeneratedContentError.

@Test
public void testDoGetGeneratedContentError() throws Exception {
    Exception mockFileNotFoundException = mock(FileNotFoundException.class);
    doThrow(mockFileNotFoundException).when(fileResource.fileService).doGetGeneratedContent(PATH_ID);
    Messages mockMessages = mock(Messages.class);
    doReturn(mockMessages).when(fileResource).getMessagesInstance();
    // Test 1
    List<RepositoryFileDto> testList = fileResource.doGetGeneratedContent(PATH_ID);
    assertEquals(0, testList.size());
    // Test 2
    Throwable mockThrowable = mock(RuntimeException.class);
    doThrow(mockThrowable).when(fileResource.fileService).doGetGeneratedContent(PATH_ID);
    testList = fileResource.doGetGeneratedContent(PATH_ID);
    assertEquals(0, testList.size());
    verify(fileResource.fileService, times(2)).doGetGeneratedContent(PATH_ID);
    verify(fileResource, times(1)).getMessagesInstance();
    verify(mockMessages, times(1)).getString("FileResource.GENERATED_CONTENT_FAILED", PATH_ID);
}
Also used : RepositoryFileDto(org.pentaho.platform.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 63 with RepositoryFileDto

use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto 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)

Example 64 with RepositoryFileDto

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

the class UnifiedRepositoryToWebServiceAdapter method getDataForReadInBatch.

@Override
@SuppressWarnings("unchecked")
public <T extends IRepositoryFileData> java.util.List<T> getDataForReadInBatch(final List<RepositoryFile> files, final Class<T> dataClass) {
    List<RepositoryFileDto> fileDtos = new ArrayList<RepositoryFileDto>(files.size());
    for (RepositoryFile file : files) {
        fileDtos.add(repositoryFileAdapter.marshal(file));
    }
    if (dataClass.equals(NodeRepositoryFileData.class)) {
        List<NodeRepositoryFileDataDto> nodeData = repoWebService.getDataAsNodeForReadInBatch(fileDtos);
        List<T> data = new ArrayList<T>(nodeData.size());
        for (NodeRepositoryFileDataDto node : nodeData) {
            data.add((T) nodeRepositoryFileDataAdapter.unmarshal(node));
        }
        return data;
    } else if (dataClass.equals(SimpleRepositoryFileData.class)) {
        List<SimpleRepositoryFileDataDto> nodeData = repoWebService.getDataAsBinaryForReadInBatch(fileDtos);
        List<T> data = new ArrayList<T>(nodeData.size());
        for (SimpleRepositoryFileDataDto node : nodeData) {
            data.add((T) SimpleRepositoryFileDataDto.convert(node));
        }
        return data;
    } else {
        throw new IllegalArgumentException();
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) NodeRepositoryFileDataDto(org.pentaho.platform.repository2.unified.webservices.NodeRepositoryFileDataDto) ArrayList(java.util.ArrayList) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) ArrayList(java.util.ArrayList) List(java.util.List)

Example 65 with RepositoryFileDto

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

the class RepositoryFileUtils method convertFromRepositoryFileTree.

public static RepositoryFileTreeDto convertFromRepositoryFileTree(RepositoryFileTree tree) {
    RepositoryFileTreeDto fileTreeDto = new RepositoryFileTreeDto();
    List<RepositoryFileTreeDto> fileList = new ArrayList<RepositoryFileTreeDto>();
    RepositoryFileDto file = convertFromRepositoryFile(tree.getFile());
    fileTreeDto.setFile(file);
    for (RepositoryFileTree treeItem : tree.getChildren()) {
        fileList.add(convertFromRepositoryFileTree(treeItem));
    }
    fileTreeDto.setChildren(fileList);
    return fileTreeDto;
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) RepositoryFileTreeDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileTreeDto) ArrayList(java.util.ArrayList) RepositoryFileTree(org.pentaho.gwt.widgets.client.filechooser.RepositoryFileTree)

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