use of com.linkedin.data.schema.ArrayDataSchema in project rest.li by linkedin.
the class TestArrayTemplate method testBytesArray.
@Test
public void testBytesArray() {
ArrayDataSchema schema = (ArrayDataSchema) DataTemplateUtil.parseSchema("{ \"type\" : \"array\", \"items\" : \"bytes\" }");
List<ByteString> input = Arrays.asList(ByteString.copyAvroString("1", false), ByteString.copyAvroString("3", false), ByteString.copyAvroString("5", false), ByteString.copyAvroString("7", false), ByteString.copyAvroString("11", false));
List<ByteString> adds = Arrays.asList(ByteString.copyAvroString("13", false), ByteString.copyAvroString("17", false), ByteString.copyAvroString("19", false));
List<Object> badInput = asList(true, 99, 999L, 88.0f, 888.0, "Ā", new StringMap(), new StringArray(), null);
List<Object> badOutput = asList(true, 99, 999L, 88.0f, 888.0, "Ā", new DataMap(), new DataList());
testArray(BytesArray.class, schema, input, adds);
testArrayBadInput(BytesArray.class, schema, input, badInput, badOutput);
}
use of com.linkedin.data.schema.ArrayDataSchema 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.schema.ArrayDataSchema in project rest.li by linkedin.
the class TestSchemaSampleDataGenerator method testArraySchema.
@Test
public void testArraySchema() {
for (Map.Entry<DataSchema.Type, Class<? extends DirectArrayTemplate<?>>> entry : _dataSchemaTypeToprimitiveArrayMap.entrySet()) {
final PrimitiveDataSchema itemsSchema = DataSchemaUtil.dataSchemaTypeToPrimitiveDataSchema(entry.getKey());
final ArrayDataSchema arraySchema = new ArrayDataSchema(itemsSchema);
final DataList value = (DataList) SchemaSampleDataGenerator.buildData(arraySchema, _spec);
final ParameterizedType arrayType = (ParameterizedType) entry.getValue().getGenericSuperclass();
assert (arrayType.getRawType() == DirectArrayTemplate.class);
Assert.assertSame(value.get(0).getClass(), arrayType.getActualTypeArguments()[0]);
}
}
use of com.linkedin.data.schema.ArrayDataSchema in project rest.li by linkedin.
the class TestArray method testStringMapArray.
@Test
public void testStringMapArray() {
TestDataTemplateUtil.FieldInfo fieldInfo = TestDataTemplateUtil.fieldInfo(new ArrayTest(), "stringMapArray");
@SuppressWarnings("unchecked") Class<StringMapArray> templateClass = (Class<StringMapArray>) fieldInfo.getFieldClass();
ArrayDataSchema schema = (ArrayDataSchema) fieldInfo.getField().getType();
List<StringMap> input = new ArrayList<StringMap>();
for (int i = 0; i < 5; ++i) {
input.add(new StringMap());
input.get(i).put("input key " + i, "value " + i);
}
List<StringMap> adds = new ArrayList<StringMap>();
for (int i = 0; i < 5; ++i) {
adds.add(new StringMap());
input.get(i).put("add key " + i, "value " + i);
}
TestArrayTemplate.testArray(templateClass, schema, input, adds);
}
use of com.linkedin.data.schema.ArrayDataSchema in project rest.li by linkedin.
the class TestArray method testIntegerArray.
@Test
public void testIntegerArray() {
TestDataTemplateUtil.FieldInfo fieldInfo = TestDataTemplateUtil.fieldInfo(new ArrayTest(), "intArray");
@SuppressWarnings("unchecked") Class<IntegerArray> templateClass = (Class<IntegerArray>) fieldInfo.getFieldClass();
ArrayDataSchema schema = (ArrayDataSchema) fieldInfo.getField().getType();
// must be unique
List<Integer> input = Arrays.asList(1, 3, 5, 7, 9);
List<Integer> adds = Arrays.asList(11, 13);
TestArrayTemplate.testArray(templateClass, schema, input, adds);
}
Aggregations