Search in sources :

Example 16 with RepositoryFileDto

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

the class FileServiceTest method testDoGetLocalProperties.

@Test
public void testDoGetLocalProperties() throws Exception {
    String pathId = "path:to:file:file1.ext";
    String fileId = "file1";
    String locale = "";
    doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
    Set<String> propertiesList = new HashSet<String>();
    propertiesList.add("prop1");
    propertiesList.add("prop2");
    RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
    doReturn(fileId).when(repositoryFileDto).getId();
    doReturn(repositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
    Properties properties = mock(Properties.class);
    doReturn("value1").when(properties).getProperty("prop1");
    doReturn("value2").when(properties).getProperty("prop2");
    doReturn(false).when(properties).isEmpty();
    doReturn(propertiesList).when(properties).stringPropertyNames();
    PropertiesWrapper propertiesWrapper = mock(PropertiesWrapper.class);
    when(propertiesWrapper.getProperties()).thenReturn(properties);
    doReturn(propertiesWrapper).when(fileService.defaultUnifiedRepositoryWebService).getLocalePropertiesForFileById(anyString(), anyString());
    List<StringKeyStringValueDto> keyValueList = fileService.doGetLocaleProperties(pathId, locale);
    verify(fileService.defaultUnifiedRepositoryWebService).getFile("/path/to/file/file1.ext");
    verify(properties).getProperty("prop1");
    verify(properties).getProperty("prop2");
    verify(properties).isEmpty();
    verify(properties).stringPropertyNames();
    verify(fileService.defaultUnifiedRepositoryWebService).getLocalePropertiesForFileById(anyString(), anyString());
    assertEquals(2, keyValueList.size());
    assertEquals("prop1", keyValueList.get(1).getKey());
    assertEquals("prop2", keyValueList.get(0).getKey());
    assertEquals("value1", keyValueList.get(1).getValue());
    assertEquals("value2", keyValueList.get(0).getValue());
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) StringKeyStringValueDto(org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto) Matchers.anyString(org.mockito.Matchers.anyString) Properties(java.util.Properties) PropertiesWrapper(org.pentaho.platform.repository2.unified.webservices.PropertiesWrapper) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with RepositoryFileDto

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

the class FileServiceTest method testDoGetChildren.

@Test
public void testDoGetChildren() {
    RepositoryFileDto mockRepositoryFileDto = mock(RepositoryFileDto.class);
    Collator mockCollator = mock(Collator.class);
    List<RepositoryFileDto> mockRepositoryFileDtos = new ArrayList<RepositoryFileDto>();
    mockRepositoryFileDtos.add(mockRepositoryFileDto);
    RepositoryRequest mockRepositoryRequest = mock(RepositoryRequest.class);
    doReturn(true).when(fileService).isPathValid(anyString());
    doReturn(mockRepositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
    doReturn(mockCollator).when(fileService).getCollator(anyInt());
    doReturn(mockRepositoryRequest).when(fileService).getRepositoryRequest((RepositoryFileDto) anyObject(), anyBoolean(), anyString(), anyBoolean());
    doReturn(mockRepositoryFileDtos).when(fileService.defaultUnifiedRepositoryWebService).getChildrenFromRequest(mockRepositoryRequest);
    doReturn(true).when(fileService).isShowingTitle(mockRepositoryRequest);
    List<RepositoryFileDto> repositoryFileDtos = fileService.doGetChildren("mock:path:fileName", null, true, true);
    verify(fileService, times(1)).isPathValid(anyString());
    verify(fileService.defaultUnifiedRepositoryWebService, times(1)).getFile(anyString());
    verify(fileService, times(1)).getCollator(anyInt());
    verify(fileService, times(1)).getRepositoryRequest((RepositoryFileDto) anyObject(), anyBoolean(), anyString(), anyBoolean());
    verify(fileService.defaultUnifiedRepositoryWebService, times(1)).getChildrenFromRequest(mockRepositoryRequest);
    verify(fileService, times(1)).isShowingTitle(mockRepositoryRequest);
    assertEquals(mockRepositoryFileDtos, repositoryFileDtos);
    assertEquals(1, repositoryFileDtos.size());
    assertEquals(mockRepositoryFileDto, repositoryFileDtos.get(0));
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) ArrayList(java.util.ArrayList) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) Collator(java.text.Collator) Test(org.junit.Test)

Example 18 with RepositoryFileDto

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

the class FileServiceTest 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.repository2.unified.webservices.RepositoryFileDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 19 with RepositoryFileDto

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

the class UnifiedRepositoryPurgeService method processPurgeForTree.

private void processPurgeForTree(RepositoryFileTreeDto tree, PurgeUtilitySpecification purgeSpecification) {
    for (RepositoryFileTreeDto child : tree.getChildren()) {
        try {
            if (!child.getChildren().isEmpty()) {
                processPurgeForTree(child, purgeSpecification);
            }
            RepositoryFileDto file = child.getFile();
            getLogger().setCurrentFilePath(file.getPath());
            if (file.isVersioned()) {
                if (purgeSpecification.isPurgeFiles()) {
                    getLogger().info("Purge File");
                    // the latest version will be removed with deleteFileWithPermanentFlag
                    keepNumberOfVersions(file.getId(), 1);
                    getRepoWs().deleteFileWithPermanentFlag(file.getId(), true, "purge utility");
                } else if (purgeSpecification.isPurgeRevisions()) {
                    getLogger().info("Purging Revisions");
                    deleteAllVersions(file.getId());
                } else {
                    if (purgeSpecification.getBeforeDate() != null) {
                        getLogger().info("Checking/purging by Revision date");
                        deleteVersionsBeforeDate(file.getId(), purgeSpecification.getBeforeDate());
                    }
                    if (purgeSpecification.getVersionCount() >= 0) {
                        getLogger().info("Checking/purging by number of Revisions");
                        keepNumberOfVersions(file.getId(), purgeSpecification.getVersionCount());
                    }
                }
            }
        } catch (Exception e) {
            getLogger().error(e);
        }
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) RepositoryFileTreeDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileTreeDto) KettleException(org.pentaho.di.core.exception.KettleException)

Example 20 with RepositoryFileDto

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

the class FileServiceIT 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.api.repository2.unified.webservices.RepositoryFileDto) FileNotFoundException(java.io.FileNotFoundException) 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