use of de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException in project FAAAST-Service by FraunhoferIOSB.
the class IntegrationTestHttpEndpoint method testGETShellsWithAssetIds.
@Test
public void testGETShellsWithAssetIds() throws IOException, DeserializationException {
String assetIdValue = "https://acplt.org/Test_Asset";
List<AssetAdministrationShell> expected = environment.getAssetAdministrationShells().stream().filter(x -> x.getAssetInformation().getGlobalAssetId().getKeys().stream().anyMatch(y -> y.getValue().equalsIgnoreCase(assetIdValue))).collect(Collectors.toList());
String assetIdsParameter = "[{\"key\": \"globalAssetId\",\"value\":\"" + assetIdValue + "\"}]";
HttpResponse response = getListCall(HTTP_SHELLS + "?assetIds=" + Base64.getUrlEncoder().encodeToString(assetIdsParameter.getBytes(StandardCharsets.UTF_8)));
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
List<AssetAdministrationShell> actual = retrieveResourceFromResponseList(response, AssetAdministrationShell.class);
Assert.assertEquals(expected, actual);
}
use of de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException in project FAAAST-Service by FraunhoferIOSB.
the class IntegrationTestHttpEndpoint method testGETShellsWithIdShort.
@Test
public void testGETShellsWithIdShort() throws IOException, DeserializationException {
List<AssetAdministrationShell> expected = environment.getAssetAdministrationShells().stream().filter(x -> x.getIdShort().equalsIgnoreCase(environment.getAssetAdministrationShells().get(0).getIdShort())).collect(Collectors.toList());
HttpResponse response = getListCall(HTTP_SHELLS + "?idShort=" + environment.getAssetAdministrationShells().get(0).getIdShort());
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
List<AssetAdministrationShell> actual = retrieveResourceFromResponseList(response, AssetAdministrationShell.class);
Assert.assertEquals(expected, actual);
}
use of de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException in project FAAAST-Service by FraunhoferIOSB.
the class JsonDeserializerTest method compareValueList.
private void compareValueList(Map<SubmodelElement, File> input) throws DeserializationException, IOException {
List<Object> expected = input.keySet().stream().map(x -> ElementValueMapper.toValue(x)).collect(Collectors.toList());
TypeInfo typeInfo = TypeExtractor.extractTypeInfo(input.keySet());
List<ElementValue> actual = deserializer.readValueList(filesAsJsonArray(input), typeInfo);
Assert.assertEquals(expected, actual);
}
use of de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException in project FAAAST-Service by FraunhoferIOSB.
the class SetSubmodelElementValueByPathRequestMapper method parse.
@Override
public Request parse(HttpRequest httpRequest) {
final List<Key> path = ElementPathHelper.toKeys(EncodingHelper.urlDecode(httpRequest.getPathElements().get(4)));
final Identifier identifier = IdentifierHelper.parseIdentifier(EncodingHelper.base64Decode(httpRequest.getPathElements().get(1)));
return SetSubmodelElementValueByPathRequest.builder().id(identifier).path(path).value(httpRequest.getBody()).valueParser(new ElementValueParser<Object>() {
@Override
public <U extends ElementValue> U parse(Object raw, Class<U> type) throws DeserializationException {
if (ElementValue.class.isAssignableFrom(type)) {
return deserializer.readValue(raw.toString(), serviceContext.getTypeInfo(ReferenceHelper.toReference(path, identifier, Submodel.class)));
} else if (SubmodelElement.class.isAssignableFrom(type)) {
SubmodelElement submodelElement = (SubmodelElement) deserializer.read(raw.toString(), type);
return ElementValueMapper.toValue(submodelElement);
}
throw new DeserializationException(String.format("error deserializing payload - invalid type '%s' (must be either instance of ElementValue or SubmodelElement", type.getSimpleName()));
}
}).build();
}
use of de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException in project FAAAST-Service by FraunhoferIOSB.
the class JsonDeserializerTest method compareValueMap.
private void compareValueMap(Map<SubmodelElement, File> input) throws DeserializationException, IOException {
Map<Object, ElementValue> expected = input.keySet().stream().collect(Collectors.toMap(x -> x.getIdShort(), x -> ElementValueMapper.toValue(x)));
TypeInfo typeInfo = TypeExtractor.extractTypeInfo(input.keySet().stream().collect(Collectors.toMap(x -> x.getIdShort(), x -> x)));
Map<Object, ElementValue> actual = deserializer.readValueMap(filesAsJsonObject(input), typeInfo);
Assert.assertEquals(expected, actual);
}
Aggregations