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;
});
}
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)));
}
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))));
}
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");
}
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");
}
Aggregations