use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsTitlesTest method postTitle.
private ExtractableResponse<Response> postTitle(List<String> tags) throws IOException, URISyntaxException {
String titleCreatedIdStubResponseFile = "responses/rmapi/titles/post-title-response.json";
String titlePostStubRequestFile = "requests/kb-ebsco/title/post-title-request.json";
String getTitleByTitleIdStubFile = "responses/rmapi/titles/get-title-by-id-for-post-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} \"userDefinedField2\": \"test 2\",\n\"userDefinedField3\": \"\",\n\"userDefinedField4\" : null,\n\"userDefinedField5\": \"test 5\"", 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(titleCreatedIdStubResponseFile)).withStatus(SC_OK)));
stubFor(get(new UrlPathPattern(new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/titles/" + STUB_TITLE_ID), true)).willReturn(new ResponseDefinitionBuilder().withBody(readFile(getTitleByTitleIdStubFile)).withStatus(SC_OK)));
ObjectMapper mapper = new ObjectMapper();
TitlePostRequest request = mapper.readValue(readFile(titlePostStubRequestFile), TitlePostRequest.class);
request.getData().getAttributes().setTags(new Tags().withTagList(tags));
return postWithOk(EHOLDINGS_TITLES_PATH, mapper.writeValueAsString(request), STUB_TOKEN_HEADER);
}
use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsProvidersImplTest method shouldReturnProvidersOnGetWithPackages.
@Test
public void shouldReturnProvidersOnGetWithPackages() throws IOException, URISyntaxException, JSONException {
String stubResponseFile = "responses/rmapi/vendors/get-vendor-by-id-response.json";
String expectedProviderFile = "responses/kb-ebsco/providers/expected-provider-with-packages.json";
stubFor(get(PROVIDER_URL_PATTERN).willReturn(new ResponseDefinitionBuilder().withBody(readFile(stubResponseFile))));
stubFor(get(new UrlPathPattern(new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/vendors/" + STUB_VENDOR_ID + "/packages.*"), true)).willReturn(new ResponseDefinitionBuilder().withBody(readFile(STUB_PACKAGE_RESPONSE))));
String actualProvider = getWithOk(PROVIDER_BY_ID + "?include=packages", STUB_TOKEN_HEADER).asString();
JSONAssert.assertEquals(readFile(expectedProviderFile), actualProvider, false);
}
use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsResourcesImplTest method shouldPostResourceToRMAPI.
@Test
public void shouldPostResourceToRMAPI() throws IOException, URISyntaxException, JSONException {
String stubTitleResponseFile = "responses/rmapi/resources/get-resource-by-id-success-response.json";
String stubPackageResponseFile = "responses/rmapi/packages/get-custom-package-by-id-response.json";
String stubPackageResourcesFile = "responses/rmapi/resources/get-resources-by-package-id-response.json";
String postStubRequest = "requests/kb-ebsco/resource/post-resources-request.json";
String expectedResourceFile = "responses/kb-ebsco/resources/expected-resource-after-post.json";
EqualToJsonPattern putRequestBodyPattern = new EqualToJsonPattern(readFile("requests/rmapi/resources/select-resource-request.json"), true, true);
mockPackageResources(stubPackageResourcesFile);
mockPackage(stubPackageResponseFile);
mockTitle(stubTitleResponseFile);
mockResource(stubTitleResponseFile);
mockPut(new RegexPattern(MANAGED_RESOURCE_ENDPOINT), putRequestBodyPattern, SC_NO_CONTENT);
String actualResponse = postWithOk("eholdings/resources", readFile(postStubRequest), STUB_TOKEN_HEADER).asString();
JSONAssert.assertEquals(readFile(expectedResourceFile), actualResponse, true);
verify(1, putRequestedFor(new UrlPathPattern(new EqualToPattern(MANAGED_RESOURCE_ENDPOINT), false)).withRequestBody(putRequestBodyPattern));
}
use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsResourcesImplTest method shouldReturnResourcesAndFailedIds.
@Test
public void shouldReturnResourcesAndFailedIds() throws IOException, URISyntaxException, JSONException {
String postBody = readFile("requests/kb-ebsco/resource/post-resources-bulk-with-invalid-ids.json");
String expectedResourceFile = "responses/kb-ebsco/resources/expected-resources-bulk-response-with-failed-ids.json";
String resourceResponse1 = "responses/rmapi/resources/get-resource-by-id-success-response.json";
mockGet(new EqualToPattern(MANAGED_RESOURCE_ENDPOINT), resourceResponse1);
String resourceResponse2 = "responses/rmapi/resources/get-custom-resource-updated-response.json";
mockGet(new EqualToPattern(CUSTOM_RESOURCE_ENDPOINT), resourceResponse2);
String notFoundResponse = "responses/rmapi/resources/get-resource-by-id-not-found-response.json";
stubFor(get(new UrlPathPattern(new EqualToPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/vendors/186/packages/3150130/titles/19087948"), false)).willReturn(new ResponseDefinitionBuilder().withBody(readFile(notFoundResponse)).withStatus(404)));
final String actualResponse = postWithOk(RESOURCES_BULK_FETCH, postBody, STUB_TOKEN_HEADER).asString();
JSONAssert.assertEquals(readFile(expectedResourceFile), actualResponse, false);
}
use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsResourcesImplTest method shouldReturn422OnPutPackageWithInvalidAccessTypeId.
@Test
public void shouldReturn422OnPutPackageWithInvalidAccessTypeId() throws URISyntaxException, IOException {
String requestBody = readFile("requests/kb-ebsco/resource/put-managed-resource-with-invalid-access-type.json");
Errors error = putWithStatus(STUB_MANAGED_RESOURCE_PATH, requestBody, SC_UNPROCESSABLE_ENTITY, CONTENT_TYPE_HEADER, STUB_TOKEN_HEADER).as(Errors.class);
verify(0, putRequestedFor(new UrlPathPattern(new RegexPattern(MANAGED_RESOURCE_ENDPOINT), true)));
assertEquals(1, error.getErrors().size());
assertEquals("must match \"^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[1-5][a-fA-F0-9]{3}-[89abAB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$\"", error.getErrors().get(0).getMessage());
}
Aggregations