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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Jan 31 21:16:12 EST 2009


Author: flavia.rainone at jboss.com
Date: 2009-01-31 21:16:12 -0500 (Sat, 31 Jan 2009)
New Revision: 83736

Added:
   projects/aop/trunk/aop/src/test/java/org/jboss/test/aop/classloader/
   projects/aop/trunk/aop/src/test/java/org/jboss/test/aop/classloader/UserDefinedCL.java
   projects/aop/trunk/aop/src/test/java/org/jboss/test/aop/classloader/UserDefinedCLTestCase.java
   projects/aop/trunk/aop/src/test/java/org/jboss/test/aop/classloader/scenario/
   projects/aop/trunk/aop/src/test/java/org/jboss/test/aop/classloader/scenario/POJO.java
   projects/aop/trunk/aop/src/test/java/org/jboss/test/aop/classloader/scenario/POJOInterceptor.java
Modified:
   projects/aop/trunk/aop/build-tests-jdk50.xml
Log:
[JBAOP-582] Tests that reproduce the scenario described.

Modified: projects/aop/trunk/aop/build-tests-jdk50.xml
===================================================================
--- projects/aop/trunk/aop/build-tests-jdk50.xml	2009-02-01 01:37:18 UTC (rev 83735)
+++ projects/aop/trunk/aop/build-tests-jdk50.xml	2009-02-01 02:16:12 UTC (rev 83736)
@@ -211,6 +211,9 @@
       <jar destfile="${build.tests.classes}/org/jboss/test/aop/jdk15/dynamic/common/scenario.jar"
         basedir="${build.tests.classes}" includes="org/jboss/test/aop/jdk15/dynamic/common/scenario/**"/>
       <delete dir="${build.tests.classes}/org/jboss/test/aop/jdk15/dynamic/common/scenario"/>
+      <jar destfile="${build.tests.classes}/org/jboss/test/aop/classloader/scenario.jar"
+        basedir="${build.tests.classes}" includes="org/jboss/test/aop/classloader/scenario/**"/> 
+      <delete dir="${build.tests.classes}/org/jboss/test/aop/classloader/scenario"/>
    </target>
 
    <!-- ================================================================== -->
@@ -323,6 +326,12 @@
          <param name="no.xml" value="true"/>
          <param name="caller" value="javaagent-tests"/>
       </antcall>
+      
+      <antcall target="_run-javaagent-test" inheritRefs="true">
+         <param name="test" value="classloader"/>
+         <param name="no.xml" value="true"/>
+         <param name="caller" value="javaagent-tests"/>
+      </antcall>
 
       <!-- Add tests in _base-tests unless they should only be run in this weaving mode -->
       <antcall target="_base-jdk50-tests" inheritRefs="true">
@@ -387,6 +396,12 @@
          <param name="no.xml" value="true"/>
          <param name="use.annotations" value="true"/>
       </antcall>
+      <antcall target="_run-javaagent-test" inheritRefs="true">
+         <param name="test" value="classloader"/>
+         <param name="caller" value="javaagent-genadvisor-tests"/>
+         <param name="no.xml" value="true"/>
+         <param name="use.annotations" value="true"/>
+      </antcall>
       <!-- Only run this with loadtime weaving -->
       <antcall target="_run-javaagent-test" inheritRefs="true">
          <param name="test" value="annotationproperty"/>

