use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-kb-ebsco-java by folio-org.
the class LoadHoldingsStatusImplTest method shouldReturnStatusCompleted.
@Test
public void shouldReturnStatusCompleted(TestContext context) throws IOException, URISyntaxException {
setupDefaultLoadKBConfiguration();
mockGet(new EqualToPattern(RMAPI_HOLDINGS_STATUS_URL), "responses/rmapi/holdings/status/get-status-completed-one-page.json");
stubFor(post(new UrlPathPattern(new EqualToPattern(RMAPI_POST_HOLDINGS_URL), false)).willReturn(new ResponseDefinitionBuilder().withBody("").withStatus(202)));
mockGet(new RegexPattern(RMAPI_POST_HOLDINGS_URL), "responses/rmapi/holdings/holdings/get-holdings.json");
Async async = context.async();
handleStatusChange(COMPLETED, holdingsStatusRepository, o -> async.complete());
postWithStatus(HOLDINGS_LOAD_BY_ID_URL, "", SC_NO_CONTENT, STUB_TOKEN_HEADER);
async.await(TIMEOUT);
final HoldingsLoadingStatus status = getWithOk(STUB_HOLDINGS_LOAD_STATUS_BY_ID_URL, STUB_TOKEN_HEADER).body().as(HoldingsLoadingStatus.class);
assertThat(status.getData().getType(), equalTo(LoadStatusData.Type.STATUS));
assertThat(status.getData().getAttributes().getTotalCount(), equalTo(2));
assertThat(status.getData().getAttributes().getStatus().getName(), equalTo(COMPLETED));
assertTrue(parse(status.getData().getAttributes().getStarted(), POSTGRES_TIMESTAMP_FORMATTER).isBefore(parse(status.getData().getAttributes().getFinished(), POSTGRES_TIMESTAMP_FORMATTER)));
}
use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-kb-ebsco-java by folio-org.
the class TransactionLoadServiceFacadeTest method shouldCreateSnapshotOnInitialStatusNone.
@Test
public void shouldCreateSnapshotOnInitialStatusNone(TestContext context) throws IOException, URISyntaxException {
Async async = context.async();
mockEmptyTransactionList();
mockResponseList(new UrlPathPattern(new EqualToPattern(getStatusEndpoint(TRANSACTION_ID)), false), new ResponseDefinitionBuilder().withBody(readFile("responses/rmapi/holdings/status/get-transaction-status-completed.json")));
mockPostHoldings();
interceptor = interceptAndStop(HOLDINGS_SERVICE_ADDRESS, SNAPSHOT_CREATED_ACTION, message -> async.complete());
vertx.eventBus().addOutboundInterceptor(interceptor);
loadServiceFacade.createSnapshot(new ConfigurationMessage(stubConfiguration, STUB_CREDENTIALS_ID, STUB_TENANT));
async.await(TIMEOUT);
assertTrue(async.isSucceeded());
}
use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-kb-ebsco-java by folio-org.
the class UsersLookUpServiceTest method shouldReturn404WhenUserNotFound.
@Test
public void shouldReturn404WhenUserNotFound(TestContext context) {
final String stubUserId = "xyz";
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().withStatus(404).withStatusMessage("User Not Found")));
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 NotFoundException);
async.complete();
return null;
});
}
use of com.github.tomakehurst.wiremock.matching.UrlPathPattern 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.UrlPathPattern 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))));
}
Aggregations