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
130 changes: 127 additions & 3 deletions pacts/prl-dgs-api-CCD_CASE_DOCS_AM_API.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
"response": {
"status": 200,
"headers": {
"Content-Type": "application/vnd\u63AFuk\u98E0gov\u8E83hmcts\uED68dm\u347Adocument\u7C16v1haljson;charset=UTF-8"
"Content-Type": "application/vnd\u9375uk\u3390gov\u96D3hmcts\uB3CEdm\u8C41document\uAD7Cv11111haljson;charset=UTF-8"
},
"body": {
"caseTypeId": "PRLAPPS",
"jurisdictionId": "PRIVATELAW"
},
"matchingRules": {
"header": {
Expand All @@ -32,6 +36,38 @@
],
"combine": "AND"
}
},
"body": {
"$.caseTypeId": {
"matchers": [
{
"match": "regex",
"regex": "PRLAPPS"
}
],
"combine": "AND"
},
"$.jurisdictionId": {
"matchers": [
{
"match": "regex",
"regex": "PRIVATELAW"
}
],
"combine": "AND"
}
}
},
"generators": {
"body": {
"$.caseTypeId": {
"type": "Regex",
"regex": "PRLAPPS"
},
"$.jurisdictionId": {
"type": "Regex",
"regex": "PRIVATELAW"
}
}
}
},
Expand All @@ -53,7 +89,11 @@
"response": {
"status": 500,
"headers": {
"Content-Type": "application/vnd\uF5A0uk\uE1D7gov\u0205hmcts\u0E15dm\uCDCDdocument\u0B01v111haljson;charset=UTF-8"
"Content-Type": "application/vnd\u1F6Euk\u57B0gov\u340Ehmcts\uDD83dm\uA463document\u8F2Cv11haljson;charset=UTF-8"
},
"body": {
"caseTypeId": "PRLAPPS",
"jurisdictionId": "PRIVATELAW"
},
"matchingRules": {
"header": {
Expand All @@ -66,6 +106,38 @@
],
"combine": "AND"
}
},
"body": {
"$.caseTypeId": {
"matchers": [
{
"match": "regex",
"regex": "PRLAPPS"
}
],
"combine": "AND"
},
"$.jurisdictionId": {
"matchers": [
{
"match": "regex",
"regex": "PRIVATELAW"
}
],
"combine": "AND"
}
}
},
"generators": {
"body": {
"$.caseTypeId": {
"type": "Regex",
"regex": "PRLAPPS"
},
"$.jurisdictionId": {
"type": "Regex",
"regex": "PRIVATELAW"
}
}
}
},
Expand All @@ -86,7 +158,59 @@
}
},
"response": {
"status": 200
"status": 200,
"headers": {
"Content-Type": "application/json; charset=UTF-8"
},
"body": {
"caseTypeId": "PRLAPPS",
"jurisdictionId": "PRIVATELAW"
},
"matchingRules": {
"body": {
"$.caseTypeId": {
"matchers": [
{
"match": "regex",
"regex": "PRLAPPS"
}
],
"combine": "AND"
},
"$.jurisdictionId": {
"matchers": [
{
"match": "regex",
"regex": "PRIVATELAW"
}
],
"combine": "AND"
}
},
"header": {
"Content-Type": {
"matchers": [
{
"match": "regex",
"regex": "application/json(;\\s?charset=[\\w\\-]+)?"
}
],
"combine": "AND"
}
}
},
"generators": {
"body": {
"$.caseTypeId": {
"type": "Regex",
"regex": "PRLAPPS"
},
"$.jurisdictionId": {
"type": "Regex",
"regex": "PRIVATELAW"
}
}
}
},
"providerStates": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.apache.http.client.fluent.Executor;
import org.apache.http.client.fluent.Request;
import org.json.JSONException;
import org.junit.After;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
Expand All @@ -22,6 +22,7 @@
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.io.IOException;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand All @@ -38,68 +39,70 @@ public class CdamApiConsumerTest {


private static final String SERVICE_AUTHORIZATION_HEADER = "ServiceAuthorization";
private static final String someServiceAuthToken = "someServiceAuthToken";
private static final String invalidServiceAuthToken = "invalidServiceAuthToken";
private static final String SERVICE_AUTH_TOKEN = "someServiceAuthToken";
private static final String INVALID_AUTH_TOKEN = "invalidServiceAuthToken";
private static final String AUTHORIZATION_HEADER = "Authorization";
private static final String someAuthToken = "someAuthToken";
private static final String someDocumentId = "456c0976-3178-46dd-b9ce-5ab5d47c625a";

private static final String AUTH_TOKEN = "someAuthToken";
private static final String DOCUMENT_ID = "456c0976-3178-46dd-b9ce-5ab5d47c625a";

@BeforeEach
public void setUpEachTest() throws InterruptedException, IOException {
public void setUpEachTest() throws InterruptedException {
Thread.sleep(2000);
}

@After
void teardown() {
@AfterEach
public void teardown() {
Executor.closeIdleConnections();
}

@Pact(provider = "CCD_CASE_DOCS_AM_API", consumer = "prl-dgs-api")
RequestResponsePact downloadDocument(PactDslWithProvider builder) throws JSONException, IOException {
RequestResponsePact downloadDocument(PactDslWithProvider builder) throws JSONException {
// @formatter:off

return builder
.given("A request to download a document")
.uponReceiving("a request to download a valid document")
.method("GET")
.headers(SERVICE_AUTHORIZATION_HEADER, someServiceAuthToken)
.headers(AUTHORIZATION_HEADER, someAuthToken)
.path("/cases/documents/" + someDocumentId)
.headers(Map.of(
SERVICE_AUTHORIZATION_HEADER, SERVICE_AUTH_TOKEN,
AUTHORIZATION_HEADER, AUTH_TOKEN))
.path("/cases/documents/" + DOCUMENT_ID)
.willRespondWith()
.matchHeader(org.springframework.http.HttpHeaders.CONTENT_TYPE,
"application/vnd.uk.gov.hmcts.dm.document.v1+hal+json;charset=UTF-8")
.headers(Map.of(org.springframework.http.HttpHeaders.CONTENT_TYPE,
"application/vnd.uk.gov.hmcts.dm.document.v1+hal+json;charset=UTF-8"))
.status(HttpStatus.SC_OK)
.body(buildPactDslJsonBody())
.toPact();
}

@Test
@PactTestFor(pactMethod = "downloadDocument")
public void verifyDownloadDocument(MockServer mockServer) throws IOException {

HttpResponse downloadDocumentResponse = Request.Get(mockServer.getUrl() + "/cases/documents/" + someDocumentId)
.addHeader(SERVICE_AUTHORIZATION_HEADER, someServiceAuthToken)
.addHeader(AUTHORIZATION_HEADER, someAuthToken)
HttpResponse downloadDocumentResponse = Request.Get(mockServer.getUrl() + "/cases/documents/" + DOCUMENT_ID)
.addHeader(SERVICE_AUTHORIZATION_HEADER, SERVICE_AUTH_TOKEN)
.addHeader(AUTHORIZATION_HEADER, AUTH_TOKEN)
.execute().returnResponse();

assertEquals(200, downloadDocumentResponse.getStatusLine().getStatusCode());
}


@Pact(provider = "CCD_CASE_DOCS_AM_API", consumer = "prl-dgs-api")
RequestResponsePact noAuthDownloadDocument(PactDslWithProvider builder) throws JSONException, IOException {
RequestResponsePact noAuthDownloadDocument(PactDslWithProvider builder) throws JSONException {
// @formatter:off

return builder
.given("A request to download a document")
.uponReceiving("a request to download a valid document with invalid authorisation")
.method("GET")
.headers(SERVICE_AUTHORIZATION_HEADER, invalidServiceAuthToken)
.path("/cases/documents/" + someDocumentId)
.headers(Map.of(SERVICE_AUTHORIZATION_HEADER, INVALID_AUTH_TOKEN))
.path("/cases/documents/" + DOCUMENT_ID)
.willRespondWith()
.matchHeader(org.springframework.http.HttpHeaders.CONTENT_TYPE,
"application/vnd.uk.gov.hmcts.dm.document.v1+hal+json;charset=UTF-8")
.status(HttpStatus.SC_INTERNAL_SERVER_ERROR)
.body(buildPactDslJsonBody())
.toPact();
}

Expand All @@ -108,31 +111,29 @@ RequestResponsePact noAuthDownloadDocument(PactDslWithProvider builder) throws J
@PactTestFor(pactMethod = "noAuthDownloadDocument")
public void verifyNoAuthDownloadDocument(MockServer mockServer) throws IOException {

HttpResponse downloadDocumentResponse = Request.Get(mockServer.getUrl() + "/cases/documents/" + someDocumentId)
.addHeader(SERVICE_AUTHORIZATION_HEADER, invalidServiceAuthToken).execute().returnResponse();
HttpResponse downloadDocumentResponse = Request.Get(mockServer.getUrl() + "/cases/documents/" + DOCUMENT_ID)
.addHeader(SERVICE_AUTHORIZATION_HEADER, INVALID_AUTH_TOKEN).execute().returnResponse();

assertEquals(500, downloadDocumentResponse.getStatusLine().getStatusCode());

}

@Pact(provider = "CCD_CASE_DOCS_AM_API", consumer = "prl-dgs-api")
RequestResponsePact uploadDocument(PactDslWithProvider builder) throws JSONException, IOException {
RequestResponsePact uploadDocument(PactDslWithProvider builder) throws JSONException {
// @formatter:off

PactDslJsonBody body = new PactDslJsonBody()
.stringMatcher("caseTypeId", "PRLAPPS")
.stringMatcher("jurisdictionId", "PRIVATELAW")
.asBody();

return builder
.given("A request to upload a document")
.uponReceiving("a request to upload a document with valid authorization")
.method("POST")
.headers(SERVICE_AUTHORIZATION_HEADER, someServiceAuthToken)
.headers(AUTHORIZATION_HEADER, someAuthToken)
.headers(Map.of(
SERVICE_AUTHORIZATION_HEADER, SERVICE_AUTH_TOKEN,
AUTHORIZATION_HEADER, AUTH_TOKEN))
.path("/cases/documents")
.willRespondWith()
.status(HttpStatus.SC_OK)
.body(buildPactDslJsonBody())
.toPact();
}

Expand All @@ -141,11 +142,17 @@ RequestResponsePact uploadDocument(PactDslWithProvider builder) throws JSONExcep
public void verifyUploadDocument(MockServer mockServer) throws IOException {

HttpResponse downloadDocumentResponse = Request.Post(mockServer.getUrl() + "/cases/documents" )
.addHeader(SERVICE_AUTHORIZATION_HEADER, someServiceAuthToken)
.addHeader(AUTHORIZATION_HEADER, someAuthToken)
.addHeader(SERVICE_AUTHORIZATION_HEADER, SERVICE_AUTH_TOKEN)
.addHeader(AUTHORIZATION_HEADER, AUTH_TOKEN)
.execute().returnResponse();

assertEquals(200, downloadDocumentResponse.getStatusLine().getStatusCode());
}

private PactDslJsonBody buildPactDslJsonBody() {
return new PactDslJsonBody()
.stringMatcher("caseTypeId", "PRLAPPS")
.stringMatcher("jurisdictionId", "PRIVATELAW")
.asBody();
}
}
Loading