Search in sources :

Example 1 with HOLDINGS_SERVICE_ADDRESS

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);
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) RMAPI_POST_HOLDINGS_URL(org.folio.rest.impl.RmApiConstants.RMAPI_POST_HOLDINGS_URL) TestContext(io.vertx.ext.unit.TestContext) STUB_TOKEN_HEADER(org.folio.util.KbCredentialsTestUtil.STUB_TOKEN_HEADER) KbCredentialsTestUtil.saveKbCredentials(org.folio.util.KbCredentialsTestUtil.saveKbCredentials) FAILED(org.folio.rest.jaxrs.model.LoadStatusNameEnum.FAILED) URISyntaxException(java.net.URISyntaxException) KBTestUtil.interceptAndContinue(org.folio.util.KBTestUtil.interceptAndContinue) Autowired(org.springframework.beans.factory.annotation.Autowired) RMAPI_HOLDINGS_STATUS_URL(org.folio.rest.impl.RmApiConstants.RMAPI_HOLDINGS_STATUS_URL) LoadStatusNameEnum(org.folio.rest.jaxrs.model.LoadStatusNameEnum) LoadHoldingsMessage(org.folio.service.holdings.message.LoadHoldingsMessage) MockitoAnnotations(org.mockito.MockitoAnnotations) After(org.junit.After) Spy(org.mockito.Spy) HoldingsStatusUtil.saveStatusNotStarted(org.folio.util.HoldingsStatusUtil.saveStatusNotStarted) KBTestUtil.clearDataFromTable(org.folio.util.KBTestUtil.clearDataFromTable) KBTestUtil.interceptAndStop(org.folio.util.KBTestUtil.interceptAndStop) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) SC_INTERNAL_SERVER_ERROR(org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR) DefaultLoadHoldingsImplTest.handleStatusChange(org.folio.rest.impl.integrationsuite.DefaultLoadHoldingsImplTest.handleStatusChange) ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) LoadStatusData(org.folio.rest.jaxrs.model.LoadStatusData) CREATE_SNAPSHOT_ACTION(org.folio.service.holdings.HoldingConstants.CREATE_SNAPSHOT_ACTION) SNAPSHOT_CREATED_ACTION(org.folio.service.holdings.HoldingConstants.SNAPSHOT_CREATED_ACTION) UUID(java.util.UUID) HoldingsService(org.folio.service.holdings.HoldingsService) HOLDINGS_SERVICE_ADDRESS(org.folio.service.holdings.HoldingConstants.HOLDINGS_SERVICE_ADDRESS) KB_CREDENTIALS_TABLE_NAME(org.folio.repository.kbcredentials.KbCredentialsTableConstants.KB_CREDENTIALS_TABLE_NAME) List(java.util.List) Matchers.equalTo(org.hamcrest.Matchers.equalTo) SC_NOT_FOUND(org.apache.http.HttpStatus.SC_NOT_FOUND) Matchers.containsString(org.hamcrest.Matchers.containsString) SC_NO_CONTENT(org.apache.http.HttpStatus.SC_NO_CONTENT) Async(io.vertx.ext.unit.Async) WireMockTestBase(org.folio.rest.impl.WireMockTestBase) HOLDINGS_LOAD_BY_ID_URL(org.folio.rest.impl.integrationsuite.DefaultLoadHoldingsImplTest.HOLDINGS_LOAD_BY_ID_URL) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) RunWith(org.junit.runner.RunWith) POSTGRES_TIMESTAMP_FORMATTER(org.folio.service.holdings.HoldingsServiceImpl.POSTGRES_TIMESTAMP_FORMATTER) TestUtil.mockResponseList(org.folio.test.util.TestUtil.mockResponseList) ArrayList(java.util.ArrayList) COMPLETED(org.folio.rest.jaxrs.model.LoadStatusNameEnum.COMPLETED) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HoldingsRetryStatusTestUtil.insertRetryStatus(org.folio.util.HoldingsRetryStatusTestUtil.insertRetryStatus) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) DeliveryContext(io.vertx.core.eventbus.DeliveryContext) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) TestUtil.mockGet(org.folio.test.util.TestUtil.mockGet) Assert.assertTrue(org.junit.Assert.assertTrue) HoldingsLoadingStatus(org.folio.rest.jaxrs.model.HoldingsLoadingStatus) IOException(java.io.IOException) Test(org.junit.Test) LoadStatusNameDetailEnum(org.folio.rest.jaxrs.model.LoadStatusNameDetailEnum) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) STUB_CREDENTIALS_NAME(org.folio.util.KbCredentialsTestUtil.STUB_CREDENTIALS_NAME) LOAD_FACADE_ADDRESS(org.folio.service.holdings.HoldingConstants.LOAD_FACADE_ADDRESS) HoldingsStatusRepositoryImpl(org.folio.repository.holdings.status.HoldingsStatusRepositoryImpl) JsonapiError(org.folio.rest.jaxrs.model.JsonapiError) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) TestUtil.readFile(org.folio.test.util.TestUtil.readFile) Handler(io.vertx.core.Handler) ZonedDateTime.parse(java.time.ZonedDateTime.parse) SC_UNAUTHORIZED(org.apache.http.HttpStatus.SC_UNAUTHORIZED) HoldingsLoadingStatus(org.folio.rest.jaxrs.model.HoldingsLoadingStatus) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) Async(io.vertx.ext.unit.Async) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) DeliveryContext(io.vertx.core.eventbus.DeliveryContext) Test(org.junit.Test)

