Search code examples
springjhipsteraopspring-aop

Jhipster Custom Annotation testing not working


So basically I create a simple monolith application and create custom annotations handled using Spring's AOP module.

Issue: Annotations were not being triggered in jhipster's generated integration tests for Controller classes/beans.

But it was working for service classes.


Solution

  • Cause: These types of cases occur when the target of the annotation and the aspect exist in different application contexts and are not able to interact with each other.

    Specifically for jhipster. This occured because the mock mvc created was a minimal one which only initialized a few classes/beans related to the entity for which the tests were generated.

    The solution came with creating the mockMvc with the below code.

    import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
    

    and this in setup

    mockMvc = webAppContextSetup(webApplicationContext).build();