1

我有以下控制器定义:

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());

我该如何解决?

4

0 回答 0