Example 2 with HOLDINGS_SERVICE_ADDRESS

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());
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) 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) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) Async(io.vertx.ext.unit.Async) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) ConfigurationMessage(org.folio.service.holdings.message.ConfigurationMessage) Test(org.junit.Test)

Example 3 with HOLDINGS_SERVICE_ADDRESS

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)));
}
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 4 with HOLDINGS_SERVICE_ADDRESS

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());
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) TestContext(io.vertx.ext.unit.TestContext) STUB_TOKEN_HEADER(org.folio.util.KbCredentialsTestUtil.STUB_TOKEN_HEADER) KbCredentialsTestUtil.saveKbCredentials(org.folio.util.KbCredentialsTestUtil.saveKbCredentials) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) HoldingsMessage(org.folio.service.holdings.message.HoldingsMessage) URISyntaxException(java.net.URISyntaxException) KBTestUtil.interceptAndContinue(org.folio.util.KBTestUtil.interceptAndContinue) Autowired(org.springframework.beans.factory.annotation.Autowired) LoadStatusNameEnum(org.folio.rest.jaxrs.model.LoadStatusNameEnum) LoadHoldingsMessage(org.folio.service.holdings.message.LoadHoldingsMessage) MockitoAnnotations(org.mockito.MockitoAnnotations) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) After(org.junit.After) Spy(org.mockito.Spy) HoldingsStatusUtil.saveStatusNotStarted(org.folio.util.HoldingsStatusUtil.saveStatusNotStarted) TransactionId(org.folio.holdingsiq.model.TransactionId) JsonObject(io.vertx.core.json.JsonObject) KBTestUtil.clearDataFromTable(org.folio.util.KBTestUtil.clearDataFromTable) KBTestUtil.interceptAndStop(org.folio.util.KBTestUtil.interceptAndStop) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) SC_INTERNAL_SERVER_ERROR(org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR) HoldingsTransactionIdsList(org.folio.holdingsiq.model.HoldingsTransactionIdsList) RMAPI_DELTAS_URL(org.folio.rest.impl.RmApiConstants.RMAPI_DELTAS_URL) LoadServiceFacade(org.folio.service.holdings.LoadServiceFacade) SNAPSHOT_FAILED_ACTION(org.folio.service.holdings.HoldingConstants.SNAPSHOT_FAILED_ACTION) AfterClass(org.junit.AfterClass) ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) SNAPSHOT_CREATED_ACTION(org.folio.service.holdings.HoldingConstants.SNAPSHOT_CREATED_ACTION) STUB_TENANT(org.folio.test.util.TestUtil.STUB_TENANT) UUID(java.util.UUID) HoldingsService(org.folio.service.holdings.HoldingsService) RMAPI_TRANSACTIONS_URL(org.folio.rest.impl.RmApiConstants.RMAPI_TRANSACTIONS_URL) Collectors(java.util.stream.Collectors) HOLDINGS_SERVICE_ADDRESS(org.folio.service.holdings.HoldingConstants.HOLDINGS_SERVICE_ADDRESS) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) KB_CREDENTIALS_TABLE_NAME(org.folio.repository.kbcredentials.KbCredentialsTableConstants.KB_CREDENTIALS_TABLE_NAME) RMAPI_DELTA_BY_ID_URL(org.folio.rest.impl.RmApiConstants.RMAPI_DELTA_BY_ID_URL) List(java.util.List) StringValuePattern(com.github.tomakehurst.wiremock.matching.StringValuePattern) OffsetDateTime(java.time.OffsetDateTime) Assert.assertFalse(org.junit.Assert.assertFalse) Configuration(org.folio.holdingsiq.model.Configuration) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) SC_NO_CONTENT(org.apache.http.HttpStatus.SC_NO_CONTENT) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) HoldingsTestUtil(org.folio.util.HoldingsTestUtil) BeforeClass(org.junit.BeforeClass) HOLDINGS_LOAD_BY_ID_URL(org.folio.rest.impl.integrationsuite.DefaultLoadHoldingsImplTest.HOLDINGS_LOAD_BY_ID_URL) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) RunWith(org.junit.runner.RunWith) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) TestUtil.mockResponseList(org.folio.test.util.TestUtil.mockResponseList) ArrayList(java.util.ArrayList) DbHoldingInfo(org.folio.repository.holdings.DbHoldingInfo) COMPLETED(org.folio.rest.jaxrs.model.LoadStatusNameEnum.COMPLETED) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HoldingsRetryStatusTestUtil.insertRetryStatus(org.folio.util.HoldingsRetryStatusTestUtil.insertRetryStatus) Before(org.junit.Before) TestUtil.mockGetWithBody(org.folio.test.util.TestUtil.mockGetWithBody) InjectMocks(org.mockito.InjectMocks) DeliveryContext(io.vertx.core.eventbus.DeliveryContext) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) TestUtil.mockGet(org.folio.test.util.TestUtil.mockGet) RMAPI_TRANSACTION_STATUS_URL(org.folio.rest.impl.RmApiConstants.RMAPI_TRANSACTION_STATUS_URL) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) IOException(java.io.IOException) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) HoldingsDownloadTransaction(org.folio.holdingsiq.model.HoldingsDownloadTransaction) STUB_CREDENTIALS_NAME(org.folio.util.KbCredentialsTestUtil.STUB_CREDENTIALS_NAME) Consumer(java.util.function.Consumer) LOAD_FACADE_ADDRESS(org.folio.service.holdings.HoldingConstants.LOAD_FACADE_ADDRESS) HoldingsStatusRepositoryImpl(org.folio.repository.holdings.status.HoldingsStatusRepositoryImpl) ChronoUnit(java.time.temporal.ChronoUnit) TransactionIdTestUtil(org.folio.util.TransactionIdTestUtil) RetryStatusRepository(org.folio.repository.holdings.status.retry.RetryStatusRepository) RMAPI_DELTA_STATUS_URL(org.folio.rest.impl.RmApiConstants.RMAPI_DELTA_STATUS_URL) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) TestUtil.readFile(org.folio.test.util.TestUtil.readFile) RequestMethod(com.github.tomakehurst.wiremock.http.RequestMethod) RMAPI_TRANSACTION_BY_ID_URL(org.folio.rest.impl.RmApiConstants.RMAPI_TRANSACTION_BY_ID_URL) RMAPI_POST_TRANSACTIONS_HOLDINGS_URL(org.folio.rest.impl.RmApiConstants.RMAPI_POST_TRANSACTIONS_HOLDINGS_URL) Handler(io.vertx.core.Handler) SAVE_HOLDINGS_ACTION(org.folio.service.holdings.HoldingConstants.SAVE_HOLDINGS_ACTION) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) Async(io.vertx.ext.unit.Async) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) Test(org.junit.Test)

