use of org.folio.rest.impl.RmApiConstants.RMAPI_HOLDINGS_STATUS_URL in project mod-kb-ebsco-java by folio-org.
the class LoadHoldingsStatusImplTest method shouldReturnStatusPopulatingStagingArea.
@Test
public void shouldReturnStatusPopulatingStagingArea(TestContext context) throws IOException, URISyntaxException {
setupDefaultLoadKBConfiguration();
mockResponseList(new UrlPathPattern(new EqualToPattern(RMAPI_HOLDINGS_STATUS_URL), false), new ResponseDefinitionBuilder().withBody(readFile("responses/rmapi/holdings/status/get-status-in-progress.json")).withStatus(200), new ResponseDefinitionBuilder().withBody(readFile("responses/rmapi/holdings/status/get-status-completed.json")).withStatus(200));
Async startedAsync = context.async();
Handler<DeliveryContext<LoadHoldingsMessage>> interceptor = interceptAndContinue(LOAD_FACADE_ADDRESS, CREATE_SNAPSHOT_ACTION, message -> startedAsync.complete());
vertx.eventBus().addOutboundInterceptor(interceptor);
interceptors.add(interceptor);
Async finishedAsync = context.async();
interceptor = interceptAndStop(HOLDINGS_SERVICE_ADDRESS, SNAPSHOT_CREATED_ACTION, message -> finishedAsync.complete());
vertx.eventBus().addOutboundInterceptor(interceptor);
interceptors.add(interceptor);
postWithStatus(HOLDINGS_LOAD_BY_ID_URL, "", SC_NO_CONTENT, STUB_TOKEN_HEADER);
startedAsync.await(TIMEOUT);
final HoldingsLoadingStatus status = getWithOk(STUB_HOLDINGS_LOAD_STATUS_BY_ID_URL, STUB_TOKEN_HEADER).body().as(HoldingsLoadingStatus.class);
assertThat(status.getData().getAttributes().getStatus().getDetail(), equalTo(LoadStatusNameDetailEnum.POPULATING_STAGING_AREA));
finishedAsync.await(TIMEOUT);
}
use of org.folio.rest.impl.RmApiConstants.RMAPI_HOLDINGS_STATUS_URL in project mod-kb-ebsco-java by folio-org.
the class DefaultLoadHoldingsImplTest method shouldRetryCreationOfSnapshotWhenItFails.
@Test
public void shouldRetryCreationOfSnapshotWhenItFails(TestContext context) throws IOException, URISyntaxException {
setupDefaultLoadKBConfiguration();
stubFor(post(new UrlPathPattern(new EqualToPattern(RMAPI_POST_HOLDINGS_URL), false)).willReturn(new ResponseDefinitionBuilder().withBody("").withStatus(202)));
ResponseDefinitionBuilder failedResponse = new ResponseDefinitionBuilder().withStatus(500);
ResponseDefinitionBuilder successfulResponse = new ResponseDefinitionBuilder().withBody(readFile(RMAPI_RESPONSE_HOLDINGS_STATUS_COMPLETED));
mockResponseList(new UrlPathPattern(new EqualToPattern(RMAPI_HOLDINGS_STATUS_URL), 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_HOLDINGS_STATUS_URL in project mod-kb-ebsco-java by folio-org.
the class DefaultLoadHoldingsImplTest method shouldRetryLoadingHoldingsFromStartWhenPageFailsToLoad.
@Test
public void shouldRetryLoadingHoldingsFromStartWhenPageFailsToLoad(TestContext context) throws IOException, URISyntaxException {
setupDefaultLoadKBConfiguration();
mockGet(new EqualToPattern(RMAPI_HOLDINGS_STATUS_URL), RMAPI_RESPONSE_HOLDINGS_STATUS_COMPLETED);
stubFor(post(new UrlPathPattern(new EqualToPattern(RMAPI_POST_HOLDINGS_URL), false)).willReturn(new ResponseDefinitionBuilder().withBody("").withStatus(202)));
ResponseDefinitionBuilder successfulResponse = new ResponseDefinitionBuilder().withBody(readFile(RMAPI_RESPONSE_HOLDINGS)).withStatus(200);
ResponseDefinitionBuilder failedResponse = new ResponseDefinitionBuilder().withStatus(500);
mockResponseList(new UrlPathPattern(new EqualToPattern(RMAPI_POST_HOLDINGS_URL), 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_HOLDINGS_STATUS_URL in project mod-kb-ebsco-java by folio-org.
the class DefaultLoadHoldingsImplTest method shouldStopRetryingAfterMultipleFailures.
@Test
public void shouldStopRetryingAfterMultipleFailures(TestContext context) throws IOException, URISyntaxException {
setupDefaultLoadKBConfiguration();
mockGet(new EqualToPattern(RMAPI_HOLDINGS_STATUS_URL), RMAPI_RESPONSE_HOLDINGS_STATUS_COMPLETED);
UrlPathPattern urlPattern = new UrlPathPattern(new EqualToPattern(RMAPI_POST_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 org.folio.rest.impl.RmApiConstants.RMAPI_HOLDINGS_STATUS_URL in project mod-kb-ebsco-java by folio-org.
the class DefaultLoadServiceFacadeTest 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));
HoldingsLoadStatus status = readJsonFile("responses/rmapi/holdings/status/get-status-completed.json", HoldingsLoadStatus.class).toBuilder().created(now).build();
mockGetWithBody(new EqualToPattern(RMAPI_HOLDINGS_STATUS_URL), Json.encode(status));
mockPostHoldings();
interceptor = interceptAndStop(HOLDINGS_SERVICE_ADDRESS, SNAPSHOT_CREATED_ACTION, message -> async.complete());
vertx.eventBus().addOutboundInterceptor(interceptor);
loadServiceFacade.createSnapshot(new ConfigurationMessage(configuration, STUB_CREDENTIALS_ID, STUB_TENANT));
async.await(TIMEOUT);
WireMock.verify(0, postRequestedFor(new UrlPathPattern(new EqualToPattern(RMAPI_POST_HOLDINGS_URL), false)));
}
Aggregations