Search in sources :

Example 16 with DittoData

use of org.eclipse.vorto.service.mapping.ditto.DittoData in project vorto by eclipse.

the class JsonMappingTest method testMapUsingBase64Converter.

@Test
public void testMapUsingBase64Converter() throws Exception {
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithBase64Converter()).buildDittoMapper();
    String json = "{\"data\" : \"" + Base64.encodeBase64String("20".getBytes()) + "\"}";
    DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(json), MappingContext.empty());
    assertEquals("20", new String((byte[]) mappedDittoOutput.getFeatures().get("button").getStatusProperties().get("digital_input_state")));
}
Also used : SpecWithBase64Converter(org.eclipse.vorto.service.mapping.spec.SpecWithBase64Converter) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData) Test(org.junit.Test)

Example 17 with DittoData

use of org.eclipse.vorto.service.mapping.ditto.DittoData in project vorto by eclipse.

the class JsonMappingTest method testMapWithSimpleCondition.

@Test
public void testMapWithSimpleCondition() throws Exception {
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithCondition()).buildDittoMapper();
    String json = "{\"count\" : 2 }";
    DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(json), MappingContext.empty());
    assertNull(mappedDittoOutput.getFeatures().get("button").getStatusProperties().get("sensor_value"));
    assertEquals(2, mappedDittoOutput.getFeatures().get("button").getStatusProperties().get("sensor_value2"));
    json = "{\"count\" : 0 }";
    mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(json), MappingContext.empty());
    assertEquals(0, mappedDittoOutput.getFeatures().get("button").getStatusProperties().get("sensor_value"));
    assertNull(mappedDittoOutput.getFeatures().get("button").getStatusProperties().get("sensor_value2"));
}
Also used : SpecWithCondition(org.eclipse.vorto.service.mapping.spec.SpecWithCondition) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData) Test(org.junit.Test)

Example 18 with DittoData

use of org.eclipse.vorto.service.mapping.ditto.DittoData in project vorto by eclipse.

the class JsonMappingTest method testMapSingleFunctionblockOfInfomodel.

@Test
public void testMapSingleFunctionblockOfInfomodel() {
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithCustomFunction()).buildDittoMapper();
    String json = "{\"clickType\" : \"DOUBLE\"}";
    DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(json), MappingContext.empty());
    Feature buttonFeature = mappedDittoOutput.getFeatures().get("button");
    assertEquals(true, (Boolean) buttonFeature.getStatusProperties().get("digital_input_state"));
    assertEquals(2, buttonFeature.getStatusProperties().get("digital_input_count"));
    Feature voltageFeature = mappedDittoOutput.getFeatures().get("voltage");
    assertNull(voltageFeature);
    System.out.println(mappedDittoOutput.toJson());
}
Also used : SpecWithCustomFunction(org.eclipse.vorto.service.mapping.spec.SpecWithCustomFunction) Feature(org.eclipse.vorto.service.mapping.ditto.Feature) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData) Test(org.junit.Test)

Example 19 with DittoData

use of org.eclipse.vorto.service.mapping.ditto.DittoData in project vorto by eclipse.

the class JsonMappingTest method testDittoMappingTimestamp.

@Test
public void testDittoMappingTimestamp() throws Exception {
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithTimestamp()).buildDittoMapper();
    final Date timestamp = new Date();
    String json = "{\"time\" : " + timestamp.getTime() + "}";
    DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(json), MappingContext.empty());
    Feature buttonFeature = mappedDittoOutput.getFeatures().get("button");
    assertEquals(JSON_DATE_FORMAT.format(timestamp), buttonFeature.getStatusProperties().get("sensor_value"));
    System.out.println(mappedDittoOutput.toJson());
}
Also used : SpecWithTimestamp(org.eclipse.vorto.service.mapping.spec.SpecWithTimestamp) Feature(org.eclipse.vorto.service.mapping.ditto.Feature) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData) Date(java.util.Date) Test(org.junit.Test)

Example 20 with DittoData

use of org.eclipse.vorto.service.mapping.ditto.DittoData in project vorto by eclipse.

the class UnideMappingTest method testMapUnideMessageToDitto.

@Test
public void testMapUnideMessageToDitto() throws Exception {
    IMappingSpecification mappingSpecification = MappingSpecificationBuilder.create().infomodelId("org.eclipse.unide.devices.MobilePhone:1.0.0").targetPlatformKey("org_eclipse_unide_devices_MobilePhone_1_0_0").build();
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(mappingSpecification).buildDittoMapper();
    final String unideMessage = IOUtils.toString(UnideMappingTest.class.getClassLoader().getResourceAsStream("unide.json"));
    DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(unideMessage), MappingContext.empty());
    Feature directionFeature = mappedDittoOutput.getFeatures().get("direction");
    assertEquals(45.4231, directionFeature.getStatusProperties().get("compass_direction"));
    System.out.println(mappedDittoOutput.toJson());
}
Also used : IMappingSpecification(org.eclipse.vorto.service.mapping.spec.IMappingSpecification) Feature(org.eclipse.vorto.service.mapping.ditto.Feature) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData) Test(org.junit.Test)

Aggregations

DittoData (org.eclipse.vorto.service.mapping.ditto.DittoData)20 Test (org.junit.Test)19 Feature (org.eclipse.vorto.service.mapping.ditto.Feature)15 SpecWithCustomFunction (org.eclipse.vorto.service.mapping.spec.SpecWithCustomFunction)4 IMappingSpecification (org.eclipse.vorto.service.mapping.spec.IMappingSpecification)3 HashMap (java.util.HashMap)2 Gson (com.google.gson.Gson)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 BleGattCharacteristic (org.eclipse.vorto.service.mapping.ble.BleGattCharacteristic)1 BleGattDevice (org.eclipse.vorto.service.mapping.ble.BleGattDevice)1 GattCharacteristic (org.eclipse.vorto.service.mapping.ble.json.GattCharacteristic)1 GattDevice (org.eclipse.vorto.service.mapping.ble.json.GattDevice)1 GattService (org.eclipse.vorto.service.mapping.ble.json.GattService)1 FunctionblockData (org.eclipse.vorto.service.mapping.normalized.FunctionblockData)1 SpecGattConverter (org.eclipse.vorto.service.mapping.spec.SpecGattConverter)1 SpecWithArrayPayload (org.eclipse.vorto.service.mapping.spec.SpecWithArrayPayload)1 SpecWithBase64Converter (org.eclipse.vorto.service.mapping.spec.SpecWithBase64Converter)1 SpecWithByteArrayConverter (org.eclipse.vorto.service.mapping.spec.SpecWithByteArrayConverter)1 SpecWithCondition (org.eclipse.vorto.service.mapping.spec.SpecWithCondition)1