Example 5 with HOLDINGS_SERVICE_ADDRESS

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());
}
Also used : TestContext(io.vertx.ext.unit.TestContext) STUB_TOKEN_HEADER(org.folio.util.KbCredentialsTestUtil.STUB_TOKEN_HEADER) KbCredentialsTestUtil.saveKbCredentials(org.folio.util.KbCredentialsTestUtil.saveKbCredentials) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) HoldingsMessage(org.folio.service.holdings.message.HoldingsMessage) URISyntaxException(java.net.URISyntaxException) KBTestUtil.interceptAndContinue(org.folio.util.KBTestUtil.interceptAndContinue) Autowired(org.springframework.beans.factory.annotation.Autowired) LoadStatusNameEnum(org.folio.rest.jaxrs.model.LoadStatusNameEnum) LoadHoldingsMessage(org.folio.service.holdings.message.LoadHoldingsMessage) MockitoAnnotations(org.mockito.MockitoAnnotations) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) After(org.junit.After) Spy(org.mockito.Spy) HoldingsStatusUtil.saveStatusNotStarted(org.folio.util.HoldingsStatusUtil.saveStatusNotStarted) TransactionId(org.folio.holdingsiq.model.TransactionId) JsonObject(io.vertx.core.json.JsonObject) KBTestUtil.clearDataFromTable(org.folio.util.KBTestUtil.clearDataFromTable) KBTestUtil.interceptAndStop(org.folio.util.KBTestUtil.interceptAndStop) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) SC_INTERNAL_SERVER_ERROR(org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR) HoldingsTransactionIdsList(org.folio.holdingsiq.model.HoldingsTransactionIdsList) RMAPI_DELTAS_URL(org.folio.rest.impl.RmApiConstants.RMAPI_DELTAS_URL) LoadServiceFacade(org.folio.service.holdings.LoadServiceFacade) SNAPSHOT_FAILED_ACTION(org.folio.service.holdings.HoldingConstants.SNAPSHOT_FAILED_ACTION) AfterClass(org.junit.AfterClass) ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) SNAPSHOT_CREATED_ACTION(org.folio.service.holdings.HoldingConstants.SNAPSHOT_CREATED_ACTION) STUB_TENANT(org.folio.test.util.TestUtil.STUB_TENANT) UUID(java.util.UUID) HoldingsService(org.folio.service.holdings.HoldingsService) RMAPI_TRANSACTIONS_URL(org.folio.rest.impl.RmApiConstants.RMAPI_TRANSACTIONS_URL) Collectors(java.util.stream.Collectors) HOLDINGS_SERVICE_ADDRESS(org.folio.service.holdings.HoldingConstants.HOLDINGS_SERVICE_ADDRESS) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) KB_CREDENTIALS_TABLE_NAME(org.folio.repository.kbcredentials.KbCredentialsTableConstants.KB_CREDENTIALS_TABLE_NAME) RMAPI_DELTA_BY_ID_URL(org.folio.rest.impl.RmApiConstants.RMAPI_DELTA_BY_ID_URL) List(java.util.List) StringValuePattern(com.github.tomakehurst.wiremock.matching.StringValuePattern) OffsetDateTime(java.time.OffsetDateTime) Assert.assertFalse(org.junit.Assert.assertFalse) Configuration(org.folio.holdingsiq.model.Configuration) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) SC_NO_CONTENT(org.apache.http.HttpStatus.SC_NO_CONTENT) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) HoldingsTestUtil(org.folio.util.HoldingsTestUtil) BeforeClass(org.junit.BeforeClass) HOLDINGS_LOAD_BY_ID_URL(org.folio.rest.impl.integrationsuite.DefaultLoadHoldingsImplTest.HOLDINGS_LOAD_BY_ID_URL) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) RunWith(org.junit.runner.RunWith) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) TestUtil.mockResponseList(org.folio.test.util.TestUtil.mockResponseList) ArrayList(java.util.ArrayList) DbHoldingInfo(org.folio.repository.holdings.DbHoldingInfo) COMPLETED(org.folio.rest.jaxrs.model.LoadStatusNameEnum.COMPLETED) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HoldingsRetryStatusTestUtil.insertRetryStatus(org.folio.util.HoldingsRetryStatusTestUtil.insertRetryStatus) Before(org.junit.Before) TestUtil.mockGetWithBody(org.folio.test.util.TestUtil.mockGetWithBody) InjectMocks(org.mockito.InjectMocks) DeliveryContext(io.vertx.core.eventbus.DeliveryContext) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) TestUtil.mockGet(org.folio.test.util.TestUtil.mockGet) RMAPI_TRANSACTION_STATUS_URL(org.folio.rest.impl.RmApiConstants.RMAPI_TRANSACTION_STATUS_URL) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) IOException(java.io.IOException) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) HoldingsDownloadTransaction(org.folio.holdingsiq.model.HoldingsDownloadTransaction) STUB_CREDENTIALS_NAME(org.folio.util.KbCredentialsTestUtil.STUB_CREDENTIALS_NAME) Consumer(java.util.function.Consumer) LOAD_FACADE_ADDRESS(org.folio.service.holdings.HoldingConstants.LOAD_FACADE_ADDRESS) HoldingsStatusRepositoryImpl(org.folio.repository.holdings.status.HoldingsStatusRepositoryImpl) ChronoUnit(java.time.temporal.ChronoUnit) TransactionIdTestUtil(org.folio.util.TransactionIdTestUtil) RetryStatusRepository(org.folio.repository.holdings.status.retry.RetryStatusRepository) RMAPI_DELTA_STATUS_URL(org.folio.rest.impl.RmApiConstants.RMAPI_DELTA_STATUS_URL) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) TestUtil.readFile(org.folio.test.util.TestUtil.readFile) RequestMethod(com.github.tomakehurst.wiremock.http.RequestMethod) RMAPI_TRANSACTION_BY_ID_URL(org.folio.rest.impl.RmApiConstants.RMAPI_TRANSACTION_BY_ID_URL) RMAPI_POST_TRANSACTIONS_HOLDINGS_URL(org.folio.rest.impl.RmApiConstants.RMAPI_POST_TRANSACTIONS_HOLDINGS_URL) Handler(io.vertx.core.Handler) SAVE_HOLDINGS_ACTION(org.folio.service.holdings.HoldingConstants.SAVE_HOLDINGS_ACTION) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LoadServiceFacade(org.folio.service.holdings.LoadServiceFacade) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Async(io.vertx.ext.unit.Async) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) ArrayList(java.util.ArrayList) LoadHoldingsMessage(org.folio.service.holdings.message.LoadHoldingsMessage) HoldingsMessage(org.folio.service.holdings.message.HoldingsMessage) LoadHoldingsMessage(org.folio.service.holdings.message.LoadHoldingsMessage) Test(org.junit.Test)

