use of com.linkedin.data.schema.RecordDataSchema in project rest.li by linkedin.
the class TestSchemaSampleDataGenerator method testTyperefSchema.
@Test
public void testTyperefSchema() {
final RecordDataSchema schema = (RecordDataSchema) DataTemplateUtil.getSchema(TyperefTest.class);
final DataMap value = SchemaSampleDataGenerator.buildRecordData(schema, _spec);
for (RecordDataSchema.Field field : schema.getFields()) {
final DataSchema fieldSchema = field.getType();
if (!(fieldSchema instanceof TyperefDataSchema)) {
continue;
}
final TyperefDataSchema fieldTyperefSchema = (TyperefDataSchema) field.getType();
final Object fieldValue = value.get(field.getName());
final Object rebuildValue = SchemaSampleDataGenerator.buildData(fieldTyperefSchema.getDereferencedDataSchema(), _spec);
Assert.assertSame(fieldValue.getClass(), rebuildValue.getClass());
}
}
use of com.linkedin.data.schema.RecordDataSchema in project rest.li by linkedin.
the class TestSchemaSampleDataGenerator method testRecursivelyReferencedSchema.
@Test
public void testRecursivelyReferencedSchema() {
try {
final RecordDataSchema schema = (RecordDataSchema) DataTemplateUtil.getSchema(SelfReference.class);
final DataMap data = SchemaSampleDataGenerator.buildRecordData(schema, _spec);
Assert.assertTrue(data.getDataList("listRef").getDataMap(0).getDataList("listRef").isEmpty(), "Self referenced schema in list should not be embedded recursively");
final String firstKey = data.getDataMap("mapRef").keySet().iterator().next();
Assert.assertTrue(data.getDataMap("mapRef").getDataMap(firstKey).getDataMap("mapRef").isEmpty(), "Self referenced schema in map should not be embedded recursively");
Assert.assertFalse(data.getDataMap("indirectRef").containsKey("ref"), "Self referenced schema (via indirect reference) should not be embedded recursively");
Assert.assertFalse(data.getDataMap("unionRef").containsKey("com.linkedin.pegasus.generator.test.SelfReference"), "Self referenced schema in union should not be embedded recursively");
} catch (StackOverflowError e) {
Assert.fail("Self reference in schema should not cause stack overflow during doc gen.");
}
}
use of com.linkedin.data.schema.RecordDataSchema in project rest.li by linkedin.
the class TestCustomAnyRecord method testCustomAnyRecordSchema.
@Test
public void testCustomAnyRecordSchema() {
RecordDataSchema schemaFromInstance = (new AnyRecord()).schema();
DataSchema schemaFromClass = DataTemplateUtil.getSchema(AnyRecord.class);
assertSame(schemaFromClass, schemaFromInstance);
CustomAnyRecord custom = new CustomAnyRecord();
RecordDataSchema customSchemaFromInstance = custom.schema();
DataSchema customSchemaFromClass = DataTemplateUtil.getSchema(CustomAnyRecord.class);
assertSame(customSchemaFromClass, customSchemaFromInstance);
assertEquals(customSchemaFromClass, schemaFromClass);
}
use of com.linkedin.data.schema.RecordDataSchema in project rest.li by linkedin.
the class TestTypeRefRecordTemplate method testMapSchema.
@Test
public void testMapSchema() {
TyperefTest record = new TyperefTest();
RecordDataSchema recordDataSchema = record.schema();
DoubleMap doubleMap = new DoubleMap();
record.setDoubleRefMap(doubleMap);
doubleMap = record.getDoubleRefMap();
assertEquals(doubleMap.schema(), DataTemplateUtil.getSchema(DoubleMap.class));
assertNotEquals(recordDataSchema.getField("doubleRefMap").getType(), doubleMap.schema());
IntegerMap intMap = new IntegerMap();
record.setIntMap(intMap);
intMap = record.getIntMap();
assertEquals(intMap.schema(), DataTemplateUtil.getSchema(IntegerMap.class));
assertNotEquals(recordDataSchema.getField("intMap").getType(), intMap.schema());
record.setIntRefMap(intMap);
intMap = record.getIntRefMap();
assertEquals(intMap.schema(), DataTemplateUtil.getSchema(IntegerMap.class));
assertNotEquals(recordDataSchema.getField("intRefMap").getType(), intMap.schema());
assertNotEquals(recordDataSchema.getField("intMap").getType(), recordDataSchema.getField("intRefMap").getType());
}
use of com.linkedin.data.schema.RecordDataSchema 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);
}
}
Aggregations