[jboss-cvs] JBossAS SVN: r70950 - in projects/ejb3/trunk/interceptors/src/test: java/org/jboss/ejb3/test/interceptors/lifecycle and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 18 12:02:53 EDT 2008


Author: wolfc
Date: 2008-03-18 12:02:53 -0400 (Tue, 18 Mar 2008)
New Revision: 70950

Added:
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/lifecycle/
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/lifecycle/SessionBeanCallbackBean.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/lifecycle/unit/
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/lifecycle/unit/CallbackMethodDescriptorTestCase.java
   projects/ejb3/trunk/interceptors/src/test/resources/lifecycle/
   projects/ejb3/trunk/interceptors/src/test/resources/lifecycle/META-INF/
   projects/ejb3/trunk/interceptors/src/test/resources/lifecycle/META-INF/ejb-jar.xml
Log:
Added lifecycle callback defined in descriptor test

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/lifecycle/SessionBeanCallbackBean.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/lifecycle/SessionBeanCallbackBean.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/lifecycle/SessionBeanCallbackBean.java	2008-03-18 16:02:53 UTC (rev 70950)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007-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.ejb3.test.interceptors.lifecycle;
+
+import org.jboss.ejb3.interceptors.ManagedObject;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at ManagedObject
+public class SessionBeanCallbackBean
+{
+   private static final Logger log = Logger.getLogger(SessionBeanCallbackBean.class);
+   
+   public static int postConstructs;
+
+   public static int preDestroys;
+   
+   /**
+    * Via xml.
+    * @throws RuntimeException
+    */
+   public void ejbCreate() throws RuntimeException
+   {
+      log.debug("ejbCreate called");
+      postConstructs++;
+   }
+   
+   public void ejbRemove()
+   {
+      preDestroys++;
+   }
+}


