use of com.linkedin.data.DataList in project rest.li by linkedin.
the class TestValidation method testArrayNormalCoercionValidation.
@Test
public void testArrayNormalCoercionValidation() throws IOException {
String schemaText = "{ \"type\" : \"record\", \"name\" : \"foo\", \"fields\" : " + "[ { \"name\" : \"bar\", \"type\" : { \"type\" : \"array\", \"items\" : \"int\" } } ] }";
Object[][] inputs = { { new DataList(), new DataList() }, { new DataList(asList(1)), new DataList(asList(1)) }, { new DataList(asList(2, 3)), new DataList(asList(2, 3)) }, { new DataList(asList(1L)), new DataList(asList(1)) }, { new DataList(asList(1.0f)), new DataList(asList(1)) }, { new DataList(asList(1.0)), new DataList(asList(1)) } };
Object[] badObjects = { new Boolean(true), new Integer(1), new Long(1), new Float(1), new Double(1), new String(), new DataMap(), new DataList(asList(new Boolean(true))), new DataList(asList(new String("1"))), new DataList(asList(new DataMap())), new DataList(asList(new DataList())), new DataList(asList(new Boolean(true), new Integer(1))), new DataList(asList(new Integer(1), new Boolean(true))) };
testNormalCoercionValidation(schemaText, "bar", inputs, badObjects);
}
use of com.linkedin.data.DataList 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.DataList in project rest.li by linkedin.
the class TestCustomPoint method testCustomPointRecordArray.
@Test
public void testCustomPointRecordArray() throws CloneNotSupportedException {
final List<String> input = new ArrayList<String>(Arrays.asList("1,1", "2,2", "3,3"));
final DataList inputDataList = new DataList(input);
CustomPointRecord record = new CustomPointRecord();
CustomPointArray a1 = new CustomPointArray(inputDataList);
record.setCustomPointArray(a1);
CustomPointRecord recordCopy = new CustomPointRecord(record.data().copy());
for (int i = 0; i < input.size(); i++) {
assertEquals(recordCopy.getCustomPointArray().get(i), new CustomPoint(input.get(i)));
}
}
use of com.linkedin.data.DataList in project rest.li by linkedin.
the class TestLongStringLiteral method testSchema.
@Test
public void testSchema() {
DataSchema schema = DataTemplateUtil.getSchema(LongStringLiteral.class);
String schemaText = schema.toString();
assertTrue(schemaText.length() > 65536);
RecordDataSchema recordDataSchema = (RecordDataSchema) schema;
RecordDataSchema.Field field = recordDataSchema.getField("text");
DataList defaultValue = (DataList) field.getDefault();
assertEquals(defaultValue.size(), 400);
for (Object s : defaultValue) {
assertEquals(s, LOREM);
}
}
use of com.linkedin.data.DataList in project rest.li by linkedin.
the class TestCustomPoint method testCustomPointRecordArray.
@Test
public void testCustomPointRecordArray() throws CloneNotSupportedException {
final List<String> input = new ArrayList<String>(Arrays.asList("1,1", "2,2", "3,3"));
final DataList inputDataList = new DataList(input);
CustomPointRecord record = new CustomPointRecord();
CustomPointArray a1 = new CustomPointArray(inputDataList);
record.setCustomPointArray(a1);
CustomPointRecord recordCopy = new CustomPointRecord(record.data().copy());
for (int i = 0; i < input.size(); i++) {
assertEquals(recordCopy.getCustomPointArray().get(i), new CustomPoint(input.get(i)));
}
}
Aggregations