[jboss-cvs] JBossAS SVN: r89668 - in projects/metadata/trunk/src: main/java/org/jboss/metadata/validation/validator/ejb/jboss and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jun 2 09:41:10 EDT 2009
Author: jaikiran
Date: 2009-06-02 09:41:10 -0400 (Tue, 02 Jun 2009)
New Revision: 89668
Added:
projects/metadata/trunk/src/main/java/org/jboss/metadata/validation/validator/ejb/jboss/AtleastOneBusinessInterfaceValidator.java
projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/
projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/BeanWithBusinessInterface.java
projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/BeanWithEJB2xView.java
projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/BeanWithWebServiceEndpointInterface.java
projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/BeanWithoutAnyInterfaces.java
projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/EJB2xLocalView.java
projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/SimpleBusinessInterface.java
projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/SimpleLocalHome.java
projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/unit/
projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/unit/AtleastOneBusinessInterfaceValidatorTestCase.java
Modified:
projects/metadata/trunk/src/main/java/org/jboss/metadata/common/spi/ErrorCodes.java
Log:
JBMETA-201 A new validator to test that a bean has atleast one business interface
Modified: projects/metadata/trunk/src/main/java/org/jboss/metadata/common/spi/ErrorCodes.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/common/spi/ErrorCodes.java 2009-06-02 13:41:02 UTC (rev 89667)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/common/spi/ErrorCodes.java 2009-06-02 13:41:10 UTC (rev 89668)
@@ -38,4 +38,6 @@
String ERROR_CODE_JBMETA117 = "JBMETA-117";
String ERROR_CODE_JBMETA130 = "JBMETA-130";
+
+ String ERROR_CODE_JBMETA201 = "JBMETA-201";
}
Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/validation/validator/ejb/jboss/AtleastOneBusinessInterfaceValidator.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/validation/validator/ejb/jboss/AtleastOneBusinessInterfaceValidator.java (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/validation/validator/ejb/jboss/AtleastOneBusinessInterfaceValidator.java 2009-06-02 13:41:10 UTC (rev 89668)
@@ -0,0 +1,167 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.metadata.validation.validator.ejb.jboss;
+
+import javax.jws.WebService;
+
+import org.jboss.logging.Logger;
+import org.jboss.metadata.common.spi.ErrorCodes;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.ejb.spec.BusinessLocalsMetaData;
+import org.jboss.metadata.ejb.spec.BusinessRemotesMetaData;
+import org.jboss.metadata.validation.ValidationException;
+import org.jboss.metadata.validation.validator.ejb.JBossEjb3SessionBeanValidatorBase;
+
+/**
+ * AtleastOneBusinessInterfaceValidator
+ *
+ * Validates the presence of atleast one business interface
+ * for a bean. Throws an exception, if the bean does not
+ * implement, atleast one local or remote business interface
+ * or webservice interface
+ *
+ * @see https://jira.jboss.org/jira/browse/JBMETA-201
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class AtleastOneBusinessInterfaceValidator extends JBossEjb3SessionBeanValidatorBase
+{
+
+ /**
+ * Logger
+ */
+ private static Logger logger = Logger.getLogger(AtleastOneBusinessInterfaceValidator.class);
+
+ /**
+ * Classloader that will be used while validating metadata
+ */
+ private ClassLoader classLoader;
+
+ /**
+ * An approrpriate {@link ClassLoader} has to be passed during the
+ * construction of {@link AtleastOneBusinessInterfaceValidator}. This classloader
+ * will be used while validating the metadata passed to the {@link #validate(JBossSessionBeanMetaData)}
+ * method.
+ *
+ * @param cl The classloader that will be used for validating the metadata
+ */
+ public AtleastOneBusinessInterfaceValidator(ClassLoader cl)
+ {
+ this.classLoader = cl;
+ }
+
+ /**
+ * Checks for the presence of atleast one business interface for the bean.
+ * The validation includes a check for either a local or remote business interface.
+ * <br/>
+ * If neither is present, the validation then includes a check for either local home
+ * or a remote home (through which local/remote interfaces can be infered from the
+ * create method(s)).
+ * <br/>
+ * If there's none of these interfaces, then a {@link ValidationException}
+ * is thrown.
+ */
+ @Override
+ protected void validate(JBossSessionBeanMetaData smd) throws ValidationException
+ {
+ // let's first check if there are any local or remote business
+ // interfaces
+ BusinessLocalsMetaData businessLocals = smd.getBusinessLocals();
+ if (businessLocals != null && !businessLocals.isEmpty())
+ {
+ // there's atleast one business interface, so this is a valid bean.
+ // let's just return
+ return;
+ }
+
+ // let's check remote business interfaces
+ BusinessRemotesMetaData businessRemotes = smd.getBusinessRemotes();
+ if (businessRemotes != null && !businessRemotes.isEmpty())
+ {
+ // there's atleast one business interface, so this is a valid bean.
+ // let's just return
+ return;
+ }
+
+ // Now time to check whether there is a @LocalHome (or its xml equivalent) for the bean.
+ String localHome = smd.getLocalHome();
+ if (localHome != null)
+ {
+ // The presence of a local home is enough to prove that there's
+ // a create method in the local home interface which returns the
+ // local interface. No need to drill down into the local home interface
+ // to check for the presence of a create method. That's the job of a
+ // different validator.
+
+ return;
+
+ }
+
+ // Let's check if there's a @RemoteHome (or its xml equivalent) for the bean.
+ String remoteHome = smd.getHome();
+ if (remoteHome != null)
+ {
+ // The presence of a remote home is enough to prove that there's
+ // a create method in the remote home interface which returns the
+ // remote interface. No need to drill down into the remote home interface
+ // to check for the presence of a create method. That's the job of a
+ // different validator.
+
+ return;
+ }
+
+ // Check if the bean has a @WebService endpointInterface
+ // TODO: Instead of looking for annotation, is there a way
+ // to check the presence of a endpointInterface or a webservice through the use of metadata?
+ try
+ {
+ Class<?> beanClass = this.classLoader.loadClass(smd.getEjbClass());
+ WebService webService = beanClass.getAnnotation(WebService.class);
+ if (webService != null)
+ {
+ String endpointInterface = webService.endpointInterface();
+ // we have an endpoint interface, so its a valid bean.
+ if (endpointInterface != null)
+ {
+ if (logger.isTraceEnabled())
+ {
+ logger.trace("Bean class " + smd.getEjbClass() + " has an endpoint interface " + endpointInterface
+ + " - marking the bean as valid");
+ }
+ return;
+ }
+ }
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ throw new RuntimeException("Error loading bean class " + smd.getEjbClass());
+ }
+
+ // There was no local, remote, localhome or remotehome found
+ // let's throw an validation error
+ throw new ValidationException(ErrorCodes.ERROR_CODE_JBMETA201 + " - Bean class " + smd.getEjbClass()
+ + " for bean " + smd.getEjbName()
+ + " has no local, webservice endpointInterface or remote interfaces defined and does not implement at least one business interface");
+
+ }
+
+}
Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/BeanWithBusinessInterface.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/BeanWithBusinessInterface.java (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/BeanWithBusinessInterface.java 2009-06-02 13:41:10 UTC (rev 89668)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.metadata.jbmeta201;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
+
+/**
+ * BeanWithBusinessInterface
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateful
+ at Remote (SimpleBusinessInterface.class)
+public class BeanWithBusinessInterface implements SimpleBusinessInterface
+{
+
+}
Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/BeanWithEJB2xView.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/BeanWithEJB2xView.java (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/BeanWithEJB2xView.java 2009-06-02 13:41:10 UTC (rev 89668)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.metadata.jbmeta201;
+
+import javax.ejb.LocalHome;
+import javax.ejb.Stateless;
+
+/**
+ * BeanWithEJB2xView
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+ at LocalHome (SimpleLocalHome.class)
+public class BeanWithEJB2xView
+{
+
+}
Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/BeanWithWebServiceEndpointInterface.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/BeanWithWebServiceEndpointInterface.java (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/BeanWithWebServiceEndpointInterface.java 2009-06-02 13:41:10 UTC (rev 89668)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.metadata.jbmeta201;
+
+import javax.ejb.Stateless;
+import javax.jws.WebService;
+
+/**
+ * BeanWithWebServiceEndpointInterface
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+ at WebService(endpointInterface="org.jboss.test.metadata.jbmeta201.SimpleBusinessInterface")
+public class BeanWithWebServiceEndpointInterface
+{
+
+}
Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/BeanWithoutAnyInterfaces.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/BeanWithoutAnyInterfaces.java (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/BeanWithoutAnyInterfaces.java 2009-06-02 13:41:10 UTC (rev 89668)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.metadata.jbmeta201;
+
+import javax.ejb.Stateless;
+
+/**
+ * BeanWithoutAnyInterfaces
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+public class BeanWithoutAnyInterfaces
+{
+
+}
Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/EJB2xLocalView.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/EJB2xLocalView.java (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/EJB2xLocalView.java 2009-06-02 13:41:10 UTC (rev 89668)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.metadata.jbmeta201;
+
+import javax.ejb.EJBLocalObject;
+
+/**
+ * EJB2xLocalView
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface EJB2xLocalView extends EJBLocalObject
+{
+
+}
Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/SimpleBusinessInterface.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/SimpleBusinessInterface.java (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/SimpleBusinessInterface.java 2009-06-02 13:41:10 UTC (rev 89668)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.metadata.jbmeta201;
+
+/**
+ * SimpleBusinessInterface
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface SimpleBusinessInterface
+{
+
+}
Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/SimpleLocalHome.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/SimpleLocalHome.java (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/SimpleLocalHome.java 2009-06-02 13:41:10 UTC (rev 89668)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.metadata.jbmeta201;
+
+import javax.ejb.EJBLocalHome;
+
+/**
+ * SimpleLocalHome
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface SimpleLocalHome extends EJBLocalHome
+{
+
+ EJB2xLocalView create();
+
+}
Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/unit/AtleastOneBusinessInterfaceValidatorTestCase.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/unit/AtleastOneBusinessInterfaceValidatorTestCase.java (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta201/unit/AtleastOneBusinessInterfaceValidatorTestCase.java 2009-06-02 13:41:10 UTC (rev 89668)
@@ -0,0 +1,196 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.metadata.jbmeta201.unit;
+
+import java.lang.reflect.AnnotatedElement;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+import org.jboss.logging.Logger;
+import org.jboss.metadata.annotation.creator.ejb.jboss.JBoss50Creator;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.annotation.finder.DefaultAnnotationFinder;
+import org.jboss.metadata.common.spi.ErrorCodes;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.metadata.process.processor.ejb.jboss.SetDefaultLocalBusinessInterfaceProcessor;
+import org.jboss.metadata.validation.ValidationException;
+import org.jboss.metadata.validation.validator.ejb.jboss.AtleastOneBusinessInterfaceValidator;
+import org.jboss.test.metadata.jbmeta201.BeanWithBusinessInterface;
+import org.jboss.test.metadata.jbmeta201.BeanWithEJB2xView;
+import org.jboss.test.metadata.jbmeta201.BeanWithWebServiceEndpointInterface;
+import org.jboss.test.metadata.jbmeta201.BeanWithoutAnyInterfaces;
+
+/**
+ * AtleastOneBusinessInterfaceValidatorTestCase
+ *
+ * Tests {@link AtleastOneBusinessInterfaceValidator}
+ *
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class AtleastOneBusinessInterfaceValidatorTestCase extends TestCase
+{
+
+ /**
+ * Logger
+ */
+ private static Logger logger = Logger.getLogger(AtleastOneBusinessInterfaceValidatorTestCase.class);
+
+ /**
+ * Tests that a bean without any business interface fails validation.
+ *
+ * Note: Will not be a valid test for EJB 3.1 (no-interface feature) beans
+ * @throws Exception
+ */
+ public void testBeanWithNoBusinessInterfaces() throws Exception
+ {
+
+ Class<?> beanWithoutAnyInterfaces = BeanWithoutAnyInterfaces.class;
+
+ // Create an AnnotationFinder for the EJB impl class
+ AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+ Collection<Class<?>> classes = new ArrayList<Class<?>>();
+ classes.add(beanWithoutAnyInterfaces);
+
+ // Create
+ JBoss50Creator creator = new JBoss50Creator(finder);
+ JBossMetaData metadata = creator.create(classes);
+
+ // Run the implicit local processor
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ SetDefaultLocalBusinessInterfaceProcessor<JBossMetaData> processor = new SetDefaultLocalBusinessInterfaceProcessor<JBossMetaData>(
+ cl);
+
+ // process the metadata
+ metadata = processor.process(metadata);
+
+ AtleastOneBusinessInterfaceValidator validator = new AtleastOneBusinessInterfaceValidator(Thread.currentThread()
+ .getContextClassLoader());
+ try
+ {
+ // validate the beans
+ validator.validate(metadata);
+ // validation should have failed
+ fail("Validation of " + BeanWithoutAnyInterfaces.class.getName() + " passed, but was expected to fail");
+ }
+ catch (ValidationException ve)
+ {
+ // expected. let's now check for the error code
+ String errorMessage = ve.getMessage();
+ logger.info("Validation failed with message: " + errorMessage);
+
+ assertTrue("Validation error message does not contain the error code: " + ErrorCodes.ERROR_CODE_JBMETA201,
+ errorMessage.contains(ErrorCodes.ERROR_CODE_JBMETA201));
+
+ }
+
+ }
+
+ /**
+ * Tests that a bean with local/remote business interfaces or home/local home interfaces
+ * passes validation
+ *
+ * @throws Exception
+ */
+ public void testBeanWithBusinessInterfaces() throws Exception
+ {
+
+ // Bean with business interface
+ Class<?> beanWithBusinessInterface = BeanWithBusinessInterface.class;
+ Class<?> beanWithHomeInterface = BeanWithEJB2xView.class;
+
+ /*
+ * Create the metadata for all these beans
+ */
+
+ // Create an AnnotationFinder for the EJB impl class
+ AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+ Collection<Class<?>> classes = new ArrayList<Class<?>>();
+ classes.add(beanWithBusinessInterface);
+ classes.add(beanWithHomeInterface);
+
+ // Create
+ JBoss50Creator creator = new JBoss50Creator(finder);
+ JBossMetaData metadata = creator.create(classes);
+
+ // Run the implicit local processor
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ SetDefaultLocalBusinessInterfaceProcessor<JBossMetaData> processor = new SetDefaultLocalBusinessInterfaceProcessor<JBossMetaData>(
+ cl);
+
+ // process the metadata
+ metadata = processor.process(metadata);
+
+ AtleastOneBusinessInterfaceValidator validator = new AtleastOneBusinessInterfaceValidator(Thread.currentThread()
+ .getContextClassLoader());
+
+ // process the beans
+ validator.validate(metadata);
+ logger.info("Beans " + classes + " successfully validated");
+
+ }
+
+ /**
+ * Tests that a bean with a @WebService endpointInterface exposed passes validation
+ *
+ * @throws Exception
+ */
+ public void testBeanWithWebServiceEndpointExposed() throws Exception
+ {
+
+ // Bean with business interface
+ Class<?> beanWithWebServiceEndpointExposed = BeanWithWebServiceEndpointInterface.class;
+
+ /*
+ * Create the metadata for all these beans
+ */
+
+ // Create an AnnotationFinder for the EJB impl class
+ AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+ Collection<Class<?>> classes = new ArrayList<Class<?>>();
+ classes.add(beanWithWebServiceEndpointExposed);
+
+ // Create
+ JBoss50Creator creator = new JBoss50Creator(finder);
+ JBossMetaData metadata = creator.create(classes);
+
+ // Run the implicit local processor
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ SetDefaultLocalBusinessInterfaceProcessor<JBossMetaData> processor = new SetDefaultLocalBusinessInterfaceProcessor<JBossMetaData>(
+ cl);
+
+ // process the metadata
+ metadata = processor.process(metadata);
+
+ AtleastOneBusinessInterfaceValidator validator = new AtleastOneBusinessInterfaceValidator(Thread.currentThread()
+ .getContextClassLoader());
+
+ // process the beans
+ validator.validate(metadata);
+
+ logger.info("Successfully validated the beans " + classes);
+
+ }
+}
More information about the jboss-cvs-commits
mailing list