0

I'm writing the canonical execution time logging aspect, and I would like to test my pointcut expression.

More clearly, suppose I have the following pointcut expression in an aspect

@Around("within(@org.springframework.stereotype.Service *)") public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable { // ... } 

How can I make sure that my aspect will correctly be triggered in a test without writing an additionnal "test aspect"?

To say it otherwise, given this service class

@Service public class VisitService { VisitRepository repository; public VisitService(VisitRepository repository) { super(); this.repository = repository; } public Visit findByReferenceNumber() { return repository.findByReferenceNumber(); } } 

Is there some "Spring code" able to tell me which methods will be decorated with the logAround(...) method?

5
  • There is too little context and no code whatsoever here. What are you trying to do? Verify that Spring AOP works correctly? The AspectJ pointcut matcher used by Spring AOP is pretty well covered by tests. Or that you application works correctly? Or maybe, you want to unit-test your aspect? Commented Apr 5 at 5:35
  • @kriegaex I've added an example Commented Apr 9 at 18:22
  • You have 22k reputation and should know how to ask a question on SO and provide a minimal, complete, and verifiable example. The code fragment is too little, your question is totally unclear. If you are too busy or too lazy to provide an MCVE and clearly explain what you want to achieve and what kind of test you have in mind, I do not feel inclined to speculate and probably guess wrong anyway. You need to help me to help you. Commented Apr 10 at 7:29
  • @kriegaex I've extended the code. Commented Nov 17 at 13:14
  • That still is no MCVE. What are you trying to achieve? Are you trying to test that Spring AOP actually works? If you are trying to test the aspect, how about not a test aspect but a test service? If you are trying to write an automated test, you should write both a unit and an integration test, as usual. I answered some questions about how to test aspects here. I can send you links after I will have understood what you want to do. Commented Nov 18 at 8:11

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.