Search in sources :

Example 6 with DataList

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

the class TestArrayTemplate method testStringArray.

@Test
public void testStringArray() {
    ArrayDataSchema schema = (ArrayDataSchema) DataTemplateUtil.parseSchema("{ \"type\" : \"array\", \"items\" : \"string\" }");
    // must be unique
    List<String> input = Arrays.asList("apple", "banana", "orange", "pineapple", "graphs");
    List<String> adds = Arrays.asList("foo", "bar", "baz");
    List<Object> badInput = asList(true, 1, 2L, 3.0f, 4.0, ByteString.empty(), new StringMap(), new StringArray(), null);
    List<Object> badOutput = asList(true, 1, 2L, 3.0f, 4.0, ByteString.empty(), new DataMap(), new DataList());
    testArray(StringArray.class, schema, input, adds);
    testArrayBadInput(StringArray.class, schema, input, badInput, badOutput);
}
Also used : ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) DataList(com.linkedin.data.DataList) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 7 with DataList

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

the class TestArrayTemplate method testFloatArray.

@Test
public void testFloatArray() {
    ArrayDataSchema schema = (ArrayDataSchema) DataTemplateUtil.parseSchema("{ \"type\" : \"array\", \"items\" : \"float\" }");
    // must be unique
    List<Float> input = Arrays.asList(1.0f, 3.0f, 5.0f, 7.0f, 11.0f);
    List<Float> adds = Arrays.asList(13.0f, 17.0f, 19.0f);
    List<Object> badInput = asList(true, "hello", ByteString.empty(), new StringMap(), new StringArray(), null);
    List<Object> badOutput = asList(true, "hello", ByteString.empty(), new DataMap(), new DataList());
    testArray(FloatArray.class, schema, input, adds);
    testArrayBadInput(FloatArray.class, schema, input, badInput, badOutput);
    @SuppressWarnings("unchecked") List<? extends Number> castFrom = Arrays.asList(1, 3L, 5.0, 7.0f, 11.0f);
    testNumberArray(FloatArray.class, schema, input, castFrom);
}
Also used : ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) DataList(com.linkedin.data.DataList) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 8 with DataList

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

the class TestArrayTemplate method testIntegerArray.

@Test
public void testIntegerArray() {
    ArrayDataSchema schema = (ArrayDataSchema) DataTemplateUtil.parseSchema("{ \"type\" : \"array\", \"items\" : \"int\" }");
    // must be unique
    List<Integer> input = Arrays.asList(1, 3, 5, 7, 11);
    List<Integer> adds = Arrays.asList(13, 17, 19);
    List<Object> badInput = asList(true, "hello", ByteString.empty(), new StringMap(), new StringArray(), null);
    List<Object> badOutput = asList(true, "hello", ByteString.empty(), new DataMap(), new DataList());
    testArray(IntegerArray.class, schema, input, adds);
    testArrayBadInput(IntegerArray.class, schema, input, badInput, badOutput);
    @SuppressWarnings("unchecked") List<? extends Number> castFrom = Arrays.asList(1L, 3.0f, 5.0, 7, 11);
    testNumberArray(IntegerArray.class, schema, input, castFrom);
}
Also used : ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) DataList(com.linkedin.data.DataList) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 9 with DataList

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

the class TestArrayTemplate method testEnumArray.

@Test
public void testEnumArray() {
    // must be unique
    List<Fruits> input = Arrays.asList(Fruits.APPLE, Fruits.ORANGE, Fruits.BANANA);
    List<Fruits> adds = Arrays.asList(Fruits.GRAPES, Fruits.PINEAPPLE);
    List<Object> badInput = asList(true, 1, 2L, 3.0f, 4.0, "orange", ByteString.empty(), new StringMap(), new StringArray(), null);
    List<Object> badOutput = asList(true, 1, 2L, 3.0f, 4.0, "orange", ByteString.empty(), new DataMap(), new DataList());
    testArray(EnumArrayTemplate.class, TestArrayTemplate.EnumArrayTemplate.SCHEMA, input, adds);
    testArrayBadInput(EnumArrayTemplate.class, TestArrayTemplate.EnumArrayTemplate.SCHEMA, input, badInput, badOutput);
}
Also used : DataList(com.linkedin.data.DataList) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 10 with DataList

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

the class TestArrayTemplate 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()) {
        ArrayDataSchema schema = (ArrayDataSchema) DataTemplateUtil.parseSchema("{ \"type\" : \"array\", \"items\" : \"" + e.getKey() + "\" }");
        @SuppressWarnings("unchecked") PrimitiveLegacyArray<?> array = new PrimitiveLegacyArray<>(new DataList(), schema, (Class<?>) e.getValue());
    }
    EnumLegacyArray enumArray = new EnumLegacyArray(new DataList());
}
Also used : ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) DataList(com.linkedin.data.DataList) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) Map(java.util.Map) TestUtil.asMap(com.linkedin.data.TestUtil.asMap) Test(org.testng.annotations.Test)

Aggregations

DataList (com.linkedin.data.DataList)202 DataMap (com.linkedin.data.DataMap)151 Test (org.testng.annotations.Test)109 ByteString (com.linkedin.data.ByteString)72 TestUtil.dataMapFromString (com.linkedin.data.TestUtil.dataMapFromString)34 TestUtil.dataSchemaFromString (com.linkedin.data.TestUtil.dataSchemaFromString)33 ArrayList (java.util.ArrayList)27 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)22 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)15 DataSchema (com.linkedin.data.schema.DataSchema)14 RecordTemplate (com.linkedin.data.template.RecordTemplate)14 HashMap (java.util.HashMap)13 MapDataSchema (com.linkedin.data.schema.MapDataSchema)12 TestUtil.asReadOnlyDataMap (com.linkedin.data.TestUtil.asReadOnlyDataMap)11 Map (java.util.Map)11 List (java.util.List)10 DataProvider (org.testng.annotations.DataProvider)10 DataComplex (com.linkedin.data.DataComplex)9 EnumDataSchema (com.linkedin.data.schema.EnumDataSchema)5 UnionDataSchema (com.linkedin.data.schema.UnionDataSchema)5