@Test public void setClientCredentialsTokenResponseClientWhenClientIsNullThenThrowIllegalArgumentException() { assertThatThrownBy(() -> this.argumentResolver.setClientCredentialsTokenResponseClient(null)) .isInstanceOf(IllegalArgumentException.class); }
@SuppressWarnings("unchecked") @Test public void resolveArgumentWhenAuthorizedClientNotFoundForClientCredentialsClientThenResolvesFromTokenResponseClient() throws Exception { OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> clientCredentialsTokenResponseClient = mock(OAuth2AccessTokenResponseClient.class); this.argumentResolver.setClientCredentialsTokenResponseClient(clientCredentialsTokenResponseClient); OAuth2AccessTokenResponse accessTokenResponse = OAuth2AccessTokenResponse .withToken("access-token-1234") .tokenType(OAuth2AccessToken.TokenType.BEARER) .expiresIn(3600) .build(); when(clientCredentialsTokenResponseClient.getTokenResponse(any())).thenReturn(accessTokenResponse); when(this.authorizedClientRepository.loadAuthorizedClient(anyString(), any(), any(HttpServletRequest.class))) .thenReturn(null); MethodParameter methodParameter = this.getMethodParameter("clientCredentialsClient", OAuth2AuthorizedClient.class); OAuth2AuthorizedClient authorizedClient = (OAuth2AuthorizedClient) this.argumentResolver.resolveArgument( methodParameter, null, new ServletWebRequest(this.request), null); assertThat(authorizedClient).isNotNull(); assertThat(authorizedClient.getClientRegistration()).isSameAs(this.registration2); assertThat(authorizedClient.getPrincipalName()).isEqualTo(this.principalName); assertThat(authorizedClient.getAccessToken()).isSameAs(accessTokenResponse.getAccessToken()); verify(this.authorizedClientRepository).saveAuthorizedClient( eq(authorizedClient), eq(this.authentication), any(HttpServletRequest.class), eq(null)); }