[jboss-cvs] JBossAS SVN: r101677 - in projects/ejb3/components/singleton/trunk: testsuite/src/test/java/org/jboss/ejb3/singleton/integration/test/interceptor and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 1 12:23:55 EST 2010


Author: jaikiran
Date: 2010-03-01 12:23:54 -0500 (Mon, 01 Mar 2010)
New Revision: 101677

Added:
   projects/ejb3/components/singleton/trunk/testsuite/src/test/java/org/jboss/ejb3/singleton/integration/test/interceptor/Echo.java
Modified:
   projects/ejb3/components/singleton/trunk/aop-impl/src/main/java/org/jboss/ejb3/singleton/aop/impl/AOPBasedInterceptorRegistry.java
   projects/ejb3/components/singleton/trunk/aop-impl/src/main/java/org/jboss/ejb3/singleton/aop/impl/AOPBasedSingletonContainer.java
   projects/ejb3/components/singleton/trunk/testsuite/src/test/java/org/jboss/ejb3/singleton/integration/test/interceptor/SingletonBeanWithInterceptor.java
   projects/ejb3/components/singleton/trunk/testsuite/src/test/java/org/jboss/ejb3/singleton/integration/test/interceptor/unit/SingletonBeanInterceptorTestCase.java
Log:
EJBTHREE-2010 Singleton container implementation - testcase for interceptors on singleton bean

Modified: projects/ejb3/components/singleton/trunk/aop-impl/src/main/java/org/jboss/ejb3/singleton/aop/impl/AOPBasedInterceptorRegistry.java
===================================================================
--- projects/ejb3/components/singleton/trunk/aop-impl/src/main/java/org/jboss/ejb3/singleton/aop/impl/AOPBasedInterceptorRegistry.java	2010-03-01 17:14:16 UTC (rev 101676)
+++ projects/ejb3/components/singleton/trunk/aop-impl/src/main/java/org/jboss/ejb3/singleton/aop/impl/AOPBasedInterceptorRegistry.java	2010-03-01 17:23:54 UTC (rev 101677)
@@ -46,6 +46,14 @@
    private AOPBasedSingletonContainer aopBasedSingletonContainer;
 
    /**
+    * A hack actually. Ideally this shouldn't be stored in the interceptor
+    * registry and instead be available through {@link AOPBasedSingletonContainer}.
+    * But right now, i don't see any value of adding a public API to 
+    * the {@link AOPBasedSingletonContainer} to expose this {@link LegacySingletonBeanContext}
+    */
+   private LegacySingletonBeanContext legacySingletonBeanContext;
+   
+   /**
     * Construct an {@link AOPBasedInterceptorRegistry} for a {@link AOPBasedSingletonContainer}
     * 
     * @param aopBasedContainer The container for which the interceptor registry is being
@@ -83,17 +91,15 @@
       AOPBasedContainerInvocationContext aopInvocationContext = (AOPBasedContainerInvocationContext) containerInvocation;
       // form a AOP invocation
       MethodInfo methodInfo = aopInvocationContext.getMethodInfo();
+      
       EJBContainerInvocation<AOPBasedSingletonContainer, LegacySingletonBeanContext> invocation = new EJBContainerInvocation<AOPBasedSingletonContainer, LegacySingletonBeanContext>(
             aopInvocationContext.getMethodInfo());
       invocation.setAdvisor(methodInfo.getAdvisor());
       invocation.setArguments(containerInvocation.getArgs());
-      // get bean context (we could have used the passed one, but we need org.jboss.ejb3.BeanContext for the 
-      // AOP based invocation. Hence get it from the AOP based container)
-      org.jboss.ejb3.BeanContext<?> singletonBeanContext = new LegacySingletonBeanContext(
-            this.aopBasedSingletonContainer, targetBeanContext);
-      
+      // we ignore the passed bean context and always used the singleton bean context that we have locally
+      // TODO: Rethink on this approach
       // set the target bean context of the AOP invocation
-      invocation.setBeanContext(singletonBeanContext);
+      invocation.setBeanContext(this.legacySingletonBeanContext);
 
       try
       {
@@ -128,14 +134,13 @@
    public void invokePostConstruct(BeanContext targetBeanContext) throws Exception
    {
       // fallback on legacy AOP based lifecycle impl
-      org.jboss.ejb3.BeanContext<?> legacyBeanContext = new LegacySingletonBeanContext(this.aopBasedSingletonContainer,
-            targetBeanContext);
+      this.legacySingletonBeanContext = new LegacySingletonBeanContext(this.aopBasedSingletonContainer, targetBeanContext);
       // TODO: This passes the bean context through a series of injectors
       // which are responsible for carrying out the injection on the bean context (ex: field based
       // injection like for @PersistenceContext).
       // THIS HAS TO BE IN THE EJBLifecycleHandler SO THAT THE INJECTIONS
       // CAN HAPPEN ON LIFECYCLE EVENTS (LIKE BEAN INSTANTIATION)
-      this.aopBasedSingletonContainer.injectBeanContext(legacyBeanContext);
+      this.aopBasedSingletonContainer.injectBeanContext(legacySingletonBeanContext);
       
       // Note: The method name initialiseInterceptorInstances() gives a 
       // wrong impression. This method not just instantiates a interceptor instance,
@@ -143,10 +148,10 @@
       // instance for any injectable fields
       // TODO: Ideally, this should be split up into separate instantiation and injection
       // calls.
-      legacyBeanContext.initialiseInterceptorInstances();
+      legacySingletonBeanContext.initialiseInterceptorInstances();
       
       // invoke post construct lifecycle on the bean/interceptor instances
-      this.aopBasedSingletonContainer.invokePostConstruct(legacyBeanContext);
+      this.aopBasedSingletonContainer.invokePostConstruct(legacySingletonBeanContext);
 
    }
 

Modified: projects/ejb3/components/singleton/trunk/aop-impl/src/main/java/org/jboss/ejb3/singleton/aop/impl/AOPBasedSingletonContainer.java
===================================================================
--- projects/ejb3/components/singleton/trunk/aop-impl/src/main/java/org/jboss/ejb3/singleton/aop/impl/AOPBasedSingletonContainer.java	2010-03-01 17:14:16 UTC (rev 101676)
+++ projects/ejb3/components/singleton/trunk/aop-impl/src/main/java/org/jboss/ejb3/singleton/aop/impl/AOPBasedSingletonContainer.java	2010-03-01 17:23:54 UTC (rev 101677)
@@ -437,4 +437,5 @@
       return super.getBeanContainer();
    }
 
+   
 }

Added: projects/ejb3/components/singleton/trunk/testsuite/src/test/java/org/jboss/ejb3/singleton/integration/test/interceptor/Echo.java
===================================================================
--- projects/ejb3/components/singleton/trunk/testsuite/src/test/java/org/jboss/ejb3/singleton/integration/test/interceptor/Echo.java	                        (rev 0)
+++ projects/ejb3/components/singleton/trunk/testsuite/src/test/java/org/jboss/ejb3/singleton/integration/test/interceptor/Echo.java	2010-03-01 17:23:54 UTC (rev 101677)
@@ -0,0 +1,33 @@
+/*
+* 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.ejb3.singleton.integration.test.interceptor;
+
+/**
+ * Echo
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface Echo
+{
+   String echo(String message);
+}

Modified: projects/ejb3/components/singleton/trunk/testsuite/src/test/java/org/jboss/ejb3/singleton/integration/test/interceptor/SingletonBeanWithInterceptor.java
===================================================================
--- projects/ejb3/components/singleton/trunk/testsuite/src/test/java/org/jboss/ejb3/singleton/integration/test/interceptor/SingletonBeanWithInterceptor.java	2010-03-01 17:14:16 UTC (rev 101676)
+++ projects/ejb3/components/singleton/trunk/testsuite/src/test/java/org/jboss/ejb3/singleton/integration/test/interceptor/SingletonBeanWithInterceptor.java	2010-03-01 17:23:54 UTC (rev 101677)
@@ -21,6 +21,7 @@
 */
 package org.jboss.ejb3.singleton.integration.test.interceptor;
 
