Search in sources :

Example 1 with ValidationFailedException

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

the class DependsOnTest method testCircuit.

public void testCircuit() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // containers
    assembler.createContainer(config.configureService(SingletonSessionContainerInfo.class));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new SingletonBean(One.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Two.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Three.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Four.class)).setDependsOn("One");
    try {
        config.configureApplication(ejbJar);
        fail("Validation should have found a circular reference");
    } catch (final ValidationFailedException e) {
        final ValidationFailure[] failures = e.getFailures();
        assertEquals(1, failures.length);
        assertEquals("dependsOn.circuit", failures[0].getMessageKey());
    }
}
Also used : InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) SingletonBean(org.apache.openejb.jee.SingletonBean) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ValidationFailedException(org.apache.openejb.config.ValidationFailedException) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SingletonSessionContainerInfo(org.apache.openejb.assembler.classic.SingletonSessionContainerInfo) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 2 with ValidationFailedException

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

the class DependsOnTest method testNoSuchEjb.

public void testNoSuchEjb() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // containers
    assembler.createContainer(config.configureService(SingletonSessionContainerInfo.class));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new SingletonBean(One.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Two.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Three.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Four.class)).setDependsOn("Five");
    try {
        config.configureApplication(ejbJar);
        fail("Validation should have found a circular reference");
    } catch (final ValidationFailedException e) {
        final ValidationFailure[] failures = e.getFailures();
        assertEquals(1, failures.length);
        assertEquals("dependsOn.noSuchEjb", failures[0].getMessageKey());
    }
}
Also used : InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) SingletonBean(org.apache.openejb.jee.SingletonBean) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ValidationFailedException(org.apache.openejb.config.ValidationFailedException) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SingletonSessionContainerInfo(org.apache.openejb.assembler.classic.SingletonSessionContainerInfo) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 3 with ValidationFailedException

use of org.apache.openejb.config.ValidationFailedException 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

ValidationFailedException (org.apache.openejb.config.ValidationFailedException)3 EjbJar (org.apache.openejb.jee.EjbJar)3 Assembler (org.apache.openejb.assembler.classic.Assembler)2 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)2 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)2 SingletonSessionContainerInfo (org.apache.openejb.assembler.classic.SingletonSessionContainerInfo)2 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)2 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)2 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)2 SingletonBean (org.apache.openejb.jee.SingletonBean)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 ValidationContext (org.apache.openejb.config.ValidationContext)1 ValidationFailure (org.apache.openejb.config.ValidationFailure)1