Search in sources :

Example 21 with StringKeyStringValueDto

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

the class FileServiceIT method testDoSetLocalProperties.

@Test
public void testDoSetLocalProperties() throws Exception {
    String pathId = "path:to:file:file1.ext";
    String fileId = "file1";
    String locale = "";
    doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
    RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
    doReturn(fileId).when(repositoryFileDto).getId();
    doReturn(repositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile(nullable(String.class));
    Properties fileProperties = mock(Properties.class);
    doReturn(false).when(fileProperties).isEmpty();
    List<StringKeyStringValueDto> properties = new ArrayList<StringKeyStringValueDto>();
    properties.add(new StringKeyStringValueDto("key1", "value1"));
    properties.add(new StringKeyStringValueDto("key2", "value2"));
    fileService.doSetLocaleProperties(pathId, locale, properties);
    verify(fileService.defaultUnifiedRepositoryWebService).getFile("/path/to/file/file1.ext");
    verify(fileService.defaultUnifiedRepositoryWebService).setLocalePropertiesForFileByFileId(nullable(String.class), nullable(String.class), any(Properties.class));
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) StringKeyStringValueDto(org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto) ArrayList(java.util.ArrayList) Properties(java.util.Properties) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 22 with StringKeyStringValueDto

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

the class FileServiceIT 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(nullable(String.class));
    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(nullable(String.class), nullable(String.class));
    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(nullable(String.class), nullable(String.class));
    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.api.repository2.unified.webservices.RepositoryFileDto) StringKeyStringValueDto(org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto) Properties(java.util.Properties) PropertiesWrapper(org.pentaho.platform.repository2.unified.webservices.PropertiesWrapper) HashSet(java.util.HashSet) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 23 with StringKeyStringValueDto

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

the class FileServiceIT method doGetMetadata.