Added: projects/aop/trunk/aop/src/test/java/org/jboss/test/aop/classloader/UserDefinedCL.java
===================================================================
--- projects/aop/trunk/aop/src/test/java/org/jboss/test/aop/classloader/UserDefinedCL.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/java/org/jboss/test/aop/classloader/UserDefinedCL.java	2009-02-01 02:16:12 UTC (rev 83736)
@@ -0,0 +1,77 @@
+/*
+ * 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.test.aop.classloader;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Enumeration;
+
+/**
+ * User-defined class loader.
+ * 
+ * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class UserDefinedCL extends URLClassLoader
+{
+   public UserDefinedCL(URL url, ClassLoader parent)
+   {
+      super(new URL[]{url}, parent);
+   }
+   
+   @Override
+   public URL  getResource(String name)
+   {
+      System.out.println("GET RESOURCE: " + name);
+      new Exception().printStackTrace();
+      return null;
+   }
+   
+   @Override
+   public InputStream getResourceAsStream(String name)
+   {
+      return null;
+   }
+   
+   @Override
+   public Enumeration<URL> getResources(String name) throws IOException
+   {
+      return null;
+   }
+   
+   @Override
+   public URL  findResource(String name)
+   {
+      return null;
+   }
+   public Enumeration<URL>    findResources(String name)
+   {
+      return null;
+   }
+   
+   @Override
+   public Class<?> loadClass(String name) throws ClassNotFoundException
+   {
+      return super.loadClass(name);
+   }
+}
\ No newline at end of file

Added: projects/aop/trunk/aop/src/test/java/org/jboss/test/aop/classloader/UserDefinedCLTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/java/org/jboss/test/aop/classloader/UserDefinedCLTestCase.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/java/org/jboss/test/aop/classloader/UserDefinedCLTestCase.java	2009-02-01 02:16:12 UTC (rev 83736)
@@ -0,0 +1,91 @@
+/*
+  * 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.test.aop.classloader;
+
+import java.lang.reflect.Method;
+import java.net.URL;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.advice.AdviceBinding;
+import org.jboss.test.aop.AOPTestWithSetup;
+
+
+/**
+ * Tests interception on a "user defined class loader"-loaded scenario. Both
+ * interceptor and intercepted class are loaded by this specific loader and
+ * interception is checked for correction.
+ * 
+ * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class UserDefinedCLTestCase extends AOPTestWithSetup
+{
+   
+   private URL jarURL;
+   private final static String USER_DEFINED_PACKAGE =
+         UserDefinedCLTestCase.class.getPackage().getName() + ".scenario";
+   private final static String POJO_CLASS = USER_DEFINED_PACKAGE + ".POJO";
+   private final static String INTERCEPTOR_CLASS = USER_DEFINED_PACKAGE +
+      ".POJOInterceptor";
+   private final static String SCENARIO_TO_LOAD =
+         "/target/test-classes/org/jboss/test/aop/classloader/scenario.jar";
+   
+   public UserDefinedCLTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static void main(String[] args)
+   {
+      junit.textui.TestRunner.run(UserDefinedCLTestCase.class);
+   }
+ 
+   public void setUp() throws Exception
+   {
+      super.setUp();
+      
+      jarURL = getURLRelativeToProjectRoot(SCENARIO_TO_LOAD);
+   }
+   
+   public void testURLLoadedInterception() throws Exception
+   {
+      Thread currentThread = Thread.currentThread();
+      ClassLoader classLoader = new UserDefinedCL(jarURL,
+               currentThread.getContextClassLoader());
+      currentThread.setContextClassLoader(classLoader);
+      Class<?> clazz = Class.forName(INTERCEPTOR_CLASS, false, classLoader);
+      
+      AdviceBinding binding = new AdviceBinding("userdefinedclbinding",
+               "execution(* *->*(..))", null);
+      binding.addInterceptor(clazz);
+      AspectManager.instance().addBinding(binding);
+
+      Method resetStatus = clazz.getDeclaredMethod("resetInvokeStatus");
+      Method getStatus = clazz.getDeclaredMethod("getInvoked");
+      
+      Class<?> pojoClass = Class.forName(POJO_CLASS, false, classLoader);
+      Object pojoInstance = pojoClass.newInstance();
+      resetStatus.invoke(null);
+      Method pojoMethod = pojoClass.getDeclaredMethod("execute");
+      pojoMethod.invoke(pojoInstance);
+      assertTrue((Boolean) getStatus.invoke(null));
+   }
+}

Added: projects/aop/trunk/aop/src/test/java/org/jboss/test/aop/classloader/scenario/POJO.java
===================================================================
--- projects/aop/trunk/aop/src/test/java/org/jboss/test/aop/classloader/scenario/POJO.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/java/org/jboss/test/aop/classloader/scenario/POJO.java	2009-02-01 02:16:12 UTC (rev 83736)
@@ -0,0 +1,35 @@
+/*
+ * 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.test.aop.classloader.scenario;
+
+/**
+ * 
+ * 
+ * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class POJO
+{
+   public void execute()
+   {
+      System.out.println("Executing...");
+   }
+}

Added: projects/aop/trunk/aop/src/test/java/org/jboss/test/aop/classloader/scenario/POJOInterceptor.java
===================================================================
--- projects/aop/trunk/aop/src/test/java/org/jboss/test/aop/classloader/scenario/POJOInterceptor.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/java/org/jboss/test/aop/classloader/scenario/POJOInterceptor.java	2009-02-01 02:16:12 UTC (rev 83736)
@@ -0,0 +1,56 @@
+/*
+ * 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.test.aop.classloader.scenario;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ * 
+ * 
+ * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class POJOInterceptor implements Interceptor
+{
+   private static boolean invoked = false; 
+
+   public static boolean getInvoked()
+   {
+      return invoked;
+   }
+   
+   public static void resetInvokeStatus()
+   {
+      invoked = false;
+   }
+   
+   public String getName()
+   {
+      return this.getClass().getName();
+   }
+
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      invoked = true;
+      return invocation.invokeNext();
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list