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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jan 4 13:20:46 EST 2010


Author: jaikiran
Date: 2010-01-04 13:20:46 -0500 (Mon, 04 Jan 2010)
New Revision: 98999

Added:
   projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jbmeta242/
   projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jbmeta242/unit/
   projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jbmeta242/unit/SessionTypeTestCase.java
   projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jbmeta242/unit/SingletonMetaDataTestCase.java
   projects/metadata/ejb/trunk/src/test/resources/org/jboss/metadata/ejb/test/jbmeta242/
   projects/metadata/ejb/trunk/src/test/resources/org/jboss/metadata/ejb/test/jbmeta242/ejb-jar.xml
   projects/metadata/ejb/trunk/src/test/resources/org/jboss/metadata/ejb/test/jbmeta242/invalid-ejb-jar.xml
   projects/metadata/ejb/trunk/src/test/resources/org/jboss/metadata/ejb/test/jbmeta242/singleton-beans-ejb-jar.xml
Modified:
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/SessionBean31MetaData.java
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/SessionType.java
   projects/metadata/ejb/trunk/src/test/java/org/jboss/test/metadata/xml/EjbXmlValidationUnitTestCase.java
Log:
JBMETA-242 Added support for singleton bean metadata - 1) for session-type and 2) for init-on-startup

Modified: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/SessionBean31MetaData.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/SessionBean31MetaData.java	2010-01-04 18:20:27 UTC (rev 98998)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/SessionBean31MetaData.java	2010-01-04 18:20:46 UTC (rev 98999)
@@ -21,7 +21,6 @@
  */
 package org.jboss.metadata.ejb.spec;
 
-import javax.ejb.LocalBean;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlType;
 
@@ -35,8 +34,8 @@
  * @version $Revision: $
  */
 @XmlType(name="session-beanType", propOrder={"descriptionGroup", "ejbName", "mappedName", "home", "remote", "localHome", "local",
-      "businessLocals", "businessRemotes", "localBean", "serviceEndpoint", "ejbClass", "sessionType", "timeoutMethod", "initMethods", "removeMethods",
-      "asyncMethods",
+      "businessLocals", "businessRemotes", "localBean", "serviceEndpoint", "ejbClass", "sessionType", "timeoutMethod",
+      "initOnStartup", "initMethods", "removeMethods",  "asyncMethods",
       "transactionType", "aroundInvokes", "environmentRefsGroup", "postActivates", "prePassivates", "securityRoleRefs", "securityIdentity"})
 @JBossXmlType(modelGroup=JBossXmlConstants.MODEL_GROUP_UNORDERED_SEQUENCE)
 public class SessionBean31MetaData extends SessionBeanMetaData
@@ -51,6 +50,27 @@
     */
    private EmptyMetaData localBean;
    
+   /**
+    * init-on-startup
+    */
+   private Boolean initOnStartup;
+   
+   /**
+    * Returns the init-on-startup value of the session bean metadata.
+    * Returns null if none is defined.
+    * @return
+    */
+   public Boolean isInitOnStartup()
+   {
+      return initOnStartup;
+   }
+
+   @XmlElement(name="init-on-startup", required=false)
+   public void setInitOnStartup(Boolean initOnStartup)
+   {
+      this.initOnStartup = initOnStartup;
+   }
+
    public AsyncMethodsMetaData getAsyncMethods()
    {
       return asyncMethods;
@@ -126,14 +146,22 @@
       if(original != null && original.asyncMethods != null)
          asyncMethods.addAll(original.asyncMethods);
       // merge the no-interface information
-      if (override != null)
+      if (original != null && original.getLocalBean() != null)
       {
+         this.localBean = original.getLocalBean();
+      }
+      if (override != null && override.getLocalBean() != null)
+      {
          this.localBean = override.getLocalBean();
       }
-      else if (original != null)
+      // init-on-startup
+      if (original != null && original.initOnStartup != null)
       {
-         this.localBean = original.getLocalBean();
+         this.initOnStartup = original.initOnStartup;
       }
-      
+      if (override != null && override.initOnStartup != null)
+      {
+         this.initOnStartup = override.initOnStartup;
+      }
    }
 }

Modified: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/SessionType.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/SessionType.java	2010-01-04 18:20:27 UTC (rev 98998)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/SessionType.java	2010-01-04 18:20:46 UTC (rev 98999)
@@ -39,4 +39,7 @@
    
    /** Stateful session bean */
    Stateful,
