From 794f9b5eafe34a7dbb48cda3edaec59ff57afef5 Mon Sep 17 00:00:00 2001 From: avasseur Date: Fri, 28 Oct 2005 12:07:14 +0000 Subject: #108892 cannot reproduce: hierarchy of aop.xml accross classloader test is fine --- tests/java5/ataspectj/ajc-ant.xml | 27 ++++++ .../ataspectj/hierarchy/AppContainerTest.java | 101 +++++++++++++++++++++ .../ataspectj/ataspectj/hierarchy/aop-global.xml | 6 ++ .../ataspectj/ataspectj/hierarchy/aop-local.xml | 6 ++ .../ataspectj/ataspectj/hierarchy/app/SubApp.java | 42 +++++++++ 5 files changed, 182 insertions(+) create mode 100644 tests/java5/ataspectj/ataspectj/hierarchy/AppContainerTest.java create mode 100644 tests/java5/ataspectj/ataspectj/hierarchy/aop-global.xml create mode 100644 tests/java5/ataspectj/ataspectj/hierarchy/aop-local.xml create mode 100644 tests/java5/ataspectj/ataspectj/hierarchy/app/SubApp.java (limited to 'tests/java5') diff --git a/tests/java5/ataspectj/ajc-ant.xml b/tests/java5/ataspectj/ajc-ant.xml index 077fc2667..5c4495be4 100644 --- a/tests/java5/ataspectj/ajc-ant.xml +++ b/tests/java5/ataspectj/ajc-ant.xml @@ -186,4 +186,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/java5/ataspectj/ataspectj/hierarchy/AppContainerTest.java b/tests/java5/ataspectj/ataspectj/hierarchy/AppContainerTest.java new file mode 100644 index 000000000..5bd2330f4 --- /dev/null +++ b/tests/java5/ataspectj/ataspectj/hierarchy/AppContainerTest.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexandre Vasseur initial implementation + *******************************************************************************/ +package ataspectj.hierarchy; + +import junit.framework.TestCase; +import junit.framework.Test; +import junit.framework.TestSuite; + +import java.net.URL; +import java.net.URLClassLoader; +import java.io.File; + +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.ProceedingJoinPoint; +import ataspectj.TestHelper; + +/** + * Assumes ataspect.hierarchy.app DOES NOT EXISTS in system classpath + * but exists in 2 folder located at "/app_1" and /app_2 + * ie "/app_1/ataspect.hierarchy.app.*.class" + * + * @author Alexandre Vasseur + */ +public class AppContainerTest extends TestCase { + + public static interface IApp { + + String invoke(String input); + } + + + IApp app1; + IApp app2; + + public void setUp() throws Exception { + try { + Class k = Class.forName("ataspectj.hierarchy.app.SubApp"); + throw new Exception("config error, app must not be in system classpath"); + } catch (ClassNotFoundException e) { + ;//fine + } + + //build path and app + URL path = AppContainerTest.class.getProtectionDomain().getCodeSource().getLocation(); + String path1 = path.toString() + "app_1/"; + String path2 = path.toString() + "app_2/"; + + URLClassLoader app1CL = new URLClassLoader( + new URL[]{new URL(path1)}, + AppContainerTest.class.getClassLoader() + ); + URLClassLoader app2CL = new URLClassLoader( + new URL[]{new URL(path2)}, + AppContainerTest.class.getClassLoader() + ); + + app1 = (IApp)Class.forName("ataspectj.hierarchy.app.SubApp", false, app1CL).newInstance(); + app2 = (IApp)Class.forName("ataspectj.hierarchy.app.SubApp", false, app2CL).newInstance(); + } + + public void testApp1LocalAspect() { + String res = app1.invoke("app1"); + assertEquals("globalAspect[localAspect[app1]]", res); + } + + public void testApp2NoLocalAspect() { + String res = app2.invoke("app2"); + assertEquals("globalAspect[app2]", res); + } + + + @Aspect + public static class BaseAspect { + + @Around("execution(* ataspectj.hierarchy.app.SubApp.invoke(..))")//TODO IApp + public Object around(ProceedingJoinPoint jp) throws Throwable { + String out = (String) jp.proceed(); + return "globalAspect[" + out + "]"; + } + } + + public static void main(String[] args) { + TestHelper.runAndThrowOnFailure(suite()); + } + + public static Test suite() { + return new TestSuite(AppContainerTest.class); + } + + +} diff --git a/tests/java5/ataspectj/ataspectj/hierarchy/aop-global.xml b/tests/java5/ataspectj/ataspectj/hierarchy/aop-global.xml new file mode 100644 index 000000000..f17696441 --- /dev/null +++ b/tests/java5/ataspectj/ataspectj/hierarchy/aop-global.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/tests/java5/ataspectj/ataspectj/hierarchy/aop-local.xml b/tests/java5/ataspectj/ataspectj/hierarchy/aop-local.xml new file mode 100644 index 000000000..384b77416 --- /dev/null +++ b/tests/java5/ataspectj/ataspectj/hierarchy/aop-local.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/tests/java5/ataspectj/ataspectj/hierarchy/app/SubApp.java b/tests/java5/ataspectj/ataspectj/hierarchy/app/SubApp.java new file mode 100644 index 000000000..e724c486d --- /dev/null +++ b/tests/java5/ataspectj/ataspectj/hierarchy/app/SubApp.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexandre Vasseur initial implementation + *******************************************************************************/ +package ataspectj.hierarchy.app; + +import ataspectj.hierarchy.AppContainerTest; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; + +/** + * Leaves in child classloader in two forms, like 2 webapp + * + * @author Alexandre Vasseur + */ +public class SubApp implements AppContainerTest.IApp { + + // simple echo. May be advised or not depending on the aspect deployed there + public String invoke(String input) { + return input; + } + + // this child aspect will be LTW for only one variation of the SubApp + @Aspect + public static class SubAspect { + + @Around("execution(* ataspectj.hierarchy.app.SubApp.invoke(..))") + public Object around(ProceedingJoinPoint jp) throws Throwable { + String out = (String) jp.proceed(); + return "localAspect[" + out + "]"; + } + } + +} -- cgit v1.2.3