Search in sources :

Example 1 with DefaultDataSchemaResolver

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

the class TestUtil method pdlSchemaParserFromString.

public static PdlSchemaParser pdlSchemaParserFromString(String s) throws UnsupportedEncodingException {
    PdlSchemaParser parser = new PdlSchemaParser(new DefaultDataSchemaResolver());
    parser.parse(inputStreamFromString(s));
    return parser;
}
Also used : DefaultDataSchemaResolver(com.linkedin.data.schema.resolver.DefaultDataSchemaResolver) PdlSchemaParser(com.linkedin.data.schema.grammar.PdlSchemaParser)

Example 2 with DefaultDataSchemaResolver

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

the class TestPdlSchemaParser method testEnumParserLocations.

@Test
public void testEnumParserLocations() {
    PdlSchemaParser parser = new PdlSchemaParser(new DefaultDataSchemaResolver(), true);
    parser.parse(getClass().getResourceAsStream("TestEnumForParserContextLocations.pdl"));
    List<DataSchema> topLevelSchemas = parser.topLevelDataSchemas();
    Assert.assertEquals(topLevelSchemas.size(), 1, "Expected 1 top-level schema to be parsed.");
    EnumDataSchema topSchema = (EnumDataSchema) topLevelSchemas.get(0);
    Map<Object, PdlSchemaParser.ParseLocation> locations = parser.getParseLocations();
    checkParseLocationForEnum(locations, topSchema);
}
Also used : EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) FixedDataSchema(com.linkedin.data.schema.FixedDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) DefaultDataSchemaResolver(com.linkedin.data.schema.resolver.DefaultDataSchemaResolver) Test(org.testng.annotations.Test)

Example 3 with DefaultDataSchemaResolver

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

the class TestPdlSchemaParser method testTyperefParserLocations.

@Test
public void testTyperefParserLocations() {
    PdlSchemaParser parser = new PdlSchemaParser(new DefaultDataSchemaResolver(), true);
    parser.parse(getClass().getResourceAsStream("TestTyperefForParserContextLocations.pdl"));
    List<DataSchema> topLevelSchemas = parser.topLevelDataSchemas();
    Assert.assertEquals(topLevelSchemas.size(), 1, "Expected 1 top-level schema to be parsed.");
    TyperefDataSchema topSchema = (TyperefDataSchema) topLevelSchemas.get(0);
    Map<Object, PdlSchemaParser.ParseLocation> locations = parser.getParseLocations();
    checkParseLocationForTyperef(locations, topSchema);
}
Also used : EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) FixedDataSchema(com.linkedin.data.schema.FixedDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) DefaultDataSchemaResolver(com.linkedin.data.schema.resolver.DefaultDataSchemaResolver) Test(org.testng.annotations.Test)

Example 4 with DefaultDataSchemaResolver

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

the class TestPdlSchemaParser method testRecordParserLocations.

@Test
public void testRecordParserLocations() {
    PdlSchemaParser parser = new PdlSchemaParser(new DefaultDataSchemaResolver(), true);
    parser.parse(getClass().getResourceAsStream("TestRecordForParserContextLocations.pdl"));
    List<DataSchema> topLevelSchemas = parser.topLevelDataSchemas();
    Assert.assertEquals(topLevelSchemas.size(), 1, "Expected 1 top-level schema to be parsed.");
    RecordDataSchema mainRecordSchema = (RecordDataSchema) topLevelSchemas.get(0);
    Map<Object, PdlSchemaParser.ParseLocation> locations = parser.getParseLocations();
    checkParseLocationForRecord(locations, mainRecordSchema);
    // Checks for namespace locations.
    // Top-level namespace
    PdlSchemaParser.ParseLocation topNamespaceLoc = locations.get(mainRecordSchema.getNamespace());
    assertLocation(topNamespaceLoc, 1, 1, 1, 42, "namespace: " + mainRecordSchema.getNamespace());
    // Inline namespace
    String inlineNamespace = ((RecordDataSchema) mainRecordSchema.getField("inlineNamespacedField").getType()).getNamespace();
    PdlSchemaParser.ParseLocation inlineNamespaceLoc = locations.get(inlineNamespace);
    assertLocation(inlineNamespaceLoc, 48, 5, 48, 38, "namespace: " + inlineNamespace);
}
Also used : EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) FixedDataSchema(com.linkedin.data.schema.FixedDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) DefaultDataSchemaResolver(com.linkedin.data.schema.resolver.DefaultDataSchemaResolver) Test(org.testng.annotations.Test)

Example 5 with DefaultDataSchemaResolver

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

the class TestPdlSchemaParser method parsePdlSchema.

/**
 * Parses a .pdl file found at a given filename in the resource directory for this class.
 * @param filename file name pointing to a .pdl file
 * @return parsed data schema
 */
private DataSchema parsePdlSchema(String filename) {
    PdlSchemaParser parser = new PdlSchemaParser(new DefaultDataSchemaResolver());
    parser.parse(getClass().getResourceAsStream(filename));
    List<DataSchema> topLevelSchemas = parser.topLevelDataSchemas();
    Assert.assertEquals(topLevelSchemas.size(), 1, "Expected 1 top-level schema to be parsed.");
    return topLevelSchemas.get(0);
}
Also used : EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) FixedDataSchema(com.linkedin.data.schema.FixedDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) DefaultDataSchemaResolver(com.linkedin.data.schema.resolver.DefaultDataSchemaResolver)

Aggregations

DefaultDataSchemaResolver (com.linkedin.data.schema.resolver.DefaultDataSchemaResolver)10 DataSchema (com.linkedin.data.schema.DataSchema)6 NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)6 EnumDataSchema (com.linkedin.data.schema.EnumDataSchema)5 FixedDataSchema (com.linkedin.data.schema.FixedDataSchema)5 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)5 TyperefDataSchema (com.linkedin.data.schema.TyperefDataSchema)5 UnionDataSchema (com.linkedin.data.schema.UnionDataSchema)5 Test (org.testng.annotations.Test)4 PdlSchemaParser (com.linkedin.data.schema.grammar.PdlSchemaParser)3 FileInputStream (java.io.FileInputStream)2 DataSchemaResolver (com.linkedin.data.schema.DataSchemaResolver)1 FileDataSchemaResolver (com.linkedin.data.schema.resolver.FileDataSchemaResolver)1 MultiFormatDataSchemaResolver (com.linkedin.data.schema.resolver.MultiFormatDataSchemaResolver)1 ResourceSchema (com.linkedin.restli.restspec.ResourceSchema)1 ResourceCompatibilityChecker (com.linkedin.restli.tools.compatibility.ResourceCompatibilityChecker)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Stack (java.util.Stack)1 ParseException (org.apache.commons.cli.ParseException)1