use of com.linkedin.data.schema.DataSchema 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.DataSchema in project rest.li by linkedin.
the class TestSchemaSampleDataGenerator method testUnionSchema.
@Test
public void testUnionSchema() {
final UnionDataSchema schema = (UnionDataSchema) DataTemplateUtil.getSchema(UnionTest.UnionWithNull.class);
final Set<String> memberKeys = new HashSet<String>();
for (DataSchema memberSchema : schema.getTypes()) {
memberKeys.add(memberSchema.getUnionMemberKey());
}
final String nullMemberKey = DataSchemaConstants.NULL_DATA_SCHEMA.getUnionMemberKey();
for (int i = 0; i < memberKeys.size() * 2; ++i) {
final DataMap value = (DataMap) SchemaSampleDataGenerator.buildData(schema, _spec);
if (value == null) {
Assert.assertTrue(memberKeys.contains(nullMemberKey));
continue;
}
final String key = value.keySet().iterator().next();
Assert.assertTrue(memberKeys.contains(key));
}
}
use of com.linkedin.data.schema.DataSchema 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.DataSchema in project rest.li by linkedin.
the class TestEnum method testEnum.
private static <T extends Enum<T>> void testEnum(Class<T> enumClass) {
try {
assertTrue(Enum.class.isAssignableFrom(enumClass));
// has embedded EnumDataSchema
DataSchema schema = DataTemplateUtil.getSchema(enumClass);
assertNotNull(schema);
assertTrue(schema instanceof EnumDataSchema);
// get symbols
EnumDataSchema enumSchema = (EnumDataSchema) schema;
Set<String> schemaSymbols = new HashSet<String>(enumSchema.getSymbols());
assertNotNull(schemaSymbols);
for (String symbol : schemaSymbols) {
// IllegalArgumentException thrown if not valid symbol
Enum.valueOf(enumClass, symbol);
}
// IllegalArgumentException thrown if not valid symbol
Enum.valueOf(enumClass, "$UNKNOWN");
} catch (Exception exc) {
fail("Unexpected exception", exc);
}
}
use of com.linkedin.data.schema.DataSchema 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