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);
}
}
use of com.linkedin.data.schema.RecordDataSchema in project rest.li by linkedin.
the class TestRecord method testRecord.
private <T extends RecordTemplate> void testRecord(Class<T> recordClass) {
try {
T record = recordClass.newInstance();
RecordDataSchema schema = (RecordDataSchema) DataTemplateUtil.getSchema(recordClass);
RecordDataSchema schema2 = record.schema();
assertSame(schema, schema2);
} catch (IllegalAccessException exc) {
fail("Unexpected exception", exc);
} catch (InstantiationException exc) {
fail("Unexpected exception", exc);
}
}
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 TemplateSpecGenerator method generateNamedSchema.
private ClassTemplateSpec generateNamedSchema(NamedDataSchema schema) {
pushCurrentLocation(_schemaResolver.nameToDataSchemaLocations().get(schema.getFullName()));
// make sure no duplicate template spec classname which should be binding name of the schema
final String className = schema.getBindingName();
checkForClassNameConflict(className, schema);
final ClassTemplateSpec templateClass;
switch(schema.getType()) {
case RECORD:
templateClass = generateRecord((RecordDataSchema) schema);
break;
case ENUM:
templateClass = generateEnum((EnumDataSchema) schema);
break;
case FIXED:
templateClass = generateFixed((FixedDataSchema) schema);
break;
default:
throw unrecognizedSchemaType(null, null, schema);
}
popCurrentLocation();
return templateClass;
}
Aggregations