次のコントローラー定義があります。
public ResponseEntity switch(@PathVariable UUID userId, OAuth2Authentication authentication) { .. }
authentication
オブジェクトは自動的に注入され、すべて問題ありません。しかし、Spring の mvc テストフレームワークを使用してテストしたい場合は、次のようになります。
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]
テストは次のとおりです。
mvc.perform(post("/switch/" + USER.getUuid())
.principal(new TestingAuthenticationToken(clientId, secret, authorities))
.andExpect(status().isOk())
.andDo(MockMvcResultHandlers.print());
どうすれば解決できますか?