Search in sources :

Example 21 with FunctionblockValue

use of org.eclipse.vorto.model.runtime.FunctionblockValue in project vorto by eclipse.

the class DateConvertTest method testMappingTimestamp.

@Test
public void testMappingTimestamp() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithTimestamp()).registerConverterFunction(DateFunctionFactory.createFunctions()).build();
    final Date timestamp = new Date();
    String json = "{\"time\" : " + timestamp.getTime() + "}";
    InfomodelValue mappedOutput = mapper.mapSource(gson.fromJson(json, Object.class));
    FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
    assertEquals(JSON_DATE_FORMAT.format(timestamp), buttonFunctionblockData.getStatusProperty("sensor_value").get().getValue());
    System.out.println(mappedOutput);
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Date(java.util.Date) Test(org.junit.Test)

Example 22 with FunctionblockValue

use of org.eclipse.vorto.model.runtime.FunctionblockValue in project vorto by eclipse.

the class JsonMappingTest method testMapping.

@Test
public void testMapping() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithCustomFunction()).registerConverterFunction(TypeFunctionFactory.createFunctions()).registerConverterFunction(StringFunctionFactory.createFunctions()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
    String json = "{\"clickType\" : \"DOUBLE\", \"batteryVoltage\": \"2322mV\"}";
    InfomodelValue mappedOutput = mapper.mapSource(gson.fromJson(json, Object.class));
    FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
    assertEquals(true, (Boolean) buttonFunctionblockData.getStatusProperty("digital_input_state").get().getValue());
    assertEquals(2, buttonFunctionblockData.getStatusProperty("digital_input_count").get().getValue());
    FunctionblockValue voltageFunctionblockData = mappedOutput.get("voltage");
    assertEquals(2322f, voltageFunctionblockData.getStatusProperty("sensor_value").get().getValue());
    assertEquals("mV", voltageFunctionblockData.getStatusProperty("sensor_units").get().getValue());
    System.out.println(gson.toJson(mappedOutput.serialize()));
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) JavascriptEvalProvider(org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider) Test(org.junit.Test)

Example 23 with FunctionblockValue

use of org.eclipse.vorto.model.runtime.FunctionblockValue in project vorto by eclipse.

the class JsonMappingTest method testInvokeJsFunctionWithMultipleParams.

@Test
public void testInvokeJsFunctionWithMultipleParams() {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithMultipleParams()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
    MyData data = new MyData("Hallo".getBytes(), "#");
    InfomodelValue mappedOutput = mapper.mapSource(data);
    FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
    assertEquals("#H", buttonFunctionblockData.getStatusProperty("flag").get().getValue());
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) JavascriptEvalProvider(org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider) Test(org.junit.Test)

Example 24 with FunctionblockValue

use of org.eclipse.vorto.model.runtime.FunctionblockValue in project vorto by eclipse.

the class JsonMappingTest method testInvokeJsFunctionWithSingleByteArrayParam.

@Test
public void testInvokeJsFunctionWithSingleByteArrayParam() {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithArrayType()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
    BinaryData data = new BinaryData();
    data.setData("Hallo".getBytes());
    InfomodelValue mappedOutput = mapper.mapSource(data);
    FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
    assertEquals("H", buttonFunctionblockData.getStatusProperty("flag").get().getValue());
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) BinaryData(org.eclipse.vorto.mapping.engine.model.binary.BinaryData) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) JavascriptEvalProvider(org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider) Test(org.junit.Test)

Example 25 with FunctionblockValue

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.toShadowUpdateRequest(infomodelValue)));
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) Infomodel(org.eclipse.vorto.model.Infomodel) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test)

Aggregations

FunctionblockValue (org.eclipse.vorto.model.runtime.FunctionblockValue)32 InfomodelValue (org.eclipse.vorto.model.runtime.InfomodelValue)29 Test (org.junit.Test)29 JUnitPerfTest (com.github.noconnor.junitperf.JUnitPerfTest)12 IDataMapper (org.eclipse.vorto.mapping.engine.IDataMapper)12 JavascriptEvalProvider (org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider)7 FunctionblockModel (org.eclipse.vorto.model.FunctionblockModel)6 Infomodel (org.eclipse.vorto.model.Infomodel)5 Random (java.util.Random)4 IPayloadDeserializer (org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer)3 JSONDeserializer (org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer)3 ModelProperty (org.eclipse.vorto.model.ModelProperty)2 Date (java.util.Date)1 JXPathContext (org.apache.commons.jxpath.JXPathContext)1 JXPathInvalidAccessException (org.apache.commons.jxpath.JXPathInvalidAccessException)1 JXPathNotFoundException (org.apache.commons.jxpath.JXPathNotFoundException)1 MappingException (org.eclipse.vorto.mapping.engine.MappingException)1 BinaryData (org.eclipse.vorto.mapping.engine.model.binary.BinaryData)1 EntityPropertyValue (org.eclipse.vorto.model.runtime.EntityPropertyValue)1 SpecWithArrayPayload (org.eclipse.vorto.service.mapping.spec.SpecWithArrayPayload)1