use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsTitlesTest method shouldReturnTitlesOnGetWithResources.
@Test
public void shouldReturnTitlesOnGetWithResources() throws IOException, URISyntaxException, JSONException {
String stubResponseFile = "responses/rmapi/titles/searchTitles.json";
stubFor(get(new UrlPathPattern(new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/titles.*"), true)).willReturn(new ResponseDefinitionBuilder().withBody(readFile(stubResponseFile))));
String resourcePath = EHOLDINGS_TITLES_PATH + "?page=1&filter[name]=Mind&sort=name&include=resources";
String actualResponse = getWithOk(resourcePath, STUB_TOKEN_HEADER).asString();
JSONAssert.assertEquals(readFile("responses/kb-ebsco/titles/expected-titles-with-resources.json"), actualResponse, true);
}
use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-kb-ebsco-java by folio-org.
the class EholdingsTitlesTest method shouldReturnUpdatedValuesForCustomTitleOnSuccessfulPut.
@Test
public void shouldReturnUpdatedValuesForCustomTitleOnSuccessfulPut() throws IOException, URISyntaxException, JSONException {
String expectedTitleFile = "responses/kb-ebsco/titles/expected-updated-title.json";
String actualResponse = putTitle(null);
JSONAssert.assertEquals(readFile(expectedTitleFile), actualResponse, false);
verify(1, putRequestedFor(new UrlPathPattern(new RegexPattern(CUSTOM_RESOURCE_ENDPOINT), true)).withRequestBody(equalToJson(readFile("requests/rmapi/resources/put-custom-resource-is-selected-multiple-attributes.json"))));
}
use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-kb-ebsco-java by folio-org.
the class TransactionLoadHoldingsImplTest method shouldRetryCreationOfSnapshotWhenItFails.
@Test
public void shouldRetryCreationOfSnapshotWhenItFails(TestContext context) throws IOException, URISyntaxException {
mockEmptyTransactionList();
stubFor(post(new UrlPathPattern(new EqualToPattern(RMAPI_POST_TRANSACTIONS_HOLDINGS_URL), false)).willReturn(new ResponseDefinitionBuilder().withBody(Json.encode(createTransactionId())).withStatus(202)));
ResponseDefinitionBuilder failedResponse = new ResponseDefinitionBuilder().withStatus(500);
ResponseDefinitionBuilder successfulResponse = new ResponseDefinitionBuilder().withBody(readFile(RMAPI_RESPONSE_TRANSACTION_STATUS_COMPLETED));
mockResponseList(new UrlPathPattern(new EqualToPattern(getStatusEndpoint()), false), failedResponse, successfulResponse, successfulResponse);
Async async = context.async();
interceptor = interceptAndStop(HOLDINGS_SERVICE_ADDRESS, SNAPSHOT_CREATED_ACTION, message -> async.complete());
vertx.eventBus().addOutboundInterceptor(interceptor);
postWithStatus(HOLDINGS_LOAD_BY_ID_URL, "", SC_NO_CONTENT, STUB_TOKEN_HEADER);
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 TransactionLoadHoldingsImplTest method shouldStopRetryingAfterMultipleFailures.
@Test
public void shouldStopRetryingAfterMultipleFailures(TestContext context) throws IOException, URISyntaxException {
mockEmptyTransactionList();
mockGet(new EqualToPattern(getStatusEndpoint()), RMAPI_RESPONSE_TRANSACTION_STATUS_COMPLETED);
UrlPathPattern urlPattern = new UrlPathPattern(new EqualToPattern(RMAPI_POST_TRANSACTIONS_HOLDINGS_URL), false);
stubFor(post(urlPattern).willReturn(new ResponseDefinitionBuilder().withStatus(500)));
Async async = context.async(TEST_SNAPSHOT_RETRY_COUNT);
interceptor = interceptAndContinue(HOLDINGS_SERVICE_ADDRESS, SNAPSHOT_FAILED_ACTION, o -> async.countDown());
vertx.eventBus().addOutboundInterceptor(interceptor);
postWithStatus(HOLDINGS_LOAD_BY_ID_URL, "", SC_NO_CONTENT, STUB_TOKEN_HEADER);
async.await(TIMEOUT);
Async retryStatusAsync = context.async();
retryStatusRepository.findByCredentialsId(UUID.fromString(STUB_CREDENTIALS_ID), STUB_TENANT).thenAccept(status -> {
boolean timerExists = vertx.cancelTimer(status.getTimerId());
context.assertEquals(0, status.getRetryAttemptsLeft());
context.assertFalse(timerExists);
retryStatusAsync.complete();
});
retryStatusAsync.await(TIMEOUT);
verify(TEST_SNAPSHOT_RETRY_COUNT, RequestPatternBuilder.newRequestPattern(RequestMethod.POST, urlPattern));
}
use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-kb-ebsco-java by folio-org.
the class DefaultLoadHoldingsImplTest method shouldRetryLoadingPageWhenPageFails.
@Test
public void shouldRetryLoadingPageWhenPageFails(TestContext context) throws IOException, URISyntaxException {
setupDefaultLoadKBConfiguration();
Async async = context.async();
handleStatusChange(COMPLETED, holdingsStatusRepository, o -> async.complete());
mockGet(new EqualToPattern(RMAPI_HOLDINGS_STATUS_URL), "responses/rmapi/holdings/status/get-status-completed-one-page.json");
mockPostHoldings();
mockResponseList(new UrlPathPattern(new EqualToPattern(RMAPI_POST_HOLDINGS_URL), false), new ResponseDefinitionBuilder().withStatus(SC_INTERNAL_SERVER_ERROR), new ResponseDefinitionBuilder().withBody(readFile(RMAPI_RESPONSE_HOLDINGS)));
postWithStatus(HOLDINGS_LOAD_BY_ID_URL, "", SC_NO_CONTENT, STUB_TOKEN_HEADER);
async.await(TIMEOUT);
assertTrue(async.isSucceeded());
}
Aggregations