Search in sources :

Example 26 with UrlPathPattern

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");
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) JsonapiError(org.folio.rest.jaxrs.model.JsonapiError) Test(org.junit.Test)

Example 27 with UrlPathPattern

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.");
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) JsonapiError(org.folio.rest.jaxrs.model.JsonapiError) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 28 with UrlPathPattern

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)));
}
Also used : EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) ResourcePutRequest(org.folio.rest.jaxrs.model.ResourcePutRequest) DbResource(org.folio.repository.resources.DbResource) Resource(org.folio.rest.jaxrs.model.Resource) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 29 with UrlPathPattern

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());
}
Also used : UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) AccessTypeMapping(org.folio.repository.accesstypes.AccessTypeMapping) AccessTypesTestUtil.insertAccessTypeMapping(org.folio.util.AccessTypesTestUtil.insertAccessTypeMapping) AccessType(org.folio.rest.jaxrs.model.AccessType) Test(org.junit.Test)

Example 30 with UrlPathPattern

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.");
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) JsonapiError(org.folio.rest.jaxrs.model.JsonapiError) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)112 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)84 Test (org.junit.Test)76 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)54 Async (io.vertx.ext.unit.Async)42 Before (org.junit.Before)33 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)28 Matchers.containsString (org.hamcrest.Matchers.containsString)26 JsonObject (io.vertx.core.json.JsonObject)22 TestContext (io.vertx.ext.unit.TestContext)20 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)19 IOException (java.io.IOException)19 RunWith (org.junit.runner.RunWith)19 MappingParameters (org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters)16 WireMock.stubFor (com.github.tomakehurst.wiremock.client.WireMock.stubFor)15 URISyntaxException (java.net.URISyntaxException)15 STUB_TENANT (org.folio.test.util.TestUtil.STUB_TENANT)14 After (org.junit.After)14 WireMock.post (com.github.tomakehurst.wiremock.client.WireMock.post)13 HashMap (java.util.HashMap)13