use of org.folio.service.holdings.HoldingConstants.HOLDINGS_SERVICE_ADDRESS 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.service.holdings.HoldingConstants.HOLDINGS_SERVICE_ADDRESS in project mod-kb-ebsco-java by folio-org.
the class TransactionLoadServiceFacadeTest method shouldCreateSnapshotUsingExistingTransactionIfItIsInProgress.
@Test
public void shouldCreateSnapshotUsingExistingTransactionIfItIsInProgress(TestContext context) throws IOException, URISyntaxException {
Async async = context.async();
mockGetWithBody(new EqualToPattern(RMAPI_TRANSACTIONS_URL), readFile("responses/rmapi/holdings/status/get-transaction-list-in-progress.json"));
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 org.folio.service.holdings.HoldingConstants.HOLDINGS_SERVICE_ADDRESS 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.service.holdings.HoldingConstants.HOLDINGS_SERVICE_ADDRESS 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.service.holdings.HoldingConstants.HOLDINGS_SERVICE_ADDRESS in project mod-kb-ebsco-java by folio-org.
the class TransactionLoadHoldingsImplTest method shouldSendSaveHoldingsEventForEachLoadedPage.
@Test
public void shouldSendSaveHoldingsEventForEachLoadedPage(TestContext context) throws IOException, URISyntaxException {
mockEmptyTransactionList();
mockGet(new EqualToPattern(getStatusEndpoint()), RMAPI_RESPONSE_TRANSACTION_STATUS_COMPLETED);
mockGet(new RegexPattern(getHoldingsEndpoint()), RMAPI_RESPONSE_HOLDINGS);
List<HoldingsMessage> messages = new ArrayList<>();
Async async = context.async(EXPECTED_LOADED_PAGES);
interceptor = interceptAndStop(HOLDINGS_SERVICE_ADDRESS, SAVE_HOLDINGS_ACTION, message -> {
messages.add(((JsonObject) message.body()).getJsonObject("holdings").mapTo(HoldingsMessage.class));
async.countDown();
});
vertx.eventBus().addOutboundInterceptor(interceptor);
LoadServiceFacade proxy = LoadServiceFacade.createProxy(vertx, LOAD_FACADE_ADDRESS);
LoadHoldingsMessage message = new LoadHoldingsMessage(this.configuration, STUB_CREDENTIALS_ID, STUB_TENANT, 5001, 2, TRANSACTION_ID, null);
proxy.loadHoldings(message);
async.await(TIMEOUT);
assertEquals(2, messages.size());
assertEquals(STUB_HOLDINGS_TITLE, messages.get(0).getHoldingList().get(0).getPublicationTitle());
}
Aggregations