Skip to content

Commit

Permalink
Rework for OkhttpClient and junits
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubhangi-cs committed Dec 21, 2023
1 parent 50c9f4d commit acb2dfc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public Response retrySapTransportCall(URL endpoint, String mediaType) throws IOE
*/
private Response transport(URL endpoint, String mediaType) throws IOException, TransportException {
OkHttpClient enhancedOkHttpClient =
buildConfiguredClient(config.getProxyUrl(), config.getProxyUsername(), config.getProxyPassword()).build();
buildConfiguredClient(config.getProxyUrl(), config.getProxyUsername(), config.getProxyPassword());
Request req = buildRequest(endpoint, mediaType);

return enhancedOkHttpClient.newCall(req).execute();
Expand Down Expand Up @@ -196,9 +196,9 @@ private Request buildRequest(URL endpoint, String mediaType) {
}

/**
* Builds and configures an OkHttpClient.Builder with the specified proxy settings and authentication credentials.
* Builds and configures an OkHttpClient with the specified proxy settings and authentication credentials.
*/
private OkHttpClient.Builder buildConfiguredClient(String proxyUrl, String proxyUsername, String proxyPassword)
private OkHttpClient buildConfiguredClient(String proxyUrl, String proxyUsername, String proxyPassword)
throws MalformedURLException, TransportException {
OkHttpClient.Builder builder = getConfiguredClient();

Expand All @@ -220,7 +220,7 @@ public Request authenticate(Route route, Response response) {
}
}

return builder;
return builder.build();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,16 @@ public void testCallSuccessFactors() throws TransportException {
SuccessFactorsResponseContainer response = transporter
.callSuccessFactors(successFactorsURL.getTesterURL(), MediaType.APPLICATION_JSON, SuccessFactorsService.TEST);

Assert.assertEquals("SuccessFactors Service data version is same.",
Assert.assertEquals("SuccessFactors Service data version is not same.",
"2.0",
response.getDataServiceVersion());
Assert.assertEquals("HTTP status code is same.",
Assert.assertEquals("HTTP status code is not same.",
HttpURLConnection.HTTP_OK,
response.getHttpStatusCode());
Assert.assertEquals("HTTP response body is same.",
Assert.assertEquals("HTTP response body is not same.",
expectedBody,
TestSuccessFactorsUtil.convertInputStreamToString(response.getResponseStream()));
Assert.assertEquals("HTTP status is same", "OK", response.getHttpStatusMsg());
Assert.assertEquals("HTTP status is not same", "OK", response.getHttpStatusMsg());
}

@Test
Expand All @@ -176,16 +176,16 @@ public void testCallSuccessFactorsWithProxy() throws TransportException {
SuccessFactorsResponseContainer response = transporter
.callSuccessFactors(successFactorsURL.getTesterURL(), MediaType.APPLICATION_JSON, SuccessFactorsService.TEST);

Assert.assertEquals("SuccessFactors Service data version is same.",
Assert.assertEquals("SuccessFactors Service data version is not same.",
"2.0",
response.getDataServiceVersion());
Assert.assertEquals("HTTP status code is same.",
Assert.assertEquals("HTTP status code is not same.",
HttpURLConnection.HTTP_OK,
response.getHttpStatusCode());
Assert.assertEquals("HTTP response body is same.",
Assert.assertEquals("HTTP response body is not same.",
expectedBody,
TestSuccessFactorsUtil.convertInputStreamToString(response.getResponseStream()));
Assert.assertEquals("HTTP status is same", "OK", response.getHttpStatusMsg());
Assert.assertEquals("HTTP status is not same", "OK", response.getHttpStatusMsg());
}

@Test
Expand All @@ -196,7 +196,7 @@ public void testUnAuthorized() throws TransportException {
.callSuccessFactors(successFactorsURL.getMetadataURL(), MediaType.APPLICATION_XML,
SuccessFactorsService.METADATA);
WireMock.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/Entity/$metadata")));
Assert.assertEquals("HTTP status code is matching.",
Assert.assertEquals("HTTP status code is not matching.",
HttpURLConnection.HTTP_UNAUTHORIZED,
response.getHttpStatusCode());
}
Expand Down

0 comments on commit acb2dfc

Please sign in to comment.