Search in sources :

Example 76 with UrlPathPattern

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

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

Example 78 with UrlPathPattern

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

the class EholdingsResourcesImplTest method mockUpdateResourceScenario.

private String mockUpdateResourceScenario(String updatedResourceResponseFile, String resourceEndpoint, String resourceId, String requestBody) throws IOException, URISyntaxException {
    stubFor(get(new UrlPathPattern(new RegexPattern(resourceEndpoint), false)).willReturn(new ResponseDefinitionBuilder().withBody(readFile(updatedResourceResponseFile))));
    stubFor(put(new UrlPathPattern(new RegexPattern(resourceEndpoint), true)).willReturn(new ResponseDefinitionBuilder().withStatus(SC_NO_CONTENT)));
    return putWithOk("eholdings/resources/" + resourceId, requestBody, STUB_TOKEN_HEADER).asString();
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern)

Example 79 with UrlPathPattern

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

the class EholdingsResourcesImplTest method shouldDeleteAccessTypeMappingOnSuccessfulPut.

@Test
public void shouldDeleteAccessTypeMappingOnSuccessfulPut() throws IOException, URISyntaxException, JSONException {
    List<AccessType> accessTypes = insertAccessTypes(testData(configuration.getId()), vertx);
    String accessTypeId = accessTypes.get(0).getId();
    insertAccessTypeMapping(STUB_MANAGED_RESOURCE_ID, RESOURCE, accessTypeId, vertx);
    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"))));
    List<AccessTypeMapping> accessTypeMappingsInDB = getAccessTypeMappings(vertx);
    assertEquals(0, accessTypeMappingsInDB.size());
}
Also used : UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Matchers.containsString(org.hamcrest.Matchers.containsString) AccessTypeMapping(org.folio.repository.accesstypes.AccessTypeMapping) AccessTypesTestUtil.insertAccessTypeMapping(org.folio.util.AccessTypesTestUtil.insertAccessTypeMapping) AccessType(org.folio.rest.jaxrs.model.AccessType) Test(org.junit.Test)

Example 80 with UrlPathPattern

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

the class EholdingsStatusTest method shouldReturnTrueWhenRMAPIRequestCompletesWith200Status.

@Test
public void shouldReturnTrueWhenRMAPIRequestCompletesWith200Status() throws IOException, URISyntaxException {
    setupDefaultKBConfiguration(getWiremockUrl(), vertx);
    stubFor(get(new UrlPathPattern(new RegexPattern("/rm/rmaccounts.*"), true)).willReturn(new ResponseDefinitionBuilder().withBody(readFile("responses/rmapi/vendors/get-zero-vendors-response.json"))));
    final ConfigurationStatus status = getWithOk(EHOLDINGS_STATUS_PATH, STUB_TOKEN_HEADER).as(ConfigurationStatus.class);
    assertThat(status.getData().getAttributes().getIsConfigurationValid(), equalTo(true));
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) ConfigurationStatus(org.folio.rest.jaxrs.model.ConfigurationStatus) 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