Search in sources :

Example 16 with Name

use of com.linkedin.data.schema.Name in project rest.li by linkedin.

the class TestResourceCompatibilityChecker method bindSchemaResolvers.

private void bindSchemaResolvers() {
    StringBuilder errors = new StringBuilder();
    Name toneName = new Name("com.linkedin.greetings.api.Tone");
    EnumDataSchema tone = new EnumDataSchema(toneName);
    List<String> symbols = new ArrayList<String>();
    symbols.add("FRIENDLY");
    symbols.add("SINCERE");
    symbols.add("INSULTING");
    tone.setSymbols(symbols, errors);
    Name greetingName = new Name("com.linkedin.greetings.api.Greeting");
    RecordDataSchema prevGreeting = new RecordDataSchema(greetingName, RecordDataSchema.RecordType.RECORD);
    List<RecordDataSchema.Field> oldFields = new ArrayList<RecordDataSchema.Field>();
    RecordDataSchema.Field id = new RecordDataSchema.Field(new LongDataSchema());
    id.setName("id", errors);
    oldFields.add(id);
    RecordDataSchema.Field message = new RecordDataSchema.Field(new StringDataSchema());
    message.setName("message", errors);
    oldFields.add(message);
    RecordDataSchema.Field toneField = new RecordDataSchema.Field(tone);
    toneField.setName("tone", errors);
    toneField.setOptional(true);
    oldFields.add(toneField);
    prevGreeting.setFields(oldFields, errors);
    prevSchemaResolver.bindNameToSchema(toneName, tone, null);
    prevSchemaResolver.bindNameToSchema(greetingName, prevGreeting, null);
    // compat greeting added a new optional field "newField"
    RecordDataSchema compatGreeting = new RecordDataSchema(greetingName, RecordDataSchema.RecordType.RECORD);
    List<RecordDataSchema.Field> compatFields = new ArrayList<RecordDataSchema.Field>();
    compatFields.add(id);
    compatFields.add(message);
    compatFields.add(toneField);
    RecordDataSchema.Field newCompatField = new RecordDataSchema.Field(new StringDataSchema());
    newCompatField.setName("newField", errors);
    newCompatField.setOptional(true);
    compatFields.add(newCompatField);
    compatGreeting.setFields(compatFields, errors);
    compatSchemaResolver.bindNameToSchema(toneName, tone, null);
    compatSchemaResolver.bindNameToSchema(greetingName, compatGreeting, null);
    // incompat greeting has removed non-optional field "message",
    // has changed the type of "id" to string,
    // and added a new non-optional field "newField"
    RecordDataSchema incompatGreeting = new RecordDataSchema(greetingName, RecordDataSchema.RecordType.RECORD);
    List<RecordDataSchema.Field> incompatFields = new ArrayList<RecordDataSchema.Field>();
    RecordDataSchema.Field incompatId = new RecordDataSchema.Field(new StringDataSchema());
    incompatId.setName("id", errors);
    oldFields.add(incompatId);
    incompatFields.add(incompatId);
    incompatFields.add(toneField);
    RecordDataSchema.Field newIncompatField = new RecordDataSchema.Field(new StringDataSchema());
    newIncompatField.setName("newField", errors);
    incompatFields.add(newIncompatField);
    incompatGreeting.setFields(incompatFields, errors);
    incompatSchemaResolver.bindNameToSchema(toneName, tone, null);
    incompatSchemaResolver.bindNameToSchema(greetingName, incompatGreeting, null);
}
Also used : StringDataSchema(com.linkedin.data.schema.StringDataSchema) EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) ArrayList(java.util.ArrayList) LongDataSchema(com.linkedin.data.schema.LongDataSchema) Name(com.linkedin.data.schema.Name)

Aggregations

Name (com.linkedin.data.schema.Name)16 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)10 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)5 TyperefDataSchema (com.linkedin.data.schema.TyperefDataSchema)5 UnionDataSchema (com.linkedin.data.schema.UnionDataSchema)5 DataSchema (com.linkedin.data.schema.DataSchema)4 EnumDataSchema (com.linkedin.data.schema.EnumDataSchema)4 MapDataSchema (com.linkedin.data.schema.MapDataSchema)4 ArrayList (java.util.ArrayList)4 DataMap (com.linkedin.data.DataMap)3 HashMap (java.util.HashMap)3 DataSchemaResolver (com.linkedin.data.schema.DataSchemaResolver)2 FixedDataSchema (com.linkedin.data.schema.FixedDataSchema)2 NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)2 UnionTemplateSpec (com.linkedin.pegasus.generator.spec.UnionTemplateSpec)2 Map (java.util.Map)2 Test (org.testng.annotations.Test)2 EnumSymbolDeclarationContext (com.linkedin.data.grammar.PdlParser.EnumSymbolDeclarationContext)1 ImportDeclarationContext (com.linkedin.data.grammar.PdlParser.ImportDeclarationContext)1 PropDeclarationContext (com.linkedin.data.grammar.PdlParser.PropDeclarationContext)1