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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 10 11:43:02 EDT 2008


Author: kabir.khan at jboss.com
Date: 2008-04-10 11:43:02 -0400 (Thu, 10 Apr 2008)
New Revision: 71944

Added:
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/MyInterface.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/PerInstanceInterceptor.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/PerJoinpointInterceptor.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/ProxiedBean.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/ProxiedInterceptor.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/ProxyContainerWithPool.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/SimpleContext.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/SimplePoolInterceptor.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/unit/
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/unit/ProxyInstanceAdvisorTestCase.java
   projects/ejb3/trunk/interceptors/src/test/resources/proxyinstanceadvisor/
   projects/ejb3/trunk/interceptors/src/test/resources/proxyinstanceadvisor/jboss-aop.xml
Modified:
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/unit/ProxyTestCase.java
Log:
Add test for instance and joinpoint aspects

Modified: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/unit/ProxyTestCase.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/unit/ProxyTestCase.java	2008-04-10 15:22:29 UTC (rev 71943)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/unit/ProxyTestCase.java	2008-04-10 15:43:02 UTC (rev 71944)
@@ -36,7 +36,7 @@
  * Comment
  *
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
  */
 public class ProxyTestCase extends TestCase
 {
@@ -47,7 +47,7 @@
       //AspectManager.verbose = true;
       
       // Bootstrap AOP
-      URL url = Thread.currentThread().getContextClassLoader().getResource("proxy/jboss-aop.xml");
+      URL url = Thread.currentThread().getContextClassLoader().getResource("proxyinstanceadvisor/jboss-aop.xml");
       log.info("deploying AOP from " + url);
       AspectXmlLoader.deployXML(url);
 

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/MyInterface.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/MyInterface.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/MyInterface.java	2008-04-10 15:43:02 UTC (rev 71944)
@@ -0,0 +1,35 @@
+/*
+ * 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.proxyinstanceadvisor;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: 68647 $
+ */
+public interface MyInterface
+{
+   String sayHi(String name);
+   
+   String sayBye(String name);
+}

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/PerInstanceInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/PerInstanceInterceptor.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/PerInstanceInterceptor.java	2008-04-10 15:43:02 UTC (rev 71944)
@@ -0,0 +1,50 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.proxyinstanceadvisor;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.logging.Logger;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class PerInstanceInterceptor implements Interceptor
+{
+   Logger log = Logger.getLogger(PerInstanceInterceptor.class);
+   
+   public static PerInstanceInterceptor instance;
+   
+   public String getName()
+   {
+      return this.getClass().getName();
+   }
+
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      instance = this;
+      return invocation.invokeNext();
+   }
+
+}

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/PerJoinpointInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/PerJoinpointInterceptor.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/PerJoinpointInterceptor.java	2008-04-10 15:43:02 UTC (rev 71944)
@@ -0,0 +1,49 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.proxyinstanceadvisor;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.logging.Logger;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class PerJoinpointInterceptor implements Interceptor
+{
+   Logger log = Logger.getLogger(PerJoinpointInterceptor.class);
+
+   public static PerJoinpointInterceptor instance;
+   
+   public String getName()
+   {
+      return this.getClass().getName();
+   }
+
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      instance = this;
+      return invocation.invokeNext();
+   }
+}

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/ProxiedBean.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/ProxiedBean.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/ProxiedBean.java	2008-04-10 15:43:02 UTC (rev 71944)
@@ -0,0 +1,74 @@
+/*
+ * 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.proxyinstanceadvisor;
+
+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: 68647 $
+ */
+//@Interceptors(ProxiedInterceptor.class)
+ at ManagedObject
+public class ProxiedBean implements MyInterface
+{
+   private static final Logger log = Logger.getLogger(ProxiedBean.class);
+   
+   public static ProxiedBean instance;
+   
+//   public static int constructors = 0, aroundInvokes = 0;
+   
+   public ProxiedBean()
+   {
+      log.debug("ProxiedBean");
+//      constructors++;
+   }
+   
+//   @AroundInvoke
+//   Object aroundInvoke(InvocationContext ctx) throws Exception
+//   {
+//      log.debug("aroundInvoke " + ctx);
+//      if(ctx.getTarget() != this)
+//         throw new IllegalStateException("target is not this");
+//      if(ctx.getMethod().getDeclaringClass() != getClass())
+//         throw new IllegalStateException("method " + ctx.getMethod() + " not of this class (" + ctx.getMethod().getDeclaringClass() + " != " +  getClass() + ")");
+//      aroundInvokes++;
+//      return ctx.proceed();
+//   }
+   
+   public String sayHi(String name)
+   {
+      instance = this;
+      log.debug("sayHi");
+      return "Hi " + name;
+   }
+
+   public String sayBye(String name)
+   {
+      instance = this;
+      log.debug("sayBye");
+      return "Bye " + name;
+   }
+}

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/ProxiedInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/ProxiedInterceptor.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/ProxiedInterceptor.java	2008-04-10 15:43:02 UTC (rev 71944)
@@ -0,0 +1,66 @@
+/*
+ * 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.proxyinstanceadvisor;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+import org.jboss.logging.Logger;
+
+/**
+ * A basic interceptor, does nothing useful.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: 70766 $
+ */
+public class ProxiedInterceptor
+{
+   private static final Logger log = Logger.getLogger(ProxiedInterceptor.class);
+   
+   public static int preDestroys = 0, postConstructs = 0, aroundInvokes = 0;
+   
+//   @PreDestroy
+//   public void preDestroy(InvocationContext ctx) throws Exception
+//   {
+//      log.debug("preDestroy " + ctx);
+//      preDestroys++;
+//      ctx.proceed();
+//   }
+//   
+//   @PostConstruct
+//   public void postConstruct(InvocationContext ctx) throws Exception
+//   {
+//      log.debug("postConstruct " + ctx);
+//      postConstructs++;
+//      ctx.proceed();
+//   }
+   
+   @AroundInvoke
+   public Object aroundInvoke(InvocationContext ctx) throws Exception
+   {
+      log.debug("aroundInvoke " + ctx + this);
+      aroundInvokes++;
+      return ctx.proceed();
+   }
+}

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/ProxyContainerWithPool.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/ProxyContainerWithPool.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/ProxyContainerWithPool.java	2008-04-10 15:43:02 UTC (rev 71944)
@@ -0,0 +1,53 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.proxyinstanceadvisor;
+
+import java.lang.reflect.Constructor;
+
+import org.jboss.aop.Domain;
+import org.jboss.ejb3.interceptors.container.BeanContext;
+import org.jboss.ejb3.interceptors.proxy.ProxyContainer;
+
+/**
+ * Basically overrides  
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ProxyContainerWithPool<T> extends ProxyContainer<T>
+{
+   public ProxyContainerWithPool(String name, Domain domain, Class<? extends T> beanClass)
+   {
+      super(name, domain, beanClass);
+   }
+   
+   public ProxyContainerWithPool(String name, String domainName, Class<? extends T> beanClass)
+   {
+      super(name, domainName, beanClass);
+   }
+
+   @Override
+   protected BeanContext<T> construct(Constructor<? extends T> constructor, Object ... initargs)
+   {
+      return new SimpleContext<T>();
+   }
+   
+}

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/SimpleContext.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/SimpleContext.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/SimpleContext.java	2008-04-10 15:43:02 UTC (rev 71944)
@@ -0,0 +1,50 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.proxyinstanceadvisor;
+
+import org.jboss.ejb3.interceptors.container.BeanContext;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleContext<T> implements BeanContext<T>
+{
+   T instance;
+
+   public T getInstance()
+   {
+      return instance;
+   }
+
+   public Object[] getInterceptors()
+   {
+      return new Object[0];
+   }
+
+   public void setInstance(T instance)
+   {
+      this.instance = instance;
+   }
+
+}

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/SimplePoolInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/SimplePoolInterceptor.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/SimplePoolInterceptor.java	2008-04-10 15:43:02 UTC (rev 71944)
@@ -0,0 +1,72 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.proxyinstanceadvisor;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.ejb3.interceptors.container.ContainerMethodInvocation;
+import org.jboss.logging.Logger;
+
+/**
+ * Creates a new bean instance when told to
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimplePoolInterceptor implements Interceptor
+{
+   public static boolean createNewInstance;
+   
+   private static ProxiedBean pooledBean;
+   
+   Logger log = Logger.getLogger(SimplePoolInterceptor.class);
+   public String getName()
+   {
+      return this.getClass().getName();
+   }
+
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      ContainerMethodInvocation mi = (ContainerMethodInvocation)invocation;
+      
+      if (createNewInstance == false && pooledBean == null)
+      {
+         throw new RuntimeException("createNewInstance was false on an empty pool");
+      }
+      
+      @SuppressWarnings("unchecked")
+      SimpleContext ctx = (SimpleContext)mi.getBeanContext(); 
+      ProxiedBean bean = createNewInstance ? new ProxiedBean() : pooledBean;
+      pooledBean = bean;
+      ctx.setInstance(bean);
+      mi.setTargetObject(bean);
+      try
+      {
+         return invocation.invokeNext();
+      }
+      finally
+      {
+         ctx.setInstance(null);
+      }
+   }
+
+}

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/unit/ProxyInstanceAdvisorTestCase.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/unit/ProxyInstanceAdvisorTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxyinstanceadvisor/unit/ProxyInstanceAdvisorTestCase.java	2008-04-10 15:43:02 UTC (rev 71944)
@@ -0,0 +1,104 @@
+/*
+ * 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.proxyinstanceadvisor.unit;
+
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.jboss.aop.AspectXmlLoader;
+import org.jboss.ejb3.interceptors.proxy.ProxyContainer;
+import org.jboss.ejb3.test.interceptors.proxyinstanceadvisor.MyInterface;
+import org.jboss.ejb3.test.interceptors.proxyinstanceadvisor.PerInstanceInterceptor;
+import org.jboss.ejb3.test.interceptors.proxyinstanceadvisor.PerJoinpointInterceptor;
+import org.jboss.ejb3.test.interceptors.proxyinstanceadvisor.ProxiedBean;
+import org.jboss.ejb3.test.interceptors.proxyinstanceadvisor.ProxiedInterceptor;
+import org.jboss.ejb3.test.interceptors.proxyinstanceadvisor.ProxyContainerWithPool;
+import org.jboss.ejb3.test.interceptors.proxyinstanceadvisor.SimplePoolInterceptor;
+import org.jboss.logging.Logger;
+
+/**
+ * Make sure that PER_INSTANCE and PER_JOINPOINT container interceptors work with EJB 3 
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ProxyInstanceAdvisorTestCase extends TestCase
+{
+   private static final Logger log = Logger.getLogger(ProxyInstanceAdvisorTestCase.class);
+
+   public void test1() throws Throwable
+   {
+      //AspectManager.verbose = true;
+      
+      // Bootstrap AOP
+      URL url = Thread.currentThread().getContextClassLoader().getResource("proxyinstanceadvisor/jboss-aop.xml");
+      log.info("deploying AOP from " + url);
+      AspectXmlLoader.deployXML(url);
+
+      Thread.currentThread().setContextClassLoader(MyInterface.class.getClassLoader());
+      
+      ProxyContainerWithPool<ProxiedBean> container = new ProxyContainerWithPool<ProxiedBean>("ProxyTestCase", "InterceptorContainer", ProxiedBean.class);
+      
+      
+      Class<?> interfaces[] = { MyInterface.class };
+      MyInterface proxy = container.constructProxy(interfaces);
+      
+      reset(true);
+      String result = proxy.sayHi("Me");
+      assertEquals("Hi Me", result);
+      ProxiedBean bean1hi = ProxiedBean.instance;
+      PerInstanceInterceptor pi1hi = PerInstanceInterceptor.instance;
+      PerJoinpointInterceptor pj1hi = PerJoinpointInterceptor.instance;
+      
+      reset(false);
+      result = proxy.sayBye("Me");
+      assertEquals("Bye Me", result);
+      ProxiedBean bean1bye = ProxiedBean.instance;
+      PerInstanceInterceptor pi1bye = PerInstanceInterceptor.instance;
+      PerJoinpointInterceptor pj1bye = PerJoinpointInterceptor.instance;
+      
+      assertSame(bean1hi, bean1bye);
+      assertSame(pi1hi, pi1bye);
+      assertNotSame(pj1hi, pj1bye);
+
+      reset(true);
+      result = proxy.sayHi("Me");
+      assertEquals("Hi Me", result);
+      ProxiedBean bean2hi = ProxiedBean.instance;
+      PerInstanceInterceptor pi2hi = PerInstanceInterceptor.instance;
+      PerJoinpointInterceptor pj2hi = PerJoinpointInterceptor.instance;
+      assertNotSame(bean1hi, bean2hi);
+      
+      //FIXME - These must be enabled to start the test
+//      assertNotSame(pi2hi, pi1hi);
+//      assertNotSame(pj2hi, pj1hi);
+   }
+   
+   private void reset(boolean createNewInstance)
+   {
+      ProxiedBean.instance = null;
+      PerInstanceInterceptor.instance = null;
+      PerJoinpointInterceptor.instance = null;
+      SimplePoolInterceptor.createNewInstance = createNewInstance;      
+   }
+}

Added: projects/ejb3/trunk/interceptors/src/test/resources/proxyinstanceadvisor/jboss-aop.xml
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/resources/proxyinstanceadvisor/jboss-aop.xml	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/resources/proxyinstanceadvisor/jboss-aop.xml	2008-04-10 15:43:02 UTC (rev 71944)
@@ -0,0 +1,14 @@
+<aop>
+   <interceptor name="SimplePoolInterceptor" class="org.jboss.ejb3.test.interceptors.proxyinstanceadvisor.SimplePoolInterceptor" scope="PER_VM"/>  
+   <interceptor name="PerInstanceInterceptor" class="org.jboss.ejb3.test.interceptors.proxyinstanceadvisor.PerInstanceInterceptor" scope="PER_INSTANCE"/>  
+   <interceptor name="PerJoinpointInterceptor" class="org.jboss.ejb3.test.interceptors.proxyinstanceadvisor.PerJoinpointInterceptor" scope="PER_JOINPOINT"/>  
+	
+	<!-- TODO: this is actually the bootstrap container -->
+	<domain name="InterceptorContainer">			
+		<bind pointcut="execution(* @org.jboss.ejb3.interceptors.ManagedObject->*(..))">
+		   <interceptor-ref name="SimplePoolInterceptor"/>
+		   <interceptor-ref name="PerInstanceInterceptor"/>
+		   <interceptor-ref name="PerJoinpointInterceptor"/>
+		</bind>
+	</domain>
+</aop>
\ No newline at end of file




More information about the jboss-cvs-commits mailing list