Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] Testing advice blocks using reflection, a tool users perspective question

Hmm, further thoughts on this have led me to source level meta-data - basically J2SE 5 annotations.

What about a solution like:

If a test developer wishes to test an advice block she adds a "standard" aUnit annotation to the block with a unique name as the only parameter so that the advice block can be identified. Then in the actual test code the advice can be invoked by meta name.

If aUnit is to be used with an earlier version of Java then numerical, source code ordering dependant route could be taken instead?

Thoughts?

Cheers,

Russ

On 12 Jan 2005, at 14:03, Russell Miles wrote:

Hi everyone,

I've hit an issue with how to invoke advice usefully from the unit test method bodies in aUnit. What makes the most sense when it comes to invoking the methods? How do we identify, by name, a specific advice block that uses a different, or the same, set of pointcuts? Don't want to tie this to source code ordering if possible. The problem is:

If I have an aspect such as:

public aspect BeforeAdviceExampleAspect
{
before() : within(BeforeAdviceExampleAspect) && !within(BeforeAdviceExampleAspect)
   {
      System.out.println("Executing Before Advice");
   }

before() : within(BeforeAdviceExampleAspect) && !within(BeforeAdviceExampleAspect)
   {
      System.out.println("Executing Second Before Advice");
   }

   public void callMethod()
   {
      System.out.println("Called method on before advice");
   }
}

Both advice blocks will select the same join point and their signatures using un-enhanced AspectJ/Java reflection are:

Advice block found: public void aunit.tests.usecases.BeforeAdviceExampleAspect.ajc$before$aunit_tests_u secases_BeforeAdviceExampleAspect$1$999acf7c()
Executing Before Advice

Advice block found: public void aunit.tests.usecases.BeforeAdviceExampleAspect.ajc$before$aunit_tests_u secases_BeforeAdviceExampleAspect$2$999acf7c()
Executing Second Before Advice

So, the ordering seems to be given by the $1 or $2 part of the name. But apart from that there is no way to tell the advice blocks apart. After reversing the order of the advice in the source aspect the results looks like:

Advice block found: public void aunit.tests.usecases.BeforeAdviceExampleAspect.ajc$before$aunit_tests_u secases_BeforeAdviceExampleAspect$1$999acf7c()
Executing Second Before Advice

Advice block found: public void aunit.tests.usecases.BeforeAdviceExampleAspect.ajc$before$aunit_tests_u secases_BeforeAdviceExampleAspect$2$999acf7c()
Executing Before Advice

This proves to me that the $1 and $2 are source code location dependant; makes sense really. But this doesn't help in trying to understand how developers could easily specify that they are testing a particular piece of advice using regular Java syntax.

Any suggestions from the community?

Cheers,

Russ

_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-dev



Back to the top