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));
}
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());
}
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));
}
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);
}
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);
}
Aggregations