Search in sources :

Example 16 with MapDataSchema

use of com.linkedin.data.schema.MapDataSchema 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 17 with MapDataSchema

use of com.linkedin.data.schema.MapDataSchema in project rest.li by linkedin.

the class TestMapTemplate method testLegacyConstructor.

@Test
public void testLegacyConstructor() {
    Map<String, Class<?>> primitiveStringToClassMap = asMap("int", Integer.class, "long", Long.class, "float", Float.class, "double", Double.class, "boolean", Boolean.class, "string", String.class);
    for (Map.Entry<String, Class<?>> e : primitiveStringToClassMap.entrySet()) {
        MapDataSchema schema = (MapDataSchema) DataTemplateUtil.parseSchema("{ \"type\" : \"map\", \"values\" : \"" + e.getKey() + "\" }");
        @SuppressWarnings("unchecked") PrimitiveLegacyMap<?> map = new PrimitiveLegacyMap<Object>(new DataMap(), schema, (Class) e.getValue());
    }
    EnumLegacyMap enumMap = new EnumLegacyMap(new DataMap());
}
Also used : MapDataSchema(com.linkedin.data.schema.MapDataSchema) ByteString(com.linkedin.data.ByteString) HashMap(java.util.HashMap) DataMap(com.linkedin.data.DataMap) AbstractMap(java.util.AbstractMap) Map(java.util.Map) TestUtil.asMap(com.linkedin.data.TestUtil.asMap) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 18 with MapDataSchema

use of com.linkedin.data.schema.MapDataSchema 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 19 with MapDataSchema

use of com.linkedin.data.schema.MapDataSchema 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)

Example 20 with MapDataSchema

use of com.linkedin.data.schema.MapDataSchema in project rest.li by linkedin.

the class TestMapTemplate method testDoubleMap.

@Test
public void testDoubleMap() {
    MapDataSchema schema = (MapDataSchema) DataTemplateUtil.parseSchema("{ \"type\" : \"map\", \"values\" : \"double\" }");
    Map<String, Double> input = asMap("one", 1.0, "three", 3.0, "five", 5.0, "seven", 7.0, "eleven", 11.0);
    Map<String, Double> adds = asMap("thirteen", 13.0, "seventeen", 17.0, "nineteen", 19.0);
    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(DoubleMap.class, schema, input, adds);
    testMapBadInput(DoubleMap.class, schema, input, badInput, badOutput);
    Map<String, ? extends Number> castFrom = asMap("one", 1, "three", 3L, "five", 5.0f, "seven", 7, "eleven", 11);
    testNumberMap(DoubleMap.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

MapDataSchema (com.linkedin.data.schema.MapDataSchema)30 Test (org.testng.annotations.Test)17 DataMap (com.linkedin.data.DataMap)13 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)12 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)11 DataSchema (com.linkedin.data.schema.DataSchema)10 ByteString (com.linkedin.data.ByteString)9 DataList (com.linkedin.data.DataList)9 UnionDataSchema (com.linkedin.data.schema.UnionDataSchema)9 HashMap (java.util.HashMap)9 EnumDataSchema (com.linkedin.data.schema.EnumDataSchema)7 TyperefDataSchema (com.linkedin.data.schema.TyperefDataSchema)7 FixedDataSchema (com.linkedin.data.schema.FixedDataSchema)6 NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)6 PrimitiveDataSchema (com.linkedin.data.schema.PrimitiveDataSchema)4 TestDataTemplateUtil (com.linkedin.data.template.TestDataTemplateUtil)4 Map (java.util.Map)3 TestUtil.asMap (com.linkedin.data.TestUtil.asMap)2 ComplexDataSchema (com.linkedin.data.schema.ComplexDataSchema)2 IntegerMap (com.linkedin.data.template.IntegerMap)2