Aggregations

ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)14 WireMock.post (com.github.tomakehurst.wiremock.client.WireMock.post)14 WireMock.stubFor (com.github.tomakehurst.wiremock.client.WireMock.stubFor)14 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)14 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)14 Handler (io.vertx.core.Handler)14 DeliveryContext (io.vertx.core.eventbus.DeliveryContext)14 Async (io.vertx.ext.unit.Async)14 TestContext (io.vertx.ext.unit.TestContext)14 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)14 IOException (java.io.IOException)14 URISyntaxException (java.net.URISyntaxException)14 KB_CREDENTIALS_TABLE_NAME (org.folio.repository.kbcredentials.KbCredentialsTableConstants.KB_CREDENTIALS_TABLE_NAME)14 HOLDINGS_SERVICE_ADDRESS (org.folio.service.holdings.HoldingConstants.HOLDINGS_SERVICE_ADDRESS)14 SNAPSHOT_CREATED_ACTION (org.folio.service.holdings.HoldingConstants.SNAPSHOT_CREATED_ACTION)14 LoadHoldingsMessage (org.folio.service.holdings.message.LoadHoldingsMessage)14 TestUtil.mockResponseList (org.folio.test.util.TestUtil.mockResponseList)14 TestUtil.readFile (org.folio.test.util.TestUtil.readFile)14 HoldingsRetryStatusTestUtil.insertRetryStatus (org.folio.util.HoldingsRetryStatusTestUtil.insertRetryStatus)14 HoldingsStatusUtil.saveStatusNotStarted (org.folio.util.HoldingsStatusUtil.saveStatusNotStarted)14