+   
+   /** EJB3.1 singleton type */
+   Singleton
 }

Added: projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jbmeta242/unit/SessionTypeTestCase.java
===================================================================
--- projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jbmeta242/unit/SessionTypeTestCase.java	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jbmeta242/unit/SessionTypeTestCase.java	2010-01-04 18:20:46 UTC (rev 98999)
@@ -0,0 +1,136 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.ejb.test.jbmeta242.unit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.net.URL;
+
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.spec.EjbJar31MetaData;
+import org.jboss.metadata.ejb.spec.EjbJarMetaData;
+import org.jboss.metadata.ejb.spec.SessionBeanMetaData;
+import org.jboss.metadata.ejb.spec.SessionType;
+import org.jboss.xb.binding.JBossXBException;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.resolver.MultiClassSchemaResolver;
+import org.jboss.xb.binding.resolver.MutableSchemaResolver;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * SessionTypeTestCase
+ *
+ * Tests that the session-type element of session beans allows all the 
+ * valid session-type values as defined by EJB3.1 spec
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class SessionTypeTestCase
+{
+   private static Logger logger = Logger.getLogger(SessionTypeTestCase.class);
+
+   private static MutableSchemaResolver schemaBindingResolver;
+
+   private static UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory.newInstance();
+
+   @BeforeClass
+   public static void beforeClass()
+   {
+      schemaBindingResolver = new MultiClassSchemaResolver();
+      schemaBindingResolver.mapLocationToClass("ejb-jar_3_1.xsd", EjbJar31MetaData.class);
+   }
+
+   /**
+    * Tests the metadata created out of ejb-jar.xml with the various possible
+    * session-type values for session beans, has the correct session type set
+    * @throws Exception
+    */
+   @Test
+   public void testEjbJarXmlForSessionType() throws Exception
+   {
+      EjbJarMetaData ejb31 = unmarshal(EjbJarMetaData.class, "/org/jboss/metadata/ejb/test/jbmeta242/ejb-jar.xml");
+      assertNotNull("Metadata created out of ejb-jar.xml is null", ejb31);
+      String slsbName = "Simple31SLSB";
+      String sfsbName = "Simple31SFSB";
+      String singletonBeanName = "Simple31SingletonBean";
+      
+      SessionBeanMetaData slsb = (SessionBeanMetaData) ejb31.getEnterpriseBean(slsbName);
+      assertNotNull(slsbName + " bean was not available in metadata", slsb);
+      assertEquals(slsbName + " bean was not considered stateless", slsb.getSessionType(), SessionType.Stateless);
+
+      SessionBeanMetaData sfsb = (SessionBeanMetaData) ejb31.getEnterpriseBean(sfsbName);
+      assertNotNull(sfsbName + " bean was not available in metadata", sfsb);
+      assertEquals(sfsbName + " bean was not considered stateful", sfsb.getSessionType(), SessionType.Stateful);
+
+      SessionBeanMetaData singletonBean = (SessionBeanMetaData) ejb31.getEnterpriseBean(singletonBeanName);
+      assertNotNull(singletonBeanName + " bean was not available in metadata", singletonBean);
+      assertEquals(singletonBeanName + " bean was not considered singleton", singletonBean.getSessionType(), SessionType.Singleton);
+
+   }
+   
+   /**
+    * Tests that only valid session-type values (stateless, stateful, singleton) for session beans are allowed
+    * in ejb-jar.xml
+    * @throws Exception
+    */
+   @Test
+   public void testInvalidSessionTypeInEjbJarXml() throws Exception
+   {
+      try
+      {
+         EjbJarMetaData ejb31 = unmarshal(EjbJarMetaData.class, "/org/jboss/metadata/ejb/test/jbmeta242/invalid-ejb-jar.xml");
+         fail("Validation did NOT fail on invalid-ejb-jar.xml");
+      }
+      catch (JBossXBException jbxbe)
+      {
+         // expected to fail with validation error, because the invalid-ejb-jar.xml
+         // uses an invalid <session-type> value. 
+         // TODO: Is there a better way to check for the specific validation failure error
+         logger.debug("Caught expected failure: ", jbxbe);
+      }
+
+   }
+
+   /**
+    * Utility method
+    * 
+    * @param <T>
+    * @param type
+    * @param resource
+    * @return
+    * @throws JBossXBException
+    */
+   private static <T> T unmarshal(Class<T> type, String resource) throws JBossXBException
+   {
+      Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller();
+      unmarshaller.setValidation(false);
+      URL url = type.getResource(resource);
+      if (url == null)
+         throw new IllegalArgumentException("Failed to find resource " + resource);
+      return type.cast(unmarshaller.unmarshal(url.toString(), schemaBindingResolver));
+   }
+}

