Search in sources :

Example 21 with RepositoryFileDto

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

the class FileServiceIT method testDoCreateDirs.

@Test
public void testDoCreateDirs() throws Exception {
    String pathId = "path:to:file:file1.ext";
    doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
    RepositoryFileDto parentDir = mock(RepositoryFileDto.class);
    doReturn("").when(parentDir).getPath();
    doReturn(FileUtils.PATH_SEPARATOR).when(parentDir).getId();
    when(fileService.getRepoWs().getFile(FileUtils.PATH_SEPARATOR)).thenReturn(parentDir);
    when(fileService.getRepoWs().getFile("/path")).thenReturn(null);
    when(fileService.getRepoWs().getFile("/to")).thenReturn(null);
    when(fileService.getRepoWs().getFile("/file")).thenReturn(null);
    when(fileService.getRepoWs().getFile("/file1.ext")).thenReturn(null);
    RepositoryFileDto filePath = mock(RepositoryFileDto.class);
    doReturn("/path").when(filePath).getPath();
    doReturn("/path").when(filePath).getId();
    RepositoryFileDto fileTo = mock(RepositoryFileDto.class);
    doReturn("/path/to").when(fileTo).getPath();
    doReturn("/path/to").when(fileTo).getId();
    RepositoryFileDto fileFile = mock(RepositoryFileDto.class);
    doReturn("/path/to/file").when(fileFile).getPath();
    doReturn("/path/to/file").when(fileFile).getId();
    RepositoryFileDto fileFileExt = mock(RepositoryFileDto.class);
    doReturn("/path/to/file/file1").when(fileFileExt).getPath();
    doReturn("/path/to/file/file1").when(fileFileExt).getId();
    when(fileService.getRepoWs().createFolder(eq("/"), any(RepositoryFileDto.class), eq("/path"))).thenReturn(filePath);
    when(fileService.getRepoWs().createFolder(eq("/path"), any(RepositoryFileDto.class), eq("/path/to"))).thenReturn(fileTo);
    when(fileService.getRepoWs().createFolder(eq("/path/to"), any(RepositoryFileDto.class), eq("/path/to/file"))).thenReturn(fileFile);
    when(fileService.getRepoWs().createFolder(eq("/path/to/file"), any(RepositoryFileDto.class), eq("/path/to/file/file1.ext"))).thenReturn(fileFileExt);
    assertTrue(fileService.doCreateDir(pathId));
    verify(fileService.getRepoWs(), times(4)).createFolder(nullable(String.class), any(RepositoryFileDto.class), nullable(String.class));
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 22 with RepositoryFileDto

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

the class FileServiceIT method doSetMetadataException.

@Test
public void doSetMetadataException() {
    String pathId = "path:to:file:file1.ext";
    List<StringKeyStringValueDto> stringKeyStringValueDtos = new ArrayList<StringKeyStringValueDto>();
    doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
    doReturn(false).when(fileService.policy).isAllowed(RepositoryReadAction.NAME);
    doReturn(false).when(fileService.policy).isAllowed(RepositoryCreateAction.NAME);
    doReturn(false).when(fileService.policy).isAllowed(AdministerSecurityAction.NAME);
    RepositoryFileDto file = mock(RepositoryFileDto.class);
    doReturn(file).when(fileService.defaultUnifiedRepositoryWebService).getFile(nullable(String.class));
    RepositoryFileAclDto repositoryFileAclDto = mock(RepositoryFileAclDto.class);
    doReturn("sessionName").when(repositoryFileAclDto).getOwner();
    doReturn(repositoryFileAclDto).when(fileService.defaultUnifiedRepositoryWebService).getAcl(nullable(String.class));
    IPentahoSession pentahoSession = mock(IPentahoSession.class);
    doReturn(pentahoSession).when(fileService).getSession();
    doReturn("sessionName1").when(pentahoSession).getName();
    try {
        fileService.doSetMetadata(pathId, stringKeyStringValueDtos);
        fail();
    } catch (GeneralSecurityException e) {
    // Should catch the exception
    }
    verify(fileService.defaultUnifiedRepositoryWebService).getFile(nullable(String.class));
    verify(fileService.defaultUnifiedRepositoryWebService).getAcl(nullable(String.class));
    verify(repositoryFileAclDto).getOwner();
    verify(fileService.policy).isAllowed(nullable(String.class));
}
Also used : StringKeyStringValueDto(org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto) RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) RepositoryFileAclDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto) GeneralSecurityException(java.security.GeneralSecurityException) ArrayList(java.util.ArrayList) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 23 with RepositoryFileDto

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

the class FileServiceIT method testDoMoveFiles.

@Test
public void testDoMoveFiles() throws Exception {
    String destPathId = "/test";
    String[] params = { "file1", "file2" };
    RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
    doReturn(destPathId).when(repositoryFileDto).getPath();
    doReturn(repositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile(destPathId);
    fileService.doMoveFiles(destPathId, StringUtils.join(params, ","));
    verify(fileService.getRepoWs(), times(1)).moveFile(params[0], destPathId, null);
    verify(fileService.getRepoWs(), times(1)).moveFile(params[1], destPathId, null);
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 24 with RepositoryFileDto

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

the class FileServiceIT 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(nullable(String.class));
    RepositoryRequest mockRequest = mock(RepositoryRequest.class);
    doReturn(mockRequest).when(fileService).getRepositoryRequest(nullable(String.class), anyBoolean(), anyInt(), nullable(String.class));
    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(nullable(String.class));
    fileService.doGetTree(pathId, depth, filter, showHidden, includeAcls);
    verify(fileService, times(1)).idToPath(nullable(String.class));
    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(), nullable(String.class));
    // 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(), nullable(String.class));
    // Test 3 - includeSystemFolders is false
    mockRequest.setIncludeSystemFolders(false);
    doReturn(mockTreeDto).when(fileService.defaultUnifiedRepositoryWebService).getTreeFromRequest(mockRequest);
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) Serializable(java.io.Serializable) HashMap(java.util.HashMap) RepositoryFileTreeDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileTreeDto) ArrayList(java.util.ArrayList) Collator(java.text.Collator) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 25 with RepositoryFileDto

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

the class FileServiceIT method testDoGetFileLocales.

@Test
public void testDoGetFileLocales() {
    String param = "file1";
    RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
    List<PentahoLocale> locales = new ArrayList<PentahoLocale>();
    PentahoLocale mockedLocale = mock(PentahoLocale.class);
    locales.add(mockedLocale);
    doReturn(param).when(repositoryFileDto).getId();
    doReturn(repositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile("/" + param);
    when(fileService.defaultUnifiedRepositoryWebService.getAvailableLocalesForFileById(repositoryFileDto.getId())).thenReturn(locales);
    try {
        fileService.doGetFileLocales(param);
        verify(fileService.getRepository(), times(0)).getAvailableLocalesForFileById(repositoryFileDto.getId());
    } catch (FileNotFoundException e) {
        fail();
    } catch (InternalError e) {
        fail();
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) PentahoLocale(org.pentaho.platform.repository2.locale.PentahoLocale) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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