From c7cacbbe65f4371054afa6ab32c022c02cc60f3f Mon Sep 17 00:00:00 2001 From: Aishwarya Gosavi <aishgosavi@gmail.com> Date: Sun, 22 Apr 2018 18:42:42 -0400 Subject: [PATCH] Update TestDefaultIntrospectionResultAssembler.java Hi Justin, I am trying to throw a ParseException where the actual value and expected value are not equal for the expiration parameters. I am trying to test the catch block. I have used the same parameters which are already used in other test cases in the same file. Can you please guide me on how to approach catch case in this particular scenario, I have already tried but I am not sure this is the right way. Thank you --- ...stDefaultIntrospectionResultAssembler.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java index 141eb9aa4..d8d072798 100644 --- a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java +++ b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java @@ -304,16 +304,32 @@ public class TestDefaultIntrospectionResultAssembler { assertThat(result, is(equalTo(expected))); } - @Test(expected = ParseException.class) - public void testAssembleFrom_refresh() { + @Test(expected=ParseException.class) + public void testAssembleFrom_OAuth2AccessTokenEntityExpiration() { + + // given + OAuth2AccessTokenEntity accessToken = accessToken(null, scopes("foo", "bar"), null, "Bearer", + oauth2AuthenticationWithUser(oauth2Request("clientId"), "name")); - OAuth2RefreshTokenEntity refreshToken = refreshToken(null, - oauth2AuthenticationWithUser(oauth2Request("clientId", scopes("foo", "bar")), "name")); + UserInfo userInfo = userInfo("sub"); Set<String> authScopes = scopes("foo", "bar", "baz"); - // this should fail with an error - assembler.assembleFrom(refreshToken, null , authScopes); + // when + Map<String, Object> result = assembler.assembleFrom(accessToken, userInfo, authScopes); + + + // then + Map<String, Object> expected = new ImmutableMap.Builder<String, Object>() + .put("sub", "sub") + .put("scope", "bar foo") + .put("active", Boolean.TRUE) + .put("user_id", "name") + .put("client_id", "clientId") + .put("token_type", "Bearer") + .build(); + + assertThat(result, is(not(equalTo(expected)))); } private UserInfo userInfo(String sub) {