Added: projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jbmeta242/unit/SingletonMetaDataTestCase.java
===================================================================
--- projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jbmeta242/unit/SingletonMetaDataTestCase.java	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jbmeta242/unit/SingletonMetaDataTestCase.java	2010-01-04 18:20:46 UTC (rev 98999)
@@ -0,0 +1,112 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.ejb.test.jbmeta242.unit;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+
+import java.net.URL;
+
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.spec.EjbJar31MetaData;
+import org.jboss.metadata.ejb.spec.EjbJarMetaData;
+import org.jboss.metadata.ejb.spec.SessionBean31MetaData;
+import org.jboss.xb.binding.JBossXBException;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.resolver.MultiClassSchemaResolver;
+import org.jboss.xb.binding.resolver.MutableSchemaResolver;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * SingletonMetaDataTestCase
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class SingletonMetaDataTestCase
+{
+   private static Logger logger = Logger.getLogger(SingletonMetaDataTestCase.class);
+
+   private static MutableSchemaResolver schemaBindingResolver;
+
+   private static UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory.newInstance();
+
+   @BeforeClass
+   public static void beforeClass()
+   {
+      schemaBindingResolver = new MultiClassSchemaResolver();
+      schemaBindingResolver.mapLocationToClass("ejb-jar_3_1.xsd", EjbJar31MetaData.class);
+   }
+
+   /**
+    * Tests the metadata created out of ejb-jar.xml with the various possible
+    * session-type values for session beans, has the correct session type set
+    * @throws Exception
+    */
+   @Test
+   public void testInitOnStartup() throws Exception
+   {
+      EjbJarMetaData ejb31 = unmarshal(EjbJarMetaData.class, "/org/jboss/metadata/ejb/test/jbmeta242/singleton-beans-ejb-jar.xml");
+      assertNotNull("Metadata created out of singleton-beans-ejb-jar.xml is null", ejb31);
+      String initOnStartupBeanName = "InitOnStartupBean";
+      String nonInitOnStartupBeanName = "NonInitOnStartupBean";
+      String undefinedInitOnStartupBeanName = "UnDefinedInitOnStartupBean";
+      
+      SessionBean31MetaData initOnStartupBean = (SessionBean31MetaData) ejb31.getEnterpriseBean(initOnStartupBeanName);
+      assertNotNull(initOnStartupBeanName + " bean was not available in metadata", initOnStartupBean);
+      assertTrue(initOnStartupBeanName + " bean was not considered init-on-startup", initOnStartupBean.isInitOnStartup());
+
+      SessionBean31MetaData nonInitOnStartupBean = (SessionBean31MetaData) ejb31.getEnterpriseBean(nonInitOnStartupBeanName);
+      assertNotNull(nonInitOnStartupBeanName + " bean was not available in metadata", nonInitOnStartupBean);
+      assertFalse(nonInitOnStartupBeanName + " bean was considered init-on-startup", nonInitOnStartupBean.isInitOnStartup());
+
+      SessionBean31MetaData undefinedInitOnStartupBean = (SessionBean31MetaData) ejb31.getEnterpriseBean(undefinedInitOnStartupBeanName);
+      assertNotNull(undefinedInitOnStartupBeanName + " bean was not available in metadata", undefinedInitOnStartupBean);
+      assertNull(undefinedInitOnStartupBeanName + " bean had non-null init-on-startup", undefinedInitOnStartupBean.isInitOnStartup());
+
+   }
+   
+   
+
+   /**
+    * Utility method
+    * 
+    * @param <T>
+    * @param type
+    * @param resource
+    * @return
+    * @throws JBossXBException
+    */
+   private static <T> T unmarshal(Class<T> type, String resource) throws JBossXBException
+   {
+      Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller();
+      unmarshaller.setValidation(false);
+      URL url = type.getResource(resource);
+      if (url == null)
+         throw new IllegalArgumentException("Failed to find resource " + resource);
+      return type.cast(unmarshaller.unmarshal(url.toString(), schemaBindingResolver));
+   }
+}

