Search in sources :

Example 1 with ElementValue

use of de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue 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);
}
Also used : SetSubmodelElementValueByPathRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.SetSubmodelElementValueByPathRequest) GetAllConceptDescriptionsByDataSpecificationReferenceResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllConceptDescriptionsByDataSpecificationReferenceResponse) PutSubmodelResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutSubmodelResponse) GetAllSubmodelsResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllSubmodelsResponse) PutSubmodelElementByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutSubmodelElementByPathResponse) PostSubmodelElementResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelElementResponse) InvokeOperationSyncResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse) PostSubmodelReferenceResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelReferenceResponse) DeleteAssetAdministrationShellByIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.DeleteAssetAdministrationShellByIdResponse) PostSubmodelElementByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelElementByPathResponse) PutAssetAdministrationShellByIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutAssetAdministrationShellByIdResponse) PostSubmodelResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelResponse) GetSubmodelElementByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetSubmodelElementByPathResponse) GetAssetInformationResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAssetInformationResponse) DeleteSubmodelElementByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.DeleteSubmodelElementByPathResponse) DeleteConceptDescriptionByIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.DeleteConceptDescriptionByIdResponse) GetAllSubmodelReferencesResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllSubmodelReferencesResponse) PutSubmodelByIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutSubmodelByIdResponse) GetSubmodelResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetSubmodelResponse) GetAssetAdministrationShellResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAssetAdministrationShellResponse) GetAllConceptDescriptionsByIsCaseOfResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllConceptDescriptionsByIsCaseOfResponse) PutConceptDescriptionByIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutConceptDescriptionByIdResponse) Response(de.fraunhofer.iosb.ilt.faaast.service.model.api.Response) GetAllSubmodelsBySemanticIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllSubmodelsBySemanticIdResponse) PutAssetInformationResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutAssetInformationResponse) DeleteSubmodelByIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.DeleteSubmodelByIdResponse) GetConceptDescriptionByIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetConceptDescriptionByIdResponse) SetSubmodelElementValueByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.SetSubmodelElementValueByPathResponse) PutAssetAdministrationShellResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutAssetAdministrationShellResponse) PostAssetAdministrationShellResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostAssetAdministrationShellResponse) PostConceptDescriptionResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostConceptDescriptionResponse) GetAllAssetAdministrationShellsResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllAssetAdministrationShellsResponse) GetSubmodelByIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetSubmodelByIdResponse) InvokeOperationAsyncResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationAsyncResponse) GetAllAssetAdministrationShellsByIdShortResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllAssetAdministrationShellsByIdShortResponse) GetAssetAdministrationShellByIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAssetAdministrationShellByIdResponse) GetAllConceptDescriptionsByIdShortResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllConceptDescriptionsByIdShortResponse) GetAllConceptDescriptionsResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllConceptDescriptionsResponse) GetAllSubmodelElementsResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllSubmodelElementsResponse) DeleteSubmodelReferenceResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.DeleteSubmodelReferenceResponse) GetAllSubmodelsByIdShortResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllSubmodelsByIdShortResponse) GetAllAssetAdministrationShellsByAssetIdResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.GetAllAssetAdministrationShellsByAssetIdResponse) PropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue) StringValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.StringValue) DataElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) SetSubmodelElementValueByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.SetSubmodelElementValueByPathResponse) Test(org.junit.Test)

Example 2 with ElementValue

use of de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue in project FAAAST-Service by FraunhoferIOSB.

the class ElementValueMapperTest method testRangeToValueMapping.

@Test
public void testRangeToValueMapping() {
    RangeValue expected = RangeValue.builder().min(new DoubleValue(2.3)).max(new DoubleValue(5.1)).build();
    SubmodelElement input = new DefaultRange.Builder().valueType(expected.getMin().getDataType().getName()).min(expected.getMin().asString()).max(expected.getMax().asString()).build();
    ElementValue actual = ElementValueMapper.toValue(input);
    Assert.assertEquals(expected, actual);
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) DoubleValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.DoubleValue) RelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.RelationshipElementValue) ReferenceElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) AnnotatedRelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue) RangeValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.RangeValue) Test(org.junit.Test)

