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());
}
}
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());
}
}
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();
}
Aggregations