Search in sources :

Example 1 with SpecWithCustomFunction

use of org.eclipse.vorto.mapping.engine.converter.javascript.SpecWithCustomFunction in project vorto by eclipse.

the class JsonMappingLoadTest method init.

@BeforeClass
public static void init() {
    // // Test Case 1: No converter functions
    testCaseOneMapper = IDataMapper.newBuilder().withSpecification(new SpecWithNestedEntity()).build();
    testCaseOneJsonInput = new String[] { "{\"temperature\" : 21.3 }", "{\"temperature\" : 0.1 }", "{\"temperature\" : 11 }" };
    testCaseOneOutput = new Double[] { 21.3, 0.1, 11.0 };
    deserializer = new JSONDeserializer();
    // // Test Case 2: One Built in Converter
    testCaseTwoMapper = IDataMapper.newBuilder().withSpecification(new SpecWithTimestamp()).registerConverterFunction(DateFunctionFactory.createFunctions()).build();
    timestamp = new Date();
    testCaseTwoJson = "{\"time\" : " + timestamp.getTime() + "}";
    // // Test Case 3: One Built in Converter + 1 Javascript Function
    testCaseThreeMapper = IDataMapper.newBuilder().withSpecification(new SpecWithCustomFunction()).registerConverterFunction(TypeFunctionFactory.createFunctions()).registerConverterFunction(StringFunctionFactory.createFunctions()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
    testCaseThreeJson = "{\"clickType\" : \"DOUBLE\"}";
    testCaseThreeJsonInput = new String[] { "{\"clickType\" : \"SINGLE\"}", "{\"clickType\" : \"DOUBLE\"}", "{\"clickType\" : \"\"}" };
    testCaseThreeOutput = new Integer[] { 1, 2, 99 };
}
Also used : SpecWithTimestamp(org.eclipse.vorto.mapping.engine.converter.date.SpecWithTimestamp) SpecWithNestedEntity(org.eclipse.vorto.service.mapping.spec.SpecWithNestedEntity) JSONDeserializer(org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer) SpecWithCustomFunction(org.eclipse.vorto.mapping.engine.converter.javascript.SpecWithCustomFunction) Date(java.util.Date) JavascriptEvalProvider(org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider) BeforeClass(org.junit.BeforeClass)

Aggregations

Date (java.util.Date)1 JavascriptEvalProvider (org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider)1 SpecWithTimestamp (org.eclipse.vorto.mapping.engine.converter.date.SpecWithTimestamp)1 SpecWithCustomFunction (org.eclipse.vorto.mapping.engine.converter.javascript.SpecWithCustomFunction)1 JSONDeserializer (org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer)1 SpecWithNestedEntity (org.eclipse.vorto.service.mapping.spec.SpecWithNestedEntity)1 BeforeClass (org.junit.BeforeClass)1