Search in sources :

Example 21 with EqualToJsonPattern

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

the class EholdingsPackagesTest method shouldDeletePackageTagsOnDelete.

@Test
public void shouldDeletePackageTagsOnDelete() throws IOException, URISyntaxException {
    saveTag(vertx, FULL_PACKAGE_ID, PACKAGE, "test one");
    mockGet(new EqualToPattern(PACKAGE_BY_ID_URL), CUSTOM_PACKAGE_STUB_FILE);
    EqualToJsonPattern putBodyPattern = new EqualToJsonPattern("{\"isSelected\":false}", true, true);
    mockPut(new EqualToPattern(PACKAGE_BY_ID_URL), putBodyPattern, SC_NO_CONTENT);
    deleteWithNoContent(PACKAGES_PATH, STUB_TOKEN_HEADER);
    List<String> tagsAfterRequest = TagsTestUtil.getTagsForRecordType(vertx, PACKAGE);
    assertThat(tagsAfterRequest, empty());
}
Also used : EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 22 with EqualToJsonPattern

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

the class EholdingsPackagesTest method shouldSendDeleteRequestForPackage.

@Test
public void shouldSendDeleteRequestForPackage() throws IOException, URISyntaxException {
    EqualToJsonPattern putBodyPattern = new EqualToJsonPattern("{\"isSelected\":false}", true, true);
    mockGet(new EqualToPattern(PACKAGE_BY_ID_URL), CUSTOM_PACKAGE_STUB_FILE);
    mockPut(new EqualToPattern(PACKAGE_BY_ID_URL), putBodyPattern, SC_NO_CONTENT);
    deleteWithNoContent(PACKAGES_PATH, STUB_TOKEN_HEADER);
    verify(1, putRequestedFor(PACKAGE_URL_PATTERN).withRequestBody(putBodyPattern));
}
Also used : EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) Test(org.junit.Test)

Example 23 with EqualToJsonPattern

use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern 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 24 with EqualToJsonPattern

use of com.github.tomakehurst.wiremock.matching.EqualToJsonPattern 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 25 with EqualToJsonPattern

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

the class EholdingsResourcesImplTest method shouldDeleteAccessTypeOnDeleteRequest.

@Test
public void shouldDeleteAccessTypeOnDeleteRequest() throws IOException, URISyntaxException {
    String accessTypeId = insertAccessTypes(testData(configuration.getId()), vertx).get(0).getId();
    insertAccessTypeMapping(STUB_CUSTOM_RESOURCE_ID, RecordType.RESOURCE, accessTypeId, vertx);
    EqualToJsonPattern putBodyPattern = new EqualToJsonPattern("{\"isSelected\":false}", true, true);
    deleteResource(putBodyPattern);
    List<AccessTypeMapping> actualMappings = getAccessTypeMappings(vertx);
    assertThat(actualMappings, empty());
}
Also used : EqualToJsonPattern(com.github.tomakehurst.wiremock.matching.EqualToJsonPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) AccessTypeMapping(org.folio.repository.accesstypes.AccessTypeMapping) AccessTypesTestUtil.insertAccessTypeMapping(org.folio.util.AccessTypesTestUtil.insertAccessTypeMapping) Test(org.junit.Test)

Aggregations

EqualToJsonPattern (com.github.tomakehurst.wiremock.matching.EqualToJsonPattern)29 Test (org.junit.Test)22 Matchers.containsString (org.hamcrest.Matchers.containsString)18 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)11 DbPackage (org.folio.repository.packages.DbPackage)9 Package (org.folio.rest.jaxrs.model.Package)9 PackagesTestUtil.buildDbPackage (org.folio.util.PackagesTestUtil.buildDbPackage)9 PackagesTestUtil.savePackage (org.folio.util.PackagesTestUtil.savePackage)9 PackageByIdData (org.folio.holdingsiq.model.PackageByIdData)8 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)7 AccessTypeMapping (org.folio.repository.accesstypes.AccessTypeMapping)7 AccessTypesTestUtil.insertAccessTypeMapping (org.folio.util.AccessTypesTestUtil.insertAccessTypeMapping)7 Test (org.junit.jupiter.api.Test)5 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)4 AccessType (org.folio.rest.jaxrs.model.AccessType)4 AccessTypesTestUtil.insertAccessType (org.folio.util.AccessTypesTestUtil.insertAccessType)4 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)2 StubMapping (com.github.tomakehurst.wiremock.stubbing.StubMapping)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 TestEnvironments (fi.otavanopisto.muikku.TestEnvironments)1