[jboss-cvs] JBossAS SVN: r86661 - in projects/jboss-cl/trunk: classloader and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 2 08:03:21 EDT 2009


Author: alesj
Date: 2009-04-02 08:03:21 -0400 (Thu, 02 Apr 2009)
New Revision: 86661

Added:
   projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/
   projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/TransformTestSuite.java
   projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/
   projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/AuthorTranslator.java
   projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/JavassistTranslator.java
   projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/LocaleTranslator.java
   projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/MethodHelper.java
   projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/MixedTester.java
   projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/PolicyTester.java
   projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/SystemTester.java
   projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/test/
   projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/test/MixedTransformUnitTestCase.java
   projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/test/PolicyTransformUnitTestCase.java
   projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/test/SystemTransformUnitTestCase.java
   projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/test/TransformTest.java
Modified:
   projects/jboss-cl/trunk/classloader/pom.xml
   projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/ClassLoaderAllTestSuite.java
   projects/jboss-cl/trunk/pom.xml
Log:
[JBCL-95]; add multiple translators - tests.

Modified: projects/jboss-cl/trunk/classloader/pom.xml
===================================================================
--- projects/jboss-cl/trunk/classloader/pom.xml	2009-04-02 11:48:16 UTC (rev 86660)
+++ projects/jboss-cl/trunk/classloader/pom.xml	2009-04-02 12:03:21 UTC (rev 86661)
@@ -71,6 +71,7 @@
     </dependency>
     
     <!-- Test dependencies -->
+    
     <dependency>
       <groupId>org.jboss.test</groupId>
       <artifactId>jboss-test</artifactId>
@@ -83,5 +84,11 @@
       <optional>true</optional>
     </dependency>
     
-  </dependencies>  
+    <dependency>
+      <groupId>javassist</groupId>
+      <artifactId>javassist</artifactId>
+      <optional>true</optional>
+    </dependency>
+
+  </dependencies>
 </project>

Modified: projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/ClassLoaderAllTestSuite.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/ClassLoaderAllTestSuite.java	2009-04-02 11:48:16 UTC (rev 86660)
+++ projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/ClassLoaderAllTestSuite.java	2009-04-02 12:03:21 UTC (rev 86661)
@@ -24,7 +24,6 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 import junit.textui.TestRunner;
-
 import org.jboss.test.classloader.bootstrap.BootstrapTestSuite;
 import org.jboss.test.classloader.delegate.DelegateTestSuite;
 import org.jboss.test.classloader.domain.ClassLoaderDomainTestSuite;
@@ -35,11 +34,13 @@
 import org.jboss.test.classloader.policy.test.ClassLoaderPolicyUnitTestCase;
 import org.jboss.test.classloader.resources.ResourceTestSuite;
 import org.jboss.test.classloader.system.ClassLoaderSystemTestSuite;
+import org.jboss.test.classloader.transform.TransformTestSuite;
 
 /**
  * ClassLoader All Test Suite.
  * 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @version $Revision: 37459 $
  */
 public class ClassLoaderAllTestSuite extends TestSuite
@@ -73,7 +74,8 @@
       suite.addTest(ResourceTestSuite.suite());
       suite.addTest(JMXTestSuite.suite());
       suite.addTest(JUnitTestSuite.suite());
-      
+      suite.addTest(TransformTestSuite.suite());
+
       return suite;
    }
 }

Added: projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/TransformTestSuite.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/TransformTestSuite.java	                        (rev 0)
+++ projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/TransformTestSuite.java	2009-04-02 12:03:21 UTC (rev 86661)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.test.classloader.transform;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+import org.jboss.test.classloader.transform.test.MixedTransformUnitTestCase;
+import org.jboss.test.classloader.transform.test.PolicyTransformUnitTestCase;
+import org.jboss.test.classloader.transform.test.SystemTransformUnitTestCase;
+
+/**
+ * Transform Test Suite.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TransformTestSuite extends TestSuite
+{
+   /**
+    * For running the testsuite from the command line
+    *
+    * @param args the command line args
+    */
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   /**
+    * Create the testsuite
+    *
+    * @return the testsuite
+    */
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("Transform Tests");
+
+      suite.addTest(PolicyTransformUnitTestCase.suite());
+      suite.addTest(SystemTransformUnitTestCase.suite());
+      suite.addTest(MixedTransformUnitTestCase.suite());
+
+      return suite;
+   }
+}

Added: projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/AuthorTranslator.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/AuthorTranslator.java	                        (rev 0)
+++ projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/AuthorTranslator.java	2009-04-02 12:03:21 UTC (rev 86661)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.test.classloader.transform.support;
+
+import javassist.CtClass;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class AuthorTranslator extends JavassistTranslator
+{
+   protected void addMethods(CtClass ctClass) throws Exception
+   {
+      addMethod(ctClass, "author");
+   }
+}

