Przeglądaj źródła

unix crlf got screwed

AspectJ5_Development
avasseur 19 lat temu
rodzic
commit
19fba27b5f

+ 119
- 119
tests/java5/ataspectj/ataspectj/AfterXTest.java Wyświetl plik

@@ -1,119 +1,119 @@
/*******************************************************************************
* Copyright (c) Jonas Bonér, Alexandre Vasseur
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*******************************************************************************/
package ataspectj;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.JoinPoint;
import junit.framework.TestCase;
/**
* AfterXXX tests
*
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
public class AfterXTest extends TestCase {
static StringBuffer s_log = new StringBuffer();
static void log(String s) {
s_log.append(s).append(" ");
}
public static void main(String[] args) {
TestHelper.runAndThrowOnFailure(suite());
}
public static junit.framework.Test suite() {
return new junit.framework.TestSuite(AfterXTest.class);
}
public int dupPos(int i) throws NoSuchMethodException {
if (i > 0)
return i*2;
else
throw new NoSuchMethodException("arg is negative");
}
public void testAfterReturningAndThrowing() {
AfterXTest me = new AfterXTest();
try {
s_log = new StringBuffer();
int dup2 = me.dupPos(2);
// see after advice precedence here..
//TODO really weird after finally comes first
// see BcelWeaver fix on sorting of shadowMungerList
//assertEquals("after after2- 2 4 afterRet- 2 ", s_log.toString());
assertEquals("afterRet- 2 after2- 2 4 after ", s_log.toString());
} catch (Exception e) {
fail("Should not fail " + e.toString());
}
s_log = new StringBuffer();
try {
int dupm2 = me.dupPos(-2);
fail("should not be reached");
} catch (NoSuchMethodException e) {
//TODO really weird after finally comes first
// see BcelWeaver fix in sorting of shadowMungerList
assertEquals("after afterThrowing afterThrowing3- [arg is negative] ", s_log.toString());
}
}
@Aspect
public static class TestAspect {
@AfterReturning("execution(int ataspectj.AfterXTest.dupPos(..)) && args(arg)")
public void afterRet(int arg) {
log("afterRet-");
log(""+arg);
}
@AfterReturning(returning="ret", pointcut="execution(int ataspectj.AfterXTest.dupPos(..)) && args(arg)")
public void after2(int arg, int ret) {//CORRECT
//public void after2(int ret, int arg) {//INCORRECT
log("after2-");
log(""+arg);
log(""+ret);
}
@After("execution(int ataspectj.AfterXTest.dupPos(..))")
public void after() {
log("after");
}
@AfterThrowing("execution(int ataspectj.AfterXTest.dupPos(..))")
public void afterThrowing(JoinPoint jp) {
log("afterThrowing");
}
// formal binding is mandatory in AJ
//@AfterThrowing(throwned="java.lang.RuntimeException", pointcut="execution(int alex.test.ReturnAndThrowHelloWorld.dupPos(..))")
//public void afterThrowing2() {
@AfterThrowing(throwing= "e", pointcut="execution(int ataspectj.AfterXTest.dupPos(..))")
public void afterThrowing2(RuntimeException e) {
fail("should not be bounded");
}
@AfterThrowing(throwing= "e", value="execution(int ataspectj.AfterXTest.dupPos(..))")
public void afterThrowing3(NoSuchMethodException e) {
log("afterThrowing3-");
log("["+e.getMessage()+"]");
}
}
}
/*******************************************************************************
* Copyright (c) Jonas Bonér, Alexandre Vasseur
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*******************************************************************************/
package ataspectj;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.JoinPoint;
import junit.framework.TestCase;
/**
* AfterXXX tests
*
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
public class AfterXTest extends TestCase {
static StringBuffer s_log = new StringBuffer();
static void log(String s) {
s_log.append(s).append(" ");
}
public static void main(String[] args) {
TestHelper.runAndThrowOnFailure(suite());
}
public static junit.framework.Test suite() {
return new junit.framework.TestSuite(AfterXTest.class);
}
public int dupPos(int i) throws NoSuchMethodException {
if (i > 0)
return i*2;
else
throw new NoSuchMethodException("arg is negative");
}
public void testAfterReturningAndThrowing() {
AfterXTest me = new AfterXTest();
try {
s_log = new StringBuffer();
int dup2 = me.dupPos(2);
// see after advice precedence here..
//TODO really weird after finally comes first
// see BcelWeaver fix on sorting of shadowMungerList
//assertEquals("after after2- 2 4 afterRet- 2 ", s_log.toString());
assertEquals("afterRet- 2 after2- 2 4 after ", s_log.toString());
} catch (Exception e) {
fail("Should not fail " + e.toString());
}
s_log = new StringBuffer();
try {
int dupm2 = me.dupPos(-2);
fail("should not be reached");
} catch (NoSuchMethodException e) {
//TODO really weird after finally comes first
// see BcelWeaver fix in sorting of shadowMungerList
assertEquals("after afterThrowing afterThrowing3- [arg is negative] ", s_log.toString());
}
}
@Aspect
public static class TestAspect {
@AfterReturning("execution(int ataspectj.AfterXTest.dupPos(..)) && args(arg)")
public void afterRet(int arg) {
log("afterRet-");
log(""+arg);
}
@AfterReturning(returning="ret", pointcut="execution(int ataspectj.AfterXTest.dupPos(..)) && args(arg)")
public void after2(int arg, int ret) {//CORRECT
//public void after2(int ret, int arg) {//INCORRECT
log("after2-");
log(""+arg);
log(""+ret);
}
@After("execution(int ataspectj.AfterXTest.dupPos(..))")
public void after() {
log("after");
}
@AfterThrowing("execution(int ataspectj.AfterXTest.dupPos(..))")
public void afterThrowing(JoinPoint jp) {
log("afterThrowing");
}
// formal binding is mandatory in AJ
//@AfterThrowing(throwned="java.lang.RuntimeException", pointcut="execution(int alex.test.ReturnAndThrowHelloWorld.dupPos(..))")
//public void afterThrowing2() {
@AfterThrowing(throwing= "e", pointcut="execution(int ataspectj.AfterXTest.dupPos(..))")
public void afterThrowing2(RuntimeException e) {
fail("should not be bounded");
}
@AfterThrowing(throwing= "e", value="execution(int ataspectj.AfterXTest.dupPos(..))")
public void afterThrowing3(NoSuchMethodException e) {
log("afterThrowing3-");
log("["+e.getMessage()+"]");
}
}
}

+ 79
- 79
tests/java5/ataspectj/ataspectj/BindingTest.java Wyświetl plik

@@ -1,79 +1,79 @@
/*******************************************************************************
* Copyright (c) Jonas Bonér, Alexandre Vasseur
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*******************************************************************************/
package ataspectj;
import junit.framework.TestCase;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
/**
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
public class BindingTest extends TestCase {
public static void main(String[] args) {
TestHelper.runAndThrowOnFailure(suite());
}
public static junit.framework.Test suite() {
return new junit.framework.TestSuite(BindingTest.class);
}
public int substract(int i, int j) {
int res = i - j;
return res+1;//see +1 here
}
public static int dup(int i) {
return i*3;//see x3 here
}
public void testAroundArgs() {
int res = substract(3, 2);// should be 2 without around advice
assertEquals(1, res);
}
public void testProceedArgs() {
int res = dup((3+1));// advice will change arg with arg-1
assertEquals(6, res);
callWithinStatic();
}
private static void callWithinStatic() {
int res = dup((3+1));
assertEquals(6, res);
}
@Aspect
public static class TestAspect_1 {
@Pointcut("call(int substract(int, int)) && within(ataspectj.BindingTest) && args(arg1, arg2)")
void pc(int arg2, int arg1) {}// see rather fancy ordering here..
@Around("pc(argAdvice2, argAdvice1) && target(t)")//see here ordering remade consistent
public Object aaround(ProceedingJoinPoint jp, BindingTest t, int argAdvice1, int argAdvice2) throws Throwable {
int res = ((Integer)jp.proceed()).intValue();
return new Integer(res-1);
}
@Pointcut("call(int dup(int)) && within(ataspectj.BindingTest) && args(arg1)")
void pc2(int arg1) {}
@Around("pc2(argAdvice1)")
public Object aaround2(int argAdvice1, ProceedingJoinPoint jp) throws Throwable {
int res = ((Integer)jp.proceed(new Object[]{new Integer(argAdvice1-1)})).intValue();
return new Integer(res/3*2);
}
}
}
/*******************************************************************************
* Copyright (c) Jonas Bonér, Alexandre Vasseur
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*******************************************************************************/
package ataspectj;
import junit.framework.TestCase;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
/**
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
public class BindingTest extends TestCase {
public static void main(String[] args) {
TestHelper.runAndThrowOnFailure(suite());
}
public static junit.framework.Test suite() {
return new junit.framework.TestSuite(BindingTest.class);
}
public int substract(int i, int j) {
int res = i - j;
return res+1;//see +1 here
}
public static int dup(int i) {
return i*3;//see x3 here
}
public void testAroundArgs() {
int res = substract(3, 2);// should be 2 without around advice
assertEquals(1, res);
}
public void testProceedArgs() {
int res = dup((3+1));// advice will change arg with arg-1
assertEquals(6, res);
callWithinStatic();
}
private static void callWithinStatic() {
int res = dup((3+1));
assertEquals(6, res);
}
@Aspect
public static class TestAspect_1 {
@Pointcut("call(int substract(int, int)) && within(ataspectj.BindingTest) && args(arg1, arg2)")
void pc(int arg2, int arg1) {}// see rather fancy ordering here..
@Around("pc(argAdvice2, argAdvice1) && target(t)")//see here ordering remade consistent
public Object aaround(ProceedingJoinPoint jp, BindingTest t, int argAdvice1, int argAdvice2) throws Throwable {
int res = ((Integer)jp.proceed()).intValue();
return new Integer(res-1);
}
@Pointcut("call(int dup(int)) && within(ataspectj.BindingTest) && args(arg1)")
void pc2(int arg1) {}
@Around("pc2(argAdvice1)")
public Object aaround2(int argAdvice1, ProceedingJoinPoint jp) throws Throwable {
int res = ((Integer)jp.proceed(new Object[]{new Integer(argAdvice1-1)})).intValue();
return new Integer(res/3*2);
}
}
}

+ 75
- 75
tests/java5/ataspectj/ataspectj/CflowTest.java Wyświetl plik

@@ -1,75 +1,75 @@
/*******************************************************************************
* Copyright (c) Jonas Bonér, Alexandre Vasseur
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*******************************************************************************/
package ataspectj;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.runtime.internal.CFlowCounter;
import junit.framework.TestCase;
/**
* Test cflow (LTW of the aspect to add cflow fields to it)
*
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
public class CflowTest extends TestCase {
static StringBuffer s_log = new StringBuffer();
static void log(String s) {
s_log.append(s).append(" ");
}
public static void main(String[] args) {
TestHelper.runAndThrowOnFailure(suite());
}
public static junit.framework.Test suite() {
return new junit.framework.TestSuite(CflowTest.class);
}
public void hello() {
log("hello");
}
public void startCflow() {
hello();
}
public void testCflow() {
CflowTest me = new CflowTest();
s_log = new StringBuffer();
me.hello();
assertEquals("hello ", s_log.toString());
s_log = new StringBuffer();
me.startCflow();
assertEquals("before hello ", s_log.toString());
}
@Aspect
public static class TestAspect {
//LTW will add:
//public static final CFlowCounter ajc$cflowCounter$0 = new CFlowCounter();
@Before("execution(* ataspectj.CflowTest.hello(..)) && this(t) && cflow(execution(* ataspectj.CflowTest.startCflow(..)))")
public void before(Object t, JoinPoint jp) {
assertEquals(CflowTest.class.getName(), t.getClass().getName());
try {
//jp.proceed();
} catch (Throwable throwable) {
fail("proceed called in before Advice must be a NO-OP:" + throwable.toString());
}
log("before");
}
}
}
/*******************************************************************************
* Copyright (c) Jonas Bonér, Alexandre Vasseur
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*******************************************************************************/
package ataspectj;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.runtime.internal.CFlowCounter;
import junit.framework.TestCase;
/**
* Test cflow (LTW of the aspect to add cflow fields to it)
*
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
public class CflowTest extends TestCase {
static StringBuffer s_log = new StringBuffer();
static void log(String s) {
s_log.append(s).append(" ");
}
public static void main(String[] args) {
TestHelper.runAndThrowOnFailure(suite());
}
public static junit.framework.Test suite() {
return new junit.framework.TestSuite(CflowTest.class);
}
public void hello() {
log("hello");
}
public void startCflow() {
hello();
}
public void testCflow() {
CflowTest me = new CflowTest();
s_log = new StringBuffer();
me.hello();
assertEquals("hello ", s_log.toString());
s_log = new StringBuffer();
me.startCflow();
assertEquals("before hello ", s_log.toString());
}
@Aspect
public static class TestAspect {
//LTW will add:
//public static final CFlowCounter ajc$cflowCounter$0 = new CFlowCounter();
@Before("execution(* ataspectj.CflowTest.hello(..)) && this(t) && cflow(execution(* ataspectj.CflowTest.startCflow(..)))")
public void before(Object t, JoinPoint jp) {
assertEquals(CflowTest.class.getName(), t.getClass().getName());
try {
//jp.proceed();
} catch (Throwable throwable) {
fail("proceed called in before Advice must be a NO-OP:" + throwable.toString());
}
log("before");
}
}
}

+ 63
- 63
tests/java5/ataspectj/ataspectj/IfPointcutTest.java Wyświetl plik

@@ -1,63 +1,63 @@
/*******************************************************************************
* Copyright (c) Jonas Bonér, Alexandre Vasseur
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*******************************************************************************/
package ataspectj;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import junit.framework.TestCase;
import org.aspectj.lang.annotation.Aspect;
/**
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
public class IfPointcutTest extends TestCase {
static StringBuffer s_log = new StringBuffer();
static void log(String s) {
s_log.append(s).append(" ");
}
public void hello(int i) {
System.out.println("IfPointcutTest.hello " + i);
}
public void testIf() {
IfPointcutTest me = new IfPointcutTest();
me.hello(1);
me.hello(-1);
}
public static void main(String[] args) {
TestHelper.runAndThrowOnFailure(suite());
}
public static junit.framework.Test suite() {
return new junit.framework.TestSuite(IfPointcutTest.class);
}
@Aspect
public static class TestAspect {
public boolean positive(int i) {
return (i>=0);
}
@Pointcut("args(i) && if(i>0)")
void ifPc(int i) {}
@Before("execution(* ataspectj.IfPointcutTest.hello(int)) && ifPc(i)")
void before(int i) {
System.out.println("IfPointcutTest$TestAspect.before");
}
}
}
/*******************************************************************************
* Copyright (c) Jonas Bonér, Alexandre Vasseur
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*******************************************************************************/
package ataspectj;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import junit.framework.TestCase;
import org.aspectj.lang.annotation.Aspect;
/**
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
public class IfPointcutTest extends TestCase {
static StringBuffer s_log = new StringBuffer();
static void log(String s) {
s_log.append(s).append(" ");
}
public void hello(int i) {
System.out.println("IfPointcutTest.hello " + i);
}
public void testIf() {
IfPointcutTest me = new IfPointcutTest();
me.hello(1);
me.hello(-1);
}
public static void main(String[] args) {
TestHelper.runAndThrowOnFailure(suite());
}
public static junit.framework.Test suite() {
return new junit.framework.TestSuite(IfPointcutTest.class);
}
@Aspect
public static class TestAspect {
public boolean positive(int i) {
return (i>=0);
}
@Pointcut("args(i) && if(i>0)")
void ifPc(int i) {}
@Before("execution(* ataspectj.IfPointcutTest.hello(int)) && ifPc(i)")
void before(int i) {
System.out.println("IfPointcutTest$TestAspect.before");
}
}
}

+ 122
- 122
tests/java5/ataspectj/ataspectj/PerClauseTest.java Wyświetl plik

@@ -1,122 +1,122 @@
/*******************************************************************************
* Copyright (c) Jonas Bonér, Alexandre Vasseur
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*******************************************************************************/
package ataspectj;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Aspects;
import org.aspectj.lang.NoAspectBoundException;
import junit.framework.TestCase;
/**
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
public class PerClauseTest extends TestCase {
static StringBuffer s_log = new StringBuffer();
static void log(String s) {
s_log.append(s).append(" ");
}
public static void main(String[] args) {
TestHelper.runAndThrowOnFailure(suite());
}
public static junit.framework.Test suite() {
return new junit.framework.TestSuite(AfterXTest.class);
}
public void perTarget() {
log("perTarget");
}
public void testPerTarget() {
s_log = new StringBuffer();
perTarget();
assertEquals("AOP.perTarget perTarget ", s_log.toString());
// singleton
try {
Aspects.aspectOf(TestAspectPerTarget.class);
fail("should fail with NOABE");
} catch (NoAspectBoundException e) {
;//ok
}
// this per
try {
TestAspectPerTarget aspect = (TestAspectPerTarget) Aspects.aspectOf(TestAspectPerTarget.class, this);
assertNotNull(aspect);
} catch (NoAspectBoundException e) {
fail(e.toString());
}
// another per
PerClauseTest me = new PerClauseTest();
try {
Aspects.aspectOf(TestAspectPerTarget.class, me);
fail("should fail");
} catch (NoAspectBoundException e) {
;//ok
}
me.perTarget();
try {
TestAspectPerTarget aspect = (TestAspectPerTarget) Aspects.aspectOf(TestAspectPerTarget.class, me);
assertNotNull(aspect);
} catch (NoAspectBoundException e) {
fail(e.toString());
}
}
@Aspect("pertarget(execution(* ataspectj.PerClauseTest.perTarget()))")
public static class TestAspectPerTarget {
public TestAspectPerTarget() {
;
}
@Before("execution(* ataspectj.PerClauseTest.perTarget()) && target(t)")
public void before(JoinPoint jp, Object t) {
log("AOP."+jp.getSignature().getName());
assertTrue("perX match", this.equals(Aspects.aspectOf(getClass(), t)));
}
}
public void perCflowEntry() {
perCflow();
}
public void perCflow() {
log("perCflow");
}
public void testPerCflow() {
s_log = new StringBuffer();
perCflow();
assertEquals("perCflow ", s_log.toString());
s_log = new StringBuffer();
perCflowEntry();
assertEquals("AOP.perCflow perCflow ", s_log.toString());
}
@Aspect("percflow(execution(* ataspectj.PerClauseTest.perCflowEntry()))")
public static class TestAspectPerCflow {
public TestAspectPerCflow() {
;
}
@Before("execution(* ataspectj.PerClauseTest.perCflow())")
public void before(JoinPoint jp) {
log("AOP."+jp.getSignature().getName());
assertTrue("perX match", this.equals(Aspects.aspectOf(getClass(), Thread.currentThread())));
}
}
}
/*******************************************************************************
* Copyright (c) Jonas Bonér, Alexandre Vasseur
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*******************************************************************************/
package ataspectj;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Aspects;
import org.aspectj.lang.NoAspectBoundException;
import junit.framework.TestCase;
/**
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
public class PerClauseTest extends TestCase {
static StringBuffer s_log = new StringBuffer();
static void log(String s) {
s_log.append(s).append(" ");
}
public static void main(String[] args) {
TestHelper.runAndThrowOnFailure(suite());
}
public static junit.framework.Test suite() {
return new junit.framework.TestSuite(AfterXTest.class);
}
public void perTarget() {
log("perTarget");
}
public void testPerTarget() {
s_log = new StringBuffer();
perTarget();
assertEquals("AOP.perTarget perTarget ", s_log.toString());
// singleton
try {
Aspects.aspectOf(TestAspectPerTarget.class);
fail("should fail with NOABE");
} catch (NoAspectBoundException e) {
;//ok
}
// this per
try {
TestAspectPerTarget aspect = (TestAspectPerTarget) Aspects.aspectOf(TestAspectPerTarget.class, this);
assertNotNull(aspect);
} catch (NoAspectBoundException e) {
fail(e.toString());
}
// another per
PerClauseTest me = new PerClauseTest();
try {
Aspects.aspectOf(TestAspectPerTarget.class, me);
fail("should fail");
} catch (NoAspectBoundException e) {
;//ok
}
me.perTarget();
try {
TestAspectPerTarget aspect = (TestAspectPerTarget) Aspects.aspectOf(TestAspectPerTarget.class, me);
assertNotNull(aspect);
} catch (NoAspectBoundException e) {
fail(e.toString());
}
}
@Aspect("pertarget(execution(* ataspectj.PerClauseTest.perTarget()))")
public static class TestAspectPerTarget {
public TestAspectPerTarget() {
;
}
@Before("execution(* ataspectj.PerClauseTest.perTarget()) && target(t)")
public void before(JoinPoint jp, Object t) {
log("AOP."+jp.getSignature().getName());
assertTrue("perX match", this.equals(Aspects.aspectOf(getClass(), t)));
}
}
public void perCflowEntry() {
perCflow();
}
public void perCflow() {
log("perCflow");
}
public void testPerCflow() {
s_log = new StringBuffer();
perCflow();
assertEquals("perCflow ", s_log.toString());
s_log = new StringBuffer();
perCflowEntry();
assertEquals("AOP.perCflow perCflow ", s_log.toString());
}
@Aspect("percflow(execution(* ataspectj.PerClauseTest.perCflowEntry()))")
public static class TestAspectPerCflow {
public TestAspectPerCflow() {
;
}
@Before("execution(* ataspectj.PerClauseTest.perCflow())")
public void before(JoinPoint jp) {
log("AOP."+jp.getSignature().getName());
assertTrue("perX match", this.equals(Aspects.aspectOf(getClass(), Thread.currentThread())));
}
}
}

+ 98
- 98
tests/java5/ataspectj/ataspectj/PointcutReferenceTest.java Wyświetl plik

@@ -1,98 +1,98 @@
/*******************************************************************************
* Copyright (c) Jonas Bonér, Alexandre Vasseur
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*******************************************************************************/
package ataspectj;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.JoinPoint;
import org.aspectj.runtime.internal.CFlowCounter;
import junit.framework.TestCase;
/**
* Test pointcut reference without binding
*
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
public class PointcutReferenceTest extends TestCase {
static StringBuffer s_log = new StringBuffer();
static void log(String s) {
s_log.append(s).append(" ");
}
public static void main(String[] args) {
TestHelper.runAndThrowOnFailure(suite());
}
public static junit.framework.Test suite() {
return new junit.framework.TestSuite(PointcutReferenceTest.class);
}
public void hello() {
log("hello");
}
public void helloWithRef() {
log("helloWithRef");
}
public void testPointcutReferenceNoBinding() {
PointcutReferenceTest me = new PointcutReferenceTest();
s_log = new StringBuffer();
me.hello();
assertEquals("before hello ", s_log.toString());
}
public void testPointcutReferenceBinding() {
PointcutReferenceTest me = new PointcutReferenceTest();
s_log = new StringBuffer();
me.helloWithRef();
assertEquals("beforeWithRef helloWithRef ", s_log.toString());
}
@Aspect
public static class TestAspect {
// order of pointcut in source code does not matter for pc refs
@Pointcut("execution(* ataspectj.PointcutReferenceTest.hello(..))")
void pcRef() {}
@Pointcut("pcRef()")
void pcRef2() {}
@Before("pcRef2()")
public void before(JoinPoint jp) {
log("before");
}
// see here outer aspect reference
@Pointcut("execution(* ataspectj.PointcutReferenceTest.helloWithRef(..))" +
" && ataspectj.PointcutReferenceTest.RefAspect.pcRefObjectBinding(t)")
void pcRefBinding(Object t) {}
@Before("pcRefBinding(ttt)")
public void before(Object ttt, JoinPoint jp) {
log("beforeWithRef");
}
}
@Aspect
public static class RefAspect {
@Pointcut("this(obj)")
public void pcRefObjectBinding(PointcutReferenceTest obj) {}
}
}
/*******************************************************************************
* Copyright (c) Jonas Bonér, Alexandre Vasseur
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*******************************************************************************/
package ataspectj;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.JoinPoint;
import org.aspectj.runtime.internal.CFlowCounter;
import junit.framework.TestCase;
/**
* Test pointcut reference without binding
*
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
public class PointcutReferenceTest extends TestCase {
static StringBuffer s_log = new StringBuffer();
static void log(String s) {
s_log.append(s).append(" ");
}
public static void main(String[] args) {
TestHelper.runAndThrowOnFailure(suite());
}
public static junit.framework.Test suite() {
return new junit.framework.TestSuite(PointcutReferenceTest.class);
}
public void hello() {
log("hello");
}
public void helloWithRef() {
log("helloWithRef");
}
public void testPointcutReferenceNoBinding() {
PointcutReferenceTest me = new PointcutReferenceTest();
s_log = new StringBuffer();
me.hello();
assertEquals("before hello ", s_log.toString());
}
public void testPointcutReferenceBinding() {
PointcutReferenceTest me = new PointcutReferenceTest();
s_log = new StringBuffer();
me.helloWithRef();
assertEquals("beforeWithRef helloWithRef ", s_log.toString());
}
@Aspect
public static class TestAspect {
// order of pointcut in source code does not matter for pc refs
@Pointcut("execution(* ataspectj.PointcutReferenceTest.hello(..))")
void pcRef() {}
@Pointcut("pcRef()")
void pcRef2() {}
@Before("pcRef2()")
public void before(JoinPoint jp) {
log("before");
}
// see here outer aspect reference
@Pointcut("execution(* ataspectj.PointcutReferenceTest.helloWithRef(..))" +
" && ataspectj.PointcutReferenceTest.RefAspect.pcRefObjectBinding(t)")
void pcRefBinding(Object t) {}
@Before("pcRefBinding(ttt)")
public void before(Object ttt, JoinPoint jp) {
log("beforeWithRef");
}
}
@Aspect
public static class RefAspect {
@Pointcut("this(obj)")
public void pcRefObjectBinding(PointcutReferenceTest obj) {}
}
}

+ 75
- 75
tests/java5/ataspectj/ataspectj/PrecedenceTest.java Wyświetl plik

@@ -1,75 +1,75 @@
/*******************************************************************************
* Copyright (c) Jonas Bonér, Alexandre Vasseur
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*******************************************************************************/
package ataspectj;
import junit.framework.TestCase;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclarePrecedence;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
/**
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
public class PrecedenceTest extends TestCase {
static StringBuffer s_log = new StringBuffer();
static void log(String s) {
s_log.append(s).append(" ");
}
public static void main(String[] args) {
TestHelper.runAndThrowOnFailure(suite());
}
public static junit.framework.Test suite() {
return new junit.framework.TestSuite(PrecedenceTest.class);
}
public void hello() {
log("hello");
}
public void testPrecedence() {
s_log = new StringBuffer();
hello();
assertEquals("TestAspect_3 TestAspect_2 TestAspect_1 hello", s_log.toString());
}
@Aspect()
public static class TestAspect_1 {
@Before("execution(* ataspectj.PrecedenceTest.hello())")
void before() {
log("TestAspect_1");
}
}
@Aspect()
@DeclarePrecedence("ataspectj.PrecedenceTest.TestAspect_3, ataspectj.PrecedenceTest.TestAspect_1")
public static class TestAspect_2 {
@Before("execution(* ataspectj.PrecedenceTest.hello())")
void before() {
log("TestAspect_2");
}
}
@Aspect()
public static class TestAspect_3 {
@Before("execution(* ataspectj.PrecedenceTest.hello())")
void before() {
log("TestAspect_3");
}
}
@Aspect()
@DeclarePrecedence("ataspectj.PrecedenceTest.TestAspect_3, ataspectj.PrecedenceTest.TestAspect_2, ataspectj.PrecedenceTest.TestAspect_1, *")
public static class TestAspect_Order {
}
}
/*******************************************************************************
* Copyright (c) Jonas Bonér, Alexandre Vasseur
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*******************************************************************************/
package ataspectj;
import junit.framework.TestCase;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclarePrecedence;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
/**
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
public class PrecedenceTest extends TestCase {
static StringBuffer s_log = new StringBuffer();
static void log(String s) {
s_log.append(s).append(" ");
}
public static void main(String[] args) {
TestHelper.runAndThrowOnFailure(suite());
}
public static junit.framework.Test suite() {
return new junit.framework.TestSuite(PrecedenceTest.class);
}
public void hello() {
log("hello");
}
public void testPrecedence() {
s_log = new StringBuffer();
hello();
assertEquals("TestAspect_3 TestAspect_2 TestAspect_1 hello", s_log.toString());
}
@Aspect()
public static class TestAspect_1 {
@Before("execution(* ataspectj.PrecedenceTest.hello())")
void before() {
log("TestAspect_1");
}
}
@Aspect()
@DeclarePrecedence("ataspectj.PrecedenceTest.TestAspect_3, ataspectj.PrecedenceTest.TestAspect_1")
public static class TestAspect_2 {
@Before("execution(* ataspectj.PrecedenceTest.hello())")
void before() {
log("TestAspect_2");
}
}
@Aspect()
public static class TestAspect_3 {
@Before("execution(* ataspectj.PrecedenceTest.hello())")
void before() {
log("TestAspect_3");
}
}
@Aspect()
@DeclarePrecedence("ataspectj.PrecedenceTest.TestAspect_3, ataspectj.PrecedenceTest.TestAspect_2, ataspectj.PrecedenceTest.TestAspect_1, *")
public static class TestAspect_Order {
}
}

+ 135
- 135
tests/java5/ataspectj/ataspectj/SingletonAspectBindingsTest.java Wyświetl plik

@@ -1,135 +1,135 @@
/*******************************************************************************
* Copyright (c) Jonas Bonér, Alexandre Vasseur
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*******************************************************************************/
package ataspectj;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.DeclarePrecedence;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.runtime.internal.AroundClosure;
import junit.framework.TestCase;
/**
* Test various advice and JoinPoint + binding, without pc ref
*
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
public class SingletonAspectBindingsTest extends TestCase {
static StringBuffer s_log = new StringBuffer();
static void log(String s) {
s_log.append(s).append(" ");
}
public static void main(String[] args) {
TestHelper.runAndThrowOnFailure(suite());
}
public static junit.framework.Test suite() {
return new junit.framework.TestSuite(SingletonAspectBindingsTest.class);
}
public void hello() {
log("hello");
}
public void hello(String s) {
log("hello-");
log(s);
}
public void testExecutionWithThisBinding() {
s_log = new StringBuffer();
SingletonAspectBindingsTest me = new SingletonAspectBindingsTest();
me.hello();
// see here advice precedence as in source code order
//TODO check around relative order
// see fix in BcelWeaver sorting shadowMungerList
//assertEquals("around2_ around_ before hello after _around _around2 ", s_log.toString());
assertEquals("around_ around2_ before hello _around2 _around after ", s_log.toString());
}
public void testExecutionWithArgBinding() {
s_log = new StringBuffer();
SingletonAspectBindingsTest me = new SingletonAspectBindingsTest();
me.hello("x");
assertEquals("before- x hello- x ", s_log.toString());
}
@Aspect
public static class TestAspect {
static int s = 0;
static {
s++;
}
public TestAspect() {
// assert clinit has run when singleton aspectOf reaches that
assertTrue(s>0);
}
//public static TestAspect aspectOf() {return null;}
@Around("execution(* ataspectj.SingletonAspectBindingsTest.hello())")
public void aaround(ProceedingJoinPoint jp) {
log("around_");
try {
jp.proceed();
} catch (Throwable throwable) {
throwable.printStackTrace();
}
log("_around");
}
@Around("execution(* ataspectj.SingletonAspectBindingsTest.hello()) && this(t)")
public void around2(ProceedingJoinPoint jp, Object t) {
log("around2_");
assertEquals(SingletonAspectBindingsTest.class.getName(), t.getClass().getName());
try {
jp.proceed();
} catch (Throwable throwable) {
throwable.printStackTrace();
}
log("_around2");
}
@Before("execution(* ataspectj.SingletonAspectBindingsTest.hello())")
public void before(JoinPoint.StaticPart sjp) {
log("before");
assertEquals("hello", sjp.getSignature().getName());
}
@After("execution(* ataspectj.SingletonAspectBindingsTest.hello())")
public void after(JoinPoint.StaticPart sjp) {
log("after");
assertEquals("execution(public void ataspectj.SingletonAspectBindingsTest.hello())", sjp.toLongString());
}
//TODO see String alias, see before advice name clash - all that works
// 1/ String is in java.lang.* - see SimpleScope.javalangPrefix array
// 2/ the advice is register thru its Bcel Method mirror
@Before("execution(* ataspectj.SingletonAspectBindingsTest.hello(String)) && args(s)")
public void before(String s, JoinPoint.StaticPart sjp) {
log("before-");
log(s);
assertEquals("hello", sjp.getSignature().getName());
}
}
}
/*******************************************************************************
* Copyright (c) Jonas Bonér, Alexandre Vasseur
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*******************************************************************************/
package ataspectj;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.DeclarePrecedence;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.runtime.internal.AroundClosure;
import junit.framework.TestCase;
/**
* Test various advice and JoinPoint + binding, without pc ref
*
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
public class SingletonAspectBindingsTest extends TestCase {
static StringBuffer s_log = new StringBuffer();
static void log(String s) {
s_log.append(s).append(" ");
}
public static void main(String[] args) {
TestHelper.runAndThrowOnFailure(suite());
}
public static junit.framework.Test suite() {
return new junit.framework.TestSuite(SingletonAspectBindingsTest.class);
}
public void hello() {
log("hello");
}
public void hello(String s) {
log("hello-");
log(s);
}
public void testExecutionWithThisBinding() {
s_log = new StringBuffer();
SingletonAspectBindingsTest me = new SingletonAspectBindingsTest();
me.hello();
// see here advice precedence as in source code order
//TODO check around relative order
// see fix in BcelWeaver sorting shadowMungerList
//assertEquals("around2_ around_ before hello after _around _around2 ", s_log.toString());
assertEquals("around_ around2_ before hello _around2 _around after ", s_log.toString());
}
public void testExecutionWithArgBinding() {
s_log = new StringBuffer();
SingletonAspectBindingsTest me = new SingletonAspectBindingsTest();
me.hello("x");
assertEquals("before- x hello- x ", s_log.toString());
}
@Aspect
public static class TestAspect {
static int s = 0;
static {
s++;
}
public TestAspect() {
// assert clinit has run when singleton aspectOf reaches that
assertTrue(s>0);
}
//public static TestAspect aspectOf() {return null;}
@Around("execution(* ataspectj.SingletonAspectBindingsTest.hello())")
public void aaround(ProceedingJoinPoint jp) {
log("around_");
try {
jp.proceed();
} catch (Throwable throwable) {
throwable.printStackTrace();
}
log("_around");
}
@Around("execution(* ataspectj.SingletonAspectBindingsTest.hello()) && this(t)")
public void around2(ProceedingJoinPoint jp, Object t) {
log("around2_");
assertEquals(SingletonAspectBindingsTest.class.getName(), t.getClass().getName());
try {
jp.proceed();
} catch (Throwable throwable) {
throwable.printStackTrace();
}
log("_around2");
}
@Before("execution(* ataspectj.SingletonAspectBindingsTest.hello())")
public void before(JoinPoint.StaticPart sjp) {
log("before");
assertEquals("hello", sjp.getSignature().getName());
}
@After("execution(* ataspectj.SingletonAspectBindingsTest.hello())")
public void after(JoinPoint.StaticPart sjp) {
log("after");
assertEquals("execution(public void ataspectj.SingletonAspectBindingsTest.hello())", sjp.toLongString());
}
//TODO see String alias, see before advice name clash - all that works
// 1/ String is in java.lang.* - see SimpleScope.javalangPrefix array
// 2/ the advice is register thru its Bcel Method mirror
@Before("execution(* ataspectj.SingletonAspectBindingsTest.hello(String)) && args(s)")
public void before(String s, JoinPoint.StaticPart sjp) {
log("before-");
log(s);
assertEquals("hello", sjp.getSignature().getName());
}
}
}

+ 46
- 46
tests/java5/ataspectj/ataspectj/TestHelper.java Wyświetl plik

@@ -1,46 +1,46 @@
/*******************************************************************************
* Copyright (c) Jonas Bonér, Alexandre Vasseur
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*******************************************************************************/
package ataspectj;
import junit.textui.TestRunner;
import junit.framework.TestResult;
import java.util.Enumeration;
/**
* Helper to run a test as a main class, but still throw exception and not just print on stderr
* upon test failure.
* <p/>
* This is required for Ajc test case that are also designed to work with LTW.
*
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
public class TestHelper {
public static void runAndThrowOnFailure(junit.framework.Test test) {
TestRunner r = new TestRunner();
TestResult rr = r.doRun(test);
if (!rr.wasSuccessful()) {
StringBuffer sb = new StringBuffer("\n");
Enumeration e = rr.failures();
while (e.hasMoreElements()) {
sb.append("Failure: ");
sb.append(e.nextElement());
sb.append("\n");
}
e = rr.errors();
while (e.hasMoreElements()) {
sb.append("Error: ");
sb.append(e.nextElement());
sb.append("\n");
}
throw new RuntimeException(sb.toString());
}
}
}
/*******************************************************************************
* Copyright (c) Jonas Bonér, Alexandre Vasseur
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*******************************************************************************/
package ataspectj;
import junit.textui.TestRunner;
import junit.framework.TestResult;
import java.util.Enumeration;
/**
* Helper to run a test as a main class, but still throw exception and not just print on stderr
* upon test failure.
* <p/>
* This is required for Ajc test case that are also designed to work with LTW.
*
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
public class TestHelper {
public static void runAndThrowOnFailure(junit.framework.Test test) {
TestRunner r = new TestRunner();
TestResult rr = r.doRun(test);
if (!rr.wasSuccessful()) {
StringBuffer sb = new StringBuffer("\n");
Enumeration e = rr.failures();
while (e.hasMoreElements()) {
sb.append("Failure: ");
sb.append(e.nextElement());
sb.append("\n");
}
e = rr.errors();
while (e.hasMoreElements()) {
sb.append("Error: ");
sb.append(e.nextElement());
sb.append("\n");
}
throw new RuntimeException(sb.toString());
}
}
}

+ 107
- 107
tests/java5/ataspectj/ataspectj/XXJoinPointTest.java Wyświetl plik

@@ -1,107 +1,107 @@
/*******************************************************************************
* Copyright (c) Jonas Bonér, Alexandre Vasseur
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*******************************************************************************/
package ataspectj;
import junit.framework.TestCase;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.JoinPoint;
/**
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
public class XXJoinPointTest extends TestCase {
static StringBuffer s_log = new StringBuffer();
static void log(String s) {
s_log.append(s).append(" ");
}
public static void main(String[] args) {
TestHelper.runAndThrowOnFailure(suite());
}
public static junit.framework.Test suite() {
return new junit.framework.TestSuite(XXJoinPointTest.class);
}
public void hello() {
log("hello");
}
public void testJoinPointsInAdviceSignature() {
s_log = new StringBuffer();
XXJoinPointTest me = new XXJoinPointTest();
me.hello();
assertEquals("jp sjp esjp jp-sjp sjp-esjp sjp-jp-esjp esjp-jp-sjp hello ", s_log.toString());
}
@Aspect
public static class TestAspect {
@Pointcut("call(* ataspectj.XXJoinPointTest.hello()) && within(ataspectj.XXJoinPointTest)")
void pc() {}
@Before("pc()")
void before(JoinPoint jp) {
assertEquals("hello", jp.getSignature().getName());
log("jp");
}
@Before("pc()")
void before(JoinPoint.StaticPart sjp) {
assertEquals("hello", sjp.getSignature().getName());
log("sjp");
}
@Before("pc()")
void beforeEnclosing(JoinPoint.EnclosingStaticPart esjp) {
assertEquals("testJoinPointsInAdviceSignature", esjp.getSignature().getName());
log("esjp");
}
//weird order
@Before("pc()")
void beforeWEIRD1(JoinPoint jp, JoinPoint.StaticPart sjp) {
assertEquals("hello", jp.getSignature().getName());
assertEquals("hello", sjp.getSignature().getName());
log("jp-sjp");
}
@Before("pc()")
void before(JoinPoint.StaticPart sjp, JoinPoint.EnclosingStaticPart esjp) {
assertEquals("hello", sjp.getSignature().getName());
assertEquals("testJoinPointsInAdviceSignature", esjp.getSignature().getName());
log("sjp-esjp");
}
// conventional order
@Before("pc()")
void before(JoinPoint.StaticPart sjp, JoinPoint jp, JoinPoint.EnclosingStaticPart esjp) {
assertEquals("hello", sjp.getSignature().getName());
assertEquals("hello", jp.getSignature().getName());
assertEquals("testJoinPointsInAdviceSignature", esjp.getSignature().getName());
log("sjp-jp-esjp");
}
// weird order
@Before("pc()")
void beforeWEIRD2(JoinPoint.EnclosingStaticPart esjp, JoinPoint jp, JoinPoint.StaticPart sjp) {
assertEquals("testJoinPointsInAdviceSignature", esjp.getSignature().getName());
assertEquals("hello", jp.getSignature().getName());
assertEquals("hello", sjp.getSignature().getName());
log("esjp-jp-sjp");
}
}
}
/*******************************************************************************
* Copyright (c) Jonas Bonér, Alexandre Vasseur
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*******************************************************************************/
package ataspectj;
import junit.framework.TestCase;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.JoinPoint;
/**
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
public class XXJoinPointTest extends TestCase {
static StringBuffer s_log = new StringBuffer();
static void log(String s) {
s_log.append(s).append(" ");
}
public static void main(String[] args) {
TestHelper.runAndThrowOnFailure(suite());
}
public static junit.framework.Test suite() {
return new junit.framework.TestSuite(XXJoinPointTest.class);
}
public void hello() {
log("hello");
}
public void testJoinPointsInAdviceSignature() {
s_log = new StringBuffer();
XXJoinPointTest me = new XXJoinPointTest();
me.hello();
assertEquals("jp sjp esjp jp-sjp sjp-esjp sjp-jp-esjp esjp-jp-sjp hello ", s_log.toString());
}
@Aspect
public static class TestAspect {
@Pointcut("call(* ataspectj.XXJoinPointTest.hello()) && within(ataspectj.XXJoinPointTest)")
void pc() {}
@Before("pc()")
void before(JoinPoint jp) {
assertEquals("hello", jp.getSignature().getName());
log("jp");
}
@Before("pc()")
void before(JoinPoint.StaticPart sjp) {
assertEquals("hello", sjp.getSignature().getName());
log("sjp");
}
@Before("pc()")
void beforeEnclosing(JoinPoint.EnclosingStaticPart esjp) {
assertEquals("testJoinPointsInAdviceSignature", esjp.getSignature().getName());
log("esjp");
}
//weird order
@Before("pc()")
void beforeWEIRD1(JoinPoint jp, JoinPoint.StaticPart sjp) {
assertEquals("hello", jp.getSignature().getName());
assertEquals("hello", sjp.getSignature().getName());
log("jp-sjp");
}
@Before("pc()")
void before(JoinPoint.StaticPart sjp, JoinPoint.EnclosingStaticPart esjp) {
assertEquals("hello", sjp.getSignature().getName());
assertEquals("testJoinPointsInAdviceSignature", esjp.getSignature().getName());
log("sjp-esjp");
}
// conventional order
@Before("pc()")
void before(JoinPoint.StaticPart sjp, JoinPoint jp, JoinPoint.EnclosingStaticPart esjp) {
assertEquals("hello", sjp.getSignature().getName());
assertEquals("hello", jp.getSignature().getName());
assertEquals("testJoinPointsInAdviceSignature", esjp.getSignature().getName());
log("sjp-jp-esjp");
}
// weird order
@Before("pc()")
void beforeWEIRD2(JoinPoint.EnclosingStaticPart esjp, JoinPoint jp, JoinPoint.StaticPart sjp) {
assertEquals("testJoinPointsInAdviceSignature", esjp.getSignature().getName());
assertEquals("hello", jp.getSignature().getName());
assertEquals("hello", sjp.getSignature().getName());
log("esjp-jp-sjp");
}
}
}

Ładowanie…
Anuluj
Zapisz