Search in sources :

Example 1 with CompatibilityOptions

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

the class TestCompatibilityChecker method testCompatibility.

private void testCompatibility(String olderSchemaText, String newerSchemaText, List<CompatibilityOptions> compatibilityOptions, boolean hasError, Object[] expected, int expectedIndex) throws IOException {
    if (_debug)
        out.println(olderSchemaText + "\n" + newerSchemaText);
    DataSchema olderSchema = TestUtil.dataSchemaFromString(olderSchemaText);
    DataSchema newerSchema = TestUtil.dataSchemaFromString(newerSchemaText);
    assertNotNull(olderSchema, olderSchemaText);
    assertNotNull(newerSchema, newerSchemaText);
    for (CompatibilityOptions option : compatibilityOptions) {
        CompatibilityResult result = CompatibilityChecker.checkCompatibility(olderSchema, newerSchema, option);
        String messageText = result.getMessages().toString();
        if (_debug)
            out.println(result);
        assertEquals(result.isError(), hasError, olderSchemaText + "\n" + newerSchemaText + "\n" + messageText);
        for (int i = expectedIndex; i < expected.length; i++) {
            String expectedText = ".*" + expected[i] + "\n.*";
            if (_debug)
                out.println(expectedText);
            Pattern pattern = Pattern.compile(expectedText, Pattern.DOTALL);
            Matcher matcher = pattern.matcher(messageText);
            boolean matches = matcher.matches();
            assertTrue(matches, messageText + "\n" + expectedText);
        }
    }
}
Also used : DataSchema(com.linkedin.data.schema.DataSchema) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) CompatibilityResult(com.linkedin.data.schema.compatibility.CompatibilityResult) CompatibilityOptions(com.linkedin.data.schema.compatibility.CompatibilityOptions)

Aggregations

DataSchema (com.linkedin.data.schema.DataSchema)1 CompatibilityOptions (com.linkedin.data.schema.compatibility.CompatibilityOptions)1 CompatibilityResult (com.linkedin.data.schema.compatibility.CompatibilityResult)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1