Search in sources :

Example 1 with ValidationContext

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

the class LightWeightMappingValidator method validate.

public ValidationContext validate() {
    if (context == null) {
        context = new ValidationContext(moduleType, definition.getQName().toString());
        walkTree();
    }
    return context;
}
Also used : ValidationContext(org.apache.openejb.config.ValidationContext)

Example 2 with ValidationContext

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

the class InvokeMethod method evaluate.

@Override
public void evaluate() throws Throwable {
    final Map<Integer, List<String>> expectedKeys = validateKeys();
    setUp();
    final Object obj = testMethod.invokeExplosively(target);
    final String outputDescriptors = SystemInstance.get().getProperty(OutputGeneratedDescriptors.OUTPUT_DESCRIPTORS, "false");
    try {
        SystemInstance.get().setProperty(OutputGeneratedDescriptors.OUTPUT_DESCRIPTORS, "false");
        ValidationContext vc = null;
        if (obj instanceof EjbJar) {
            final EjbJar ejbJar = (EjbJar) obj;
            final EjbModule ejbModule = new EjbModule(ejbJar);
            vc = ejbModule.getValidation();
            assembler.createApplication(config.configureApplication(ejbModule));
        } else if (obj instanceof EjbModule) {
            final EjbModule ejbModule = (EjbModule) obj;
            vc = ejbModule.getValidation();
            assembler.createApplication(config.configureApplication(ejbModule));
        } else if (obj instanceof AppModule) {
            final AppModule appModule = (AppModule) obj;
            vc = appModule.getValidation();
            assembler.createApplication(config.configureApplication(appModule));
        }
        if (!isEmpty(expectedKeys)) {
            if (vc != null && expectedKeys.get(KeyType.FAILURE).isEmpty() && expectedKeys.get(KeyType.ERROR).isEmpty()) {
                if (!expectedKeys.get(KeyType.WARNING).isEmpty()) {
                    assertWarnings(expectedKeys.get(KeyType.WARNING), new ValidationFailedException("", vc));
                }
            } else {
                fail("A ValidationFailedException should have been thrown");
            }
        }
    } catch (final ValidationFailedException vfe) {
        if (!isEmpty(expectedKeys)) {
            if (!expectedKeys.get(KeyType.FAILURE).isEmpty()) {
                assertFailures(expectedKeys.get(KeyType.FAILURE), vfe);
            }
            if (!expectedKeys.get(KeyType.WARNING).isEmpty()) {
                assertWarnings(expectedKeys.get(KeyType.WARNING), vfe);
            }
            if (!expectedKeys.get(KeyType.ERROR).isEmpty()) {
                assertErrors(expectedKeys.get(KeyType.ERROR), vfe);
            }
        } else {
            for (final ValidationFailure failure : vfe.getFailures()) {
                System.out.println("failure = " + failure.getMessageKey());
            }
            fail("There should be no validation failures");
        }
    } finally {
        SystemInstance.get().setProperty(OutputGeneratedDescriptors.OUTPUT_DESCRIPTORS, outputDescriptors);
    }
    tearDown();
}
Also used : AppModule(org.apache.openejb.config.AppModule) ValidationFailedException(org.apache.openejb.config.ValidationFailedException) EjbModule(org.apache.openejb.config.EjbModule) ArrayList(java.util.ArrayList) List(java.util.List) ValidationContext(org.apache.openejb.config.ValidationContext) EjbJar(org.apache.openejb.jee.EjbJar) ValidationFailure(org.apache.openejb.config.ValidationFailure)

Aggregations

ValidationContext (org.apache.openejb.config.ValidationContext)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AppModule (org.apache.openejb.config.AppModule)1 EjbModule (org.apache.openejb.config.EjbModule)1 ValidationFailedException (org.apache.openejb.config.ValidationFailedException)1 ValidationFailure (org.apache.openejb.config.ValidationFailure)1 EjbJar (org.apache.openejb.jee.EjbJar)1