Search in sources :

Example 91 with DataList

use of com.linkedin.data.DataList in project rest.li by linkedin.

the class TestMapTemplate method testFooRecordMap.

@Test
public void testFooRecordMap() {
    Map<String, FooRecord> input = new HashMap<String, FooRecord>();
    for (int i = 0; i < 5; ++i) {
        String key = "input" + i;
        input.put(key, new FooRecord());
        input.get(key).setBar("subinputvalue" + i);
    }
    Map<String, FooRecord> adds = new HashMap<String, FooRecord>();
    for (int i = 0; i < 5; ++i) {
        String key = "add" + i;
        adds.put(key, new FooRecord());
        adds.get(key).setBar("subaddvalue" + i);
    }
    Map<String, Object> badInput = asMap("boolean", true, "integer", 1, "long", 2L, "float", 3.0f, "double", 4.0, "string", "hello", "bytes", ByteString.empty(), "object", new Object(), "null", null, "array", new StringArray());
    Map<String, Object> badOutput = asMap("boolean", true, "integer", 1, "long", 2L, "float", 3.0f, "double", 4.0, "string", "hello", "bytes", ByteString.empty(), "list", new DataList());
    testMap(FooRecordMap.class, FooRecordMap.SCHEMA, input, adds);
    testMapBadInput(FooRecordMap.class, FooRecordMap.SCHEMA, input, badInput, badOutput);
}
Also used : DataList(com.linkedin.data.DataList) HashMap(java.util.HashMap) ByteString(com.linkedin.data.ByteString) Test(org.testng.annotations.Test)

Example 92 with DataList

use of com.linkedin.data.DataList in project rest.li by linkedin.

the class TestMapTemplate method testBytesMap.

@Test
public void testBytesMap() {
    MapDataSchema schema = (MapDataSchema) DataTemplateUtil.parseSchema("{ \"type\" : \"map\", \"values\" : \"bytes\" }");
    Map<String, ByteString> input = asMap("one", ByteString.copyAvroString("1", false), "three", ByteString.copyAvroString("3", false), "five", ByteString.copyAvroString("5", false), "seven", ByteString.copyAvroString("7", false), "eleven", ByteString.copyAvroString("11", false));
    Map<String, ByteString> adds = asMap("thirteen", ByteString.copyAvroString("13", false), "seventeen", ByteString.copyAvroString("17", false), "nineteen", ByteString.copyAvroString("19", false));
    Map<String, Object> badInput = asMap("boolean", true, "integer", 99, "long", 999L, "float", 88.0f, "double", 888.0, "data", "Ā", "object", new Object(), "null", null, "array", new StringArray(), "record", new FooRecord());
    Map<String, Object> badOutput = asMap("boolean", true, "integer", 99, "long", 999L, "float", 88.0f, "double", 888.0, "data", "Ā", "map", new DataMap(), "list", new DataList());
    testMap(BytesMap.class, schema, input, adds);
    testMapBadInput(BytesMap.class, schema, input, badInput, badOutput);
}
Also used : DataList(com.linkedin.data.DataList) MapDataSchema(com.linkedin.data.schema.MapDataSchema) ByteString(com.linkedin.data.ByteString) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 93 with DataList

use of com.linkedin.data.DataList in project rest.li by linkedin.

the class TestMapTemplate method testMapOfStringMap.

@Test
public void testMapOfStringMap() {
    Map<String, StringMap> input = new HashMap<String, StringMap>();
    for (int i = 0; i < 5; ++i) {
        String key = "input" + i;
        input.put(key, new StringMap());
        input.get(key).put("subinput" + i, "subinputvalue" + i);
    }
    Map<String, StringMap> adds = new HashMap<String, StringMap>();
    for (int i = 0; i < 5; ++i) {
        String key = "add" + i;
        adds.put(key, new StringMap());
        adds.get(key).put("subadd" + i, "subaddvalue" + i);
    }
    Map<String, Object> badInput = asMap("boolean", true, "integer", 1, "long", 2L, "float", 3.0f, "double", 4.0, "string", "hello", "bytes", ByteString.empty(), "object", new Object(), "null", null, "array", new StringArray(), "record", new FooRecord());
    Map<String, Object> badOutput = asMap("boolean", true, "integer", 1, "long", 2L, "float", 3.0f, "double", 4.0, "string", "hello", "bytes", ByteString.empty(), "list", new DataList());
    testMap(MapOfStringMapTemplate.class, MapOfStringMapTemplate.SCHEMA, input, adds);
    testMapBadInput(MapOfStringMapTemplate.class, MapOfStringMapTemplate.SCHEMA, input, badInput, badOutput);
}
Also used : DataList(com.linkedin.data.DataList) HashMap(java.util.HashMap) ByteString(com.linkedin.data.ByteString) Test(org.testng.annotations.Test)

