Search in sources :

Example 1 with SpecWithTimestamp

use of org.eclipse.vorto.service.mapping.spec.SpecWithTimestamp 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)

Aggregations

Date (java.util.Date)1 DittoData (org.eclipse.vorto.service.mapping.ditto.DittoData)1 Feature (org.eclipse.vorto.service.mapping.ditto.Feature)1 SpecWithTimestamp (org.eclipse.vorto.service.mapping.spec.SpecWithTimestamp)1 Test (org.junit.Test)1