Search in sources :

Example 41 with RegexPattern

use of com.github.tomakehurst.wiremock.matching.RegexPattern 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)

Example 42 with RegexPattern

use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-kb-ebsco-java by folio-org.

the class EholdingsPackagesTest method shouldReturnPackagesOnGetById.

@Test
public void shouldReturnPackagesOnGetById() throws IOException, URISyntaxException, JSONException {
    mockGet(new RegexPattern(PACKAGE_BY_ID_URL), CUSTOM_PACKAGE_STUB_FILE);
    String packageData = getWithOk(PACKAGES_PATH, STUB_TOKEN_HEADER).asString();
    JSONAssert.assertEquals(readFile(EXPECTED_PACKAGE_BY_ID_STUB_FILE), packageData, false);
}
Also used : RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 43 with RegexPattern

use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-kb-ebsco-java by folio-org.

the class EholdingsPackagesTest method shouldReturnPackagesOnGet.

@Test
public void shouldReturnPackagesOnGet() throws IOException, URISyntaxException, JSONException {
    String stubResponseFile = "responses/rmapi/packages/get-packages-response.json";
    mockGet(new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/packages.*"), stubResponseFile);
    String packages = getWithOk(PACKAGES_ENDPOINT + "?q=American&filter[type]=abstractandindex&count=5", STUB_TOKEN_HEADER).asString();
    JSONAssert.assertEquals(readFile("responses/kb-ebsco/packages/expected-package-collection-with-five-elements.json"), packages, false);
}
Also used : RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 44 with RegexPattern

use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-kb-ebsco-java by folio-org.

the class EholdingsPackagesTest method shouldReturnProviderWhenIncludedFlagIsSetToProvider.

@Test
public void shouldReturnProviderWhenIncludedFlagIsSetToProvider() throws IOException, URISyntaxException, JSONException {
    mockGet(new RegexPattern(PACKAGE_BY_ID_URL), CUSTOM_PACKAGE_STUB_FILE);
    mockGet(new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/vendors/" + STUB_VENDOR_ID), VENDOR_BY_PACKAGE_ID_STUB_FILE);
    String actual = getWithOk(PACKAGES_PATH + "?include=provider", STUB_TOKEN_HEADER).asString();
    String expected = readFile("responses/kb-ebsco/packages/expected-package-by-id-with-provider.json");
    JSONAssert.assertEquals(expected, actual, false);
}
Also used : RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 45 with RegexPattern

use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-kb-ebsco-java by folio-org.

the class EholdingsCustomLabelsImplTest method shouldReturn403OnGetWithResourcesWhenRMAPI401.

@Test
public void shouldReturn403OnGetWithResourcesWhenRMAPI401() {
    mockGet(new RegexPattern(RM_API_CUSTOMER_PATH), SC_UNAUTHORIZED);
    JsonapiError error = getWithStatus(KB_CUSTOM_LABELS_PATH, SC_FORBIDDEN, STUB_TOKEN_HEADER).as(JsonapiError.class);
    assertErrorContainsTitle(error, "Unauthorized Access");
}
Also used : RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) JsonapiError(org.folio.rest.jaxrs.model.JsonapiError) Test(org.junit.Test)

Aggregations

RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)148 Test (org.junit.Test)119 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)79 Matchers.containsString (org.hamcrest.Matchers.containsString)46 Async (io.vertx.ext.unit.Async)33 JsonapiError (org.folio.rest.jaxrs.model.JsonapiError)31 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)26 Before (org.junit.Before)22 JsonObject (io.vertx.core.json.JsonObject)18 MappingParameters (org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters)16 HashMap (java.util.HashMap)13 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)12 AbstractRestTest (org.folio.rest.impl.AbstractRestTest)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 TestContext (io.vertx.ext.unit.TestContext)10 WireMockConfiguration (com.github.tomakehurst.wiremock.core.WireMockConfiguration)9 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)9 IOException (java.io.IOException)9 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)9 RunWith (org.junit.runner.RunWith)9