use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsTitlesTest method shouldReturn400WhenInvalidPostRequest.
@Test
public void shouldReturn400WhenInvalidPostRequest() throws URISyntaxException, IOException {
String errorResponse = "responses/rmapi/packages/post-package-400-error-response.json";
String titlePostStubRequestFile = "requests/kb-ebsco/title/post-title-request.json";
EqualToJsonPattern postBodyPattern = new EqualToJsonPattern("{\n \"titleName\" : \"Test Title\",\n \"edition\" : \"Test edition\",\n \"publisherName\" : \"Test publisher\",\n \"pubType\" : \"thesisdissertation\",\n \"description\" : \"Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\",\n \"isPeerReviewed\" : true,\n \"identifiersList\" : [ {\n \"id\" : \"1111-2222-3333\",\n \"subtype\" : 2,\n \"type\" : 0\n } ],\n \"contributorsList\" : [ {\n \"type\" : \"author\",\n \"contributor\" : \"smith, john\"\n }, {\n \"type\" : \"illustrator\",\n \"contributor\" : \"smith, ralph\"\n } ],\n \"peerReviewed\" : true\n}", true, true);
stubFor(post(new UrlPathPattern(new EqualToPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/vendors/" + STUB_VENDOR_ID + "/packages/" + STUB_PACKAGE_ID + "/titles"), false)).withRequestBody(postBodyPattern).willReturn(new ResponseDefinitionBuilder().withBody(readFile(errorResponse)).withStatus(SC_BAD_REQUEST)));
JsonapiError error = postWithStatus(EHOLDINGS_TITLES_PATH, readFile(titlePostStubRequestFile), SC_BAD_REQUEST, STUB_TOKEN_HEADER).as(JsonapiError.class);
assertErrorContainsTitle(error, "Package with the provided name already exists");
}
use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsResourcesImplTest method shouldDeleteTagsOnDeleteRequest.
@Test
public void shouldDeleteTagsOnDeleteRequest() throws IOException, URISyntaxException {
saveTag(vertx, STUB_CUSTOM_RESOURCE_ID, RecordType.RESOURCE, STUB_TAG_VALUE);
EqualToJsonPattern putBodyPattern = new EqualToJsonPattern("{\"isSelected\":false}", true, true);
deleteResource(putBodyPattern);
List<String> actualTags = TagsTestUtil.getTags(vertx);
assertThat(actualTags, empty());
}
use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsResourcesImplTest method shouldSendDeleteRequestForResourceAssociatedWithCustomPackage.
@Test
public void shouldSendDeleteRequestForResourceAssociatedWithCustomPackage() throws IOException, URISyntaxException {
EqualToJsonPattern putBodyPattern = new EqualToJsonPattern("{\"isSelected\":false}", true, true);
deleteResource(putBodyPattern);
verify(1, putRequestedFor(new UrlPathPattern(new EqualToPattern(CUSTOM_RESOURCE_ENDPOINT), false)).withRequestBody(putBodyPattern));
}
use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsResourcesImplTest method shouldDeselectManagedResourceOnPutWithSelectedFalse.
@Test
public void shouldDeselectManagedResourceOnPutWithSelectedFalse() throws IOException, URISyntaxException, JSONException {
String stubResponseFile = "responses/rmapi/resources/get-managed-resource-updated-response-is-selected-false.json";
String expectedResourceFile = "responses/kb-ebsco/resources/expected-managed-resource.json";
ResourcePutRequest request = readJsonFile("requests/kb-ebsco/resource/put-managed-resource-is-not-selected.json", ResourcePutRequest.class);
request.getData().getAttributes().setIsSelected(false);
String actualResponse = mockUpdateResourceScenario(stubResponseFile, MANAGED_RESOURCE_ENDPOINT, STUB_MANAGED_RESOURCE_ID, Json.encode(request));
Resource expectedResource = readJsonFile(expectedResourceFile, Resource.class);
expectedResource.getData().getAttributes().setIsSelected(false);
JSONAssert.assertEquals(Json.encode(expectedResource), actualResponse, false);
verify(1, putRequestedFor(new UrlPathPattern(new RegexPattern(MANAGED_RESOURCE_ENDPOINT), true)).withRequestBody(new EqualToJsonPattern(readFile("requests/rmapi/resources/put-managed-resource-is-not-selected.json"), true, true)));
}
use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesTest method shouldUpdateAllAttributesInCustomPackage.
@Test
public void shouldUpdateAllAttributesInCustomPackage() throws URISyntaxException, IOException {
boolean updatedSelected = true;
boolean updatedHidden = true;
String updatedBeginCoverage = "2003-01-01";
String updatedEndCoverage = "2004-01-01";
String updatedPackageName = "name of the ages forever and ever";
EqualToJsonPattern putBodyPattern = new EqualToJsonPattern(readFile("requests/rmapi/packages/put-package-custom.json"), true, true);
PackageByIdData packageData = mapper.readValue(getFile(CUSTOM_PACKAGE_STUB_FILE), PackageByIdData.class);
packageData = packageData.toByIdBuilder().isSelected(updatedSelected).visibilityData(packageData.getVisibilityData().toBuilder().isHidden(updatedHidden).build()).customCoverage(CoverageDates.builder().beginCoverage(updatedBeginCoverage).endCoverage(updatedEndCoverage).build()).packageName(updatedPackageName).contentType("streamingmedia").build();
String updatedPackageValue = mapper.writeValueAsString(packageData);
mockUpdateScenario(readFile(CUSTOM_PACKAGE_STUB_FILE), updatedPackageValue);
Package aPackage = putWithOk(PACKAGES_PATH, readFile("requests/kb-ebsco/package/put-package-custom-multiple-attributes.json"), STUB_TOKEN_HEADER).as(Package.class);
verify(putRequestedFor(PACKAGE_URL_PATTERN).withRequestBody(putBodyPattern));
assertEquals(updatedSelected, aPackage.getData().getAttributes().getIsSelected());
assertEquals(updatedHidden, aPackage.getData().getAttributes().getVisibilityData().getIsHidden());
assertEquals(updatedBeginCoverage, aPackage.getData().getAttributes().getCustomCoverage().getBeginCoverage());
assertEquals(updatedEndCoverage, aPackage.getData().getAttributes().getCustomCoverage().getEndCoverage());
assertEquals(updatedPackageName, aPackage.getData().getAttributes().getName());
assertEquals(ContentType.STREAMING_MEDIA, aPackage.getData().getAttributes().getContentType());
}
Aggregations