Search in sources :

Example 91 with RegexPattern

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

the class EholdingsPackagesTest method sendPost.

private ExtractableResponse<Response> sendPost(String requestBody) throws IOException, URISyntaxException {
    String providerStubResponseFile = "responses/rmapi/packages/get-package-provider-by-id.json";
    String packageCreatedIdStubResponseFile = "responses/rmapi/packages/post-package-response.json";
    mockGet(new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/"), providerStubResponseFile);
    mockPost(new EqualToPattern(PACKAGES_STUB_URL), new AnythingPattern(), packageCreatedIdStubResponseFile, SC_OK);
    mockGet(new EqualToPattern(PACKAGE_BY_ID_URL), PACKAGE_STUB_FILE);
    PackagePostRequest request = mapper.readValue(requestBody, PackagePostRequest.class);
    return postWithOk(PACKAGES_ENDPOINT, mapper.writeValueAsString(request), STUB_TOKEN_HEADER);
}
Also used : RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) AnythingPattern(com.github.tomakehurst.wiremock.matching.AnythingPattern) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) PackagePostRequest(org.folio.rest.jaxrs.model.PackagePostRequest)

Example 92 with RegexPattern

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

the class EholdingsPackagesTest method shouldReturnPackagesAndFailedIdsOnFetchPackagesInBulk.

@Test
public void shouldReturnPackagesAndFailedIdsOnFetchPackagesInBulk() throws IOException, URISyntaxException, JSONException {
    mockGet(new RegexPattern(PACKAGE_BY_ID_URL), PACKAGE_STUB_FILE);
    mockGet(new RegexPattern(PACKAGE_BY_ID_2_URL), PACKAGE_2_STUB_FILE);
    String notFoundResponse = "responses/rmapi/packages/get-package-by-id-not-found-response.json";
    stubFor(get(new UrlPathPattern(new EqualToPattern(PACKAGES_STUB_URL + "/9999999"), false)).willReturn(new ResponseDefinitionBuilder().withBody(readFile(notFoundResponse)).withStatus(404)));
    String postBody = readFile("requests/kb-ebsco/package/post-packages-bulk-with-non-existing-id.json");
    final String actualResponse = postWithOk(PACKAGES_BULK_FETCH_PATH, postBody, STUB_TOKEN_HEADER).asString();
    JSONAssert.assertEquals(readFile("responses/kb-ebsco/packages/expected-post-packages-bulk-with-failed-id.json"), actualResponse, false);
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) 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 93 with RegexPattern

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

the class EholdingsPackagesTest method shouldReturnResourcesWhenIncludedFlagIsSetToResources.

@Test
public void shouldReturnResourcesWhenIncludedFlagIsSetToResources() throws IOException, URISyntaxException, JSONException {
    mockGet(new RegexPattern(PACKAGE_BY_ID_URL), CUSTOM_PACKAGE_STUB_FILE);
    mockResourceById(RESOURCES_BY_PACKAGE_ID_STUB_FILE);
    Package packageData = getWithOk(PACKAGES_PATH + "?include=resources", STUB_TOKEN_HEADER).as(Package.class);
    Package expectedPackage = mapper.readValue(readFile(EXPECTED_PACKAGE_BY_ID_STUB_FILE), Package.class);
    ResourceCollection expectedResources = mapper.readValue(readFile(EXPECTED_RESOURCES_STUB_FILE), ResourceCollection.class);
    expectedPackage.getIncluded().addAll(expectedResources.getData());
    JSONAssert.assertEquals(mapper.writeValueAsString(expectedPackage), mapper.writeValueAsString(packageData), false);
}
Also used : RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Package(org.folio.rest.jaxrs.model.Package) PackagesTestUtil.buildDbPackage(org.folio.util.PackagesTestUtil.buildDbPackage) DbPackage(org.folio.repository.packages.DbPackage) PackagesTestUtil.savePackage(org.folio.util.PackagesTestUtil.savePackage) ResourceCollection(org.folio.rest.jaxrs.model.ResourceCollection) Test(org.junit.Test)

Example 94 with RegexPattern

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

the class EholdingsPackagesTest method shouldReturnPackagesOnGetWithPackageId.

@Test
public void shouldReturnPackagesOnGetWithPackageId() throws IOException, URISyntaxException, JSONException {
    String packagesStubResponseFile = "responses/rmapi/packages/get-packages-by-provider-id.json";
    String providerIdByCustIdStubResponseFile = "responses/rmapi/proxiescustomlabels/get-success-response.json";
    mockGet(new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/"), providerIdByCustIdStubResponseFile);
    mockGet(new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/vendors/" + STUB_VENDOR_ID + "/packages.*"), packagesStubResponseFile);
    String packages = getWithOk(PACKAGES_ENDPOINT + "?q=a&count=5&page=1&filter[custom]=true", STUB_TOKEN_HEADER).asString();
    JSONAssert.assertEquals(readFile("responses/kb-ebsco/packages/expected-package-collection-with-one-element.json"), packages, false);
}
Also used : RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 95 with RegexPattern

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

the class EholdingsResourcesImplTest method shouldReturnUpdatedValuesManagedResourceOnSuccessfulPut.

@Test
public void shouldReturnUpdatedValuesManagedResourceOnSuccessfulPut() throws IOException, URISyntaxException, JSONException {
    String stubResponseFile = "responses/rmapi/resources/get-managed-resource-updated-response.json";
    String expectedResourceFile = "responses/kb-ebsco/resources/expected-managed-resource.json";
    String actualResponse = mockUpdateResourceScenario(stubResponseFile, MANAGED_RESOURCE_ENDPOINT, STUB_MANAGED_RESOURCE_ID, readFile("requests/kb-ebsco/resource/put-managed-resource.json"));
    JSONAssert.assertEquals(readFile(expectedResourceFile), 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"))));
}
Also used : 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