use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsResourcesImplTest method mockUpdateResourceScenario.
private String mockUpdateResourceScenario(String updatedResourceResponseFile, String resourceEndpoint, String resourceId, String requestBody) throws IOException, URISyntaxException {
stubFor(get(new UrlPathPattern(new RegexPattern(resourceEndpoint), false)).willReturn(new ResponseDefinitionBuilder().withBody(readFile(updatedResourceResponseFile))));
stubFor(put(new UrlPathPattern(new RegexPattern(resourceEndpoint), true)).willReturn(new ResponseDefinitionBuilder().withStatus(SC_NO_CONTENT)));
return putWithOk("eholdings/resources/" + resourceId, requestBody, 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 shouldDeleteAccessTypeMappingOnSuccessfulPut.
@Test
public void shouldDeleteAccessTypeMappingOnSuccessfulPut() throws IOException, URISyntaxException, JSONException {
List<AccessType> accessTypes = insertAccessTypes(testData(configuration.getId()), vertx);
String accessTypeId = accessTypes.get(0).getId();
insertAccessTypeMapping(STUB_MANAGED_RESOURCE_ID, RESOURCE, accessTypeId, vertx);
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"))));
List<AccessTypeMapping> accessTypeMappingsInDB = getAccessTypeMappings(vertx);
assertEquals(0, accessTypeMappingsInDB.size());
}
use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsStatusTest method shouldReturnTrueWhenRMAPIRequestCompletesWith200Status.
@Test
public void shouldReturnTrueWhenRMAPIRequestCompletesWith200Status() throws IOException, URISyntaxException {
setupDefaultKBConfiguration(getWiremockUrl(), vertx);
stubFor(get(new UrlPathPattern(new RegexPattern("/rm/rmaccounts.*"), true)).willReturn(new ResponseDefinitionBuilder().withBody(readFile("responses/rmapi/vendors/get-zero-vendors-response.json"))));
final ConfigurationStatus status = getWithOk(EHOLDINGS_STATUS_PATH, STUB_TOKEN_HEADER).as(ConfigurationStatus.class);
assertThat(status.getData().getAttributes().getIsConfigurationValid(), equalTo(true));
}
use of com.github.tomakehurst.wiremock.matching.RegexPattern 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.RegexPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsProvidersImplTest method shouldReturnEmptyResponseWhenProvidersReturnedWithErrorOnSearchByTags.
@Test
public void shouldReturnEmptyResponseWhenProvidersReturnedWithErrorOnSearchByTags() {
String credentialsId = configuration.getId();
ProvidersTestUtil.saveProvider(buildDbProvider(STUB_VENDOR_ID, credentialsId, STUB_VENDOR_NAME), vertx);
ProvidersTestUtil.saveProvider(buildDbProvider(STUB_VENDOR_ID_2, credentialsId, STUB_VENDOR_NAME_2), vertx);
saveTag(vertx, STUB_VENDOR_ID, PROVIDER, STUB_TAG_VALUE);
saveTag(vertx, STUB_VENDOR_ID_2, PROVIDER, STUB_TAG_VALUE);
mockGet(new RegexPattern(".*vendors/.*"), SC_INTERNAL_SERVER_ERROR);
ProviderCollection providerCollection = getWithOk(PROVIDER_PATH + "?filter[tags]=" + STUB_TAG_VALUE, STUB_TOKEN_HEADER).as(ProviderCollection.class);
List<Providers> providers = providerCollection.getData();
assertEquals(2, (int) providerCollection.getMeta().getTotalResults());
assertEquals(0, providers.size());
}
Aggregations