Skip to content
Advertisement

Testing @PreAuthorize annotation with hasAuthority()

I am trying to unit test my apis that have @PreAuthorize annotation. I am getting the cognito groups from the Jwt and using them as authorities. I check the same in the preauthorize annotation in the api methods. UPDATE: I get the 404 No mapping Delete profile/VOlUc3F5A_test.txt exists

Test class:

JavaScript

Controller method:

JavaScript

Advertisement

Answer

The error message states that this.mockMvc is null. In the code that you have shared, you are not initializing this.mockMvc anywhere.

Perhaps you mean to autowire it

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement