use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesTest method sendPost.
private ExtractableResponse<Response> sendPost(String requestBody) throws IOException, URISyntaxException {
String providerStubResponseFile = "responses/rmapi/packages/get-package-provider-by-id.json";
String packageCreatedIdStubResponseFile = "responses/rmapi/packages/post-package-response.json";
mockGet(new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/"), providerStubResponseFile);
mockPost(new EqualToPattern(PACKAGES_STUB_URL), new AnythingPattern(), packageCreatedIdStubResponseFile, SC_OK);
mockGet(new EqualToPattern(PACKAGE_BY_ID_URL), PACKAGE_STUB_FILE);
PackagePostRequest request = mapper.readValue(requestBody, PackagePostRequest.class);
return postWithOk(PACKAGES_ENDPOINT, mapper.writeValueAsString(request), STUB_TOKEN_HEADER);
}
use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesTest method shouldReturnPackagesAndFailedIdsOnFetchPackagesInBulk.
@Test
public void shouldReturnPackagesAndFailedIdsOnFetchPackagesInBulk() throws IOException, URISyntaxException, JSONException {
mockGet(new RegexPattern(PACKAGE_BY_ID_URL), PACKAGE_STUB_FILE);
mockGet(new RegexPattern(PACKAGE_BY_ID_2_URL), PACKAGE_2_STUB_FILE);
String notFoundResponse = "responses/rmapi/packages/get-package-by-id-not-found-response.json";
stubFor(get(new UrlPathPattern(new EqualToPattern(PACKAGES_STUB_URL + "/9999999"), false)).willReturn(new ResponseDefinitionBuilder().withBody(readFile(notFoundResponse)).withStatus(404)));
String postBody = readFile("requests/kb-ebsco/package/post-packages-bulk-with-non-existing-id.json");
final String actualResponse = postWithOk(PACKAGES_BULK_FETCH_PATH, postBody, STUB_TOKEN_HEADER).asString();
JSONAssert.assertEquals(readFile("responses/kb-ebsco/packages/expected-post-packages-bulk-with-failed-id.json"), actualResponse, false);
}
use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesTest method shouldReturnResourcesWhenIncludedFlagIsSetToResources.
@Test
public void shouldReturnResourcesWhenIncludedFlagIsSetToResources() throws IOException, URISyntaxException, JSONException {
mockGet(new RegexPattern(PACKAGE_BY_ID_URL), CUSTOM_PACKAGE_STUB_FILE);
mockResourceById(RESOURCES_BY_PACKAGE_ID_STUB_FILE);
Package packageData = getWithOk(PACKAGES_PATH + "?include=resources", STUB_TOKEN_HEADER).as(Package.class);
Package expectedPackage = mapper.readValue(readFile(EXPECTED_PACKAGE_BY_ID_STUB_FILE), Package.class);
ResourceCollection expectedResources = mapper.readValue(readFile(EXPECTED_RESOURCES_STUB_FILE), ResourceCollection.class);
expectedPackage.getIncluded().addAll(expectedResources.getData());
JSONAssert.assertEquals(mapper.writeValueAsString(expectedPackage), mapper.writeValueAsString(packageData), false);
}
use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesTest method shouldReturnPackagesOnGetWithPackageId.
@Test
public void shouldReturnPackagesOnGetWithPackageId() throws IOException, URISyntaxException, JSONException {
String packagesStubResponseFile = "responses/rmapi/packages/get-packages-by-provider-id.json";
String providerIdByCustIdStubResponseFile = "responses/rmapi/proxiescustomlabels/get-success-response.json";
mockGet(new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/"), providerIdByCustIdStubResponseFile);
mockGet(new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/vendors/" + STUB_VENDOR_ID + "/packages.*"), packagesStubResponseFile);
String packages = getWithOk(PACKAGES_ENDPOINT + "?q=a&count=5&page=1&filter[custom]=true", STUB_TOKEN_HEADER).asString();
JSONAssert.assertEquals(readFile("responses/kb-ebsco/packages/expected-package-collection-with-one-element.json"), packages, false);
}
use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsResourcesImplTest method shouldReturnUpdatedValuesManagedResourceOnSuccessfulPut.
@Test
public void shouldReturnUpdatedValuesManagedResourceOnSuccessfulPut() throws IOException, URISyntaxException, JSONException {
String stubResponseFile = "responses/rmapi/resources/get-managed-resource-updated-response.json";
String expectedResourceFile = "responses/kb-ebsco/resources/expected-managed-resource.json";
String actualResponse = mockUpdateResourceScenario(stubResponseFile, MANAGED_RESOURCE_ENDPOINT, STUB_MANAGED_RESOURCE_ID, readFile("requests/kb-ebsco/resource/put-managed-resource.json"));
JSONAssert.assertEquals(readFile(expectedResourceFile), actualResponse, false);
verify(1, putRequestedFor(new UrlPathPattern(new RegexPattern(MANAGED_RESOURCE_ENDPOINT), true)).withRequestBody(equalToJson(readFile("requests/rmapi/resources/put-managed-resource-is-selected-multiple-attributes.json"))));
}
Aggregations