Search in sources :

Example 21 with RegexPattern

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

the class EholdingsProvidersImplTest method shouldReturnProviderPackagesWhenValidId.

@Test
public void shouldReturnProviderPackagesWhenValidId() throws IOException, URISyntaxException, JSONException {
    mockGet(new RegexPattern(PROVIDER_PACKAGES_RM_API_PATH), STUB_PACKAGE_RESPONSE);
    String actual = getWithOk(PROVIDER_PACKAGES, STUB_TOKEN_HEADER).asString();
    String expected = readFile("responses/kb-ebsco/packages/expected-package-collection-with-one-element.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 22 with RegexPattern

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

the class EholdingsTitlesTest method shouldUpdateOnlyTagsOnPutForNonCustomTitle.

@Test
public void shouldUpdateOnlyTagsOnPutForNonCustomTitle() throws IOException, URISyntaxException {
    String resourceResponse = "responses/rmapi/resources/get-managed-resource-updated-response.json";
    ObjectMapper mapper = new ObjectMapper();
    TitlePutRequest request = mapper.readValue(readFile("requests/kb-ebsco/title/put-title.json"), TitlePutRequest.class);
    List<String> newTags = Arrays.asList(STUB_TAG_VALUE, STUB_TAG_VALUE_2);
    request.getData().getAttributes().setTags(new Tags().withTagList(newTags));
    stubFor(get(new UrlPathPattern(new RegexPattern(CUSTOM_TITLE_ENDPOINT), false)).willReturn(new ResponseDefinitionBuilder().withBody(readFile(resourceResponse))));
    putWithOk(EHOLDINGS_TITLES_PATH + "/" + STUB_CUSTOM_TITLE_ID, mapper.writeValueAsString(request), STUB_TOKEN_HEADER);
    List<String> tags = TagsTestUtil.getTags(vertx);
    assertThat(tags, containsInAnyOrder(newTags.toArray()));
    WireMock.verify(0, putRequestedFor(anyUrl()));
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) TitlePutRequest(org.folio.rest.jaxrs.model.TitlePutRequest) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Tags(org.folio.rest.jaxrs.model.Tags) Test(org.junit.Test)

Example 23 with RegexPattern

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

the class EholdingsTitlesTest method shouldReturn404WhenRMAPINotFoundOnTitleGet.

@Test
public void shouldReturn404WhenRMAPINotFoundOnTitleGet() throws IOException, URISyntaxException {
    String stubResponseFile = "responses/rmapi/titles/get-title-by-id-not-found-response.json";
    stubFor(get(new UrlPathPattern(new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/titles.*"), true)).willReturn(new ResponseDefinitionBuilder().withBody(readFile(stubResponseFile)).withStatus(404)));
    JsonapiError error = getWithStatus(EHOLDINGS_TITLES_PATH + "/" + STUB_TITLE_ID, SC_NOT_FOUND, STUB_TOKEN_HEADER).as(JsonapiError.class);
    assertErrorContainsTitle(error, "Title not found");
}
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 24 with RegexPattern

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

the class EholdingsTitlesTest method shouldReturnTitleWithoutResourcesWhenInvalidInclude.

@Test
public void shouldReturnTitleWithoutResourcesWhenInvalidInclude() throws IOException, URISyntaxException, JSONException {
    String rmapiResponseFile = "responses/rmapi/titles/get-title-by-id-response.json";
    String rmapiUrl = "/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/titles.*";
    mockGet(new RegexPattern(rmapiUrl), rmapiResponseFile);
    String actual = getWithStatus(EHOLDINGS_TITLES_PATH + "/" + STUB_TITLE_ID + "?include=badValue", SC_OK, STUB_TOKEN_HEADER).asString();
    String expected = readFile("responses/kb-ebsco/titles/get-title-by-id-invalid-include-response.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 25 with RegexPattern

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

the class EholdingsTitlesTest method shouldReturnTitlesOnGet.

@Test
public void shouldReturnTitlesOnGet() throws IOException, URISyntaxException, JSONException {
    String stubResponseFile = "responses/rmapi/titles/searchTitles.json";
    stubFor(get(new UrlPathPattern(new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/titles.*"), true)).willReturn(new ResponseDefinitionBuilder().withBody(readFile(stubResponseFile))));
    String resourcePath = EHOLDINGS_TITLES_PATH + "?page=1&filter[name]=Mind&sort=name";
    String actualResponse = getWithOk(resourcePath, STUB_TOKEN_HEADER).asString();
    JSONAssert.assertEquals(readFile("responses/kb-ebsco/titles/expected-titles.json"), actualResponse, true);
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) 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