Example 94 with DataList

use of com.linkedin.data.DataList in project rest.li by linkedin.

the class TestMapTemplate method testStringMap.

@Test
public void testStringMap() {
    MapDataSchema schema = (MapDataSchema) DataTemplateUtil.parseSchema("{ \"type\" : \"map\", \"values\" : \"string\" }");
    Map<String, String> input = asMap("one", "1", "three", "3", "five", "5", "seven", "7", "eleven", "11");
    Map<String, String> adds = asMap("thirteen", "13", "seventeen", "17", "nineteen", "19");
    Map<String, Object> badInput = asMap("boolean", true, "integer", 99, "long", 999L, "float", 88.0f, "double", 888.0, "bytes", ByteString.empty(), "object", new Object(), "null", null, "array", new StringArray(), "record", new FooRecord());
    Map<String, Object> badOutput = asMap("boolean", true, "integer", 99, "long", 999L, "float", 88.0f, "double", 888.0, "bytes", ByteString.empty(), "map", new DataMap(), "list", new DataList());
    testMap(StringMap.class, schema, input, adds);
    testMapBadInput(StringMap.class, schema, input, badInput, badOutput);
}
Also used : DataList(com.linkedin.data.DataList) MapDataSchema(com.linkedin.data.schema.MapDataSchema) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 95 with DataList

use of com.linkedin.data.DataList in project rest.li by linkedin.

the class TestMapTemplate method testFloatMap.

@Test
public void testFloatMap() {
    MapDataSchema schema = (MapDataSchema) DataTemplateUtil.parseSchema("{ \"type\" : \"map\", \"values\" : \"float\" }");
    Map<String, Float> input = asMap("one", 1.0f, "three", 3.0f, "five", 5.0f, "seven", 7.0f, "eleven", 11.0f);
    Map<String, Float> adds = asMap("thirteen", 13.0f, "seventeen", 17.0f, "nineteen", 19.0f);
    Map<String, Object> badInput = asMap("boolean", true, "string", "hello", "bytes", ByteString.empty(), "object", new Object(), "null", null, "array", new StringArray(), "record", new FooRecord());
    Map<String, Object> badOutput = asMap("boolean", true, "string", "hello", "bytes", ByteString.empty(), "map", new DataMap(), "list", new DataList());
    testMap(FloatMap.class, schema, input, adds);
    testMapBadInput(FloatMap.class, schema, input, badInput, badOutput);
    Map<String, ? extends Number> castFrom = asMap("one", 1, "three", 3L, "five", 5.0, "seven", 7, "eleven", 11);
    testNumberMap(FloatMap.class, schema, input, castFrom);
}
Also used : DataList(com.linkedin.data.DataList) MapDataSchema(com.linkedin.data.schema.MapDataSchema) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Aggregations

DataList (com.linkedin.data.DataList)160 DataMap (com.linkedin.data.DataMap)126 Test (org.testng.annotations.Test)102 ByteString (com.linkedin.data.ByteString)64 TestUtil.dataMapFromString (com.linkedin.data.TestUtil.dataMapFromString)34 TestUtil.dataSchemaFromString (com.linkedin.data.TestUtil.dataSchemaFromString)33 ArrayList (java.util.ArrayList)22 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)17 DataSchema (com.linkedin.data.schema.DataSchema)10 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)10 HashMap (java.util.HashMap)10 MapDataSchema (com.linkedin.data.schema.MapDataSchema)9 RecordTemplate (com.linkedin.data.template.RecordTemplate)9 Map (java.util.Map)8 DataProvider (org.testng.annotations.DataProvider)8 List (java.util.List)7 PathSpec (com.linkedin.data.schema.PathSpec)6 PatchTree (com.linkedin.data.transform.patch.request.PatchTree)5 DataComplex (com.linkedin.data.DataComplex)4 CustomPoint (com.linkedin.data.template.TestCustom.CustomPoint)4