use of org.folio.service.holdings.HoldingConstants.SAVE_HOLDINGS_ACTION 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.SAVE_HOLDINGS_ACTION 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());
}
use of org.folio.service.holdings.HoldingConstants.SAVE_HOLDINGS_ACTION 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.service.holdings.HoldingConstants.SAVE_HOLDINGS_ACTION in project mod-kb-ebsco-java by folio-org.
the class DefaultLoadHoldingsImplTest method shouldSendSaveHoldingsEventForEachLoadedPage.
@Test
public void shouldSendSaveHoldingsEventForEachLoadedPage(TestContext context) throws IOException, URISyntaxException {
mockGet(new EqualToPattern(RMAPI_HOLDINGS_STATUS_URL), RMAPI_RESPONSE_HOLDINGS_STATUS_COMPLETED);
mockGet(new RegexPattern(RMAPI_POST_HOLDINGS_URL), 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);
proxy.loadHoldings(new LoadHoldingsMessage(stubConfiguration, STUB_CREDENTIALS_ID, STUB_TENANT, 5001, 2, null, null));
async.await(TIMEOUT);
assertEquals(2, messages.size());
assertEquals(STUB_HOLDINGS_TITLE, messages.get(0).getHoldingList().get(0).getPublicationTitle());
}
Aggregations