2

I'm trying to do an integration test. These are my components:

UsersService

@ManageSession
public List<T> get() {
    //...
    return something;
}

ManageSessionAspect

@Autowired
AuthService authService;

@Before("manageSessionMethod()") //methods annotated with @ManageSession
public void doSomething() {
    authService.doSomething();
}

I need to test UsersService.get() method. But I want to disable the aspect OR I want to be able to mock the AuthService inside it.

I have tried using an is() pointcut, but I get:

if() pointcut designator isn't supported by Spring.

Can you help me? Thanks.

cb4
  • 6,689
  • 7
  • 45
  • 57
Héctor
  • 24,444
  • 35
  • 132
  • 243

1 Answers1

1

This is a perfect use case for spring profiles. You can define profiles and tie your configuration classes to these profiles. A configuration tied to a profile will only get activated if the profile is active. See my answer on a related question for further details: A: How to mock bean and avoiding NoUniqueBeanDefinitionException. You will need to define a profile (eg.: test or integration-test) and use that profile in a configuration class to provide a mock implementation for your AuthService.

As a side note, I would strongly suggest you go with AspectJ (preferably compile-time weaving) instead of Spring AOP as it's much more powerful.

Community
  • 1
  • 1
Nándor Előd Fekete
  • 6,988
  • 1
  • 22
  • 47