use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesTest method shouldUpdateAllAttributesInCustomPackageAndCreateNewAccessTypeMapping.
@Test
public void shouldUpdateAllAttributesInCustomPackageAndCreateNewAccessTypeMapping() throws URISyntaxException, IOException {
List<AccessType> accessTypes = insertAccessTypes(testData(configuration.getId()), vertx);
String accessTypeId = accessTypes.get(0).getId();
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);
String putBody = String.format(readFile("requests/kb-ebsco/package/put-package-custom-with-access-type.json"), accessTypeId);
Package aPackage = putWithOk(PACKAGES_PATH, putBody, 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());
List<AccessTypeMapping> accessTypeMappingsInDB = getAccessTypeMappings(vertx);
assertEquals(1, accessTypeMappingsInDB.size());
assertEquals(aPackage.getData().getId(), accessTypeMappingsInDB.get(0).getRecordId());
assertEqualsUUID(accessTypeId, accessTypeMappingsInDB.get(0).getAccessTypeId());
assertEquals(PACKAGE, accessTypeMappingsInDB.get(0).getRecordType());
assertNotNull(aPackage.getIncluded());
assertEquals(accessTypeId, aPackage.getData().getRelationships().getAccessType().getData().getId());
assertEquals(accessTypeId, ((LinkedHashMap<?, ?>) aPackage.getIncluded().get(0)).get("id"));
}
use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesTest method shouldReturn200WhenPackagePostIsValid.
@Test
public void shouldReturn200WhenPackagePostIsValid() throws URISyntaxException, IOException {
String packagePostStubRequestFile = "requests/kb-ebsco/package/post-package-request.json";
String packagePostRMAPIRequestFile = "requests/rmapi/packages/post-package.json";
final Package createdPackage = sendPost(readFile(packagePostStubRequestFile)).as(Package.class);
assertTrue(Objects.isNull(createdPackage.getData().getAttributes().getTags()));
EqualToJsonPattern postBodyPattern = new EqualToJsonPattern(readFile(packagePostRMAPIRequestFile), false, true);
verify(1, postRequestedFor(new UrlPathPattern(new EqualToPattern(PACKAGES_STUB_URL), false)).withRequestBody(postBodyPattern));
}
use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesTest method shouldReturn200WhenSelectingPackage.
@Test
public void shouldReturn200WhenSelectingPackage() throws URISyntaxException, IOException {
boolean updatedIsSelected = true;
EqualToJsonPattern putBodyPattern = new EqualToJsonPattern(readFile("requests/rmapi/packages/put-package-is-selected.json"), true, true);
PackageByIdData packageData = mapper.readValue(getFile(PACKAGE_STUB_FILE), PackageByIdData.class);
packageData = packageData.toByIdBuilder().isSelected(updatedIsSelected).build();
String updatedPackageValue = mapper.writeValueAsString(packageData);
mockUpdateScenario(readFile(PACKAGE_STUB_FILE), updatedPackageValue);
Package aPackage = putWithOk(PACKAGES_PATH, readFile("requests/kb-ebsco/package/put-package-selected.json"), STUB_TOKEN_HEADER).as(Package.class);
assertEquals(updatedIsSelected, aPackage.getData().getAttributes().getIsSelected());
verify(putRequestedFor(PACKAGE_URL_PATTERN).withRequestBody(putBodyPattern));
}
use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesTest method shouldReturn400WhenPackagePostDataIsInvalid.
@Test
public void shouldReturn400WhenPackagePostDataIsInvalid() throws URISyntaxException, IOException {
String providerStubResponseFile = "responses/rmapi/packages/get-package-provider-by-id.json";
String packagePostStubRequestFile = "requests/kb-ebsco/package/post-package-request.json";
String response = "responses/rmapi/packages/post-package-400-error-response.json";
EqualToJsonPattern postBodyPattern = new EqualToJsonPattern("{\n \"contentType\" : 1,\n \"packageName\" : \"TEST_NAME\",\n \"customCoverage\" : {\n \"beginCoverage\" : \"2017-12-23\",\n \"endCoverage\" : \"2018-03-30\"\n }\n}", false, true);
mockGet(new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/vendors.*"), providerStubResponseFile);
mockPost(new EqualToPattern(PACKAGES_STUB_URL), postBodyPattern, response, SC_BAD_REQUEST);
RestAssured.given().spec(getRequestSpecification()).header(STUB_TOKEN_HEADER).body(readFile(packagePostStubRequestFile)).when().post(PACKAGES_ENDPOINT).then().statusCode(SC_BAD_REQUEST);
}
use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesTest method shouldPassIsFullPackageAttributeToRMAPI.
@Test
public void shouldPassIsFullPackageAttributeToRMAPI() throws URISyntaxException, IOException {
PackageByIdData updatedPackage = mapper.readValue(getFile(PACKAGE_STUB_FILE), PackageByIdData.class).toByIdBuilder().isSelected(true).build();
mockUpdateScenario(readFile(PACKAGE_STUB_FILE), mapper.writeValueAsString(updatedPackage));
PackagePutRequest request = mapper.readValue(readFile("requests/kb-ebsco/package/put-package-selected.json"), PackagePutRequest.class);
request.getData().getAttributes().setIsFullPackage(false);
putWithOk(PACKAGES_PATH, mapper.writeValueAsString(request), STUB_TOKEN_HEADER).as(Package.class);
PackagePut rmApiPutRequest = mapper.readValue(readFile("requests/rmapi/packages/put-package-is-selected.json"), PackagePut.class).toBuilder().isFullPackage(false).build();
verify(putRequestedFor(PACKAGE_URL_PATTERN).withRequestBody(new EqualToJsonPattern(mapper.writeValueAsString(rmApiPutRequest), true, true)));
}
Aggregations