Search in sources :

Example 56 with RegexPattern

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

the class EHoldingsRootProxyImplTest method shouldReturnRootProxyWhenUserAssignedToKbCredentials.

@Test
public void shouldReturnRootProxyWhenUserAssignedToKbCredentials() throws IOException, URISyntaxException, JSONException {
    saveKbCredentials(STUB_CREDENTIALS_ID, getWiremockUrl(), STUB_CREDENTIALS_NAME, STUB_API_KEY, STUB_CUSTOMER_ID, vertx);
    saveAssignedUser(JOHN_ID, STUB_CREDENTIALS_ID, vertx);
    mockGet(new RegexPattern(RMAPI_ROOT_PROXY_CUSTOM_LABELS_URL), RMAPI_ROOT_PROXY_CUSTOM_LABELS_RESPONSE);
    String actual = getWithStatus(EHOLDINGS_ROOT_PROXY_URL, SC_OK, JOHN_TOKEN_HEADER).asString();
    String expected = readFile(KB_EBSCO_GET_ROOT_PROXY_RESPONSE);
    JSONAssert.assertEquals(expected, actual, true);
}
Also used : RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Test(org.junit.Test)

Example 57 with RegexPattern

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

the class UsersLookUpServiceTest method shouldReturn200WhenUserIdIsValid.

@Test
public void shouldReturn200WhenUserIdIsValid(TestContext context) throws IOException, URISyntaxException {
    final String stubUserId = "88888888-8888-4888-8888-888888888888";
    final String stubUserIdEndpoint = GET_USER_ENDPOINT + stubUserId;
    Async async = context.async();
    OKAPI_HEADERS.put(XOkapiHeaders.TENANT, STUB_TENANT);
    OKAPI_HEADERS.put(XOkapiHeaders.URL, getWiremockUrl());
    OKAPI_HEADERS.put(XOkapiHeaders.USER_ID, stubUserId);
    stubFor(get(new UrlPathPattern(new RegexPattern(stubUserIdEndpoint), true)).willReturn(new ResponseDefinitionBuilder().withBody(TestUtil.readFile(USER_INFO_STUB_FILE))));
    CompletableFuture<User> info = usersLookUpService.lookUpUser(new OkapiParams(OKAPI_HEADERS));
    info.thenCompose(userInfo -> {
        context.assertNotNull(userInfo);
        context.assertEquals("cedrick", userInfo.getUserName());
        context.assertEquals("firstname_test", userInfo.getFirstName());
        context.assertNull(userInfo.getMiddleName());
        context.assertEquals("lastname_test", userInfo.getLastName());
        async.complete();
        return null;
    }).exceptionally(throwable -> {
        context.fail(throwable);
        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) Test(org.junit.Test)

Example 58 with RegexPattern

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

the class PackageServiceImplTest method shouldReturnCachedPackage.

@Test
public void shouldReturnCachedPackage() throws IOException, URISyntaxException {
    RegexPattern getPackagePattern = new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/vendors/" + STUB_VENDOR_ID + "/packages/" + STUB_PACKAGE_ID);
    Configuration configuration = Configuration.builder().url("http://127.0.0.1:" + userMockServer.port()).customerId(STUB_CUSTOMER_ID).apiKey("API KEY").build();
    PackageServiceImpl service = new PackageServiceImpl(configuration, Vertx.vertx(), STUB_TENANT, null, null, new VertxCache<>(Vertx.vertx(), 60, "packageCache"), null);
    mockGet(getPackagePattern, CUSTOM_PACKAGE_STUB_FILE);
    PackageId packageId = PackageId.builder().packageIdPart(STUB_PACKAGE_ID).providerIdPart(STUB_VENDOR_ID).build();
    service.retrievePackage(packageId, Collections.emptyList(), true).join();
    service.retrievePackage(packageId, Collections.emptyList(), true).join();
    verify(1, getRequestedFor(new UrlPattern(getPackagePattern, true)));
}
Also used : WireMockConfiguration(com.github.tomakehurst.wiremock.core.WireMockConfiguration) Configuration(org.folio.holdingsiq.model.Configuration) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) PackageId(org.folio.holdingsiq.model.PackageId) UrlPattern(com.github.tomakehurst.wiremock.matching.UrlPattern) Test(org.junit.Test)

Example 59 with RegexPattern

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

the class ResourceServiceImplTest method shouldReturnCachedResource.

@Test
public void shouldReturnCachedResource() throws IOException, URISyntaxException {
    RegexPattern getResourcePattern = new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/vendors/" + STUB_VENDOR_ID + "/packages/" + STUB_PACKAGE_ID + "/titles/" + STUB_TITLE_ID);
    Configuration configuration = Configuration.builder().url("http://127.0.0.1:" + userMockServer.port()).customerId(STUB_CUSTOMER_ID).apiKey("API KEY").build();
    ResourcesServiceImpl service = new ResourcesServiceImpl(configuration, Vertx.vertx(), STUB_TENANT, null, null, new VertxCache<>(Vertx.vertx(), 60, "resourceCache"));
    mockGet(getResourcePattern, CUSTOM_RESOURCE_STUB_FILE);
    ResourceId resourceId = ResourceId.builder().packageIdPart(STUB_PACKAGE_ID).providerIdPart(STUB_VENDOR_ID).titleIdPart(STUB_TITLE_ID).build();
    service.retrieveResource(resourceId, Collections.emptyList(), true).join();
    service.retrieveResource(resourceId, Collections.emptyList(), true).join();
    verify(1, getRequestedFor(new UrlPattern(getResourcePattern, true)));
}
Also used : WireMockConfiguration(com.github.tomakehurst.wiremock.core.WireMockConfiguration) Configuration(org.folio.holdingsiq.model.Configuration) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) ResourceId(org.folio.holdingsiq.model.ResourceId) UrlPattern(com.github.tomakehurst.wiremock.matching.UrlPattern) Test(org.junit.Test)

Example 60 with RegexPattern

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

the class TitleServiceImplTest method shouldNotUseCache.

@Test
public void shouldNotUseCache() throws IOException, URISyntaxException {
    RegexPattern getTitlePattern = new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/titles/" + STUB_TITLE_ID);
    TitlesServiceImpl service = new TitlesServiceImpl(configuration, Vertx.vertx(), STUB_TENANT, new VertxCache<>(Vertx.vertx(), 60, "titleCache"));
    mockGet(getTitlePattern, TITLE_STUB_FILE);
    service.retrieveTitle(STUB_TITLE_ID, false).join();
    verify(1, getRequestedFor(new UrlPattern(getTitlePattern, true)));
}
Also used : RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) UrlPattern(com.github.tomakehurst.wiremock.matching.UrlPattern) 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