use of de.fraunhofer.iosb.ilt.faaast.service.model.api.Response in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandlerManagerTest method testSetSubmodelElementValueByPathRequest.
@Test
public void testSetSubmodelElementValueByPathRequest() throws ResourceNotFoundException, AssetConnectionException {
when(persistence.get((Reference) any(), any())).thenReturn(environment.getSubmodels().get(0).getSubmodelElements().get(0));
when(assetConnectionManager.hasValueProvider(any())).thenReturn(true);
PropertyValue propertyValue = new PropertyValue.Builder().value(new StringValue("Test")).build();
SetSubmodelElementValueByPathRequest request = new SetSubmodelElementValueByPathRequest.Builder<ElementValue>().id(environment.getSubmodels().get(0).getIdentification()).value(propertyValue).valueParser(new ElementValueParser<ElementValue>() {
@Override
public <U extends ElementValue> U parse(ElementValue raw, Class<U> type) {
return (U) raw;
}
}).path(ReferenceHelper.toKeys(SUBMODEL_ELEMENT_REF)).build();
Response response = manager.execute(request);
SetSubmodelElementValueByPathResponse expected = new SetSubmodelElementValueByPathResponse.Builder().statusCode(StatusCode.Success).build();
Assert.assertEquals(expected, response);
verify(assetValueProvider).setValue(propertyValue);
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.api.Response in project FAAAST-Service by FraunhoferIOSB.
the class OpcUaEndpoint method writeValue.
/**
* Writes the Value of the given SubmodelElement into the service.
*
* @param element The desired SubmodelElement including the new value
* @param submodel The corresponding submodel
* @param refElement The reference to the SubmodelElement
* @return True if the write succeeded, false otherwise
*/
public boolean writeValue(SubmodelElement element, Submodel submodel, Reference refElement) {
boolean retval = false;
if (element == null) {
throw new IllegalArgumentException("element == null");
} else if (submodel == null) {
throw new IllegalArgumentException("submodel == null");
}
try {
SetSubmodelElementValueByPathRequest request = new SetSubmodelElementValueByPathRequest();
List<Key> path = new ArrayList<>();
path.addAll(refElement.getKeys());
request.setId(submodel.getIdentification());
request.setPath(path);
request.setValueParser(new OpcUaElementValueParser());
if (element instanceof MultiLanguageProperty) {
MultiLanguageProperty mlp = (MultiLanguageProperty) element;
if ((mlp.getValues() != null) && (mlp.getValues().size() > 1)) {
for (int i = 0; i < mlp.getValues().size(); i++) {
logger.info("writeValue: MLP " + i + ": " + mlp.getValues().get(i).getValue());
}
}
}
request.setRawValue(ElementValueMapper.toValue(element));
if (request.getRawValue() instanceof MultiLanguagePropertyValue) {
MultiLanguagePropertyValue mlpv = (MultiLanguagePropertyValue) request.getRawValue();
if ((mlpv.getLangStringSet() != null) && (mlpv.getLangStringSet().size() > 1)) {
for (int i = 0; i < mlpv.getLangStringSet().size(); i++) {
logger.info("writeValue: MLPV " + i + ": " + mlpv.getLangStringSet().toArray()[i]);
}
}
}
Response response = service.execute(request);
logger.info("writeValue: Submodel " + submodel.getIdentification().getIdentifier() + "; Element " + element.getIdShort() + "; Status: " + response.getStatusCode());
if (isSuccess(response.getStatusCode())) {
retval = true;
}
} catch (Exception ex) {
logger.error("writeValue error", ex);
}
return retval;
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.api.Response in project FAAAST-Service by FraunhoferIOSB.
the class HttpEndpointTest method testGetAllSubmodelElements_ValueOnly.
@Test
public void testGetAllSubmodelElements_ValueOnly() throws Exception {
List<SubmodelElement> submodelElements = List.of(new DefaultProperty.Builder().idShort("property1").value("hello world").valueType("string").build(), new DefaultRange.Builder().idShort("range1").min("1.1").max("2.0").valueType("double").build());
when(serviceContext.execute(any())).thenReturn(GetAllSubmodelElementsResponse.builder().statusCode(StatusCode.Success).payload(submodelElements).build());
ContentResponse response = execute(HttpMethod.GET, "/submodels/foo/submodel/submodel-elements", new OutputModifier.Builder().content(Content.Value).build());
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
List<ElementValue> actual = deserializer.readValueList(new String(response.getContent()), TypeExtractor.extractTypeInfo(submodelElements));
List<ElementValue> expected = submodelElements.stream().map(x -> (ElementValue) ElementValueMapper.toValue(x)).collect(Collectors.toList());
Assert.assertEquals(expected, actual);
}
Aggregations