Modified: projects/metadata/ejb/trunk/src/test/java/org/jboss/test/metadata/xml/EjbXmlValidationUnitTestCase.java
===================================================================
--- projects/metadata/ejb/trunk/src/test/java/org/jboss/test/metadata/xml/EjbXmlValidationUnitTestCase.java	2010-01-04 18:20:27 UTC (rev 98998)
+++ projects/metadata/ejb/trunk/src/test/java/org/jboss/test/metadata/xml/EjbXmlValidationUnitTestCase.java	2010-01-04 18:20:46 UTC (rev 98999)
@@ -36,5 +36,7 @@
       exclude("JBoss42_testNoDoctype.xml");
       // dtd doesn't support prefix mapping (xmlns:prefix_name must declared attributes)
       exclude("JBoss42_testServiceRefQnameWithNS.xml");
+      // intentional invalid xml file using in org.jboss.metadata.ejb.test.jbmeta242.unit.SessionTypeTestCase
+      exclude("invalid-ejb-jar.xml");
    }
 }

Added: projects/metadata/ejb/trunk/src/test/resources/org/jboss/metadata/ejb/test/jbmeta242/ejb-jar.xml
===================================================================
--- projects/metadata/ejb/trunk/src/test/resources/org/jboss/metadata/ejb/test/jbmeta242/ejb-jar.xml	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/test/resources/org/jboss/metadata/ejb/test/jbmeta242/ejb-jar.xml	2010-01-04 18:20:46 UTC (rev 98999)
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
+      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+      	  http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
+      version="3.1">
+   <enterprise-beans>
+      <session>
+         <ejb-name>Simple31SLSB</ejb-name>
+         <session-type>Stateless</session-type>
+      </session>
+      <session>
+         <ejb-name>Simple31SFSB</ejb-name>
+         <session-type>Stateful</session-type>
+      </session>
+      <session>
+         <ejb-name>Simple31SingletonBean</ejb-name>
+         <session-type>Singleton</session-type>
+      </session>
+   </enterprise-beans>
+</ejb-jar>
\ No newline at end of file

Added: projects/metadata/ejb/trunk/src/test/resources/org/jboss/metadata/ejb/test/jbmeta242/invalid-ejb-jar.xml
===================================================================
--- projects/metadata/ejb/trunk/src/test/resources/org/jboss/metadata/ejb/test/jbmeta242/invalid-ejb-jar.xml	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/test/resources/org/jboss/metadata/ejb/test/jbmeta242/invalid-ejb-jar.xml	2010-01-04 18:20:46 UTC (rev 98999)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
+      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+          http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
+      version="3.1">
+   <enterprise-beans>
+      <session>
+         <ejb-name>InvalidBean</ejb-name>
+         <session-type>InvalidSessionBeanType</session-type>
+      </session>
+   </enterprise-beans>
+</ejb-jar>
\ No newline at end of file

Added: projects/metadata/ejb/trunk/src/test/resources/org/jboss/metadata/ejb/test/jbmeta242/singleton-beans-ejb-jar.xml
===================================================================
--- projects/metadata/ejb/trunk/src/test/resources/org/jboss/metadata/ejb/test/jbmeta242/singleton-beans-ejb-jar.xml	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/test/resources/org/jboss/metadata/ejb/test/jbmeta242/singleton-beans-ejb-jar.xml	2010-01-04 18:20:46 UTC (rev 98999)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
+      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+          http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
+      version="3.1">
+   <enterprise-beans>
+      <session>
+         <ejb-name>InitOnStartupBean</ejb-name>
+         <session-type>Singleton</session-type>
+         <init-on-startup>true</init-on-startup>
+      </session>
+      <session>
+         <ejb-name>NonInitOnStartupBean</ejb-name>
+         <session-type>Singleton</session-type>
+         <init-on-startup>false</init-on-startup>
+      </session>
+      <session>
+         <ejb-name>UnDefinedInitOnStartupBean</ejb-name>
+         <session-type>Singleton</session-type>
+      </session>
+   </enterprise-beans>
+</ejb-jar>
\ No newline at end of file




More information about the jboss-cvs-commits mailing list