@Test(expectedExceptions = ConnectionException.class) public void testMigrateInvalidResponse() throws Exception { ObjectWriter writer = mapper.writerFor(OAuthMigrationResponse.class); Response mockResponse = new Response( IOUtils.toInputStream(writer.writeValueAsString(new OAuthMigrationResponse()), StandardCharsets.UTF_8), 500, intuit_tid); mockedHttpRequestClient.setMockResponse(mockResponse); OAuthMigrationResponse actualOAuthMigrationResponse = oAuth2MigrationClient.migrate(); }
public OAuthMigrationResponse migrate() throws ConnectionException { logger.debug("Enter OAuthMigrationClient::migrate"); try { HttpRequestClient client = new HttpRequestClient(oAuthMigrationRequest.getOauth2config().getProxyConfig()); String requestjson = new JSONObject().put("scope", getScopeValue(oAuthMigrationRequest.getScope())) .put("redirect_uri", getRedirectUrl() ) .put("client_id", oAuthMigrationRequest.getOauth2config().getClientId()) .put("client_secret",oAuthMigrationRequest.getOauth2config().getClientSecret()) .toString(); Request request = new Request.RequestBuilder(MethodType.GET, getMigrationAPIUrl(oAuthMigrationRequest.getEnvironment())) .requiresAuthentication(true) .postJson(requestjson) .build(); Response response = client.makeJsonRequest(request, oAuthMigrationRequest); logger.debug("Response Code : " + response.getStatusCode()); if (response.getStatusCode() == 200) { ObjectReader reader = mapper.readerFor(OAuthMigrationResponse.class); OAuthMigrationResponse oAuthMigrationResponse = reader.readValue(response.getContent()); oAuthMigrationResponse.setIntuit_tid(response.getIntuit_tid()); return oAuthMigrationResponse; } else { logger.debug("failed calling migrate API"); throw new ConnectionException("failed calling migrate API", response.getStatusCode() + ""); } } catch (Exception ex) { logger.error("Exception while calling migrate", ex); throw new ConnectionException(ex.getMessage(), ex); } }
OAuthMigrationClient { public OAuthMigrationResponse migrate() throws ConnectionException { logger.debug("Enter OAuthMigrationClient::migrate"); try { HttpRequestClient client = new HttpRequestClient(oAuthMigrationRequest.getOauth2config().getProxyConfig()); String requestjson = new JSONObject().put("scope", getScopeValue(oAuthMigrationRequest.getScope())) .put("redirect_uri", getRedirectUrl() ) .put("client_id", oAuthMigrationRequest.getOauth2config().getClientId()) .put("client_secret",oAuthMigrationRequest.getOauth2config().getClientSecret()) .toString(); Request request = new Request.RequestBuilder(MethodType.GET, getMigrationAPIUrl(oAuthMigrationRequest.getEnvironment())) .requiresAuthentication(true) .postJson(requestjson) .build(); Response response = client.makeJsonRequest(request, oAuthMigrationRequest); logger.debug("Response Code : " + response.getStatusCode()); if (response.getStatusCode() == 200) { ObjectReader reader = mapper.readerFor(OAuthMigrationResponse.class); OAuthMigrationResponse oAuthMigrationResponse = reader.readValue(response.getContent()); oAuthMigrationResponse.setIntuit_tid(response.getIntuit_tid()); return oAuthMigrationResponse; } else { logger.debug("failed calling migrate API"); throw new ConnectionException("failed calling migrate API", response.getStatusCode() + ""); } } catch (Exception ex) { logger.error("Exception while calling migrate", ex); throw new ConnectionException(ex.getMessage(), ex); } } }
OAuthMigrationClient { public OAuthMigrationResponse migrate() throws ConnectionException { logger.debug("Enter OAuthMigrationClient::migrate"); try { HttpRequestClient client = new HttpRequestClient(oAuthMigrationRequest.getOauth2config().getProxyConfig()); String requestjson = new JSONObject().put("scope", getScopeValue(oAuthMigrationRequest.getScope())) .put("redirect_uri", getRedirectUrl() ) .put("client_id", oAuthMigrationRequest.getOauth2config().getClientId()) .put("client_secret",oAuthMigrationRequest.getOauth2config().getClientSecret()) .toString(); Request request = new Request.RequestBuilder(MethodType.GET, getMigrationAPIUrl(oAuthMigrationRequest.getEnvironment())) .requiresAuthentication(true) .postJson(requestjson) .build(); Response response = client.makeJsonRequest(request, oAuthMigrationRequest); logger.debug("Response Code : " + response.getStatusCode()); if (response.getStatusCode() == 200) { ObjectReader reader = mapper.readerFor(OAuthMigrationResponse.class); OAuthMigrationResponse oAuthMigrationResponse = reader.readValue(response.getContent()); oAuthMigrationResponse.setIntuit_tid(response.getIntuit_tid()); return oAuthMigrationResponse; } else { logger.debug("failed calling migrate API"); throw new ConnectionException("failed calling migrate API", response.getStatusCode() + ""); } } catch (Exception ex) { logger.error("Exception while calling migrate", ex); throw new ConnectionException(ex.getMessage(), ex); } } OAuthMigrationClient(OAuthMigrationRequest request); protected  OAuthMigrationClient(); }
OAuthMigrationClient { public OAuthMigrationResponse migrate() throws ConnectionException { logger.debug("Enter OAuthMigrationClient::migrate"); try { HttpRequestClient client = new HttpRequestClient(oAuthMigrationRequest.getOauth2config().getProxyConfig()); String requestjson = new JSONObject().put("scope", getScopeValue(oAuthMigrationRequest.getScope())) .put("redirect_uri", getRedirectUrl() ) .put("client_id", oAuthMigrationRequest.getOauth2config().getClientId()) .put("client_secret",oAuthMigrationRequest.getOauth2config().getClientSecret()) .toString(); Request request = new Request.RequestBuilder(MethodType.GET, getMigrationAPIUrl(oAuthMigrationRequest.getEnvironment())) .requiresAuthentication(true) .postJson(requestjson) .build(); Response response = client.makeJsonRequest(request, oAuthMigrationRequest); logger.debug("Response Code : " + response.getStatusCode()); if (response.getStatusCode() == 200) { ObjectReader reader = mapper.readerFor(OAuthMigrationResponse.class); OAuthMigrationResponse oAuthMigrationResponse = reader.readValue(response.getContent()); oAuthMigrationResponse.setIntuit_tid(response.getIntuit_tid()); return oAuthMigrationResponse; } else { logger.debug("failed calling migrate API"); throw new ConnectionException("failed calling migrate API", response.getStatusCode() + ""); } } catch (Exception ex) { logger.error("Exception while calling migrate", ex); throw new ConnectionException(ex.getMessage(), ex); } } OAuthMigrationClient(OAuthMigrationRequest request); protected  OAuthMigrationClient(); OAuthMigrationResponse migrate(); String getScopeValue(Scope scope); String getRedirectUrl(); }
OAuthMigrationClient { public OAuthMigrationResponse migrate() throws ConnectionException { logger.debug("Enter OAuthMigrationClient::migrate"); try { HttpRequestClient client = new HttpRequestClient(oAuthMigrationRequest.getOauth2config().getProxyConfig()); String requestjson = new JSONObject().put("scope", getScopeValue(oAuthMigrationRequest.getScope())) .put("redirect_uri", getRedirectUrl() ) .put("client_id", oAuthMigrationRequest.getOauth2config().getClientId()) .put("client_secret",oAuthMigrationRequest.getOauth2config().getClientSecret()) .toString(); Request request = new Request.RequestBuilder(MethodType.GET, getMigrationAPIUrl(oAuthMigrationRequest.getEnvironment())) .requiresAuthentication(true) .postJson(requestjson) .build(); Response response = client.makeJsonRequest(request, oAuthMigrationRequest); logger.debug("Response Code : " + response.getStatusCode()); if (response.getStatusCode() == 200) { ObjectReader reader = mapper.readerFor(OAuthMigrationResponse.class); OAuthMigrationResponse oAuthMigrationResponse = reader.readValue(response.getContent()); oAuthMigrationResponse.setIntuit_tid(response.getIntuit_tid()); return oAuthMigrationResponse; } else { logger.debug("failed calling migrate API"); throw new ConnectionException("failed calling migrate API", response.getStatusCode() + ""); } } catch (Exception ex) { logger.error("Exception while calling migrate", ex); throw new ConnectionException(ex.getMessage(), ex); } } OAuthMigrationClient(OAuthMigrationRequest request); protected  OAuthMigrationClient(); OAuthMigrationResponse migrate(); String getScopeValue(Scope scope); String getRedirectUrl();  }