From 83b69b79510f7faec8675e332868b2e4314c05f1 Mon Sep 17 00:00:00 2001 From: kimi Date: Thu, 21 Jun 2012 17:52:22 +0800 Subject: [PATCH] =?UTF-8?q?DUBBO-440=20=E6=B7=BB=E5=8A=A0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dubbo-common/pom.xml | 5 ++ .../dubbo/common/bytecode/ProxyTest.java | 67 ++++++++++++++----- pom.xml | 6 ++ 3 files changed, 60 insertions(+), 18 deletions(-) diff --git a/dubbo-common/pom.xml b/dubbo-common/pom.xml index 36c15f367..a4e0e030d 100644 --- a/dubbo-common/pom.xml +++ b/dubbo-common/pom.xml @@ -61,5 +61,10 @@ sorcerer-javac provided + + cglib + cglib-nodep + test + \ No newline at end of file diff --git a/dubbo-common/src/test/java/com/alibaba/dubbo/common/bytecode/ProxyTest.java b/dubbo-common/src/test/java/com/alibaba/dubbo/common/bytecode/ProxyTest.java index eef0bce3d..687340034 100644 --- a/dubbo-common/src/test/java/com/alibaba/dubbo/common/bytecode/ProxyTest.java +++ b/dubbo-common/src/test/java/com/alibaba/dubbo/common/bytecode/ProxyTest.java @@ -1,26 +1,31 @@ -/* - * Copyright 1999-2011 Alibaba Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/* + * Copyright 1999-2011 Alibaba Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.alibaba.dubbo.common.bytecode; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; -import com.alibaba.dubbo.common.bytecode.Proxy; +import org.junit.Assert; +import org.junit.Test; + import junit.framework.TestCase; +import net.sf.cglib.proxy.Enhancer; +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; public class ProxyTest extends TestCase { @@ -42,12 +47,38 @@ public class ProxyTest extends TestCase } return null; } - }); - + }); + assertNull(instance.getName()); instance.setName("qianlei", "hello"); } + @Test + public void testCglibProxy() throws Exception { + ITest test = (ITest)Proxy.getProxy(ITest.class).newInstance(new InvocationHandler() { + + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + System.out.println(method.getName()); + return null; + } + }); + + Enhancer enhancer = new Enhancer(); + enhancer.setSuperclass(test.getClass()); + enhancer.setCallback(new MethodInterceptor() { + + public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { + return null; + } + }); + try { + enhancer.create(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + Assert.fail(); + } + } + public static interface ITest { String getName(); diff --git a/pom.xml b/pom.xml index 50998af57..a7d2ee30d 100644 --- a/pom.xml +++ b/pom.xml @@ -110,6 +110,7 @@ 0.4 2.0-M5.1 3.0 + 2.2 1.6.2 1.1 @@ -313,6 +314,11 @@ ${easymock_version} test + + cglib + cglib-nodep + ${cglib_version} + -- GitLab