use of org.folio.rest.impl.RmApiConstants.RMAPI_POST_TRANSACTIONS_HOLDINGS_URL in project mod-kb-ebsco-java by folio-org.
the class TransactionLoadServiceFacadeTest method shouldNotCreateSnapshotIfItWasRecentlyCreated.
@Test
public void shouldNotCreateSnapshotIfItWasRecentlyCreated(TestContext context) throws IOException, URISyntaxException {
Async async = context.async();
String now = HOLDINGS_STATUS_TIME_FORMATTER.format(LocalDateTime.now(ZoneOffset.UTC));
HoldingsTransactionIdsList idList = readJsonFile("responses/rmapi/holdings/status/get-transaction-list.json", HoldingsTransactionIdsList.class);
HoldingsDownloadTransaction firstTransaction = idList.getHoldingsDownloadTransactionIds().get(0);
idList.getHoldingsDownloadTransactionIds().set(0, firstTransaction.toBuilder().creationDate(now).build());
HoldingsLoadTransactionStatus status = readJsonFile("responses/rmapi/holdings/status/get-transaction-status-completed.json", HoldingsLoadTransactionStatus.class).toBuilder().creationDate(now).build();
mockGetWithBody(new EqualToPattern(RMAPI_TRANSACTIONS_URL), Json.encode(idList));
mockGetWithBody(new EqualToPattern(getStatusEndpoint(TRANSACTION_ID)), Json.encode(status));
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);
WireMock.verify(0, postRequestedFor(new UrlPathPattern(new EqualToPattern(RMAPI_POST_TRANSACTIONS_HOLDINGS_URL), false)));
}
use of org.folio.rest.impl.RmApiConstants.RMAPI_POST_TRANSACTIONS_HOLDINGS_URL in project mod-kb-ebsco-java by folio-org.
the class TransactionLoadHoldingsImplTest method shouldRetryLoadingHoldingsFromStartWhenPageFailsToLoad.
@Test
public void shouldRetryLoadingHoldingsFromStartWhenPageFailsToLoad(TestContext context) throws IOException, URISyntaxException {
mockEmptyTransactionList();
mockGet(new EqualToPattern(getStatusEndpoint()), RMAPI_RESPONSE_TRANSACTION_STATUS_COMPLETED);
stubFor(post(new UrlPathPattern(new EqualToPattern(RMAPI_POST_TRANSACTIONS_HOLDINGS_URL), false)).willReturn(new ResponseDefinitionBuilder().withBody(Json.encode(createTransactionId())).withStatus(202)));
ResponseDefinitionBuilder successfulResponse = new ResponseDefinitionBuilder().withBody(readFile(RMAPI_RESPONSE_HOLDINGS)).withStatus(200);
ResponseDefinitionBuilder failedResponse = new ResponseDefinitionBuilder().withStatus(500);
mockResponseList(new UrlPathPattern(new EqualToPattern(getHoldingsEndpoint()), false), successfulResponse, failedResponse, failedResponse, successfulResponse);
int firstTryPages = 1;
int secondTryPages = 2;
Async async = context.async(firstTryPages + secondTryPages);
interceptor = interceptAndStop(HOLDINGS_SERVICE_ADDRESS, SAVE_HOLDINGS_ACTION, message -> async.countDown());
vertx.eventBus().addOutboundInterceptor(interceptor);
postWithStatus(HOLDINGS_LOAD_BY_ID_URL, "", SC_NO_CONTENT, STUB_TOKEN_HEADER);
async.await(TIMEOUT);
assertTrue(async.isSucceeded());
}
use of org.folio.rest.impl.RmApiConstants.RMAPI_POST_TRANSACTIONS_HOLDINGS_URL 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 org.folio.rest.impl.RmApiConstants.RMAPI_POST_TRANSACTIONS_HOLDINGS_URL 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));
}
Aggregations