[jboss-cvs] JBossAS SVN: r60924 - projects/aop/trunk/aop/src/test/org/jboss/test/aop/proxy.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Feb 26 18:48:17 EST 2007


Author: kabir.khan at jboss.com
Date: 2007-02-26 18:48:17 -0500 (Mon, 26 Feb 2007)
New Revision: 60924

Added:
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/proxy/OverrideObjectClass.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/proxy/OverrideObjectInterface.java
Modified:
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/proxy/ProxyTestCase.java
Log:
Add test to verify that when generating a proxy for to a class, and the class already contains the methods from the introduced interface that the original interface method is called.

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/proxy/OverrideObjectClass.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/proxy/OverrideObjectClass.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/proxy/OverrideObjectClass.java	2007-02-26 23:48:17 UTC (rev 60924)
@@ -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.test.aop.proxy;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class OverrideObjectClass implements OverrideObjectInterface
+{
+   boolean invokedEquals;
+   boolean invokedHashCode;
+   boolean invokedToString;
+   
+   public boolean equals(Object o)
+   {
+      invokedEquals = true;
+      return super.equals(o);
+   }
+
+   public int hashCode()
+   {
+      invokedHashCode = true;
+      return 0;
+   }
+
+   public String toString()
+   {
+      invokedToString = true;
+      return String.valueOf(System.identityHashCode(this));
+   }
+
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/proxy/OverrideObjectInterface.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/proxy/OverrideObjectInterface.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/proxy/OverrideObjectInterface.java	2007-02-26 23:48:17 UTC (rev 60924)
@@ -0,0 +1,34 @@
+/*
+* 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.test.aop.proxy;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface OverrideObjectInterface
+{
+   boolean equals(Object o);
+   int hashCode();
+   String toString();
+}

Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/proxy/ProxyTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/proxy/ProxyTestCase.java	2007-02-26 23:19:21 UTC (rev 60923)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/proxy/ProxyTestCase.java	2007-02-26 23:48:17 UTC (rev 60924)
@@ -41,11 +41,13 @@
 import org.jboss.aop.proxy.Proxy;
 import org.jboss.aop.proxy.ProxyFactory;
 import org.jboss.aop.proxy.ProxyMixin;
+import org.jboss.aop.proxy.container.AOPProxyFactoryParameters;
 import org.jboss.aop.proxy.container.AspectManaged;
 import org.jboss.aop.proxy.container.ClassProxyContainer;
 import org.jboss.aop.proxy.container.ContainerProxyCacheKey;
 import org.jboss.aop.proxy.container.ContainerProxyFactory;
 import org.jboss.aop.proxy.container.Delegate;
+import org.jboss.aop.proxy.container.GeneratedAOPProxyFactory;
 import org.jboss.test.aop.AOPTestWithSetup;
 
 import junit.framework.Test;
@@ -184,15 +186,6 @@
       domain.addBinding(binding);
       }
 
-
-      /*
-      CtClass clazz = ContainerProxyFactory.createProxyCtClass(ContainerProxyFactory.getIntroductions(POJO.class, container), POJO.class);
-      FileOutputStream fo = new FileOutputStream(clazz.getName() + ".class");
-      DataOutputStream dos = new DataOutputStream(fo);
-      clazz.toBytecode(dos);
-      dos.close();
-      */
-
       Class proxyClass = ContainerProxyFactory.getProxyClass(POJO.class, domain);
       ClassProxyContainer container = new ClassProxyContainer("test", domain);
       domain.setAdvisor(container);
@@ -248,4 +241,38 @@
       proxy.finalMethod();
       assertFalse(EchoInterceptor.intercepted);
    }
+   
+   
+   public void testHollowProxyWithInterfaceContainingObjectMethods() throws Exception
+   {
+      //Here to verify that we do not "crash" with methods already in the proxy class (toString(), equals() and hashCode() all exist in the template)
+      AOPProxyFactoryParameters params = new AOPProxyFactoryParameters();
+      params.setObjectAsSuperClass(true);
+      params.setInterfaces(new Class[] {OverrideObjectInterface.class});
+      
+      GeneratedAOPProxyFactory factory = new GeneratedAOPProxyFactory();
+      Object o = factory.createAdvisedProxy(params);
+      assertTrue(o instanceof OverrideObjectInterface);
+
+      assertTrue(o.equals(o));
+      assertEquals(o.hashCode(), o.hashCode());
+      assertEquals(o.toString(), o.toString());
+      
+      OverrideObjectClass tgt = new OverrideObjectClass();
+      assertNotNull(tgt);
+      ((Delegate)o).setDelegate(tgt);
+      Object target = ((Delegate)o).getDelegate();
+      assertSame(tgt, target);
+      
+      assertFalse(tgt.invokedEquals);
+      assertFalse(tgt.invokedHashCode);
+      assertFalse(tgt.invokedToString);
+
+      assertTrue(o.equals(o));
+      assertTrue(tgt.invokedEquals);
+      assertEquals(o.hashCode(), o.hashCode());
+      assertTrue(tgt.invokedHashCode);
+      assertEquals(o.toString(), o.toString());
+      assertTrue(tgt.invokedToString);
+   }
 }




More information about the jboss-cvs-commits mailing list