Search in sources :

Example 6 with NamedDataSchema

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

the class TestAbstractGenerator method verify.

private void verify(String[] args, Map.Entry<File, Map.Entry<String, String>> entry, Exception exc, File targetDir, boolean debug) throws IOException {
    if (debug) {
        out.println(entry);
        if (exc != null)
            out.println(exc);
    }
    String pdscFileName = (entry.getValue().getKey());
    if (_expectedSchemas.contains(pdscFileName)) {
        File expectedOutputFile = schemaOutputFile(targetDir.getCanonicalPath(), entry.getValue().getValue());
        assertTrue(expectedOutputFile.exists());
        FileInputStream is = new FileInputStream(expectedOutputFile);
        byte[] bytes = new byte[is.available()];
        try {
            is.read(bytes);
        } finally {
            is.close();
        }
        String fileSchemaText = new String(bytes);
        DataSchema fileSchema = DataTemplateUtil.parseSchema(fileSchemaText);
        assertTrue(fileSchema instanceof NamedDataSchema);
        // run the generator again
        // verify that output file has not changed
        // test up-to-date
        long beforeLastModified = expectedOutputFile.lastModified();
        TestGenerator.main(args, debug);
        long afterLastModified = expectedOutputFile.lastModified();
        assertEquals(beforeLastModified, afterLastModified, expectedOutputFile.getPath());
    } else if (_badPegasusSchemas.containsKey(pdscFileName)) {
        assertTrue(exc != null);
        String message = exc.getMessage();
        assertTrue(message.contains(_badPegasusSchemas.get(pdscFileName)));
    }
}
Also used : DataSchema(com.linkedin.data.schema.DataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) TestUtil.dataMapFromString(com.linkedin.data.TestUtil.dataMapFromString) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 7 with NamedDataSchema

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

the class TestSchemaFilter method testInputs.

private static void testInputs(Object[][] inputs, boolean isAvroUnionMode) throws IOException {
    for (Object[] row : inputs) {
        String schemaText = (String) row[0];
        Predicate predicate = (Predicate) row[1];
        String expected = (String) row[2];
        NamedDataSchema schema = dataSchemaFromString(schemaText, isAvroUnionMode);
        DataSchema filteredSchema = null;
        SchemaParser parser = new SchemaParser();
        parser.getValidationOptions().setAvroUnionMode(isAvroUnionMode);
        filteredSchema = Filters.removeByPredicate(schema, predicate, parser);
        if (filteredSchema != null) {
            // Schema string match
            String expectedSchemaText = expected;
            DataSchema expectedSchema = dataSchemaFromString(expectedSchemaText, isAvroUnionMode);
            assertEquals(filteredSchema.toString(), expectedSchema.toString());
            assertEquals(filteredSchema, expectedSchema);
        } else {
            String parserMessage = parser.errorMessage();
            assertTrue(parserMessage.contains(expected), "\nContains :" + expected + "\nActual   :" + parserMessage);
        }
    }
}
Also used : NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) SchemaParser(com.linkedin.data.schema.SchemaParser) Predicate(com.linkedin.data.it.Predicate)

Example 8 with NamedDataSchema

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

the class PdlEncoderTest method assertRoundTrip.

private void assertRoundTrip(String relativeName) throws IOException {
    String fullName = "com.linkedin.pegasus.generator.test.idl." + relativeName;
    String path = "/" + fullName.replace('.', '/') + ".pdl";
    NamedDataSchema parsed = parseSchema(fullName);
    String original = loadSchema(path);
    assertNotNull(parsed, "Failed to resolve: " + fullName + "resolver path: " + pegasusSrcDir.getAbsolutePath());
    StringWriter writer = new StringWriter();
    SchemaToPdlEncoder encoder = new SchemaToPdlEncoder(writer);
    encoder.setTypeReferenceFormat(SchemaToPdlEncoder.TypeReferenceFormat.PRESERVE);
    encoder.encode(parsed);
    String encoded = writer.toString();
    assertEqualsIgnoringSpacing(original, encoded);
}
Also used : NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) SchemaToPdlEncoder(com.linkedin.data.schema.SchemaToPdlEncoder) StringWriter(java.io.StringWriter)

Example 9 with NamedDataSchema

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

the class PdlEncoderTest method parseSchema.

private NamedDataSchema parseSchema(String name) throws IOException {
    StringBuilder errors = new StringBuilder();
    NamedDataSchema dataSchema = resolver.findDataSchema(name, errors);
    if (errors.length() > 0) {
        fail("Parse error: " + errors.toString());
    }
    return dataSchema;
}
Also used : NamedDataSchema(com.linkedin.data.schema.NamedDataSchema)

Example 10 with NamedDataSchema

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

the class TemplateSpecGenerator method getImmediateCustomInfo.

private CustomInfoSpec getImmediateCustomInfo(DataSchema schema) {
    if (_immediateCustomMap.containsKey(schema)) {
        return _immediateCustomMap.get(schema);
    }
    CustomInfoSpec immediate = null;
    for (DataSchema current = schema; current != null; current = dereferenceIfTyperef(current)) {
        final CustomClasses customClasses = getCustomClasses(current);
        if (customClasses != null) {
            immediate = new CustomInfoSpec((NamedDataSchema) schema, (NamedDataSchema) current, customClasses.customClass, customClasses.customCoercerClass);
            break;
        }
    }
    // immediate may be null
    _immediateCustomMap.put(schema, immediate);
    return immediate;
}
Also used : FixedDataSchema(com.linkedin.data.schema.FixedDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) MapDataSchema(com.linkedin.data.schema.MapDataSchema) ComplexDataSchema(com.linkedin.data.schema.ComplexDataSchema) PrimitiveDataSchema(com.linkedin.data.schema.PrimitiveDataSchema) EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) CustomInfoSpec(com.linkedin.pegasus.generator.spec.CustomInfoSpec)

Aggregations

NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)46 DataSchema (com.linkedin.data.schema.DataSchema)25 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)16 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)12 MapDataSchema (com.linkedin.data.schema.MapDataSchema)11 TyperefDataSchema (com.linkedin.data.schema.TyperefDataSchema)11 UnionDataSchema (com.linkedin.data.schema.UnionDataSchema)11 DataMap (com.linkedin.data.DataMap)8 IOException (java.io.IOException)8 DataSchemaLocation (com.linkedin.data.schema.DataSchemaLocation)7 PrimitiveDataSchema (com.linkedin.data.schema.PrimitiveDataSchema)7 EnumDataSchema (com.linkedin.data.schema.EnumDataSchema)6 FixedDataSchema (com.linkedin.data.schema.FixedDataSchema)6 SchemaParser (com.linkedin.data.schema.SchemaParser)6 ComplexDataSchema (com.linkedin.data.schema.ComplexDataSchema)5 File (java.io.File)5 Test (org.testng.annotations.Test)5 CustomInfoSpec (com.linkedin.pegasus.generator.spec.CustomInfoSpec)4 RestLiInternalException (com.linkedin.restli.internal.server.RestLiInternalException)4 FileInputStream (java.io.FileInputStream)4