use of com.linkedin.pegasus.generator.spec.UnionTemplateSpec in project rest.li by linkedin.
the class TestTemplateSpecGenerator method testCustomInfoForUnionMembers.
@Test(dataProvider = "customTypeDataForUnion")
public void testCustomInfoForUnionMembers(final List<DataSchema> customTypedSchemas) {
final UnionDataSchema union = new UnionDataSchema();
union.setTypes(customTypedSchemas, null);
final TyperefDataSchema typeref = new TyperefDataSchema(new Name(INPUT_SCHEMA_NAME));
typeref.setReferencedType(union);
final TemplateSpecGenerator generator = new TemplateSpecGenerator(_resolver);
final UnionTemplateSpec spec = (UnionTemplateSpec) generator.generate(typeref, _location);
for (int i = 0; i < customTypedSchemas.size(); ++i) {
Assert.assertNotNull(spec.getMembers().get(i).getCustomInfo());
Assert.assertEquals(spec.getMembers().get(i).getCustomInfo().getCustomClass().getClassName(), CustomTypeUtil.getJavaCustomTypeClassNameFromSchema((TyperefDataSchema) customTypedSchemas.get(i)));
}
}
use of com.linkedin.pegasus.generator.spec.UnionTemplateSpec in project rest.li by linkedin.
the class TemplateSpecGenerator method generateUnion.
private ClassTemplateSpec generateUnion(UnionDataSchema schema, TyperefDataSchema typerefDataSchema) {
assert typerefDataSchema.getRef() == schema;
pushCurrentLocation(_schemaResolver.nameToDataSchemaLocations().get(typerefDataSchema.getFullName()));
final UnionTemplateSpec unionClass = new UnionTemplateSpec(schema);
unionClass.setNamespace(typerefDataSchema.getNamespace());
unionClass.setPackage(typerefDataSchema.getPackage());
unionClass.setClassName(typerefDataSchema.getName());
unionClass.setModifiers(ModifierSpec.PUBLIC);
registerClassTemplateSpec(typerefDataSchema, unionClass);
final TyperefTemplateSpec typerefInfoClass = new TyperefTemplateSpec(typerefDataSchema);
typerefInfoClass.setEnclosingClass(unionClass);
typerefInfoClass.setClassName("UnionTyperefInfo");
typerefInfoClass.setModifiers(ModifierSpec.PRIVATE, ModifierSpec.STATIC, ModifierSpec.FINAL);
final UnionTemplateSpec result = generateUnion(schema, unionClass);
result.setTyperefClass(typerefInfoClass);
popCurrentLocation();
return result;
}
Aggregations