Search in sources :

Example 1 with ValidationException

use of org.apache.openejb.config.ValidationException in project tomee by apache.

the class ValidationAssertions method assertValidation.

private static void assertValidation(final List<String> expectedKeys, final ValidationException[] validations) {
    final List<String> actualKeys = new ArrayList<>();
    for (final ValidationException validation : validations) {
        actualKeys.add(validation.getMessageKey());
    }
    Collections.sort(expectedKeys);
    Collections.sort(actualKeys);
    final String actual = org.apache.openejb.util.Join.join("\n", actualKeys);
    final String expected = org.apache.openejb.util.Join.join("\n", expectedKeys);
    Assert.assertEquals("Keys do not match", expected, actual);
    // Check for the expected keys
    for (final String key : expectedKeys) {
        Assert.assertTrue("Missing key: " + key, actualKeys.contains(key));
    }
    Assert.assertEquals("Number of failures don't match", expectedKeys.size(), actualKeys.size());
    // the key is not in the getMessage() output
    for (final ValidationException validation : validations) {
        final String key = validation.getMessageKey();
        for (final Integer level : Arrays.asList(1, 2, 3)) {
            final String message = validation.getMessage(level);
            Assert.assertFalse("No message text (key=" + key + ", level=" + level + "): " + message, message.contains(key));
            Assert.assertFalse("Not all parameters substituted (key=" + key + ", level=" + level + "): " + message, message.matches(".*\\{[0-9]\\}.*"));
        }
    }
}
Also used : ValidationException(org.apache.openejb.config.ValidationException) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)1 ValidationException (org.apache.openejb.config.ValidationException)1