Search in sources :

Example 1 with HoldingsDownloadTransaction

use of org.folio.holdingsiq.model.HoldingsDownloadTransaction 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)));
}
Also used : HoldingsDownloadTransaction(org.folio.holdingsiq.model.HoldingsDownloadTransaction) TestContext(io.vertx.ext.unit.TestContext) KbCredentialsTestUtil.saveKbCredentials(org.folio.util.KbCredentialsTestUtil.saveKbCredentials) URISyntaxException(java.net.URISyntaxException) Autowired(org.springframework.beans.factory.annotation.Autowired) LoadHoldingsMessage(org.folio.service.holdings.message.LoadHoldingsMessage) After(org.junit.After) HoldingsStatusUtil.saveStatusNotStarted(org.folio.util.HoldingsStatusUtil.saveStatusNotStarted) TransactionId(org.folio.holdingsiq.model.TransactionId) KBTestUtil.clearDataFromTable(org.folio.util.KBTestUtil.clearDataFromTable) KBTestUtil.interceptAndStop(org.folio.util.KBTestUtil.interceptAndStop) ZoneOffset(java.time.ZoneOffset) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) HoldingsTransactionIdsList(org.folio.holdingsiq.model.HoldingsTransactionIdsList) ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) HOLDINGS_STATUS_TIME_FORMATTER(org.folio.service.holdings.AbstractLoadServiceFacade.HOLDINGS_STATUS_TIME_FORMATTER) SNAPSHOT_CREATED_ACTION(org.folio.service.holdings.HoldingConstants.SNAPSHOT_CREATED_ACTION) STUB_TENANT(org.folio.test.util.TestUtil.STUB_TENANT) RMAPI_TRANSACTIONS_URL(org.folio.rest.impl.RmApiConstants.RMAPI_TRANSACTIONS_URL) HOLDINGS_SERVICE_ADDRESS(org.folio.service.holdings.HoldingConstants.HOLDINGS_SERVICE_ADDRESS) KB_CREDENTIALS_TABLE_NAME(org.folio.repository.kbcredentials.KbCredentialsTableConstants.KB_CREDENTIALS_TABLE_NAME) Configuration(org.folio.holdingsiq.model.Configuration) TransactionLoadServiceFacade(org.folio.service.holdings.TransactionLoadServiceFacade) Async(io.vertx.ext.unit.Async) WireMockTestBase(org.folio.rest.impl.WireMockTestBase) Json(io.vertx.core.json.Json) LocalDateTime(java.time.LocalDateTime) RunWith(org.junit.runner.RunWith) WireMock.postRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor) TestUtil.mockResponseList(org.folio.test.util.TestUtil.mockResponseList) WireMock(com.github.tomakehurst.wiremock.client.WireMock) HoldingsRetryStatusTestUtil.insertRetryStatus(org.folio.util.HoldingsRetryStatusTestUtil.insertRetryStatus) Before(org.junit.Before) TestUtil.mockGetWithBody(org.folio.test.util.TestUtil.mockGetWithBody) DeliveryContext(io.vertx.core.eventbus.DeliveryContext) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RMAPI_TRANSACTION_STATUS_URL(org.folio.rest.impl.RmApiConstants.RMAPI_TRANSACTION_STATUS_URL) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) HoldingsLoadTransactionStatus(org.folio.holdingsiq.model.HoldingsLoadTransactionStatus) TestUtil.readJsonFile(org.folio.test.util.TestUtil.readJsonFile) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) HoldingsDownloadTransaction(org.folio.holdingsiq.model.HoldingsDownloadTransaction) STUB_CREDENTIALS_NAME(org.folio.util.KbCredentialsTestUtil.STUB_CREDENTIALS_NAME) ConfigurationMessage(org.folio.service.holdings.message.ConfigurationMessage) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) TestUtil.readFile(org.folio.test.util.TestUtil.readFile) RMAPI_POST_TRANSACTIONS_HOLDINGS_URL(org.folio.rest.impl.RmApiConstants.RMAPI_POST_TRANSACTIONS_HOLDINGS_URL) Handler(io.vertx.core.Handler) Collections(java.util.Collections) HoldingsLoadTransactionStatus(org.folio.holdingsiq.model.HoldingsLoadTransactionStatus) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) Async(io.vertx.ext.unit.Async) HoldingsTransactionIdsList(org.folio.holdingsiq.model.HoldingsTransactionIdsList) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) ConfigurationMessage(org.folio.service.holdings.message.ConfigurationMessage) Test(org.junit.Test)

Example 2 with HoldingsDownloadTransaction

use of org.folio.holdingsiq.model.HoldingsDownloadTransaction in project mod-kb-ebsco-java by folio-org.

the class TransactionLoadServiceFacade method getLastLoadingStatus.

