TwinPayloadFactory { public static JsonObject toShadowUpdateRequest(InfomodelValue infomodelData) { return gson.toJsonTree(UpdateRequest.create().withReported(infomodelData)).getAsJsonObject(); }  static JsonObject toShadowUpdateRequest(InfomodelValue infomodelData);  }
@Test public void testCreateRequestSingleFbProperty() { 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.toShadowUpdateRequest(infomodelValue))); }
@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.toShadowUpdateRequest(infomodelValue))); }