use of org.eclipse.vorto.model.runtime.FunctionblockValue in project vorto by eclipse.
the class TwinPayloadFactoryTest method testCreateRequestSingleMultipleFbProperties.
@Test
public void testCreateRequestSingleMultipleFbProperties() {
FunctionblockModel fbm = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Temperature:1.0.0")).statusProperty(ModelProperty.createPrimitiveProperty("value", true, PrimitiveType.FLOAT)).build();
Infomodel infomodel = Infomodel.Builder(ModelId.fromPrettyFormat("com.acme:TemperatureSensor:1.0.0")).withProperty(ModelProperty.Builder("indoorTemperature", fbm).build()).withProperty(ModelProperty.Builder("outdoorTemperature", fbm).build()).build();
FunctionblockValue indoorTemperature = new FunctionblockValue(fbm);
indoorTemperature.withStatusProperty("value", 20.2);
FunctionblockValue outdoorTemperature = new FunctionblockValue(fbm);
outdoorTemperature.withStatusProperty("value", 9.2);
InfomodelValue infomodelValue = new InfomodelValue(infomodel);
infomodelValue.withFunctionblock("indoorTemperature", indoorTemperature);
infomodelValue.withFunctionblock("outdoorTemperature", outdoorTemperature);
System.out.println(gson.toJson(TwinPayloadFactory.toDittoProtocol(infomodelValue, "com.acme:Sensor-1")));
}
use of org.eclipse.vorto.model.runtime.FunctionblockValue in project vorto by eclipse.
the class TwinPayloadFactoryTest method testCreateRequestSingleFbPropertyforEntireInfomodel.
@Test
public void testCreateRequestSingleFbPropertyforEntireInfomodel() {
FunctionblockModel fbm = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Temperature:1.0.0")).statusProperty(ModelProperty.createPrimitiveProperty("value", true, PrimitiveType.FLOAT)).build();
Infomodel infomodel = Infomodel.Builder(ModelId.fromPrettyFormat("com.acme:TemperatureSensor:1.0.0")).withProperty(ModelProperty.Builder("temperature", fbm).build()).build();
FunctionblockValue fbValue = new FunctionblockValue(fbm);
fbValue.withStatusProperty("value", 20.2);
InfomodelValue infomodelValue = new InfomodelValue(infomodel);
infomodelValue.withFunctionblock("temperature", fbValue);
System.out.println(gson.toJson(TwinPayloadFactory.toDittoProtocol(infomodelValue, "com.acme:Sensor-1")));
}
use of org.eclipse.vorto.model.runtime.FunctionblockValue in project vorto by eclipse.
the class BinaryMappingLoadTest method tripleNestedConverter3.
@Test
@JUnitPerfTest(threads = THREAD_AMOUNT_3, durationMs = TEST_DURATION_3, rampUpPeriodMs = RAMP_PERIOD, warmUpMs = WARMUP_DURATION_3, maxExecutionsPerSecond = EXECUTIONS_PER_SECOND_3)
public void tripleNestedConverter3() throws Exception {
InfomodelValue mappedDittoOutput = testCaseThreeMapper.mapSource(gson.fromJson(testCaseThreeJson, Object.class));
FunctionblockValue button = mappedDittoOutput.get("button");
assertEquals(2, button.getStatusProperty("sensor_value").get().getValue());
}
use of org.eclipse.vorto.model.runtime.FunctionblockValue in project vorto by eclipse.
the class DataMapperTest method testMapSingleFunctionblockOfInfomodel2.
@Test
public void testMapSingleFunctionblockOfInfomodel2() {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithConditionedRules()).build();
final String sampleHomeConnectRESTResponse = "{\"data\" : { \"key\" : \"DoorState\", \"value\" : \"Locked\"}}";
IPayloadDeserializer deserializer = new JSONDeserializer();
InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(sampleHomeConnectRESTResponse));
System.out.println(mappedOutput);
assertNull(mappedOutput.get("operationState"));
FunctionblockValue doorStateFunctionblockData = mappedOutput.get("doorState");
assertEquals("Locked", (String) doorStateFunctionblockData.getStatusProperty("sensor_value").get().getValue());
}
use of org.eclipse.vorto.model.runtime.FunctionblockValue in project vorto by eclipse.
the class JsonMappingLoadTest method builtInConverterAndJs4.
@Test
@JUnitPerfTest(threads = THREAD_AMOUNT_4, durationMs = TEST_DURATION_4, rampUpPeriodMs = RAMP_PERIOD, warmUpMs = WARMUP_DURATION_4, maxExecutionsPerSecond = EXECUTIONS_PER_SECOND_4)
public void builtInConverterAndJs4() throws Exception {
int r = new Random().nextInt(2 + 1);
InfomodelValue mappedOutput = testCaseThreeMapper.mapSource(gson.fromJson(testCaseThreeJsonInput[r], Object.class));
FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
assertEquals(true, (Boolean) buttonFunctionblockData.getStatusProperty("digital_input_state").get().getValue());
assertEquals(testCaseThreeOutput[r], buttonFunctionblockData.getStatusProperty("digital_input_count").get().getValue());
FunctionblockValue voltageFunctionblockData = mappedOutput.get("voltage");
assertNull(voltageFunctionblockData);
}
Aggregations