Search in sources :

Example 1 with SpecWithCustomFunction

use of org.eclipse.vorto.service.mapping.spec.SpecWithCustomFunction in project vorto by eclipse.

the class JsonMappingTest method testDittoMappingOnlyOneFeature.

@Test
public void testDittoMappingOnlyOneFeature() throws Exception {
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithCustomFunction()).buildDittoMapper();
    String json = "{\"clickType\" : \"DOUBLE\", \"batteryVoltage\": \"2322mV\"}";
    DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(json), MappingContext.functionblockProperties("button"));
    Feature buttonFeature = mappedDittoOutput.getFeatures().get("button");
    assertEquals(true, (Boolean) buttonFeature.getStatusProperties().get("digital_input_state"));
    assertEquals(2, buttonFeature.getStatusProperties().get("digital_input_count"));
    assertNull(mappedDittoOutput.getFeatures().get("voltage"));
    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 2 with SpecWithCustomFunction

use of org.eclipse.vorto.service.mapping.spec.SpecWithCustomFunction in project vorto by eclipse.

the class JsonMappingTest method testMapDevicePayloadWithInitialValue.

@Test
public void testMapDevicePayloadWithInitialValue() {
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithCustomFunction()).buildDittoMapper();
    String json = "{\"clickType\" : \"DOUBLE\", \"batteryVoltage\": \"0mV\"}";
    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");
    assertEquals(0f, voltageFeature.getStatusProperties().get("sensor_value"));
    assertEquals("mV", voltageFeature.getStatusProperties().get("sensor_units"));
    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 3 with SpecWithCustomFunction

use of org.eclipse.vorto.service.mapping.spec.SpecWithCustomFunction in project vorto by eclipse.

the class JsonMappingTest method testDittoMapping.

@Test
public void testDittoMapping() throws Exception {
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithCustomFunction()).buildDittoMapper();
    String json = "{\"clickType\" : \"DOUBLE\", \"batteryVoltage\": \"2322mV\"}";
    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");
    assertEquals(2322f, voltageFeature.getStatusProperties().get("sensor_value"));
    assertEquals("mV", voltageFeature.getStatusProperties().get("sensor_units"));
    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 4 with SpecWithCustomFunction

use of org.eclipse.vorto.service.mapping.spec.SpecWithCustomFunction 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 5 with SpecWithCustomFunction

use of org.eclipse.vorto.service.mapping.spec.SpecWithCustomFunction in project vorto by eclipse.

the class CustomMapperPluginTest method testSomePlatformMapping.

@SuppressWarnings("unchecked")
@Test
public void testSomePlatformMapping() throws Exception {
    IDataMapper<PlatformData> mapper = new SomePlatformMapper(new SpecWithCustomFunction());
    String json = "{\"clickType\" : \"DOUBLE\", \"batteryVoltage\": \"2322mV\"}";
    PlatformData mappedData = mapper.map(DataInput.newInstance().fromJson(json), MappingContext.empty());
    Map<String, Object> reportedButton = (Map<String, Object>) mappedData.getState().getReported().get("button");
    assertEquals(true, (Boolean) reportedButton.get("digital_input_state"));
    assertEquals(2, reportedButton.get("digital_input_count"));
    Map<String, Object> reportedVoltage = (Map<String, Object>) mappedData.getState().getReported().get("voltage");
    assertEquals(2322f, reportedVoltage.get("sensor_value"));
    assertEquals("mV", reportedVoltage.get("sensor_units"));
    System.out.println(mappedData.toJson());
}
Also used : SpecWithCustomFunction(org.eclipse.vorto.service.mapping.spec.SpecWithCustomFunction) Map(java.util.Map) Test(org.junit.Test)

Aggregations

SpecWithCustomFunction (org.eclipse.vorto.service.mapping.spec.SpecWithCustomFunction)5 Test (org.junit.Test)5 DittoData (org.eclipse.vorto.service.mapping.ditto.DittoData)4 Feature (org.eclipse.vorto.service.mapping.ditto.Feature)4 Map (java.util.Map)1