public void testParseFromHTTPResponseWithCustomParams()
throws Exception {
HTTPResponse httpResponse = new HTTPResponse(HTTPResponse.SC_OK);
httpResponse.setContentType(CommonContentTypes.APPLICATION_JSON);
httpResponse.setCacheControl("no-store");
httpResponse.setPragma("no-cache");
JSONObject o = new JSONObject();
final String accessTokenString = "SlAV32hkKG";
o.put("access_token", accessTokenString);
o.put("token_type", "Bearer");
final String refreshTokenString = "8xLOxBtZp8";
o.put("refresh_token", refreshTokenString);
final long exp = 3600;
o.put("expires_in", exp);
o.put("sub_sid", "abc");
o.put("priority", 10);
httpResponse.setContent(o.toString());
AccessTokenResponse atr = AccessTokenResponse.parse(httpResponse);
AccessToken accessToken = atr.getAccessToken();
assertEquals(accessTokenString, accessToken.getValue());
assertEquals(exp, accessToken.getLifetime());
assertNull(accessToken.getScope());
RefreshToken refreshToken = atr.getRefreshToken();
assertEquals(refreshTokenString, refreshToken.getValue());
// Custom param
assertEquals("abc", (String)atr.getCustomParams().get("sub_sid"));
assertEquals(10, ((Number)atr.getCustomParams().get("priority")).intValue());
assertEquals(2, atr.getCustomParams().size());
// Test pair getter
TokenPair pair = atr.getTokenPair();
assertEquals(accessToken, pair.getAccessToken());
assertEquals(refreshToken, pair.getRefreshToken());
httpResponse = atr.toHTTPResponse();
assertEquals(CommonContentTypes.APPLICATION_JSON, httpResponse.getContentType());
assertEquals("no-store", httpResponse.getCacheControl());
assertEquals("no-cache", httpResponse.getPragma());
o = httpResponse.getContentAsJSONObject();
assertEquals(accessTokenString, o.get("access_token"));
assertEquals("Bearer", o.get("token_type"));
assertEquals(refreshTokenString, o.get("refresh_token"));
assertEquals(3600l, o.get("expires_in"));