Added: projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/JavassistTranslator.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/JavassistTranslator.java	                        (rev 0)
+++ projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/JavassistTranslator.java	2009-04-02 12:03:21 UTC (rev 86661)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.test.classloader.transform.support;
+
+import java.security.ProtectionDomain;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtMethod;
+import javassist.CtNewMethod;
+import org.jboss.util.loading.Translator;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class JavassistTranslator implements Translator
+{
+   private ClassPool pool = ClassPool.getDefault();
+
+   public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws Exception
+   {
+      // do not modify MethodHelper
+      if (className.contains("MethodHelper"))
+         return classfileBuffer;
+
+      CtClass ctClass = pool.getCtClass(className);
+      ctClass.defrost();
+      addMethods(ctClass);
+      return ctClass.toBytecode();
+   }
+
+   protected abstract void addMethods(CtClass ctClass) throws Exception;
+
+   protected void addMethod(CtClass ctClass, String methodName) throws Exception
+   {
+      CtMethod body = pool.getCtClass(MethodHelper.class.getName()).getDeclaredMethod(methodName);
+      CtMethod newMethod = CtNewMethod.delegator(body, ctClass);
+      ctClass.addMethod(newMethod);
+   }
+
+   public void unregisterClassLoader(ClassLoader loader)
+   {
+   }
+}
\ No newline at end of file

Added: projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/LocaleTranslator.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/LocaleTranslator.java	                        (rev 0)
+++ projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/LocaleTranslator.java	2009-04-02 12:03:21 UTC (rev 86661)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.test.classloader.transform.support;
+
+import javassist.CtClass;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class LocaleTranslator extends JavassistTranslator
+{
+   protected void addMethods(CtClass ctClass) throws Exception
+   {
+      addMethod(ctClass, "locale");
+   }
+}
\ No newline at end of file

Added: projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/MethodHelper.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/MethodHelper.java	                        (rev 0)
+++ projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/MethodHelper.java	2009-04-02 12:03:21 UTC (rev 86661)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.test.classloader.transform.support;
+
+import java.util.Locale;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class MethodHelper
+{
+   public static String author()
+   {
+      return System.getProperty("user.name", "Ales");     
+   }
+
+   public static Locale locale()
+   {
+      return Locale.getDefault();     
+   }
+}
\ No newline at end of file

Added: projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/MixedTester.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/MixedTester.java	                        (rev 0)
+++ projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/MixedTester.java	2009-04-02 12:03:21 UTC (rev 86661)
@@ -0,0 +1,29 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.test.classloader.transform.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class MixedTester
+{
+}
\ No newline at end of file

Added: projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/PolicyTester.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/PolicyTester.java	                        (rev 0)
+++ projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/PolicyTester.java	2009-04-02 12:03:21 UTC (rev 86661)
@@ -0,0 +1,29 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.test.classloader.transform.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class PolicyTester
+{
+}

Added: projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/SystemTester.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/SystemTester.java	                        (rev 0)
+++ projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/support/SystemTester.java	2009-04-02 12:03:21 UTC (rev 86661)
@@ -0,0 +1,29 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.test.classloader.transform.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class SystemTester
+{
+}
\ No newline at end of file

