use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsTitlesTest method mockGetManagedTitleById.
private void mockGetManagedTitleById() throws IOException, URISyntaxException {
String stubResponseFile = "responses/rmapi/titles/get-title-by-id-response.json";
stubFor(get(new UrlPathPattern(new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/titles.*"), true)).willReturn(new ResponseDefinitionBuilder().withBody(readFile(stubResponseFile))));
}
use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsTitlesTest method shouldReturn500WhenRMApiReturns500ErrorOnTitleGet.
@Test
public void shouldReturn500WhenRMApiReturns500ErrorOnTitleGet() {
stubFor(get(new UrlPathPattern(new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/titles.*"), true)).willReturn(new ResponseDefinitionBuilder().withStatus(500)));
JsonapiError error = getWithStatus(EHOLDINGS_TITLES_PATH + "/" + STUB_TITLE_ID, SC_INTERNAL_SERVER_ERROR, STUB_TOKEN_HEADER).as(JsonapiError.class);
assertErrorContainsTitle(error, "Invalid RMAPI response");
}
use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsTitlesTest method shouldUpdateTitleDataOnSecondPut.
@Test
public void shouldUpdateTitleDataOnSecondPut() throws IOException, URISyntaxException {
String newName = "new name";
String updatedResponse = "responses/rmapi/resources/get-custom-resource-updated-title-name-response.json";
putTitle(readFile(updatedResponse), Collections.singletonList(STUB_TAG_VALUE));
ObjectMapper mapper = new ObjectMapper();
TitlePutRequest request = mapper.readValue(readFile("requests/kb-ebsco/title/put-title.json"), TitlePutRequest.class);
request.getData().getAttributes().withName(newName);
stubFor(get(new UrlPathPattern(new RegexPattern(CUSTOM_TITLE_ENDPOINT), false)).willReturn(new ResponseDefinitionBuilder().withBody(readFile(updatedResponse))));
putWithOk(EHOLDINGS_TITLES_PATH + "/" + STUB_CUSTOM_TITLE_ID, mapper.writeValueAsString(request), STUB_TOKEN_HEADER);
List<DbTitle> titles = TitlesTestUtil.getTitles(vertx);
assertEquals(1, titles.size());
assertEqualsLong(titles.get(0).getId());
assertEquals(newName, titles.get(0).getName());
}
use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsTitlesTest method putTitle.
private String putTitle(String updatedResourceResponse, List<String> tags) throws IOException, URISyntaxException {
stubFor(get(new UrlPathPattern(new RegexPattern(CUSTOM_TITLE_ENDPOINT), false)).willReturn(new ResponseDefinitionBuilder().withBody(updatedResourceResponse)));
stubFor(put(new UrlPathPattern(new RegexPattern(CUSTOM_RESOURCE_ENDPOINT), true)).willReturn(new ResponseDefinitionBuilder().withStatus(SC_NO_CONTENT)));
ObjectMapper mapper = new ObjectMapper();
TitlePutRequest titleToBeUpdated = mapper.readValue(readFile("requests/kb-ebsco/title/put-title.json"), TitlePutRequest.class);
if (tags != null) {
titleToBeUpdated.getData().getAttributes().setTags(new Tags().withTagList(tags));
}
return putWithOk(EHOLDINGS_TITLES_PATH + "/" + STUB_CUSTOM_TITLE_ID, mapper.writeValueAsString(titleToBeUpdated), STUB_TOKEN_HEADER).asString();
}
use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsResourcesImplTest method shouldReturn400OnPutPackageWithNotExistedAccessType.
@Test
public void shouldReturn400OnPutPackageWithNotExistedAccessType() throws URISyntaxException, IOException {
String requestBody = readFile("requests/kb-ebsco/resource/put-managed-resource-with-missing-access-type.json");
JsonapiError error = putWithStatus(STUB_MANAGED_RESOURCE_PATH, requestBody, SC_BAD_REQUEST, CONTENT_TYPE_HEADER, STUB_TOKEN_HEADER).as(JsonapiError.class);
verify(0, putRequestedFor(new UrlPathPattern(new RegexPattern(MANAGED_RESOURCE_ENDPOINT), true)));
assertErrorContainsTitle(error, "Access type not found: id = 99999999-9999-1999-a999-999999999999");
}
Aggregations