@Test
public void doGetMetadata() {
    String pathId = "path:to:file:file1.ext";
    List<StringKeyStringValueDto> stringKeyStringValueDtos = new ArrayList<StringKeyStringValueDto>();
    StringKeyStringValueDto stringKeyStringValueDto1 = mock(StringKeyStringValueDto.class);
    doReturn("key1").when(stringKeyStringValueDto1).getKey();
    doReturn("value1").when(stringKeyStringValueDto1).getValue();
    StringKeyStringValueDto stringKeyStringValueDto2 = mock(StringKeyStringValueDto.class);
    doReturn("key2").when(stringKeyStringValueDto2).getKey();
    doReturn("value2").when(stringKeyStringValueDto2).getValue();
    stringKeyStringValueDtos.add(stringKeyStringValueDto1);
    stringKeyStringValueDtos.add(stringKeyStringValueDto2);
    doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
    RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
    doReturn(repositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile(nullable(String.class));
    doReturn(true).when(repositoryFileDto).isHidden();
    doReturn(stringKeyStringValueDtos).when(fileService.defaultUnifiedRepositoryWebService).getFileMetadata(nullable(String.class));
    // Test 1
    try {
        List<StringKeyStringValueDto> list = fileService.doGetMetadata(pathId);
        assertEquals(4, list.size());
        Boolean hasIsHidden = false;
        Boolean hasScheduable = false;
        for (StringKeyStringValueDto item : list) {
            if (item.getKey().equals("_PERM_HIDDEN")) {
                hasIsHidden = true;
            }
            if (item.getKey().equals(RepositoryFile.SCHEDULABLE_KEY)) {
                hasScheduable = true;
            }
        }
        assertTrue(hasIsHidden);
        assertTrue(hasScheduable);
    } catch (FileNotFoundException e) {
        fail();
    }
    stringKeyStringValueDtos = new ArrayList<StringKeyStringValueDto>();
    stringKeyStringValueDtos.add(stringKeyStringValueDto1);
    stringKeyStringValueDtos.add(stringKeyStringValueDto2);
    StringKeyStringValueDto stringKeyStringValueDto3 = mock(StringKeyStringValueDto.class);
    doReturn(RepositoryFile.SCHEDULABLE_KEY).when(stringKeyStringValueDto3).getKey();
    doReturn("value3").when(stringKeyStringValueDto3).getValue();
    stringKeyStringValueDtos.add(stringKeyStringValueDto3);
    doReturn(stringKeyStringValueDtos).when(fileService.defaultUnifiedRepositoryWebService).getFileMetadata(nullable(String.class));
    // Test 2
    try {
        List<StringKeyStringValueDto> list = fileService.doGetMetadata(pathId);
        assertEquals(4, list.size());
        Boolean hasIsHidden = false;
        Boolean hasScheduable = false;
        for (StringKeyStringValueDto item : list) {
            if (item.getKey().equals("_PERM_HIDDEN")) {
                hasIsHidden = true;
            }
            if (item.getKey().equals(RepositoryFile.SCHEDULABLE_KEY)) {
                hasScheduable = true;
            }
        }
        assertTrue(hasIsHidden);
        assertTrue(hasScheduable);
    } catch (FileNotFoundException e) {
        fail();
    }
    doReturn(null).when(fileService.defaultUnifiedRepositoryWebService).getFileMetadata(nullable(String.class));
    // Test 3
    try {
        List<StringKeyStringValueDto> list = fileService.doGetMetadata(null);
        assertEquals(null, list);
    } catch (FileNotFoundException e) {
        fail();
    }
    verify(fileService, times(2)).idToPath(pathId);
    verify(fileService.defaultUnifiedRepositoryWebService, times(3)).getFile(nullable(String.class));
    verify(fileService.defaultUnifiedRepositoryWebService, times(3)).getFileMetadata(nullable(String.class));
}
Also used : StringKeyStringValueDto(org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto) RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 24 with StringKeyStringValueDto

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

the class UnifiedRepositoryToWebServiceAdapter method setFileMetadata.

@Override
public void setFileMetadata(final Serializable fileId, Map<String, Serializable> metadataMap) {
    Assert.notNull(fileId);
    Assert.notNull(metadataMap);
    List<StringKeyStringValueDto> fileMetadataMap = new ArrayList<StringKeyStringValueDto>(metadataMap.size());
    for (final String key : metadataMap.keySet()) {
        fileMetadataMap.add(new StringKeyStringValueDto(key, metadataMap.get(key).toString()));
    }
    repoWebService.setFileMetadata(fileId.toString(), fileMetadataMap);
}
Also used : StringKeyStringValueDto(org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto) ArrayList(java.util.ArrayList)

Example 25 with StringKeyStringValueDto

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

the class FileResourceTest method testDoSetMetadataError.

@Test
public void testDoSetMetadataError() throws Exception {
    List<StringKeyStringValueDto> metadata = mock(List.class);
    Response mockUnauthorizedResponse = mock(Response.class);
    doReturn(mockUnauthorizedResponse).when(fileResource).buildStatusResponse(Response.Status.UNAUTHORIZED);
    Throwable mockThrowable = mock(RuntimeException.class);
    String errMsg = "errMsg";
    doReturn(errMsg).when(mockThrowable).getMessage();
    Response mockThrowableResponse = mock(Response.class);
    doReturn(mockThrowableResponse).when(fileResource).buildServerErrorResponse(errMsg);
    // Test 1
    Exception mockGeneralSecurityException = mock(GeneralSecurityException.class);
    doThrow(mockGeneralSecurityException).when(fileResource.fileService).doSetMetadata(PATH_ID, metadata);
    Response testResponse = fileResource.doSetMetadata(PATH_ID, metadata);
    assertEquals(mockUnauthorizedResponse, testResponse);
    // Test 2
    doThrow(mockThrowable).when(fileResource.fileService).doSetMetadata(PATH_ID, metadata);
    testResponse = fileResource.doSetMetadata(PATH_ID, metadata);
    assertEquals(mockThrowableResponse, testResponse);
    verify(fileResource.fileService, times(2)).doSetMetadata(PATH_ID, metadata);
    verify(fileResource, times(1)).buildStatusResponse(Response.Status.UNAUTHORIZED);
    verify(mockThrowable, times(1)).getMessage();
    verify(fileResource, times(1)).buildServerErrorResponse(errMsg);
}
Also used : StringKeyStringValueDto(org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto) Response(javax.ws.rs.core.Response) 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)

Aggregations

StringKeyStringValueDto (org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto)20 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)14 RepositoryFileDto (org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto)12 GeneralSecurityException (java.security.GeneralSecurityException)9 FileNotFoundException (java.io.FileNotFoundException)8 Serializable (java.io.Serializable)8 Properties (java.util.Properties)8 Matchers.anyString (org.mockito.Matchers.anyString)6 StringKeyStringValueDto (org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto)6 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)5 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 IOException (java.io.IOException)4 IllegalSelectorException (java.nio.channels.IllegalSelectorException)4 InvalidParameterException (java.security.InvalidParameterException)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)4