Added: projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/test/MixedTransformUnitTestCase.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/test/MixedTransformUnitTestCase.java	                        (rev 0)
+++ projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/test/MixedTransformUnitTestCase.java	2009-04-02 12:03:21 UTC (rev 86661)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.test.classloader.transform.test;
+
+import java.lang.reflect.Method;
+
+import junit.framework.Test;
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.test.classloader.transform.support.AuthorTranslator;
+import org.jboss.test.classloader.transform.support.LocaleTranslator;
+
+/**
+ * Per policy transformation tests.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class MixedTransformUnitTestCase extends TransformTest
+{
+   public MixedTransformUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(MixedTransformUnitTestCase.class);
+   }
+
+   protected void prepareTransform(ClassLoaderSystem system, ClassLoaderPolicy policy)
+   {
+      policy.addTranslator(new AuthorTranslator());
+      system.addTranslator(new LocaleTranslator());
+   }
+
+   protected String getClassName()
+   {
+      return "org.jboss.test.classloader.transform.support.MixedTester";
+   }
+
+   protected void testInstance(Object instance) throws Exception
+   {
+      Method author = instance.getClass().getDeclaredMethod("author");
+      assertNotNull(author.invoke(instance));
+
+      Method locale = instance.getClass().getDeclaredMethod("locale");
+      assertNotNull(locale.invoke(instance));
+   }
+}
\ No newline at end of file

Added: projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/test/PolicyTransformUnitTestCase.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/test/PolicyTransformUnitTestCase.java	                        (rev 0)
+++ projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/test/PolicyTransformUnitTestCase.java	2009-04-02 12:03:21 UTC (rev 86661)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.test.classloader.transform.test;
+
+import java.lang.reflect.Method;
+
+import junit.framework.Test;
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.test.classloader.transform.support.AuthorTranslator;
+
+/**
+ * Per policy transformation tests.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class PolicyTransformUnitTestCase extends TransformTest
+{
+   public PolicyTransformUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(PolicyTransformUnitTestCase.class);
+   }
+
+   protected void prepareTransform(ClassLoaderSystem system, ClassLoaderPolicy policy)
+   {
+      policy.addTranslator(new AuthorTranslator());
+   }
+
+   protected String getClassName()
+   {
+      return "org.jboss.test.classloader.transform.support.PolicyTester";
+   }
+
+   protected void testInstance(Object instance) throws Exception
+   {
+      Method author = instance.getClass().getDeclaredMethod("author");
+      assertNotNull(author.invoke(instance));
+
+      try
+      {
+         instance.getClass().getDeclaredMethod("locale");
+         fail("Should not be here.");
+      }
+      catch (Exception ignored)
+      {
+      }
+   }
+}
\ No newline at end of file

Added: projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/test/SystemTransformUnitTestCase.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/test/SystemTransformUnitTestCase.java	                        (rev 0)
+++ projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/test/SystemTransformUnitTestCase.java	2009-04-02 12:03:21 UTC (rev 86661)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.test.classloader.transform.test;
+
+import java.lang.reflect.Method;
+
+import junit.framework.Test;
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.test.classloader.transform.support.LocaleTranslator;
+
+/**
+ * Per policy transformation tests.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class SystemTransformUnitTestCase extends TransformTest
+{
+   public SystemTransformUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(SystemTransformUnitTestCase.class);
+   }
+
+   protected void prepareTransform(ClassLoaderSystem system, ClassLoaderPolicy policy)
+   {
+      system.addTranslator(new LocaleTranslator());
+   }
+
+   protected String getClassName()
+   {
+      return "org.jboss.test.classloader.transform.support.SystemTester";
+   }
+
+   protected void testInstance(Object instance) throws Exception
+   {
+      try
+      {
+         instance.getClass().getDeclaredMethod("author");
+         fail("Should not be here.");
+      }
+      catch (Exception ignored)
+      {
+      }
+
+      Method locale = instance.getClass().getDeclaredMethod("locale");
+      assertNotNull(locale.invoke(instance));
+   }
+}
\ No newline at end of file

Added: projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/test/TransformTest.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/test/TransformTest.java	                        (rev 0)
+++ projects/jboss-cl/trunk/classloader/src/test/java/org/jboss/test/classloader/transform/test/TransformTest.java	2009-04-02 12:03:21 UTC (rev 86661)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.test.classloader.transform.test;
+
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.test.support.MockClassLoaderPolicy;
+import org.jboss.test.classloader.AbstractClassLoaderTest;
+
+/**
+ * Transformation tests.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class TransformTest extends AbstractClassLoaderTest
+{
+   protected TransformTest(String name)
+   {
+      super(name);
+   }
+
+   public void testTransform() throws Exception
+   {
+      ClassLoaderSystem system = createClassLoaderSystemWithModifiedBootstrap();
+      MockClassLoaderPolicy policy = createMockClassLoaderPolicy();
+      policy.setPaths("org/jboss/test/classloader/transform");
+      prepareTransform(system, policy);
+
+      ClassLoader cl = system.registerClassLoaderPolicy(policy);
+      Class<?> clazz = cl.loadClass(getClassName());
+      Object instance = clazz.newInstance();
+      testInstance(instance);
+   }
+
+   protected abstract void prepareTransform(ClassLoaderSystem system, ClassLoaderPolicy policy);
+
+   protected abstract String getClassName();
+
+   protected abstract void testInstance(Object instance) throws Exception;
+}

Modified: projects/jboss-cl/trunk/pom.xml
===================================================================
--- projects/jboss-cl/trunk/pom.xml	2009-04-02 11:48:16 UTC (rev 86660)
+++ projects/jboss-cl/trunk/pom.xml	2009-04-02 12:03:21 UTC (rev 86661)
@@ -37,6 +37,7 @@
     <version.jbossxb>2.0.0.GA</version.jbossxb>
     <version.org.jboss.test>1.1.1.GA</version.org.jboss.test>
     <version.junit>4.4</version.junit>
+    <version.javassist>3.10.0.GA</version.javassist>
   </properties>
 
   <build>
@@ -236,6 +237,7 @@
       </dependency>
       
       <!-- test dependencies -->
+
       <dependency>
         <groupId>org.jboss.test</groupId>
         <artifactId>jboss-test</artifactId>
@@ -250,6 +252,13 @@
         <scope>test</scope>
       </dependency>
       
+      <dependency>
+        <groupId>javassist</groupId>
+        <artifactId>javassist</artifactId>
+        <version>${version.javassist}</version>
+        <scope>test</scope>
+      </dependency>
+
     </dependencies>
   </dependencyManagement>
 




More information about the jboss-cvs-commits mailing list