Search in sources :

Example 81 with UrlPathPattern

use of com.github.tomakehurst.wiremock.matching.UrlPathPattern 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);
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) TitlePostRequest(org.folio.rest.jaxrs.model.TitlePostRequest) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Tags(org.folio.rest.jaxrs.model.Tags)

Example 82 with UrlPathPattern

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

the class EholdingsProvidersImplTest method shouldReturnProvidersOnGetWithPackages.

@Test
public void shouldReturnProvidersOnGetWithPackages() throws IOException, URISyntaxException, JSONException {
    String stubResponseFile = "responses/rmapi/vendors/get-vendor-by-id-response.json";
    String expectedProviderFile = "responses/kb-ebsco/providers/expected-provider-with-packages.json";
    stubFor(get(PROVIDER_URL_PATTERN).willReturn(new ResponseDefinitionBuilder().withBody(readFile(stubResponseFile))));
    stubFor(get(new UrlPathPattern(new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/vendors/" + STUB_VENDOR_ID + "/packages.*"), true)).willReturn(new ResponseDefinitionBuilder().withBody(readFile(STUB_PACKAGE_RESPONSE))));
    String actualProvider = getWithOk(PROVIDER_BY_ID + "?include=packages", STUB_TOKEN_HEADER).asString();
    JSONAssert.assertEquals(readFile(expectedProviderFile), actualProvider, false);
}
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)

Example 83 with UrlPathPattern

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

the class EholdingsResourcesImplTest method shouldPostResourceToRMAPI.

@Test
public void shouldPostResourceToRMAPI() throws IOException, URISyntaxException, JSONException {
    String stubTitleResponseFile = "responses/rmapi/resources/get-resource-by-id-success-response.json";
    String stubPackageResponseFile = "responses/rmapi/packages/get-custom-package-by-id-response.json";
    String stubPackageResourcesFile = "responses/rmapi/resources/get-resources-by-package-id-response.json";
    String postStubRequest = "requests/kb-ebsco/resource/post-resources-request.json";
    String expectedResourceFile = "responses/kb-ebsco/resources/expected-resource-after-post.json";
    EqualToJsonPattern putRequestBodyPattern = new EqualToJsonPattern(readFile("requests/rmapi/resources/select-resource-request.json"), true, true);
    mockPackageResources(stubPackageResourcesFile);
    mockPackage(stubPackageResponseFile);
    mockTitle(stubTitleResponseFile);
    mockResource(stubTitleResponseFile);
    mockPut(new RegexPattern(MANAGED_RESOURCE_ENDPOINT), putRequestBodyPattern, SC_NO_CONTENT);
    String actualResponse = postWithOk("eholdings/resources", readFile(postStubRequest), STUB_TOKEN_HEADER).asString();
    JSONAssert.assertEquals(readFile(expectedResourceFile), actualResponse, true);
    verify(1, putRequestedFor(new UrlPathPattern(new EqualToPattern(MANAGED_RESOURCE_ENDPOINT), false)).withRequestBody(putRequestBodyPattern));
}
Also used : EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 84 with UrlPathPattern

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

the class EholdingsResourcesImplTest method shouldReturnResourcesAndFailedIds.

@Test
public void shouldReturnResourcesAndFailedIds() throws IOException, URISyntaxException, JSONException {
    String postBody = readFile("requests/kb-ebsco/resource/post-resources-bulk-with-invalid-ids.json");
    String expectedResourceFile = "responses/kb-ebsco/resources/expected-resources-bulk-response-with-failed-ids.json";
    String resourceResponse1 = "responses/rmapi/resources/get-resource-by-id-success-response.json";
    mockGet(new EqualToPattern(MANAGED_RESOURCE_ENDPOINT), resourceResponse1);
    String resourceResponse2 = "responses/rmapi/resources/get-custom-resource-updated-response.json";
    mockGet(new EqualToPattern(CUSTOM_RESOURCE_ENDPOINT), resourceResponse2);
    String notFoundResponse = "responses/rmapi/resources/get-resource-by-id-not-found-response.json";
    stubFor(get(new UrlPathPattern(new EqualToPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/vendors/186/packages/3150130/titles/19087948"), false)).willReturn(new ResponseDefinitionBuilder().withBody(readFile(notFoundResponse)).withStatus(404)));
    final String actualResponse = postWithOk(RESOURCES_BULK_FETCH, postBody, STUB_TOKEN_HEADER).asString();
    JSONAssert.assertEquals(readFile(expectedResourceFile), actualResponse, false);
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 85 with UrlPathPattern

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

the class EholdingsResourcesImplTest method shouldReturn422OnPutPackageWithInvalidAccessTypeId.

@Test
public void shouldReturn422OnPutPackageWithInvalidAccessTypeId() throws URISyntaxException, IOException {
    String requestBody = readFile("requests/kb-ebsco/resource/put-managed-resource-with-invalid-access-type.json");
    Errors error = putWithStatus(STUB_MANAGED_RESOURCE_PATH, requestBody, SC_UNPROCESSABLE_ENTITY, CONTENT_TYPE_HEADER, STUB_TOKEN_HEADER).as(Errors.class);
    verify(0, putRequestedFor(new UrlPathPattern(new RegexPattern(MANAGED_RESOURCE_ENDPOINT), true)));
    assertEquals(1, error.getErrors().size());
    assertEquals("must match \"^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[1-5][a-fA-F0-9]{3}-[89abAB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$\"", error.getErrors().get(0).getMessage());
}
Also used : Errors(org.folio.rest.jaxrs.model.Errors) 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

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