Question

I'm totally new in AOP world.

After reading some books(ex, spring in action), I have a basic question for AOP -- How can we ensure AOP is still working or not working in existing system especially when the system is changing.

You know in real world, especially when the program is still under implementation, the design is always changing. It might be the big program structure changing, might be the refactor. In a word, the program is always changing.

However, the way we adopt AOP in our program is depend on the implementation detail. (ex, the public/private method name) If the implementation detail is changed, possibly the AOP will not work. What's worse, if we're working in a big team, possibly someone will change some implementation detail on which AOP depends, but he is not aware at all. Then the big question is how we can know the AOP is not working in such case? Is there any compilation guarantee or at least junit case guarantee?

Thanks a lot for answer.

Was it helpful?

Solution

This can be tested with Junit and spring-test, a Junit test class can be written that get's injected with an object from the layer at which your aspect is being applied and mock the layer beneath it.

Then call the object to which the aspect is applied and assert that the results are as expected.

This is an example of how to test if method security (applied via aspects) is working. The test confirms that an AccessDeniedException is thrown as expected, proving that the aspect is working.

Other aspects could be tested in a similar way using spring-test and mocks.

OTHER TIPS

The only way to really test this is with some automated testing, otherwise, as you have pointed out, people could change implementation detail and break the existing AOP. Spring provides integration testing support that will load the beans from your contianer (and also load your AOP). http://docs.spring.io/spring/docs/3.0.0.M3/reference/html/ch10s03.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top