use of io.adminshell.aas.v3.model.SubmodelElement in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandlerManagerTest method testReadValueFromAssetConnectionAndUpdatePersistence.
@Test
public void testReadValueFromAssetConnectionAndUpdatePersistence() throws AssetConnectionException, ResourceNotFoundException {
RequestHandler requestHandler = new DeleteSubmodelByIdRequestHandler(persistence, messageBus, assetConnectionManager);
Reference parentRef = new DefaultReference.Builder().key(new DefaultKey.Builder().value("sub").idType(KeyType.IRI).type(KeyElements.SUBMODEL).build()).build();
SubmodelElement prop1 = new DefaultProperty.Builder().idShort("prop1").value("test").valueType("string").build();
SubmodelElement range = new DefaultRange.Builder().idShort("range1").max("1.0").min("0").valueType("double").build();
SubmodelElement prop2 = new DefaultProperty.Builder().idShort("prop2").value("test").valueType("string").build();
SubmodelElementCollection collection = new DefaultSubmodelElementCollection.Builder().idShort("col1").value(prop2).build();
SubmodelElement prop1_new = new DefaultProperty.Builder().idShort("prop1").value("testNew").valueType("string").build();
SubmodelElement range_new = new DefaultRange.Builder().idShort("range1").max("1.0").min("0").valueType("double").build();
SubmodelElement prop2_new = new DefaultProperty.Builder().idShort("prop2").value("testNew").valueType("string").build();
List<SubmodelElement> submodelElements = List.of(prop1, range, collection);
AssetValueProvider provider_prop1 = mock(AssetValueProvider.class);
AssetValueProvider provider_prop2 = mock(AssetValueProvider.class);
AssetValueProvider provider_range1 = mock(AssetValueProvider.class);
when(assetConnectionManager.hasValueProvider(any())).thenReturn(true);
// mock value prop1
when(assetConnectionManager.getValueProvider(AasUtils.toReference(parentRef, prop1))).thenReturn(provider_prop1);
when(provider_prop1.getValue()).thenReturn(ElementValueMapper.toValue(prop1_new));
// mock value prop2
when(assetConnectionManager.getValueProvider(AasUtils.toReference(AasUtils.toReference(parentRef, collection), prop2))).thenReturn(provider_prop2);
when(provider_prop2.getValue()).thenReturn(ElementValueMapper.toValue(prop2_new));
// mock value range
when(assetConnectionManager.getValueProvider(AasUtils.toReference(parentRef, range))).thenReturn(provider_range1);
when(provider_range1.getValue()).thenReturn(ElementValueMapper.toValue(range_new));
requestHandler.readValueFromAssetConnectionAndUpdatePersistence(parentRef, submodelElements);
verify(persistence).put(null, AasUtils.toReference(parentRef, prop1), prop1_new);
verify(persistence).put(null, AasUtils.toReference(AasUtils.toReference(parentRef, collection), prop2), prop2_new);
Assert.assertEquals(prop1_new, prop1);
Assert.assertEquals(prop2_new, prop2);
Assert.assertEquals(range_new, range);
}
use of io.adminshell.aas.v3.model.SubmodelElement in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandlerManagerTest method testPostSubmodelElementRequest.
@Test
public void testPostSubmodelElementRequest() throws ResourceNotFoundException {
Reference reference = ReferenceHelper.toReference(environment.getSubmodels().get(0).getIdentification(), Submodel.class);
when(persistence.put(reference, (Reference) null, environment.getSubmodels().get(0).getSubmodelElements().get(0))).thenReturn(environment.getSubmodels().get(0).getSubmodelElements().get(0));
PostSubmodelElementRequest request = new PostSubmodelElementRequest.Builder().id(environment.getSubmodels().get(0).getIdentification()).submodelElement(environment.getSubmodels().get(0).getSubmodelElements().get(0)).build();
PostSubmodelElementResponse response = manager.execute(request);
PostSubmodelElementResponse expected = new PostSubmodelElementResponse.Builder().statusCode(StatusCode.SuccessCreated).payload(environment.getSubmodels().get(0).getSubmodelElements().get(0)).build();
Assert.assertEquals(expected, response);
}
use of io.adminshell.aas.v3.model.SubmodelElement in project FAAAST-Service by FraunhoferIOSB.
the class InvokeOperationSyncRequestHandler method process.
@Override
public InvokeOperationSyncResponse process(InvokeOperationSyncRequest request) {
Reference reference = ReferenceHelper.toReference(request.getPath(), request.getId(), Submodel.class);
InvokeOperationSyncResponse response = new InvokeOperationSyncResponse();
try {
// Check if submodelelement does exist
Operation operation = (Operation) persistence.get(reference, new OutputModifier());
publishOperationInvokeEventMessage(reference, toValues(request.getInputArguments()), toValues(request.getInoutputArguments()));
OperationResult operationResult = executeOperationSync(reference, request);
response.setPayload(operationResult);
response.setStatusCode(StatusCode.Success);
} catch (ResourceNotFoundException ex) {
response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
} catch (Exception ex) {
response.setStatusCode(StatusCode.ServerInternalError);
}
publishOperationFinishEventMessage(reference, toValues(response.getPayload().getOutputArguments()), toValues(response.getPayload().getInoutputArguments()));
return response;
}
use of io.adminshell.aas.v3.model.SubmodelElement in project FAAAST-Service by FraunhoferIOSB.
the class PostSubmodelElementRequestHandler method process.
@Override
public PostSubmodelElementResponse process(PostSubmodelElementRequest request) {
PostSubmodelElementResponse response = new PostSubmodelElementResponse();
try {
Reference parentReference = ReferenceHelper.toReference(request.getId(), Submodel.class);
Reference childReference = AasUtils.toReference(parentReference, request.getSubmodelElement());
SubmodelElement submodelElement = persistence.put(parentReference, null, request.getSubmodelElement());
response.setPayload(submodelElement);
response.setStatusCode(StatusCode.SuccessCreated);
writeValueToAssetConnection(childReference, ElementValueMapper.toValue(submodelElement));
publishElementCreateEventMessage(parentReference, submodelElement);
} catch (ResourceNotFoundException ex) {
response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
} catch (Exception ex) {
response.setStatusCode(StatusCode.ServerInternalError);
}
return response;
}
use of io.adminshell.aas.v3.model.SubmodelElement in project FAAAST-Service by FraunhoferIOSB.
the class ElementValueMapperTest method testEntitySetValueMapping.
@Test
public void testEntitySetValueMapping() throws ValueFormatException {
SubmodelElement actual = new DefaultEntity.Builder().statement(new DefaultProperty.Builder().idShort("property").build()).build();
EntityValue value = EntityValue.builder().statement("property", PropertyValue.of(Datatype.String, "foo")).entityType(EntityType.SELF_MANAGED_ENTITY).globalAssetId(List.of(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.SUBMODEL).value("http://example.org/submodel/1").build(), new DefaultKey.Builder().idType(KeyType.ID_SHORT).type(KeyElements.PROPERTY).value("property1").build())).build();
SubmodelElement expected = new DefaultEntity.Builder().statement(new DefaultProperty.Builder().idShort(value.getStatements().keySet().iterator().next()).valueType(Datatype.String.getName()).value("foo").build()).entityType(value.getEntityType()).globalAssetId(new DefaultReference.Builder().keys(value.getGlobalAssetId()).build()).build();
ElementValueMapper.setValue(actual, value);
Assert.assertEquals(expected, actual);
}
Aggregations