Search in sources :

Example 1 with RangeValue

use of de.fraunhofer.iosb.ilt.faaast.service.model.value.RangeValue 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 2 with RangeValue

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

the class RangeValueMapper method toValue.

@Override
public RangeValue toValue(Range submodelElement) {
    if (submodelElement == null) {
        return null;
    }
    RangeValue rangeValue = new RangeValue();
    try {
        rangeValue.setMin(TypedValueFactory.create(submodelElement.getValueType(), submodelElement.getMin()));
        rangeValue.setMax(TypedValueFactory.create(submodelElement.getValueType(), submodelElement.getMax()));
    } catch (ValueFormatException ex) {
        // TODO properly throw?
        throw new RuntimeException("invalid data value");
    }
    return rangeValue;
}
Also used : ValueFormatException(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.ValueFormatException) RangeValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.RangeValue)

Example 3 with RangeValue

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

the class ElementValueMapperTest method testRangeSetValueMapping.

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

Aggregations

RangeValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.RangeValue)3 DoubleValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.DoubleValue)2 SubmodelElement (io.adminshell.aas.v3.model.SubmodelElement)2 Test (org.junit.Test)2 AnnotatedRelationshipElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue)1 ElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue)1 ReferenceElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue)1 RelationshipElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.RelationshipElementValue)1 ValueFormatException (de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.ValueFormatException)1 DefaultRange (io.adminshell.aas.v3.model.impl.DefaultRange)1