Example 3 with ElementValue

use of de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue in project FAAAST-Service by FraunhoferIOSB.

the class ElementValueMapperTest method testMultiLanguagePropertyToValueMapping.

@Test
public void testMultiLanguagePropertyToValueMapping() {
    MultiLanguagePropertyValue expected = MultiLanguagePropertyValue.builder().value("deutsch", "de").value("english", "en").build();
    SubmodelElement input = new DefaultMultiLanguageProperty.Builder().values(List.copyOf(expected.getLangStringSet())).build();
    ElementValue actual = ElementValueMapper.toValue(input);
    Assert.assertEquals(expected, actual);
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) RelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.RelationshipElementValue) ReferenceElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) AnnotatedRelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue) MultiLanguagePropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.MultiLanguagePropertyValue) Test(org.junit.Test)

Example 4 with ElementValue

use of de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue in project FAAAST-Service by FraunhoferIOSB.

the class ElementValueMapperTest method testEntityToValueMapping.

@Test
public void testEntityToValueMapping() throws ValueFormatException {
    EntityValue expected = 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 input = new DefaultEntity.Builder().statement(new DefaultProperty.Builder().category("Test").idShort(expected.getStatements().keySet().iterator().next()).valueType(Datatype.String.getName()).value("foo").build()).entityType(expected.getEntityType()).globalAssetId(new DefaultReference.Builder().keys(expected.getGlobalAssetId()).build()).build();
    ElementValue actual = ElementValueMapper.toValue(input);
    Assert.assertEquals(expected, actual);
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) EntityValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.EntityValue) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) RelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.RelationshipElementValue) ReferenceElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) AnnotatedRelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue) DefaultProperty(io.adminshell.aas.v3.model.impl.DefaultProperty) Test(org.junit.Test)

Example 5 with ElementValue

use of de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue in project FAAAST-Service by FraunhoferIOSB.

the class ElementValueMapperTest method testSubmodelElementCollectionToValueMapping.

@Test
public void testSubmodelElementCollectionToValueMapping() {
    PropertyValue propertyValue = PropertyValue.builder().value(new StringValue("testValue")).build();
    PropertyValue propertyValue2 = PropertyValue.builder().value(new StringValue("testValue2")).build();
    SubmodelElementCollectionValue expected = SubmodelElementCollectionValue.builder().value("prop1", propertyValue).value("prop2", propertyValue2).build();
    SubmodelElement input = new DefaultSubmodelElementCollection.Builder().value(new DefaultProperty.Builder().idShort("prop1").value("testValue").build()).value(new DefaultProperty.Builder().idShort("prop2").value("testValue2").build()).build();
    ElementValue actual = ElementValueMapper.toValue(input);
    Assert.assertEquals(expected, actual);
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) SubmodelElementCollectionValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.SubmodelElementCollectionValue) PropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue) MultiLanguagePropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.MultiLanguagePropertyValue) DefaultSubmodelElementCollection(io.adminshell.aas.v3.model.impl.DefaultSubmodelElementCollection) StringValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.StringValue) RelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.RelationshipElementValue) ReferenceElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) AnnotatedRelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue) DefaultProperty(io.adminshell.aas.v3.model.impl.DefaultProperty) Test(org.junit.Test)

Aggregations

ElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue)25 SubmodelElement (io.adminshell.aas.v3.model.SubmodelElement)20 Test (org.junit.Test)15 AnnotatedRelationshipElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue)11 ReferenceElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue)11 RelationshipElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.RelationshipElementValue)11 PropertyValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue)7 TypeInfo (de.fraunhofer.iosb.ilt.faaast.service.typing.TypeInfo)6 ElementValueMapper (de.fraunhofer.iosb.ilt.faaast.service.model.value.mapper.ElementValueMapper)5 Reference (io.adminshell.aas.v3.model.Reference)5 DefaultProperty (io.adminshell.aas.v3.model.impl.DefaultProperty)5 List (java.util.List)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 DeserializationException (de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException)4 ResourceNotFoundException (de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)4 DataElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue)4 RangeValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.RangeValue)4 Datatype (de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.Datatype)4 TypeExtractor (de.fraunhofer.iosb.ilt.faaast.service.typing.TypeExtractor)4