Search in sources :

Example 86 with RegexPattern

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

the class UsersLookUpServiceTest method shouldReturn401WhenUnauthorizedAccess.

@Test
public void shouldReturn401WhenUnauthorizedAccess(TestContext context) {
    final String stubUserId = "a49cefad-7447-4f2f-9004-de32e7a6cc53";
    final String stubUserIdEndpoint = GET_USER_ENDPOINT + stubUserId;
    Async async = context.async();
    OKAPI_HEADERS.put(XOkapiHeaders.URL, getWiremockUrl());
    OKAPI_HEADERS.put(XOkapiHeaders.USER_ID, stubUserId);
    stubFor(get(new UrlPathPattern(new RegexPattern(stubUserIdEndpoint), true)).willReturn(new ResponseDefinitionBuilder().withStatus(401).withStatusMessage("Authorization Failure")));
    CompletableFuture<User> info = usersLookUpService.lookUpUser(new OkapiParams(OKAPI_HEADERS));
    info.thenCompose(result -> {
        context.assertNull(result);
        async.complete();
        return null;
    }).exceptionally(exception -> {
        context.assertTrue(exception.getCause() instanceof NotAuthorizedException);
        async.complete();
        return null;
    });
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) TestRule(org.junit.rules.TestRule) XOkapiHeaders(org.folio.okapi.common.XOkapiHeaders) URISyntaxException(java.net.URISyntaxException) WireMockConfiguration(com.github.tomakehurst.wiremock.core.WireMockConfiguration) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) Map(java.util.Map) TestUtil(org.folio.test.util.TestUtil) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) Vertx(io.vertx.core.Vertx) IOException(java.io.IOException) Test(org.junit.Test) STUB_TENANT(org.folio.test.util.TestUtil.STUB_TENANT) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) OkapiParams(org.folio.common.OkapiParams) NotFoundException(javax.ws.rs.NotFoundException) TestStartLoggingRule(org.folio.test.junit.TestStartLoggingRule) Rule(org.junit.Rule) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) Slf4jNotifier(com.github.tomakehurst.wiremock.common.Slf4jNotifier) OkapiParams(org.folio.common.OkapiParams) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Async(io.vertx.ext.unit.Async) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) Test(org.junit.Test)

Example 87 with RegexPattern

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

the class ProviderServiceImplTest method shouldReturnCachedProviderOnSecondRequest.

@Test
public void shouldReturnCachedProviderOnSecondRequest() throws IOException, URISyntaxException {
    RegexPattern getVendorPattern = new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/vendors/" + STUB_VENDOR_ID);
    Configuration configuration = Configuration.builder().url("http://127.0.0.1:" + userMockServer.port()).customerId(STUB_CUSTOMER_ID).apiKey("API KEY").build();
    ProvidersServiceImpl service = new ProvidersServiceImpl(configuration, Vertx.vertx(), STUB_TENANT, null, new VertxCache<>(Vertx.vertx(), 60, "vendorCache"));
    mockGet(getVendorPattern, VENDOR_STUB_FILE);
    service.retrieveProvider(STUB_VENDOR_ID, null, true).join();
    service.retrieveProvider(STUB_VENDOR_ID, null, true).join();
    verify(1, getRequestedFor(new UrlPattern(getVendorPattern, true)));
}
Also used : WireMockConfiguration(com.github.tomakehurst.wiremock.core.WireMockConfiguration) Configuration(org.folio.holdingsiq.model.Configuration) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) UrlPattern(com.github.tomakehurst.wiremock.matching.UrlPattern) Test(org.junit.Test)

Example 88 with RegexPattern

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

the class TitlesTestUtil method mockGetTitles.

public static void mockGetTitles() throws IOException, URISyntaxException {
    String stubResponseFile = "responses/rmapi/titles/get-title-by-id-response.json";
    stubFor(get(new UrlPathPattern(new RegexPattern("/rm/rmaccounts/TEST_CUSTOMER_ID/titles/" + STUB_MANAGED_TITLE_ID), true)).willReturn(new ResponseDefinitionBuilder().withBody(readFile(stubResponseFile))));
    String stubResponseFile2 = "responses/rmapi/titles/get-title-by-id-2-response.json";
    stubFor(get(new UrlPathPattern(new RegexPattern("/rm/rmaccounts/TEST_CUSTOMER_ID/titles/" + STUB_MANAGED_TITLE_ID_2), true)).willReturn(new ResponseDefinitionBuilder().withBody(readFile(stubResponseFile2))));
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern)

Example 89 with RegexPattern

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

the class EholdingsPackagesTest method shouldReturn400OnPutPackageWithNotExistedAccessType.

@Test
public void shouldReturn400OnPutPackageWithNotExistedAccessType() throws URISyntaxException, IOException {
    String requestBody = readFile("requests/kb-ebsco/package/put-package-with-not-existed-access-type.json");
    mockGet(new RegexPattern(PACKAGE_BY_ID_URL), CUSTOM_PACKAGE_STUB_FILE);
    JsonapiError error = putWithStatus(PACKAGES_PATH, requestBody, SC_BAD_REQUEST, CONTENT_TYPE_HEADER, STUB_TOKEN_HEADER).as(JsonapiError.class);
    assertErrorContainsTitle(error, "Access type not found: id = 99999999-9999-1999-a999-999999999999");
}
Also used : 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 90 with RegexPattern

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

the class EholdingsPackagesTest method shouldReturn404OnGetWithResourcesWhenPackageNotFound.

@Test
public void shouldReturn404OnGetWithResourcesWhenPackageNotFound() {
    mockGet(new RegexPattern(RESOURCES_BY_PACKAGE_ID_URL + ".*"), SC_NOT_FOUND);
    JsonapiError error = getWithStatus(PACKAGE_RESOURCES_PATH, SC_NOT_FOUND, STUB_TOKEN_HEADER).as(JsonapiError.class);
    assertErrorContainsTitle(error, "Package not found");
}
Also used : RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) JsonapiError(org.folio.rest.jaxrs.model.JsonapiError) 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