use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsTitlesTest method shouldReturn500WhenRMApiReturns500Error.
@Test
public void shouldReturn500WhenRMApiReturns500Error() {
stubFor(get(new UrlPathPattern(new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/titles.*"), true)).willReturn(new ResponseDefinitionBuilder().withStatus(500)));
JsonapiError error = getWithStatus(EHOLDINGS_TITLES_PATH + "?filter[name]=news", SC_INTERNAL_SERVER_ERROR, STUB_TOKEN_HEADER).as(JsonapiError.class);
assertErrorContainsTitle(error, "Invalid RMAPI response");
}
use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsResourcesImplTest method shouldReturn404WhenRMAPINotFoundOnResourceGet.
@Test
public void shouldReturn404WhenRMAPINotFoundOnResourceGet() throws IOException, URISyntaxException {
String stubResponseFile = "responses/rmapi/resources/get-resource-by-id-not-found-response.json";
stubFor(get(new UrlPathPattern(new RegexPattern(MANAGED_PACKAGE_ENDPOINT + "/titles.*"), true)).willReturn(new ResponseDefinitionBuilder().withBody(readFile(stubResponseFile)).withStatus(404)));
JsonapiError error = getWithStatus(STUB_MANAGED_RESOURCE_PATH, SC_NOT_FOUND, STUB_TOKEN_HEADER).as(JsonapiError.class);
assertErrorContainsTitle(error, "Title is no longer in this package.");
}
use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsResourcesImplTest method shouldDeselectManagedResourceOnPutWithSelectedFalse.
@Test
public void shouldDeselectManagedResourceOnPutWithSelectedFalse() throws IOException, URISyntaxException, JSONException {
String stubResponseFile = "responses/rmapi/resources/get-managed-resource-updated-response-is-selected-false.json";
String expectedResourceFile = "responses/kb-ebsco/resources/expected-managed-resource.json";
ResourcePutRequest request = readJsonFile("requests/kb-ebsco/resource/put-managed-resource-is-not-selected.json", ResourcePutRequest.class);
request.getData().getAttributes().setIsSelected(false);
String actualResponse = mockUpdateResourceScenario(stubResponseFile, MANAGED_RESOURCE_ENDPOINT, STUB_MANAGED_RESOURCE_ID, Json.encode(request));
Resource expectedResource = readJsonFile(expectedResourceFile, Resource.class);
expectedResource.getData().getAttributes().setIsSelected(false);
JSONAssert.assertEquals(Json.encode(expectedResource), actualResponse, false);
verify(1, putRequestedFor(new UrlPathPattern(new RegexPattern(MANAGED_RESOURCE_ENDPOINT), true)).withRequestBody(new EqualToJsonPattern(readFile("requests/rmapi/resources/put-managed-resource-is-not-selected.json"), true, true)));
}
use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsResourcesImplTest method shouldCreateNewAccessTypeMappingOnSuccessfulPut.
@Test
public void shouldCreateNewAccessTypeMappingOnSuccessfulPut() throws IOException, URISyntaxException, JSONException {
List<AccessType> accessTypes = insertAccessTypes(testData(configuration.getId()), vertx);
String accessTypeId = accessTypes.get(0).getId();
String stubResponseFile = "responses/rmapi/resources/get-managed-resource-updated-response.json";
String expectedResourceFile = "responses/kb-ebsco/resources/expected-resource-by-id-with-access-type.json";
String requestBody = format(readFile("requests/kb-ebsco/resource/put-resource-with-access-type.json"), accessTypeId);
String actualResponse = mockUpdateResourceScenario(stubResponseFile, MANAGED_RESOURCE_ENDPOINT, STUB_MANAGED_RESOURCE_ID, requestBody);
String expectedJson = format(readFile(expectedResourceFile), accessTypeId, accessTypeId);
JSONAssert.assertEquals(expectedJson, 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(1, accessTypeMappingsInDB.size());
assertEquals(accessTypeId, accessTypeMappingsInDB.get(0).getAccessTypeId().toString());
assertEquals(RESOURCE, accessTypeMappingsInDB.get(0).getRecordType());
}
use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesTest method shouldReturn400OnGetWithResourcesWhenRMAPI400.
@Test
public void shouldReturn400OnGetWithResourcesWhenRMAPI400() throws IOException, URISyntaxException {
String stubResponseFile = "responses/rmapi/packages/get-package-resources-400-response.json";
stubFor(get(new UrlPathPattern(new RegexPattern(PACKAGE_BY_ID_URL + "/titles.*"), true)).willReturn(new ResponseDefinitionBuilder().withBody(readFile(stubResponseFile)).withStatus(SC_BAD_REQUEST)));
JsonapiError error = getWithStatus(PACKAGE_RESOURCES_PATH, SC_BAD_REQUEST, STUB_TOKEN_HEADER).as(JsonapiError.class);
assertErrorContainsTitle(error, "Parameter Count is outside the range 1-100.");
}
Aggregations