Search in sources :

Example 6 with PdlSchemaParser

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

the class TestDataSchemaResolver method lookup.

public void lookup(DataSchemaResolver resolver, String[][] lookups, char separator, boolean debug, SchemaFormatType extension) {
    PegasusSchemaParser parser = extension.equals(PDSC) ? new SchemaParser(resolver) : new PdlSchemaParser(resolver);
    for (String[] entry : lookups) {
        String name = entry[0];
        String expectFound = entry[1];
        String expected = entry[2];
        DataSchema schema = parser.lookupName(name);
        if (debug) {
            out.println("----" + name + "-----");
        }
        String errorMessage = parser.errorMessage();
        if (debug && errorMessage.isEmpty() == false) {
            out.println(errorMessage);
        }
        if (expectFound == ERROR) {
            assertTrue(parser.hasError());
            assertTrue(expected == null || errorMessage.contains(expected), "Expected: " + expected + "\n Actual: " + errorMessage);
        } else if (expectFound == FOUND) {
            assertTrue(schema != null);
            String schemaText = schema.toString();
            if (debug) {
                out.println(schemaText);
            }
            assertFalse(parser.hasError());
            assertTrue(schema instanceof NamedDataSchema);
            NamedDataSchema namedSchema = (NamedDataSchema) schema;
            assertEquals(namedSchema.getFullName(), name);
            assertTrue(schemaText.contains(expected));
            assertTrue(resolver.bindings().containsKey(name));
            assertSame(resolver.bindings().get(name), namedSchema);
            String location = entry[3];
            DataSchemaLocation namedSchemalocation = resolver.nameToDataSchemaLocations().get(name);
            String locationNorm;
            if (namedSchemalocation.toString().contains(".jar")) {
                locationNorm = location.replace(separator, '/');
            } else {
                locationNorm = location.replace('/', separator);
            }
            assertNotNull(namedSchemalocation);
            assertEquals(namedSchemalocation.toString().indexOf(locationNorm), namedSchemalocation.toString().length() - locationNorm.length());
            assertTrue(resolver.locationResolved(namedSchemalocation));
        } else if (expectFound == NOT_FOUND) {
            assertTrue(schema == null);
            assertFalse(parser.hasError());
            assertTrue(expected == null || errorMessage.contains(expected));
            assertFalse(resolver.bindings().containsKey(name));
        } else {
            assertTrue(false);
        }
    }
}
Also used : DataSchema(com.linkedin.data.schema.DataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) PegasusSchemaParser(com.linkedin.data.schema.PegasusSchemaParser) SchemaParser(com.linkedin.data.schema.SchemaParser) PdlSchemaParser(com.linkedin.data.schema.grammar.PdlSchemaParser) PegasusSchemaParser(com.linkedin.data.schema.PegasusSchemaParser) PdlSchemaParser(com.linkedin.data.schema.grammar.PdlSchemaParser) DataSchemaLocation(com.linkedin.data.schema.DataSchemaLocation)

Example 7 with PdlSchemaParser

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

the class PdlEncoderTest method parseSchema.

private DataSchema parseSchema(File file) throws IOException {
    DataSchemaResolver resolver = MultiFormatDataSchemaResolver.withBuiltinFormats(pegasusSrcDir.getAbsolutePath());
    AbstractSchemaParser parser = new PdlSchemaParser(resolver);
    parser.parse(new FileInputStream(file));
    return extractSchema(parser, file.getAbsolutePath());
}
Also used : MultiFormatDataSchemaResolver(com.linkedin.data.schema.resolver.MultiFormatDataSchemaResolver) DataSchemaResolver(com.linkedin.data.schema.DataSchemaResolver) AbstractSchemaParser(com.linkedin.data.schema.AbstractSchemaParser) PdlSchemaParser(com.linkedin.data.schema.grammar.PdlSchemaParser) FileInputStream(java.io.FileInputStream)

Aggregations

PdlSchemaParser (com.linkedin.data.schema.grammar.PdlSchemaParser)7 DataSchema (com.linkedin.data.schema.DataSchema)3 DataSchemaResolver (com.linkedin.data.schema.DataSchemaResolver)3 NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)3 DefaultDataSchemaResolver (com.linkedin.data.schema.resolver.DefaultDataSchemaResolver)3 MultiFormatDataSchemaResolver (com.linkedin.data.schema.resolver.MultiFormatDataSchemaResolver)3 FileInputStream (java.io.FileInputStream)3 AbstractSchemaParser (com.linkedin.data.schema.AbstractSchemaParser)2 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)2 DataList (com.linkedin.data.DataList)1 DataMap (com.linkedin.data.DataMap)1 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)1 DataSchemaLocation (com.linkedin.data.schema.DataSchemaLocation)1 PegasusSchemaParser (com.linkedin.data.schema.PegasusSchemaParser)1 SchemaParser (com.linkedin.data.schema.SchemaParser)1 EXTENSION_ANNOTATION_NAMESPACE (com.linkedin.data.schema.annotation.ExtensionSchemaAnnotationHandler.EXTENSION_ANNOTATION_NAMESPACE)1 CoercionMode (com.linkedin.data.schema.validation.CoercionMode)1 RequiredMode (com.linkedin.data.schema.validation.RequiredMode)1 UnrecognizedFieldMode (com.linkedin.data.schema.validation.UnrecognizedFieldMode)1 ValidateDataAgainstSchema (com.linkedin.data.schema.validation.ValidateDataAgainstSchema)1