Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,21 @@
<maven.sonatype.ossindex.plugin.version>3.1.0</maven.sonatype.ossindex.plugin.version>
<maven.surefire.plugin.version>2.22.2</maven.surefire.plugin.version>
<maven.checkstyle.plugin.version>3.2.2</maven.checkstyle.plugin.version>

<mockito.version>3.12.4</mockito.version>
</properties>

<dependencies>
<!-- Keep logging at the beginning of the file so that org.slf4j dependency is imported at its latest version required by logging to work -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
<groupId>com.github.onsdigital</groupId>
<artifactId>dp-logging</artifactId>
<version>${dp.logging.version}</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.3.1</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -74,13 +81,20 @@
<version>4.13.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>2.0.2-beta</version>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
Expand All @@ -95,12 +109,6 @@
<version>2.12.2</version>
</dependency>

<dependency>
<groupId>com.github.onsdigital</groupId>
<artifactId>dp-logging</artifactId>
<version>${dp.logging.version}</version>
</dependency>

</dependencies>

<!-- notes on checkstyle-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down