@Override
protected CompletableFuture<HoldingsStatus> getLastLoadingStatus(LoadService loadingService) {
    return loadingService.getTransactions().thenCompose(transactions -> {
        if (transactions.getHoldingsDownloadTransactionIds().isEmpty()) {
            return CompletableFuture.completedFuture(createNoneStatus());
        }
        List<HoldingsDownloadTransaction> sortedTransactions = sortByDate(transactions);
        HoldingsDownloadTransaction lastTransaction = sortedTransactions.get(sortedTransactions.size() - 1);
        return getLoadingStatus(loadingService, lastTransaction.getTransactionId());
    });
}
Also used : HoldingsDownloadTransaction(org.folio.holdingsiq.model.HoldingsDownloadTransaction)

Example 3 with HoldingsDownloadTransaction

use of org.folio.holdingsiq.model.HoldingsDownloadTransaction in project mod-kb-ebsco-java by folio-org.

the class TransactionLoadHoldingsImplTest method shouldUpdateHoldingsWithDeltas.

@Test
public void shouldUpdateHoldingsWithDeltas(TestContext context) throws IOException, URISyntaxException {
    HoldingsTestUtil.saveHolding(STUB_CREDENTIALS_ID, Json.decodeValue(readFile("responses/kb-ebsco/holdings/custom-holding.json"), DbHoldingInfo.class), OffsetDateTime.now(), vertx);
    HoldingsTestUtil.saveHolding(STUB_CREDENTIALS_ID, Json.decodeValue(readFile("responses/kb-ebsco/holdings/custom-holding2.json"), DbHoldingInfo.class), OffsetDateTime.now(), vertx);
    TransactionIdTestUtil.addTransactionId(STUB_CREDENTIALS_ID, PREVIOUS_TRANSACTION_ID, vertx);
    HoldingsDownloadTransaction previousTransaction = HoldingsDownloadTransaction.builder().creationDate(OffsetDateTime.now().minus(500, ChronoUnit.HOURS).toString()).transactionId(PREVIOUS_TRANSACTION_ID).build();
    mockTransactionList(Collections.singletonList(previousTransaction));
    mockPostHoldings();
    mockGet(new EqualToPattern(getStatusEndpoint(PREVIOUS_TRANSACTION_ID)), RMAPI_RESPONSE_TRANSACTION_STATUS_COMPLETED);
    mockGet(new EqualToPattern(getStatusEndpoint(TRANSACTION_ID)), RMAPI_RESPONSE_TRANSACTION_STATUS_COMPLETED);
    mockPostDeltaReport();
    mockGet(new EqualToPattern(getDeltaReportStatusEndpoint()), "responses/rmapi/holdings/status/get-delta-report-status-completed.json");
    mockGet(new EqualToPattern(getDeltaEndpoint()), "responses/rmapi/holdings/delta/get-delta.json");
    Async async = context.async();
    handleStatusChange(COMPLETED, holdingsStatusRepository, o -> async.complete());
    postWithStatus(HOLDINGS_LOAD_BY_ID_URL, "", SC_NO_CONTENT, STUB_TOKEN_HEADER);
    async.await(TIMEOUT);
    Map<String, DbHoldingInfo> holdings = HoldingsTestUtil.getHoldings(vertx).stream().collect(Collectors.toMap(this::getHoldingsId, Function.identity()));
    assertFalse(holdings.containsKey(DELETED_HOLDING_ID));
    DbHoldingInfo updatedHolding = holdings.get(UPDATED_HOLDING_ID);
    assertEquals("Test Title Updated", updatedHolding.getPublicationTitle());
    assertEquals("Test one Press Updated", updatedHolding.getPublisherName());
    assertEquals("Book", updatedHolding.getResourceType());
    DbHoldingInfo addedHolding = holdings.get(ADDED_HOLDING_ID);
    assertEquals("Added test title", addedHolding.getPublicationTitle());
    assertEquals("Added test publisher", addedHolding.getPublisherName());
    assertEquals("Book", addedHolding.getResourceType());
}
Also used : HoldingsDownloadTransaction(org.folio.holdingsiq.model.HoldingsDownloadTransaction) Async(io.vertx.ext.unit.Async) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DbHoldingInfo(org.folio.repository.holdings.DbHoldingInfo) Test(org.junit.Test)

Aggregations

HoldingsDownloadTransaction (org.folio.holdingsiq.model.HoldingsDownloadTransaction)3 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)2 Async (io.vertx.ext.unit.Async)2 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)1 WireMock (com.github.tomakehurst.wiremock.client.WireMock)1 WireMock.post (com.github.tomakehurst.wiremock.client.WireMock.post)1 WireMock.postRequestedFor (com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor)1 WireMock.stubFor (com.github.tomakehurst.wiremock.client.WireMock.stubFor)1 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)1 Handler (io.vertx.core.Handler)1 DeliveryContext (io.vertx.core.eventbus.DeliveryContext)1 Json (io.vertx.core.json.Json)1 TestContext (io.vertx.ext.unit.TestContext)1 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 LocalDateTime (java.time.LocalDateTime)1 ZoneOffset (java.time.ZoneOffset)1 Collections (java.util.Collections)1 Configuration (org.folio.holdingsiq.model.Configuration)1