You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/12/26 09:35:58 UTC
svn commit: r1425854 - in /openejb/trunk/openejb/container/openejb-core/src:
main/java/org/apache/openejb/config/
main/java/org/apache/openejb/config/rules/
main/resources/org/apache/openejb/config/rules/
test/java/org/apache/openejb/config/rules/
Author: rmannibucau
Date: Wed Dec 26 08:35:57 2012
New Revision: 1425854
URL: http://svn.apache.org/viewvc?rev=1425854&view=rev
Log:
TOMEE-678 Check that if @Inject points are used, CDI is enabled
Added:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCdiEnabled.java
- copied, changed from r1425853, openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckClasses.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckCdiEnabledTest.java
- copied, changed from r1425853, openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckMissingClassTest.java
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/EjbModule.java
openejb/trunk/openejb/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/InvokeMethod.java
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java?rev=1425854&r1=1425853&r2=1425854&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java Wed Dec 26 08:35:57 2012
@@ -29,6 +29,7 @@ import org.apache.openejb.cli.SystemExit
import org.apache.openejb.config.rules.CheckAssemblyBindings;
import org.apache.openejb.config.rules.CheckAsynchronous;
import org.apache.openejb.config.rules.CheckCallbacks;
+import org.apache.openejb.config.rules.CheckCdiEnabled;
import org.apache.openejb.config.rules.CheckClasses;
import org.apache.openejb.config.rules.CheckDependsOn;
import org.apache.openejb.config.rules.CheckDescriptorLocation;
@@ -128,19 +129,16 @@ public class AppValidator {
new CheckDescriptorLocation(),
new CheckAnnotations(),
new CheckIncorrectPropertyNames(),
- new CheckRestMethodArePublic()
+ new CheckRestMethodArePublic(),
+ new CheckCdiEnabled()
};
if (additionalValidators == null || additionalValidators.length == 0) {
return defaultRules;
}
final ValidationRule[] rules = new ValidationRule[additionalValidators.length + defaultRules.length];
- for (int i = 0; i < additionalValidators.length; i++) {
- rules[i] = additionalValidators[i];
- }
- for (int i = 0; i < defaultRules.length; i++) {
- rules[i + additionalValidators.length] = defaultRules[i];
- }
+ System.arraycopy(additionalValidators, 0, rules, 0, additionalValidators.length);
+ System.arraycopy(defaultRules, 0, rules, additionalValidators.length, defaultRules.length);
return rules;
}
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/EjbModule.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/EjbModule.java?rev=1425854&r1=1425853&r2=1425854&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/EjbModule.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/EjbModule.java Wed Dec 26 08:35:57 2012
@@ -97,6 +97,11 @@ public class EjbModule extends Module im
this.finder.set(finder);
}
+ public EjbModule finder(IAnnotationFinder finder) {
+ this.finder.set(finder);
+ return this;
+ }
+
public ClientModule getClientModule() {
return clientModule;
}
Copied: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCdiEnabled.java (from r1425853, openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckClasses.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCdiEnabled.java?p2=openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCdiEnabled.java&p1=openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckClasses.java&r1=1425853&r2=1425854&rev=1425854&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckClasses.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckCdiEnabled.java Wed Dec 26 08:35:57 2012
@@ -16,356 +16,16 @@
*/
package org.apache.openejb.config.rules;
-import org.apache.openejb.OpenEJBException;
-import org.apache.openejb.OpenEJBRuntimeException;
import org.apache.openejb.config.EjbModule;
-import org.apache.openejb.jee.EnterpriseBean;
-import org.apache.openejb.jee.EntityBean;
-import org.apache.openejb.jee.Interceptor;
-import org.apache.openejb.jee.RemoteBean;
-import org.apache.openejb.jee.SessionBean;
-import org.apache.openejb.util.SafeToolkit;
-import org.apache.openejb.util.Strings;
-import org.apache.openejb.util.proxy.DynamicProxyImplFactory;
-import org.apache.xbean.finder.ClassFinder;
-import javax.ejb.EJBHome;
-import javax.ejb.EJBLocalHome;
-import javax.ejb.EJBLocalObject;
-import javax.ejb.EJBObject;
-import javax.ejb.Local;
-import javax.ejb.Remote;
-import javax.jws.WebService;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-import static java.lang.reflect.Modifier.isAbstract;
-
-/**
- * @version $Rev$ $Date$
- */
-public class CheckClasses extends ValidationBase {
-
- private static final List<Class<? extends Annotation>> beanOnlyAnnotations = new ArrayList<Class<? extends Annotation>>();
-
- static {
- beanOnlyAnnotations.add(javax.annotation.PostConstruct.class);
- beanOnlyAnnotations.add(javax.annotation.PreDestroy.class);
- beanOnlyAnnotations.add(javax.annotation.Resource.class);
- beanOnlyAnnotations.add(javax.annotation.Resources.class);
- beanOnlyAnnotations.add(javax.annotation.security.DeclareRoles.class);
- beanOnlyAnnotations.add(javax.annotation.security.DenyAll.class);
- beanOnlyAnnotations.add(javax.annotation.security.PermitAll.class);
- beanOnlyAnnotations.add(javax.annotation.security.RolesAllowed.class);
- beanOnlyAnnotations.add(javax.annotation.security.RunAs.class);
-
- beanOnlyAnnotations.add(javax.ejb.EJB.class);
- beanOnlyAnnotations.add(javax.ejb.EJBs.class);
- beanOnlyAnnotations.add(javax.ejb.Init.class);
- beanOnlyAnnotations.add(javax.ejb.PostActivate.class);
- beanOnlyAnnotations.add(javax.ejb.PrePassivate.class);
- beanOnlyAnnotations.add(javax.ejb.Remove.class);
- beanOnlyAnnotations.add(javax.ejb.Timeout.class);
- beanOnlyAnnotations.add(javax.ejb.TransactionAttribute.class);
- beanOnlyAnnotations.add(javax.ejb.TransactionManagement.class);
- }
+import javax.inject.Inject;
+public class CheckCdiEnabled extends ValidationBase {
public void validate(EjbModule ejbModule) {
- for (EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
- try {
- Class<?> beanClass = check_hasEjbClass(bean);
-
- // All the subsequent checks require the bean class
- if (beanClass == null) continue;
-
- if (!(bean instanceof RemoteBean)) continue;
-
- if (bean instanceof SessionBean && ((SessionBean) bean).getProxy() != null) {
- continue;
- }
-
- RemoteBean b = (RemoteBean) bean;
-
- check_isEjbClass(b);
- check_hasDependentClasses(b, b.getEjbClass(), "ejb-class");
- check_hasInterface(b);
-
- if (b.getRemote() != null){
- checkInterface(b, beanClass, "remote", b.getRemote());
- }
-
- if (b.getHome() != null) {
- checkInterface(b, beanClass, "home", b.getHome());
- }
-
- if (b.getLocal() != null) {
- checkInterface(b, beanClass, "local", b.getLocal());
- }
-
- if (b.getLocalHome() != null) {
- checkInterface(b, beanClass, "local-home", b.getLocalHome());
- }
-
- if (b instanceof SessionBean) {
- SessionBean sessionBean = (SessionBean) b;
-
- for (String interfce : sessionBean.getBusinessLocal()) {
- checkInterface(b, beanClass, "business-local", interfce);
- }
-
- for (String interfce : sessionBean.getBusinessRemote()) {
- checkInterface(b, beanClass, "business-remote", interfce);
- }
- }
- } catch (RuntimeException e) {
- throw new OpenEJBRuntimeException(bean.getEjbName(), e);
- }
- }
-
- for (Interceptor interceptor : ejbModule.getEjbJar().getInterceptors()) {
- check_hasInterceptorClass(interceptor);
- }
- }
-
- private void checkInterface(RemoteBean b, Class<?> beanClass, String tag, String className) {
- Class<?> interfce = lookForClass(className, tag, b.getEjbName());
-
- if (interfce == null) return;
-
- check_hasDependentClasses(b, className, tag);
-
- tag = Strings.lcfirst(Strings.camelCase(tag));
-
- if (isValidInterface(b, interfce, beanClass, tag));
-
- ClassFinder finder = new ClassFinder(interfce);
-
- for (Class<? extends Annotation> annotation : beanOnlyAnnotations) {
-
- if (interfce.isAnnotationPresent(annotation)){
- warn(b, "interface.beanOnlyAnnotation", annotation.getSimpleName(), interfce.getName(), b.getEjbClass());
- }
-
- for (Method method : finder.findAnnotatedMethods(annotation)) {
- warn(b, "interfaceMethod.beanOnlyAnnotation", annotation.getSimpleName(), interfce.getName(), method.getName(), b.getEjbClass());
- }
- }
-
- }
-
- private void check_hasInterface(RemoteBean b) {
- if (b.getRemote() != null) return;
- if (b.getLocal() != null) return;
-
- Class<?> beanClass = null;
- try {
- beanClass = loadClass(b.getEjbClass());
- } catch (OpenEJBException e) {
- }
-
- if (b instanceof EntityBean){
- fail(b, "noInterfaceDeclared.entity", beanClass.getSimpleName());
- return;
- }
-
- if (b.getBusinessLocal().size() > 0) return;
- if (b.getBusinessRemote().size() > 0) return;
-
- if (((SessionBean) b).getServiceEndpoint() != null) return;
-
- if (beanClass.isAnnotationPresent(WebService.class)) return;
-
- //fail(b, "noInterfaceDeclared.session");
- }
-
- private void check_hasDependentClasses(RemoteBean b, String className, String type) {
- try {
- ClassLoader cl = module.getClassLoader();
- Class<?> clazz = cl.loadClass(className);
- for (Object item : clazz.getFields()) { item.toString(); }
- for (Object item : clazz.getMethods()) { item.toString(); }
- for (Object item : clazz.getConstructors()) { item.toString(); }
- for (Object item : clazz.getAnnotations()) { item.toString(); }
- // checking for any declared enum constants
- for(Class klass: clazz.getClasses()){
- if(klass.isEnum()){
- klass.toString();
- }
- }
- } catch (ClassNotFoundException e) {
- /*
- # 0 - Referring Class name
- # 1 - Dependent Class name
- # 2 - Element (home, ejb-class, remote)
- # 3 - Bean name
- */
- String missingClass = e.getMessage();
- fail(b, "missing.dependent.class", className, missingClass, type, b.getEjbName());
- } catch (NoClassDefFoundError e) {
- /*
- # 0 - Referring Class name
- # 1 - Dependent Class name
- # 2 - Element (home, ejb-class, remote)
- # 3 - Bean name
- */
- String missingClass = e.getMessage();
- fail(b, "missing.dependent.class", className, missingClass, type, b.getEjbName());
- }
- }
-
- public Class<?> check_hasEjbClass(EnterpriseBean b) {
-
- String ejbName = b.getEjbName();
-
- Class<?> beanClass = lookForClass(b.getEjbClass(), "ejb-class", ejbName);
- boolean isDynamicProxyImpl = DynamicProxyImplFactory.isKnownDynamicallyImplemented(beanClass);
-
- if (beanClass == null) return null;
-
- if (beanClass.isInterface() && !isDynamicProxyImpl){
- fail(ejbName, "interfaceDeclaredAsBean", beanClass.getName());
- }
-
- if (isCmp(b)) return beanClass;
-
- if (isAbstract(beanClass.getModifiers()) && !isDynamicProxyImpl){
- fail(ejbName, "abstractDeclaredAsBean", beanClass.getName());
- }
-
- return beanClass;
- }
-
- private void check_hasInterceptorClass(Interceptor i) {
-
- lookForClass(i.getInterceptorClass(), "interceptor-class", "Interceptor");
-
- }
-
- private void check_isEjbClass(RemoteBean b) {
-
- if (b instanceof SessionBean) {
-
- // DMB: Beans in ejb 3 are not required to implement javax.ejb.SessionBean
- // but it would still be nice to think of some sort of check to do here.
- // compareTypes(b, b.getEjbClass(), javax.ejb.SessionBean.class);
-
- } else if (b instanceof EntityBean) {
-
- compareTypes(b, b.getEjbClass(), javax.ejb.EntityBean.class);
-
- }
-
- }
-
- private Class<?> lookForClass(String clazz, String type, String ejbName) {
- try {
- return loadClass(clazz);
- } catch (OpenEJBException e) {
- /*
- # 0 - Class name
- # 1 - Element (home, ejb-class, remote)
- # 2 - Bean name
- */
-
- fail(ejbName, "missing.class", clazz, type, ejbName);
-
- } catch (NoClassDefFoundError e) {
- /*
- # 0 - Class name
- # 1 - Element (home, ejb-class, remote)
- # 2 - Bean name
- # 3 - Misslocated Class name
- */
- fail(ejbName, "misslocated.class", clazz, type, ejbName, e.getMessage());
-
- throw e;
- }
-
- return null;
- }
-
- private boolean isValidInterface(RemoteBean b, Class clazz, Class beanClass, String tag) {
-
- if (clazz.equals(beanClass)) {
-
- fail(b, "xml." + tag + ".beanClass", clazz.getName());
-
- } else if (!clazz.isInterface()) {
-
- fail(b, "xml." + tag + ".notInterface", clazz.getName());
-
- } else if (EJBHome.class.isAssignableFrom(clazz)) {
-
- if (tag.equals("home")) return true;
-
- fail(b, "xml." + tag + ".ejbHome", clazz.getName());
-
- } else if (EJBLocalHome.class.isAssignableFrom(clazz)) {
-
- if (tag.equals("localHome")) return true;
-
- fail(b, "xml." + tag + ".ejbLocalHome", clazz.getName());
-
- } else if (EJBObject.class.isAssignableFrom(clazz)) {
-
- if (tag.equals("remote")) return true;
-
- fail(b, "xml." + tag + ".ejbObject", clazz.getName());
-
- } else if (EJBLocalObject.class.isAssignableFrom(clazz)) {
-
- if (tag.equals("local")) return true;
-
- fail(b, "xml." + tag + ".ejbLocalObject", clazz.getName());
-
- } else {
- if (tag.equals("businessLocal") || tag.equals("businessRemote")) {
-
- return true;
-
- } else if (clazz.isAnnotationPresent(Local.class)) {
-
- fail(b, "xml." + tag + ".businessLocal", clazz.getName());
-
- } else if (clazz.isAnnotationPresent(Remote.class)) {
-
- fail(b, "xml." + tag + ".businessRemote", clazz.getName());
-
- } else {
-
- fail(b, "xml." + tag + ".unknown", clazz.getName());
-
- }
-
- }
-
- // must be tagged as <home>, <local-home>, <remote>, or <local>
-
- return false;
- }
-
- private void compareTypes(RemoteBean b, String clazz1, Class<?> class2) {
- Class<?> class1 = null;
- try {
- class1 = loadClass(clazz1);
- } catch (OpenEJBException e) {
- return;
- }
-
- if (class1 != null && !class2.isAssignableFrom(class1)) {
- fail(b, "wrong.class.type", clazz1, class2.getName());
- }
- }
-
- protected Class<?> loadClass(String clazz) throws OpenEJBException {
- ClassLoader cl = module.getClassLoader();
- try {
- return Class.forName(clazz, false, cl);
- } catch (ClassNotFoundException cnfe) {
- throw new OpenEJBException(SafeToolkit.messages.format("cl0007", clazz, module.getJarLocation()), cnfe);
+ if (ejbModule.getBeans() == null
+ && (!ejbModule.getFinder().findAnnotatedMethods(Inject.class).isEmpty()
+ || !ejbModule.getFinder().findAnnotatedFields(Inject.class).isEmpty())) {
+ warn(ejbModule.getModuleId(), "cdi.notEnabled", ejbModule.getModuleId());
}
}
}
-
Modified: openejb/trunk/openejb/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties?rev=1425854&r1=1425853&r2=1425854&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/resources/org/apache/openejb/config/rules/Messages.properties Wed Dec 26 08:35:57 2012
@@ -915,3 +915,7 @@ public interface {0} extends {2}'{}'
1.too.many.interfaces = Ejb [{0}] implements too many interfaces: {1}
2.too.many.interfaces = Ejb [{0}] implements too many interfaces: {1}. Use @Local(<interface>) or keep a single interface.
3.too.many.interfaces = Ejb [{0}] implements too many interfaces: {1}. Use @Local(<interface>) or keep a single interface.
+
+1.cdi.notEnabled = The application [{0}] uses @Inject but CDI is not enabled.
+2.cdi.notEnabled = The application [{0}] uses @Inject but CDI is not enabled. Maybe you'd need to add a beans.xml file.
+3.cdi.notEnabled = The application [{0}] uses @Inject but CDI is not enabled. Maybe you'd need to add a beans.xml file. It should be in WEB-INF for a webapp or in META-INF for a jar.
\ No newline at end of file
Copied: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckCdiEnabledTest.java (from r1425853, openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckMissingClassTest.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckCdiEnabledTest.java?p2=openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckCdiEnabledTest.java&p1=openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckMissingClassTest.java&r1=1425853&r2=1425854&rev=1425854&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckMissingClassTest.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckCdiEnabledTest.java Wed Dec 26 08:35:57 2012
@@ -16,140 +16,23 @@
*/
package org.apache.openejb.config.rules;
-import java.rmi.RemoteException;
-
-import javax.ejb.EJBException;
-import javax.ejb.EntityContext;
-import javax.ejb.RemoveException;
-import javax.ejb.SessionBean;
-import javax.ejb.SessionContext;
-
import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.config.EjbModule;
import org.apache.openejb.jee.EjbJar;
-import org.apache.openejb.jee.EntityBean;
-import org.apache.openejb.jee.PersistenceType;
-import org.apache.openejb.jee.StatefulBean;
-import org.apache.openejb.jee.StatelessBean;
+import org.apache.xbean.finder.AnnotationFinder;
+import org.apache.xbean.finder.archive.ClassesArchive;
import org.junit.runner.RunWith;
-@RunWith(ValidationRunner.class)
-public class CheckMissingClassTest {
- @Keys(@Key(value = "missing.class", count = 16))
- public EjbJar wrongClassType() throws OpenEJBException {
- System.setProperty("openejb.validation.output.level", "VERBOSE");
- EjbJar ejbJar = new EjbJar();
- StatelessBean stateless = new StatelessBean(FooStateless.class);
- stateless.setHomeAndRemote("WrongHome", "WrongRemote");
- stateless.setLocal("WrongLocal");
- stateless.setLocalHome("WrongLocalHome");
- ejbJar.addEnterpriseBean(stateless);
- StatefulBean stateful = new StatefulBean(FooStateful.class);
- stateful.setHomeAndRemote("WrongHome", "WrongRemote");
- stateful.setLocal("WrongLocal");
- stateful.setLocalHome("WrongLocalHome");
- ejbJar.addEnterpriseBean(stateful);
- EntityBean bmpEntityBean = new EntityBean(FooEntityBMP.class, PersistenceType.BEAN);
- bmpEntityBean.setHome("WrongHome");
- bmpEntityBean.setLocalHome("WrongLocalHome");
- bmpEntityBean.setRemote("WrongRemote");
- bmpEntityBean.setLocal("WrongLocal");
- ejbJar.addEnterpriseBean(bmpEntityBean);
- EntityBean cmpEntityBean = new EntityBean(FooEntityCMP.class, PersistenceType.CONTAINER);
- cmpEntityBean.setHome("WrongHome");
- cmpEntityBean.setLocalHome("WrongLocalHome");
- cmpEntityBean.setRemote("WrongRemote");
- cmpEntityBean.setLocal("WrongLocal");
- ejbJar.addEnterpriseBean(cmpEntityBean);
- return ejbJar;
- }
-
- private static class FooStateless implements SessionBean {
- public void ejbCreate() {}
-
- @Override
- public void ejbActivate() throws EJBException, RemoteException {}
-
- @Override
- public void ejbPassivate() throws EJBException, RemoteException {}
-
- @Override
- public void ejbRemove() throws EJBException, RemoteException {}
-
- @Override
- public void setSessionContext(SessionContext arg0) throws EJBException, RemoteException {}
- }
-
- private static class FooStateful implements SessionBean {
- public void ejbCreate() {}
-
- @Override
- public void ejbActivate() throws EJBException, RemoteException {}
-
- @Override
- public void ejbPassivate() throws EJBException, RemoteException {}
-
- @Override
- public void ejbRemove() throws EJBException, RemoteException {}
-
- @Override
- public void setSessionContext(SessionContext arg0) throws EJBException, RemoteException {}
- }
-
- private static class FooEntityBMP implements javax.ejb.EntityBean {
- public String ejbCreate(String id) {
- return null;
- }
+import javax.inject.Inject;
- public void ejbPostCreate(String id) {};
-
- @Override
- public void ejbActivate() throws EJBException, RemoteException {}
-
- @Override
- public void ejbLoad() throws EJBException, RemoteException {}
-
- @Override
- public void ejbPassivate() throws EJBException, RemoteException {}
-
- @Override
- public void ejbRemove() throws RemoveException, EJBException, RemoteException {}
-
- @Override
- public void ejbStore() throws EJBException, RemoteException {}
-
- @Override
- public void setEntityContext(EntityContext arg0) throws EJBException, RemoteException {}
-
- @Override
- public void unsetEntityContext() throws EJBException, RemoteException {}
+@RunWith(ValidationRunner.class)
+public class CheckCdiEnabledTest {
+ @Keys(@Key(value = "cdi.notEnabled", type = KeyType.WARNING))
+ public EjbModule cdiShouldBeOn() throws OpenEJBException {
+ return new EjbModule(new EjbJar())
+ .finder(new AnnotationFinder(new ClassesArchive(Bean1.class, Bean2.class)));
}
- private static class FooEntityCMP implements javax.ejb.EntityBean {
- public String ejbCreate(String id) {
- return null;
- }
-
- public void ejbPostCreate(String id) {};
-
- @Override
- public void ejbActivate() throws EJBException, RemoteException {}
-
- @Override
- public void ejbLoad() throws EJBException, RemoteException {}
-
- @Override
- public void ejbPassivate() throws EJBException, RemoteException {}
-
- @Override
- public void ejbRemove() throws RemoveException, EJBException, RemoteException {}
-
- @Override
- public void ejbStore() throws EJBException, RemoteException {}
-
- @Override
- public void setEntityContext(EntityContext arg0) throws EJBException, RemoteException {}
-
- @Override
- public void unsetEntityContext() throws EJBException, RemoteException {}
- }
+ public static class Bean1 {}
+ public static class Bean2 { @Inject private Bean1 bean1; }
}
Modified: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/InvokeMethod.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/InvokeMethod.java?rev=1425854&r1=1425853&r2=1425854&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/InvokeMethod.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/InvokeMethod.java Wed Dec 26 08:35:57 2012
@@ -30,12 +30,14 @@ import java.util.Set;
import java.util.Map.Entry;
import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.assembler.classic.EjbJarInfo;
import org.apache.openejb.assembler.classic.SecurityServiceInfo;
import org.apache.openejb.assembler.classic.TransactionServiceInfo;
import org.apache.openejb.config.AppModule;
import org.apache.openejb.config.ConfigurationFactory;
import org.apache.openejb.config.EjbModule;
import org.apache.openejb.config.OutputGeneratedDescriptors;
+import org.apache.openejb.config.ValidationContext;
import org.apache.openejb.config.ValidationFailedException;
import org.apache.openejb.config.ValidationFailure;
import org.apache.openejb.jee.EjbJar;
@@ -76,18 +78,29 @@ public class InvokeMethod extends Statem
try {
SystemInstance.get().setProperty(OutputGeneratedDescriptors.OUTPUT_DESCRIPTORS, "false");
+ ValidationContext vc = null;
if (obj instanceof EjbJar) {
- EjbJar ejbJar = (EjbJar) obj;
- assembler.createApplication(config.configureApplication(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) {
EjbModule ejbModule = (EjbModule) obj;
+ vc = ejbModule.getValidation();
assembler.createApplication(config.configureApplication(ejbModule));
} else if (obj instanceof AppModule) {
AppModule appModule = (AppModule) obj;
+ vc = appModule.getValidation();
assembler.createApplication(config.configureApplication(appModule));
}
if (!isEmpty(expectedKeys)) {
- fail("A ValidationFailedException should have been thrown");
+ 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 (ValidationFailedException vfe) {
if (!isEmpty(expectedKeys)) {