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);
}
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);
}
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);
}
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);
}
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());
}
Aggregations