I have the following controller definition:
public ResponseEntity switch(@PathVariable UUID userId, OAuth2Authentication authentication) { .. }
authentication
object injected automatically, everything is fine. But once I want to test is with spring's mvc test framework I get:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: argument type mismatch
Method [public org.springframework.http.ResponseEntity com.oauth.controller.SwitchController.switch(java.util.UUID,org.springframework.security.oauth2.provider.OAuth2Authentication)]
Resolved arguments:
[0] [type=java.util.UUID] [value=73e76822-a9d7-4ead-b876-7a4e6fced77f]
[1] [type=org.springframework.security.authentication.TestingAuthenticationToken] [value=org.springframework.security.authentication.TestingAuthenticationToken@a421525e: Principal: CLIENT; Credentials: [PROTECTED]; Authenticated: true; Details: null; Granted Authorities: ROLE_USER]
and test is:
mvc.perform(post("/switch/" + USER.getUuid())
.principal(new TestingAuthenticationToken(clientId, secret, authorities))
.andExpect(status().isOk())
.andDo(MockMvcResultHandlers.print());
How can I solve it?