OAuth1aService extends OAuthService { public static OAuthResponse parseAuthResponse(String response) { final TreeMap<String, String> params = UrlUtils.getQueryParams(response, false); final String token = params.get(OAuthConstants.PARAM_TOKEN); final String secret = params.get(OAuthConstants.PARAM_TOKEN_SECRET); final String userName = params.get(PARAM_SCREEN_NAME); final long userId; if (params.containsKey(PARAM_USER_ID)) { userId = Long.parseLong(params.get(PARAM_USER_ID)); } else { userId = 0L; } if (token == null || secret == null) { return null; } else { return new OAuthResponse(new TwitterAuthToken(token, secret), userName, userId); } } OAuth1aService(TwitterCore twitterCore, TwitterApi api); void requestTempToken(final Callback<OAuthResponse> callback); String buildCallbackUrl(TwitterAuthConfig authConfig); void requestAccessToken(final Callback<OAuthResponse> callback,
            TwitterAuthToken requestToken, String verifier); String getAuthorizeUrl(TwitterAuthToken requestToken); static OAuthResponse parseAuthResponse(String response);  }
@Test public void testParseAuthResponse() { final String response = "oauth_token=7588892-kagSNqWge8gB1WwE3plnFsJHAZVfxWD7Vb57p0b4&" + "oauth_token_secret=PbKfYqSryyeKDWz4ebtY3o5ogNLG11WJuZBc9fQrQo&" + "screen_name=test&user_id=1"; final OAuthResponse authResponse = OAuth1aService.parseAuthResponse(response); assertEquals("7588892-kagSNqWge8gB1WwE3plnFsJHAZVfxWD7Vb57p0b4", authResponse.authToken.token); assertEquals("PbKfYqSryyeKDWz4ebtY3o5ogNLG11WJuZBc9fQrQo", authResponse.authToken.secret); assertEquals("test", authResponse.userName); assertEquals(1L, authResponse.userId); }
@Test public void testParseAuthResponse_noQueryParameters() { final String response = "noQueryParameters"; final OAuthResponse authResponse = OAuth1aService.parseAuthResponse(response); assertNull(authResponse); }
@Test public void testParseAuthResponse_noToken() { final String response = "oauth_token_secret=PbKfYqSryyeKDWz4ebtY3o5ogNLG11WJuZBc9fQrQo&" + "screen_name=test&user_id=1"; final OAuthResponse authResponse = OAuth1aService.parseAuthResponse(response); assertNull(authResponse); }
@Test public void testParseAuthResponse_noSecret() { final String response = "oauth_token=7588892-kagSNqWge8gB1WwE3plnFsJHAZVfxWD7Vb57p0b4&" + "screen_name=test&user_id=1"; final OAuthResponse authResponse = OAuth1aService.parseAuthResponse(response); assertNull(authResponse); }
@Test public void testParseAuthResponse_noScreenName() { final String response = "oauth_token=7588892-kagSNqWge8gB1WwE3plnFsJHAZVfxWD7Vb57p0b4&" + "oauth_token_secret=PbKfYqSryyeKDWz4ebtY3o5ogNLG11WJuZBc9fQrQo&" + "user_id=1"; final OAuthResponse authResponse = OAuth1aService.parseAuthResponse(response); assertEquals("7588892-kagSNqWge8gB1WwE3plnFsJHAZVfxWD7Vb57p0b4", authResponse.authToken.token); assertEquals("PbKfYqSryyeKDWz4ebtY3o5ogNLG11WJuZBc9fQrQo", authResponse.authToken.secret); assertNull(authResponse.userName); assertEquals(1L, authResponse.userId); }
@Test public void testParseAuthResponse_noUserId() { final String response = "oauth_token=7588892-kagSNqWge8gB1WwE3plnFsJHAZVfxWD7Vb57p0b4&" + "oauth_token_secret=PbKfYqSryyeKDWz4ebtY3o5ogNLG11WJuZBc9fQrQo&" + "screen_name=test"; final OAuthResponse authResponse = OAuth1aService.parseAuthResponse(response); assertEquals("7588892-kagSNqWge8gB1WwE3plnFsJHAZVfxWD7Vb57p0b4", authResponse.authToken.token); assertEquals("PbKfYqSryyeKDWz4ebtY3o5ogNLG11WJuZBc9fQrQo", authResponse.authToken.secret); assertEquals("test", authResponse.userName); assertEquals(0L, authResponse.userId); }