[jboss-cvs] JBossAS SVN: r79601 - in projects/metadata/trunk/src: test/java/org/jboss/test/metadata and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Oct 16 14:45:22 EDT 2008


Author: ALRubinger
Date: 2008-10-16 14:45:22 -0400 (Thu, 16 Oct 2008)
New Revision: 79601

Added:
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta130/
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta130/TestBean.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta130/TestRemoteBusiness.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta130/unit/
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta130/unit/CompleteEjb2xViewTestCase.java
Modified:
   projects/metadata/trunk/src/main/java/org/jboss/metadata/common/spi/ErrorCodes.java
Log:
[JBMETA-130] Unit Tests to validate a Complete EJB2.x View

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	2008-10-16 18:43:58 UTC (rev 79600)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/common/spi/ErrorCodes.java	2008-10-16 18:45:22 UTC (rev 79601)
@@ -36,4 +36,6 @@
     */
 
    String ERROR_CODE_JBMETA117 = "JBMETA-117";
+   
+   String ERROR_CODE_JBMETA130 = "JBMETA-130";
 }

Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta130/TestBean.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta130/TestBean.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta130/TestBean.java	2008-10-16 18:45:22 UTC (rev 79601)
@@ -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.jbmeta130;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+/**
+ * TestBean
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at Remote(TestRemoteBusiness.class)
+public class TestBean implements TestRemoteBusiness
+{
+
+}

Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta130/TestRemoteBusiness.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta130/TestRemoteBusiness.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta130/TestRemoteBusiness.java	2008-10-16 18:45:22 UTC (rev 79601)
@@ -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.jbmeta130;
+
+/**
+ * TestRemoteBusiness
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface TestRemoteBusiness
+{
+
+}

Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta130/unit/CompleteEjb2xViewTestCase.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta130/unit/CompleteEjb2xViewTestCase.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta130/unit/CompleteEjb2xViewTestCase.java	2008-10-16 18:45:22 UTC (rev 79601)
@@ -0,0 +1,204 @@
+/*
+ * 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.jbmeta130.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.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.validation.ValidationException;
+import org.jboss.metadata.validation.validator.Validator;
+import org.jboss.metadata.validation.validator.ejb.jboss.CompleteEjb2xViewValidator;
+import org.jboss.test.metadata.jbmeta130.TestBean;
+
+/**
+ * CompleteEjb2xViewTestCase
+ * 
+ * Tests that Session EJBs have a complete EJB2.x View as defined by 
+ * the ejb-jar schema:
+ * 
+ * "Either both the local-home and the local elements or 
+ * both the home and the remote elements must be specified 
+ * for the session bean." 
+ * 
+ * JBMETA-130
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class CompleteEjb2xViewTestCase extends TestCase
+{
+   // -------------------------------------------------------------------||
+   // Class Members -----------------------------------------------------||
+   // -------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(CompleteEjb2xViewTestCase.class);
+
+   // -------------------------------------------------------------------||
+   // Instance Members --------------------------------------------------||
+   // -------------------------------------------------------------------||
+
+   private JBossSessionBeanMetaData smd;
+
+   // -------------------------------------------------------------------||
+   // Tests -------------------------------------------------------------||
+   // -------------------------------------------------------------------||
+
+   /**
+    * Tests that an EJB declaring remote component interface also has a home
+    */
+   public void testRemoteAlsoHasRemoteHome() throws Throwable
+   {
+      // Get the metadata
+      JBossSessionBeanMetaData smd = this.smd;
+
+      // Add a remote component interface only
+      smd.setRemote("RemoteWithNoHome");
+
+      // Run through the validator
+      this.runValidationAndEnsureFails(smd);
+   }
+
+   /**
+    * Tests that an EJB declaring a home interface also has a remote component interface
+    */
+   public void testHomeAlsoHasRemote() throws Throwable
+   {
+      // Get the metadata
+      JBossSessionBeanMetaData smd = this.smd;
+
+      // Add a home interface only
+      smd.setHome("HomeWithNoRemote");
+
+      // Run through the validator
+      this.runValidationAndEnsureFails(smd);
+   }
+
+   /**
+    * Tests that an EJB declaring local component interface also has a localHome
+    */
+   public void testLocalAlsoHasLocalHome() throws Throwable
+   {
+      // Get the metadata
+      JBossSessionBeanMetaData smd = this.smd;
+
+      // Add a local component interface only
+      smd.setLocal("LocalWithNoLocalHome");
+
+      // Run through the validator
+      this.runValidationAndEnsureFails(smd);
+   }
+
+   /**
+    * Tests that an EJB declaring a localHome interface also has a local component interface
+    */
+   public void testLocalHomeAlsoHasLocal() throws Throwable
+   {
+      // Get the metadata
+      JBossSessionBeanMetaData smd = this.smd;
+
+      // Add a localHome interface only
+      smd.setLocalHome("LocalHomeWithNoLocal");
+
+      // Run through the validator
+      this.runValidationAndEnsureFails(smd);
+   }
+
+   // -------------------------------------------------------------------||
+   // Lifecycle Methods -------------------------------------------------||
+   // -------------------------------------------------------------------||
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      // Call super
+      super.setUp();
+
+      // Define the EJB Impl class
+      Class<?> ejbImplementationClass = TestBean.class;
+
+      /*
+       * Create the metadata
+       */
+
+      // Create an AnnotationFinder for the EJB impl class
+      AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+      Collection<Class<?>> classes = new ArrayList<Class<?>>();
+      classes.add(ejbImplementationClass);
+
+      // Create
+      JBoss50Creator creator = new JBoss50Creator(finder);
+      JBossMetaData md = creator.create(classes);
+
+      // Get the Metadata
+      smd = (JBossSessionBeanMetaData) md.getEnterpriseBean(TestBean.class.getSimpleName());
+   }
+
+   /**
+    * Runs the CompleteEjb2xViewValidator on the JBossMetaData for the specified
+    * EJB and ensures that it fails as expected
+    * 
+    * @param smd
+    */
+   protected void runValidationAndEnsureFails(JBossSessionBeanMetaData smd)
+   {
+      // Set up a validator
+      Validator validator = CompleteEjb2xViewValidator.INSTANCE;
+
+      // Validate
+      try
+      {
+         validator.validate(smd.getJBossMetaData());
+      }
+      // Expected
+      catch (ValidationException e)
+      {
+         // Get the expected error code
+         String errorCode = ErrorCodes.ERROR_CODE_JBMETA130;
+
+         // Get the error message
+         String errorMessage = e.getMessage();
+
+         // Ensure the code is in the error message, so we've got the right exception
+         TestCase.assertTrue("Validation failed as expected, but error code of " + errorCode
+               + " was not referenced.  Instead error was: " + errorMessage, errorMessage.contains(errorCode));
+
+         // Return
+         log.info("Obtained expected message: " + errorMessage);
+         return;
+      }
+
+      // If we've reached here, validation succeeded and the test fails
+      TestCase.fail("Metadata from invalid construct improperly passed validation");
+
+   }
+
+}




More information about the jboss-cvs-commits mailing list