diff --git a/pom.xml b/pom.xml index 3a4be5f..14d6994 100644 --- a/pom.xml +++ b/pom.xml @@ -32,14 +32,21 @@ 3.1.0 2.22.2 3.2.2 - + 3.12.4 + - org.apache.httpcomponents - httpclient - 4.5.14 + com.github.onsdigital + dp-logging + ${dp.logging.version} + + + + org.apache.httpcomponents.client5 + httpclient5 + 5.3.1 @@ -74,13 +81,20 @@ 4.13.2 test + org.mockito - mockito-all - 2.0.2-beta + mockito-core + ${mockito.version} test + + org.mockito + mockito-inline + ${mockito.version} + test + org.hamcrest @@ -95,12 +109,6 @@ 2.12.2 - - com.github.onsdigital - dp-logging - ${dp.logging.version} - - diff --git a/src/main/java/com/github/onsdigital/dp/authorisation/permissions/APIClient.java b/src/main/java/com/github/onsdigital/dp/authorisation/permissions/APIClient.java index 0691364..468dd0e 100644 --- a/src/main/java/com/github/onsdigital/dp/authorisation/permissions/APIClient.java +++ b/src/main/java/com/github/onsdigital/dp/authorisation/permissions/APIClient.java @@ -3,12 +3,12 @@ import com.github.onsdigital.dp.authorisation.exceptions.Messages; import com.github.onsdigital.dp.authorisation.permissions.models.Bundle; import com.google.gson.Gson; -import org.apache.http.HttpEntity; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; +import org.apache.hc.client5.http.ClientProtocolException; +import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.client5.http.impl.classic.HttpClients; +import org.apache.hc.core5.http.HttpEntity; import java.io.IOException; import java.io.InputStream; @@ -52,7 +52,7 @@ public Bundle getPermissionsBundle() throws Exception { try (CloseableHttpClient httpClient = httpClientSupplier.get(); CloseableHttpResponse response = httpClient.execute(request)) { - int statusCode = response.getStatusLine().getStatusCode(); + int statusCode = response.getCode(); info().data(statusCodeTitle, statusCode).log("GetPermissionsBundle: request successfully executed"); diff --git a/src/test/java/com/github/onsdigital/dp/authorisation/permissions/APIClientTest.java b/src/test/java/com/github/onsdigital/dp/authorisation/permissions/APIClientTest.java index fa088ca..922b3c3 100644 --- a/src/test/java/com/github/onsdigital/dp/authorisation/permissions/APIClientTest.java +++ b/src/test/java/com/github/onsdigital/dp/authorisation/permissions/APIClientTest.java @@ -6,10 +6,9 @@ import com.github.onsdigital.dp.authorisation.permissions.models.Policy; import com.github.onsdigital.dp.authorisation.permissions.models.Condition; import com.google.gson.Gson; -import org.apache.http.HttpEntity; -import org.apache.http.StatusLine; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import org.hamcrest.CoreMatchers; import org.junit.Before; import org.junit.Test; @@ -60,9 +59,7 @@ public void testGetPermissionBundle_success() throws Exception { try (InputStream responseBody = new ByteArrayInputStream(expectedJson.getBytes())) { when(httpClient.execute(Matchers.any())).thenReturn(response); - StatusLine statusLine = mock(StatusLine.class); - when(response.getStatusLine()).thenReturn(statusLine); - when(statusLine.getStatusCode()).thenReturn(200); + when(response.getCode()).thenReturn(200); HttpEntity entity = mock(HttpEntity.class); when(response.getEntity()).thenReturn(entity); when(entity.getContent()).thenReturn(responseBody); @@ -77,11 +74,9 @@ public void testGetPermissionBundle_success() throws Exception { public void testGetContentHash_non200Status() { try { CloseableHttpResponse response = mock(CloseableHttpResponse.class); - StatusLine statusLine = mock(StatusLine.class); when(httpClient.execute(Matchers.any())).thenReturn(response); - when(response.getStatusLine()).thenReturn(statusLine); - when(statusLine.getStatusCode()).thenReturn(400); + when(response.getCode()).thenReturn(400); client.getPermissionsBundle(); } catch (Exception ex) {