Property changes on: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/lifecycle/SessionBeanCallbackBean.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/lifecycle/unit/CallbackMethodDescriptorTestCase.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/lifecycle/unit/CallbackMethodDescriptorTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/lifecycle/unit/CallbackMethodDescriptorTestCase.java	2008-03-18 16:02:53 UTC (rev 70950)
@@ -0,0 +1,141 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.ejb3.test.interceptors.lifecycle.unit;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.AspectXmlLoader;
+import org.jboss.ejb3.interceptors.direct.AbstractDirectContainer;
+import org.jboss.ejb3.interceptors.metadata.BeanInterceptorMetaDataBridge;
+import org.jboss.ejb3.interceptors.metadata.InterceptorComponentMetaDataLoaderFactory;
+import org.jboss.ejb3.interceptors.metadata.InterceptorMetaDataBridge;
+import org.jboss.ejb3.metadata.MetaDataBridge;
+import org.jboss.ejb3.metadata.annotation.AnnotationRepositoryToMetaData;
+import org.jboss.ejb3.test.interceptors.lifecycle.SessionBeanCallbackBean;
+import org.jboss.ejb3.test.interceptors.metadata.MetadataBean;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.jboss.JBoss50MetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.spec.EjbJar30MetaData;
+import org.jboss.metadata.ejb.spec.InterceptorMetaData;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
+import org.jboss.xb.builder.JBossXBBuilder;
+import org.w3c.dom.ls.LSInput;
+
+/**
+ * Test bean lifecycle callbacks defined in the descriptor. 
+ * 
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision$
+ */
+public class CallbackMethodDescriptorTestCase extends TestCase
+{
+   private static final Logger log = Logger.getLogger(CallbackMethodDescriptorTestCase.class);
+   
+   private class MyContainer<T> extends AbstractDirectContainer<T, MyContainer<T>>
+   {
+      public MyContainer(String name, String domainName, Class<? extends T> beanClass, JBossEnterpriseBeanMetaData beanMetaData)
+      {
+         super();
+         
+         ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+         AnnotationRepositoryToMetaData annotations = new AnnotationRepositoryToMetaData(beanClass, beanMetaData, name, classLoader);
+         List<MetaDataBridge<InterceptorMetaData>> interceptorBridges = new ArrayList<MetaDataBridge<InterceptorMetaData>>();
+         interceptorBridges.add(new InterceptorMetaDataBridge());
+         annotations.addComponentMetaDataLoaderFactory(new InterceptorComponentMetaDataLoaderFactory(interceptorBridges));
+         annotations.addMetaDataBridge(new BeanInterceptorMetaDataBridge());
+         
+         initializeAdvisor(name, getDomain(domainName), beanClass, annotations);
+      }
+   }
+   
+   protected static SchemaBindingResolver schemaResolverForClass(final Class<?> root)
+   {
+      return new SchemaBindingResolver()
+      {
+         public String getBaseURI()
+         {
+            return null;
+         }
+
+         public SchemaBinding resolve(String nsUri, String baseURI, String schemaLocation)
+         {
+            return JBossXBBuilder.build(root);
+         }
+
+         public LSInput resolveAsLSInput(String nsUri, String baseUri, String schemaLocation)
+         {
+            return null;
+         }
+
+         public void setBaseURI(String baseURI)
+         {
+         }
+      };
+   }
+
+   public void test() throws Throwable
+   {
+      AspectManager.verbose = true;
+      
+      // To make surefire happy
+      Thread.currentThread().setContextClassLoader(MetadataBean.class.getClassLoader());
+      
+      // Bootstrap AOP
+      // FIXME: use the right jboss-aop.xml
+      URL url = Thread.currentThread().getContextClassLoader().getResource("proxy/jboss-aop.xml");
+      log.info("deploying AOP from " + url);
+      AspectXmlLoader.deployXML(url);
+      
+      // Bootstrap metadata
+      UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory.newInstance();
+      Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller();
+      url = Thread.currentThread().getContextClassLoader().getResource("lifecycle/META-INF/ejb-jar.xml");
+      EjbJar30MetaData metaData = (EjbJar30MetaData) unmarshaller.unmarshal(url.toString(), schemaResolverForClass(EjbJar30MetaData.class));
+      JBoss50MetaData jbossMetaData = new JBoss50MetaData();
+      jbossMetaData.merge(null, metaData);
+      
+      JBossEnterpriseBeanMetaData beanMetaData = jbossMetaData.getEnterpriseBean("SessionBeanCallbackBean");
+      assertNotNull(beanMetaData);
+      
+      assertEquals(0, SessionBeanCallbackBean.postConstructs);
+      
+      MyContainer<SessionBeanCallbackBean> container = new MyContainer<SessionBeanCallbackBean>("SessionBeanCallbackBean", "Test", SessionBeanCallbackBean.class, beanMetaData);
+      
+      SessionBeanCallbackBean bean = container.construct();
+      
+      assertEquals("SessionBeanCallbackBean ejbCreate must have been called once", 1, SessionBeanCallbackBean.postConstructs);
+      
+      container.destroy(bean);
+      assertEquals(1, SessionBeanCallbackBean.preDestroys);
+      
+      bean = null;
+   }
+}


Property changes on: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/lifecycle/unit/CallbackMethodDescriptorTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/ejb3/trunk/interceptors/src/test/resources/lifecycle/META-INF/ejb-jar.xml
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/resources/lifecycle/META-INF/ejb-jar.xml	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/resources/lifecycle/META-INF/ejb-jar.xml	2008-03-18 16:02:53 UTC (rev 70950)
@@ -0,0 +1,22 @@
+<?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_0.xsd"
+        version="3.0">
+    <display-name>CallbackMethodDescriptorTest</display-name>
+    <!-- Must define a bean here, because we have no annotation on it -->
+    <!-- (Can't use @Stateless within ejb3-interceptors) -->
+    <enterprise-beans>
+    	<session>
+    		<ejb-name>SessionBeanCallbackBean</ejb-name>
+    		<post-construct>
+    			<lifecycle-callback-method>ejbCreate</lifecycle-callback-method>
+    		</post-construct>
+    		<pre-destroy>
+    			<lifecycle-callback-method>ejbRemove</lifecycle-callback-method>
+    		</pre-destroy>
+    	</session>
+    </enterprise-beans>
+</ejb-jar>
\ No newline at end of file


Property changes on: projects/ejb3/trunk/interceptors/src/test/resources/lifecycle/META-INF/ejb-jar.xml
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native




More information about the jboss-cvs-commits mailing list