+import javax.ejb.Remote;
 import javax.ejb.Singleton;
 import javax.interceptor.Interceptors;
 
@@ -35,7 +36,8 @@
 @Interceptors (SimpleInterceptor.class)
 @Singleton
 @RemoteBinding (jndiBinding = SingletonBeanWithInterceptor.JNDI_NAME)
-public class SingletonBeanWithInterceptor
+ at Remote (Echo.class)
+public class SingletonBeanWithInterceptor implements Echo 
 {
 
    public static final String JNDI_NAME = "SingletonInterceptorTestBean";

Modified: projects/ejb3/components/singleton/trunk/testsuite/src/test/java/org/jboss/ejb3/singleton/integration/test/interceptor/unit/SingletonBeanInterceptorTestCase.java
===================================================================
--- projects/ejb3/components/singleton/trunk/testsuite/src/test/java/org/jboss/ejb3/singleton/integration/test/interceptor/unit/SingletonBeanInterceptorTestCase.java	2010-03-01 17:14:16 UTC (rev 101676)
+++ projects/ejb3/components/singleton/trunk/testsuite/src/test/java/org/jboss/ejb3/singleton/integration/test/interceptor/unit/SingletonBeanInterceptorTestCase.java	2010-03-01 17:23:54 UTC (rev 101677)
@@ -27,9 +27,11 @@
 import junit.framework.Assert;
 
 import org.jboss.ejb3.singleton.integration.test.common.AbstractSingletonTestCase;
+import org.jboss.ejb3.singleton.integration.test.interceptor.Echo;
 import org.jboss.ejb3.singleton.integration.test.interceptor.SingletonBeanWithInterceptor;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Test;
 
 /**
  * SingletonBeanInterceptorTestCase
@@ -69,9 +71,10 @@
     * 
     * @throws Exception
     */
+   @Test
    public void testInterception() throws Exception
    {
-      SingletonBeanWithInterceptor singleton = (SingletonBeanWithInterceptor) this.getInitialContext().lookup(SingletonBeanWithInterceptor.JNDI_NAME);
+      Echo singleton = (Echo) this.getInitialContext().lookup(SingletonBeanWithInterceptor.JNDI_NAME);
       String message = "some message which will be intercepted";
       String expectedInterceptedMessage = message + "-intercepted";
       String result = singleton.echo(message);




More information about the jboss-cvs-commits mailing list