Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AnnotationsConsumerTest extends BaseConsumerTest {
private static final String ANNOTATIONS_PROVIDER_NAME = "annotation_api_annotation_provider";
private static final String ANNOTATIONS_API_BASE_PATH = "/api/annotations";

private final String exampleAnnotationId = "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a";
private static final String EXAMPLE_ANNOTATION_ID = "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a";

@Pact(provider = ANNOTATIONS_PROVIDER_NAME, consumer = "annotation_api")
public V4Pact createAnnotation201(PactDslWithProvider builder) {
Expand Down Expand Up @@ -114,7 +114,7 @@ public V4Pact getAnnotation200(PactDslWithProvider builder) {
return builder
.given("gets the annotation by given id")
.uponReceiving("A request to get a single annotation")
.path(ANNOTATIONS_API_BASE_PATH + "/" + exampleAnnotationId)
.path(ANNOTATIONS_API_BASE_PATH + "/" + EXAMPLE_ANNOTATION_ID)
.method(HttpMethod.GET.toString())
.headers(getHeaders())
.willRespondWith()
Expand All @@ -130,7 +130,7 @@ void testGetAnnotation200(MockServer mockServer) {
.given()
.headers(getHeaders())
.contentType(ContentType.JSON)
.get(mockServer.getUrl() + ANNOTATIONS_API_BASE_PATH + "/" + exampleAnnotationId)
.get(mockServer.getUrl() + ANNOTATIONS_API_BASE_PATH + "/" + EXAMPLE_ANNOTATION_ID)
.then()
.statusCode(HttpStatus.OK.value());
}
Expand All @@ -140,7 +140,7 @@ public V4Pact deleteAnnotation200(PactDslWithProvider builder) {
return builder
.given("annotation exists for deletion")
.uponReceiving("A request to delete an annotation")
.path(ANNOTATIONS_API_BASE_PATH + "/" + exampleAnnotationId)
.path(ANNOTATIONS_API_BASE_PATH + "/" + EXAMPLE_ANNOTATION_ID)
.method(HttpMethod.DELETE.toString())
.headers(getHeaders())
.willRespondWith()
Expand All @@ -155,7 +155,7 @@ void testDeleteAnnotation200(MockServer mockServer) {
.given()
.headers(getHeaders())
.contentType(ContentType.JSON)
.delete(mockServer.getUrl() + ANNOTATIONS_API_BASE_PATH + "/" + exampleAnnotationId)
.delete(mockServer.getUrl() + ANNOTATIONS_API_BASE_PATH + "/" + EXAMPLE_ANNOTATION_ID)
.then()
.statusCode(HttpStatus.OK.value());
}
Expand All @@ -176,7 +176,7 @@ protected void getLambdaDslObject(LambdaDslObject body) {
buildAuditingFields(comment);
comment
.uuid("id", UUID.randomUUID())
.uuid("annotationId", UUID.fromString(exampleAnnotationId))
.uuid("annotationId", UUID.fromString(EXAMPLE_ANNOTATION_ID))
.stringType("content", "This is a sample annotation comment text which can vary.");
})
.eachLike("rectangles", rectangle -> {
Expand All @@ -187,7 +187,7 @@ protected void getLambdaDslObject(LambdaDslObject body) {
.numberType("width", 250.0)
.numberType("y", 55.2)
.uuid("id", UUID.randomUUID())
.uuid("annotationId", UUID.fromString(exampleAnnotationId))
.uuid("annotationId", UUID.fromString(EXAMPLE_ANNOTATION_ID))
.numberType("height", 80.7);
});

Expand All @@ -205,7 +205,7 @@ protected void getLambdaDslObject(LambdaDslObject body) {
.uuid("createdBy", EXAMPLE_USER_ID)
)
.uuid("annotationSetId", UUID.fromString("c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f"))
.uuid("id", UUID.fromString(exampleAnnotationId))
.uuid("id", UUID.fromString(EXAMPLE_ANNOTATION_ID))
.integerType("page", 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
class BookmarkConsumerTest extends BaseConsumerTest {

private static final String BOOKMARK_PROVIDER_NAME = "annotation_api_bookmark_provider";
private static final String BOOKMARKS_API_BASE_PATH = "/api/bookmarks";
private static final String BOOKMARKS_MULTIPLE_API_PATH = "/api/bookmarks_multiple";
private static final String DOCUMENT_BOOKMARKS_API_PATH_FORMAT = "/api/%s/bookmarks";
private static final String BOOKMARKS_API_BASE_URI = "/api/bookmarks";
private static final String BOOKMARKS_MULTIPLE_API_URI = "/api/bookmarks_multiple";
private static final String DOCUMENT_BOOKMARKS_API_URI_FORMAT = "/api/%s/bookmarks";

private static final UUID EXAMPLE_BOOKMARK_ID = UUID.fromString("1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d");
private static final UUID ANOTHER_EXAMPLE_BOOKMARK_ID = UUID.fromString("5a6b7c8d-9e0f-1a2b-3c4d-5e6f7a8b9c0a");
Expand All @@ -38,7 +38,7 @@ public V4Pact createBookmark201(PactDslWithProvider builder) {
return builder
.given("bookmark is created successfully")
.uponReceiving("A request to create a bookmark")
.path(BOOKMARKS_API_BASE_PATH)
.path(BOOKMARKS_API_BASE_URI)
.method(HttpMethod.POST.toString())
.headers(getHeaders())
.body(createBookmarkDsl(EXAMPLE_BOOKMARK_ID))
Expand All @@ -56,7 +56,7 @@ void testCreateBookmark201(MockServer mockServer) {
.headers(getHeaders())
.contentType(ContentType.JSON)
.body(createBookmarkDsl(EXAMPLE_BOOKMARK_ID).getBody().toString())
.post(mockServer.getUrl() + BOOKMARKS_API_BASE_PATH)
.post(mockServer.getUrl() + BOOKMARKS_API_BASE_URI)
.then()
.statusCode(HttpStatus.CREATED.value());
}
Expand All @@ -66,7 +66,7 @@ public V4Pact updateBookmark200(PactDslWithProvider builder) {
return builder
.given("bookmark is updated successfully")
.uponReceiving("A request to update a bookmark")
.path(BOOKMARKS_API_BASE_PATH)
.path(BOOKMARKS_API_BASE_URI)
.method(HttpMethod.PUT.toString())
.headers(getHeaders())
.body(createBookmarkDsl(EXAMPLE_BOOKMARK_ID))
Expand All @@ -84,7 +84,7 @@ void testUpdateBookmark200(MockServer mockServer) {
.headers(getHeaders())
.contentType(ContentType.JSON)
.body(createBookmarkDsl(EXAMPLE_BOOKMARK_ID).getBody().toString())
.put(mockServer.getUrl() + BOOKMARKS_API_BASE_PATH)
.put(mockServer.getUrl() + BOOKMARKS_API_BASE_URI)
.then()
.statusCode(HttpStatus.OK.value());
}
Expand All @@ -94,7 +94,7 @@ public V4Pact updateMultipleBookmarks200(PactDslWithProvider builder) {
return builder
.given("bookmarks are updated successfully")
.uponReceiving("A request to update multiple bookmarks")
.path(BOOKMARKS_MULTIPLE_API_PATH)
.path(BOOKMARKS_MULTIPLE_API_URI)
.method(HttpMethod.PUT.toString())
.headers(getHeaders())
.body(createBookmarkListDsl())
Expand All @@ -112,14 +112,14 @@ void testUpdateMultipleBookmarks200(MockServer mockServer) {
.headers(getHeaders())
.contentType(ContentType.JSON)
.body(createBookmarkListDsl().getBody().toString())
.put(mockServer.getUrl() + BOOKMARKS_MULTIPLE_API_PATH)
.put(mockServer.getUrl() + BOOKMARKS_MULTIPLE_API_URI)
.then()
.statusCode(HttpStatus.OK.value());
}

@Pact(provider = BOOKMARK_PROVIDER_NAME, consumer = ANNOTATION_CONSUMER)
public V4Pact getAllDocumentBookmarks200(PactDslWithProvider builder) {
String documentBookmarksPath = String.format(DOCUMENT_BOOKMARKS_API_PATH_FORMAT, EXAMPLE_DOCUMENT_ID);
String documentBookmarksPath = String.format(DOCUMENT_BOOKMARKS_API_URI_FORMAT, EXAMPLE_DOCUMENT_ID);
return builder
.given("bookmarks exist for a document")
.uponReceiving("A request to get all bookmarks for a document")
Expand All @@ -135,7 +135,7 @@ public V4Pact getAllDocumentBookmarks200(PactDslWithProvider builder) {
@Test
@PactTestFor(pactMethod = "getAllDocumentBookmarks200", providerName = BOOKMARK_PROVIDER_NAME)
void testGetAllDocumentBookmarks200(MockServer mockServer) {
String documentBookmarksPath = String.format(DOCUMENT_BOOKMARKS_API_PATH_FORMAT, EXAMPLE_DOCUMENT_ID);
String documentBookmarksPath = String.format(DOCUMENT_BOOKMARKS_API_URI_FORMAT, EXAMPLE_DOCUMENT_ID);
SerenityRest
.given()
.headers(getHeaders())
Expand All @@ -147,11 +147,11 @@ void testGetAllDocumentBookmarks200(MockServer mockServer) {

@Pact(provider = BOOKMARK_PROVIDER_NAME, consumer = ANNOTATION_CONSUMER)
public V4Pact deleteBookmark200(PactDslWithProvider builder) {
String bookmarkPath = BOOKMARKS_API_BASE_PATH + "/" + EXAMPLE_BOOKMARK_ID;
String bookmarkUri = BOOKMARKS_API_BASE_URI + "/" + EXAMPLE_BOOKMARK_ID;
return builder
.given("bookmark exists for deletion")
.uponReceiving("A request to delete a bookmark")
.path(bookmarkPath)
.path(bookmarkUri)
.method(HttpMethod.DELETE.toString())
.headers(getHeaders())
.willRespondWith()
Expand All @@ -162,12 +162,12 @@ public V4Pact deleteBookmark200(PactDslWithProvider builder) {
@Test
@PactTestFor(pactMethod = "deleteBookmark200", providerName = BOOKMARK_PROVIDER_NAME)
void testDeleteBookmark200(MockServer mockServer) {
String bookmarkPath = BOOKMARKS_API_BASE_PATH + "/" + EXAMPLE_BOOKMARK_ID;
String bookmarkUri = BOOKMARKS_API_BASE_URI + "/" + EXAMPLE_BOOKMARK_ID;
SerenityRest
.given()
.headers(getHeaders())
.contentType(ContentType.JSON)
.delete(mockServer.getUrl() + bookmarkPath)
.delete(mockServer.getUrl() + bookmarkUri)
.then()
.statusCode(HttpStatus.OK.value());
}
Expand All @@ -177,7 +177,7 @@ public V4Pact deleteMultipleBookmarks200(PactDslWithProvider builder) {
return builder
.given("bookmarks exist for multiple deletion")
.uponReceiving("A request to delete multiple bookmarks")
.path(BOOKMARKS_MULTIPLE_API_PATH)
.path(BOOKMARKS_MULTIPLE_API_URI)
.method(HttpMethod.DELETE.toString())
.headers(getHeaders())
.body(createDeleteBookmarkRequestDsl())
Expand All @@ -194,7 +194,7 @@ void testDeleteMultipleBookmarks200(MockServer mockServer) {
.headers(getHeaders())
.contentType(ContentType.JSON)
.body(createDeleteBookmarkRequestDsl().getBody().toString())
.delete(mockServer.getUrl() + BOOKMARKS_MULTIPLE_API_PATH)
.delete(mockServer.getUrl() + BOOKMARKS_MULTIPLE_API_URI)
.then()
.statusCode(HttpStatus.OK.value());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
class FilterAnnotationSetConsumerTest extends BaseConsumerTest {

private static final String FILTER_ANNOTATION_SET_PROVIDER_NAME = "annotation_api_filter_annotation_set_provider";
private static final String FILTER_ANNOTATION_SET_API_PATH = "/api/annotation-sets/filter";
private static final String FILTER_ANNOTATION_SET_API_URI = "/api/annotation-sets/filter";
private static final String EXAMPLE_DOCUMENT_ID = "f401727b-5a50-40bb-ac4d-87dc34910b6e";
private static final UUID EXAMPLE_ANNOTATION_SET_ID = UUID.fromString("4f6fe7a2-b8a6-4f0a-9f7c-8d9e1b0c9b3a");
public static final String DOCUMENT_ID = "documentId";

private final AnnotationsConsumerTest annotationsConsumerTestHelper = new AnnotationsConsumerTest();

Expand All @@ -33,9 +34,9 @@ public V4Pact filterAnnotationSetByDocumentId200(PactDslWithProvider builder) {
return builder
.given("an annotation set exists for the given document id")
.uponReceiving("A request to filter an annotation set by document id")
.path(FILTER_ANNOTATION_SET_API_PATH)
.path(FILTER_ANNOTATION_SET_API_URI)
.method(HttpMethod.GET.toString())
.matchQuery("documentId", ".+", EXAMPLE_DOCUMENT_ID)
.matchQuery(DOCUMENT_ID, ".+", EXAMPLE_DOCUMENT_ID)
.headers(getHeaders())
.willRespondWith()
.status(HttpStatus.OK.value())
Expand All @@ -49,8 +50,8 @@ void testFilterAnnotationSetByDocumentId200(MockServer mockServer) {
SerenityRest
.given()
.headers(getHeaders())
.queryParam("documentId", EXAMPLE_DOCUMENT_ID)
.get(mockServer.getUrl() + FILTER_ANNOTATION_SET_API_PATH)
.queryParam(DOCUMENT_ID, EXAMPLE_DOCUMENT_ID)
.get(mockServer.getUrl() + FILTER_ANNOTATION_SET_API_URI)
.then()
.statusCode(HttpStatus.OK.value());
}
Expand All @@ -62,7 +63,7 @@ private DslPart createAnnotationSetDsl() {
private void buildAnnotationSetBody(LambdaDslObject body) {
body
.uuid("id", EXAMPLE_ANNOTATION_SET_ID)
.stringType("documentId", EXAMPLE_DOCUMENT_ID);
.stringType(DOCUMENT_ID, EXAMPLE_DOCUMENT_ID);
buildAuditingFields(body);
body.eachLike("annotations", annotationsConsumerTestHelper::getLambdaDslObject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public RequestResponsePact executeGetIdamAccessTokenAndGet200(PactDslWithProvide

@Test
@PactTestFor(pactMethod = "executeGetIdamAccessTokenAndGet200")
public void should_post_to_token_endpoint_and_receive_access_token_with_200_response(MockServer mockServer)
public void shouldPostToTokenEndpointAndReceiveAccessTokenWith200Response(MockServer mockServer)
throws JSONException {
String actualResponseBody =
SerenityRest
Expand Down Expand Up @@ -130,7 +130,7 @@ public RequestResponsePact executeGetUserDetailsAndGet200(PactDslWithProvider bu

@Test
@PactTestFor(pactMethod = "executeGetUserDetailsAndGet200")
public void should_get_user_details_with_access_token(MockServer mockServer) throws JSONException {
public void shouldGetUserDetailsWithAccessToken(MockServer mockServer) throws JSONException {

Map<String, String> headers = Maps.newHashMap();
headers.put(HttpHeaders.AUTHORIZATION, "Bearer eyJ0eXAiOiJKV1QiLCJraWQiOiJiL082T3ZWdjEre");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class MetaDataConsumerTest extends BaseConsumerTest {

private static final String METADATA_PROVIDER_NAME = "annotation_api_metadata_provider";
private static final String METADATA_API_BASE_PATH = "/api/metadata";
private static final String METADATA_API_BASE_URI = "/api/metadata/";

private static final UUID EXAMPLE_DOCUMENT_ID = UUID.fromString("8c53579b-d935-4204-82c8-250329c29d91");
private static final Integer EXAMPLE_ROTATION_ANGLE = 90;
Expand All @@ -29,7 +29,7 @@ public V4Pact createMetaData201(PactDslWithProvider builder) {
return builder
.given("metadata can be created for a document")
.uponReceiving("A request to create metadata")
.path(METADATA_API_BASE_PATH + "/")
.path(METADATA_API_BASE_URI)
.method(HttpMethod.POST.toString())
.headers(getHeaders())
.body(createMetaDataDsl())
Expand All @@ -47,14 +47,14 @@ void testCreateMetaData201(MockServer mockServer) {
.headers(getHeaders())
.contentType(ContentType.JSON)
.body(createMetaDataDsl().getBody().toString())
.post(mockServer.getUrl() + METADATA_API_BASE_PATH + "/")
.post(mockServer.getUrl() + METADATA_API_BASE_URI)
.then()
.statusCode(HttpStatus.CREATED.value());
}

@Pact(provider = METADATA_PROVIDER_NAME, consumer = ANNOTATION_CONSUMER)
public V4Pact getMetaData200(PactDslWithProvider builder) {
String metadataPath = METADATA_API_BASE_PATH + "/" + EXAMPLE_DOCUMENT_ID;
String metadataPath = METADATA_API_BASE_URI + EXAMPLE_DOCUMENT_ID;
return builder
.given("metadata exists for a document")
.uponReceiving("A request to get metadata for a document")
Expand All @@ -70,7 +70,7 @@ public V4Pact getMetaData200(PactDslWithProvider builder) {
@Test
@PactTestFor(pactMethod = "getMetaData200", providerName = METADATA_PROVIDER_NAME)
void testGetMetaData200(MockServer mockServer) {
String metadataPath = METADATA_API_BASE_PATH + "/" + EXAMPLE_DOCUMENT_ID;
String metadataPath = METADATA_API_BASE_URI + EXAMPLE_DOCUMENT_ID;
SerenityRest
.given()
.headers(getHeaders())
Expand All @@ -81,10 +81,10 @@ void testGetMetaData200(MockServer mockServer) {
}

private DslPart createMetaDataDsl() {
return newJsonBody(body -> {
body
.integerType("rotationAngle", EXAMPLE_ROTATION_ANGLE)
.uuid("documentId", EXAMPLE_DOCUMENT_ID);
}).build();
return newJsonBody(body ->
body
.integerType("rotationAngle", EXAMPLE_ROTATION_ANGLE)
.uuid("documentId", EXAMPLE_DOCUMENT_ID))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import au.com.dius.pact.provider.junitsupport.Provider;
import au.com.dius.pact.provider.junitsupport.State;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
Expand All @@ -10,6 +11,7 @@
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import uk.gov.hmcts.reform.em.annotation.rest.AnnotationSetResource;
import uk.gov.hmcts.reform.em.annotation.service.AnnotationSetService;
import uk.gov.hmcts.reform.em.annotation.service.dto.AnnotationDTO;
Expand All @@ -31,14 +33,23 @@
})
public class AnnotationSetProviderTest extends BaseProviderTest {

@Autowired
private AnnotationSetResource annotationSetResource;
private final AnnotationSetResource annotationSetResource;

@MockitoBean
private AnnotationSetService annotationSetService;

private static final UUID EXAMPLE_ANNOTATION_SET_ID = UUID.fromString("4f6fe7a2-b8a6-4f0a-9f7c-8d9e1b0c9b3a");

@Autowired
public AnnotationSetProviderTest(
MockMvc mockMvc,
ObjectMapper objectMapper,
AnnotationSetResource annotationSetResource
) {
super(mockMvc, objectMapper);
this.annotationSetResource = annotationSetResource;
}


@Override
protected Object[] getControllersUnderTest() {
Expand Down
Loading