AuthTokenManager implements TokenManager { @Override public void grantToken() { MultivaluedMap<String, String> mvm = new CaseInsensitiveMap<String>(); mvm.putSingle(OAuth2Constants.GRANT_TYPE, "password"); mvm.putSingle("username", config.getUsername()); mvm.putSingle("password", config.getPassword()); consumeGrantTokenService(mvm); } AuthTokenManager(AuthSettings config); @Override void grantToken(); @Override String getAccessTokenString(); @Override String getRealm();  }
@Test public void testGrantToken() throws Exception { when(response.getExpiresIn()).thenReturn(1000l); this.tokenManager.grantToken(); ArgumentCaptor<MultivaluedMap> mapCaptor = ArgumentCaptor.forClass(MultivaluedMap.class); verify(this.tokenService, times(1)).grantToken(eq("realm1"), anyString(), mapCaptor.capture()); MultivaluedMap<String, String> mvm = mapCaptor.getValue(); Assert.assertEquals("user1", mvm.get("username").get(0)); Assert.assertEquals("password1", mvm.get("password").get(0)); }
@Test public void testGrantPublicToken() throws Exception { when(response.getExpiresIn()).thenReturn(1000l); when(config.isPublicClient()).thenReturn(true); this.tokenManager.grantToken(); ArgumentCaptor<MultivaluedMap> mapCaptor = ArgumentCaptor.forClass(MultivaluedMap.class); verify(this.tokenService, times(1)).grantToken(eq("realm1"), anyString(), mapCaptor.capture()); MultivaluedMap<String, String> mvm = mapCaptor.getValue(); Assert.assertEquals("password", mvm.get(OAuth2Constants.GRANT_TYPE).get(0)); Assert.assertEquals("user1", mvm.get("username").get(0)); Assert.assertEquals("password1", mvm.get("password").get(0)); Assert.assertEquals("clientId1", mvm.get(OAuth2Constants.CLIENT_ID).get(0)); }
@Test(expected = RuntimeException.class) public void testClientError() throws Exception { ResteasyClientException exception = mock(ResteasyClientException.class); doThrow(exception).when(tokenService).grantToken(anyString(), anyString(), any(MultivaluedMap.class)); when(response.getExpiresIn()).thenReturn(1000l); when(config.isPublicClient()).thenReturn(true); this.tokenManager.grantToken(); Assert.assertNull(this.tokenManager.accessTokenResponse); }