Search in sources :

Example 1 with HoldingsLoadingStatus

use of org.folio.rest.jaxrs.model.HoldingsLoadingStatus in project mod-kb-ebsco-java by folio-org.

the class LoadHoldingsStatusImplTest method shouldReturnStatusNotStarted.

@Test
public void shouldReturnStatusNotStarted() {
    setupDefaultLoadKBConfiguration();
    final HoldingsLoadingStatus status = getWithOk(STUB_HOLDINGS_LOAD_STATUS_BY_ID_URL, STUB_TOKEN_HEADER).body().as(HoldingsLoadingStatus.class);
    assertThat(status.getData().getAttributes().getStatus().getName(), equalTo(LoadStatusNameEnum.NOT_STARTED));
}
Also used : HoldingsLoadingStatus(org.folio.rest.jaxrs.model.HoldingsLoadingStatus) Test(org.junit.Test)

Example 2 with HoldingsLoadingStatus

use of org.folio.rest.jaxrs.model.HoldingsLoadingStatus in project mod-kb-ebsco-java by folio-org.

the class LoadHoldingsStatusImplTest method shouldReturnErrorWhenRMAPIReturnsError.

@Test
public void shouldReturnErrorWhenRMAPIReturnsError(TestContext context) {
    setupDefaultLoadKBConfiguration();
    mockGet(new EqualToPattern(RMAPI_HOLDINGS_STATUS_URL), SC_INTERNAL_SERVER_ERROR);
    Async finishedAsync = context.async(SNAPSHOT_RETRIES);
    handleStatusChange(FAILED, holdingsStatusRepository, o -> finishedAsync.countDown());
    postWithStatus(HOLDINGS_LOAD_BY_ID_URL, "", SC_NO_CONTENT, STUB_TOKEN_HEADER);
    finishedAsync.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().getName(), equalTo(FAILED));
}
Also used : HoldingsLoadingStatus(org.folio.rest.jaxrs.model.HoldingsLoadingStatus) Async(io.vertx.ext.unit.Async) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) Test(org.junit.Test)

Example 3 with HoldingsLoadingStatus

use of org.folio.rest.jaxrs.model.HoldingsLoadingStatus 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 4 with HoldingsLoadingStatus

use of org.folio.rest.jaxrs.model.HoldingsLoadingStatus in project mod-kb-ebsco-java by folio-org.

the class EholdingsKbCredentialsImplTest method shouldReturnStatusNotStartedOnKbCredentialsCreation.

@Test
public void shouldReturnStatusNotStartedOnKbCredentialsCreation() {
    KbCredentialsPostRequest kbCredentialsPostRequest = new KbCredentialsPostRequest().withData(stubbedCredentials());
    String postBody = Json.encode(kbCredentialsPostRequest);
    mockVerifyValidCredentialsRequest();
    KbCredentials actual = postWithStatus(KB_CREDENTIALS_ENDPOINT, postBody, SC_CREATED, STUB_TOKEN_HEADER).as(KbCredentials.class);
    final HoldingsLoadingStatus status = getStatus(actual.getId(), vertx);
    assertEquals(LoadStatusNameEnum.NOT_STARTED, status.getData().getAttributes().getStatus().getName());
    final RetryStatus retryStatus = getRetryStatus(actual.getId(), vertx);
    assertThat(retryStatus, notNullValue());
}
Also used : KbCredentialsTestUtil.saveKbCredentials(org.folio.util.KbCredentialsTestUtil.saveKbCredentials) KbCredentialsTestUtil.getKbCredentials(org.folio.util.KbCredentialsTestUtil.getKbCredentials) KbCredentials(org.folio.rest.jaxrs.model.KbCredentials) HoldingsLoadingStatus(org.folio.rest.jaxrs.model.HoldingsLoadingStatus) Matchers.containsString(org.hamcrest.Matchers.containsString) RetryStatus(org.folio.repository.holdings.status.retry.RetryStatus) HoldingsRetryStatusTestUtil.getRetryStatus(org.folio.util.HoldingsRetryStatusTestUtil.getRetryStatus) KbCredentialsPostRequest(org.folio.rest.jaxrs.model.KbCredentialsPostRequest) Test(org.junit.Test)

Example 5 with HoldingsLoadingStatus

use of org.folio.rest.jaxrs.model.HoldingsLoadingStatus in project mod-kb-ebsco-java by folio-org.

the class DefaultLoadHoldingsImplTest method shouldStartLoadingWhenStatusInProgressAndStartedMoreThen5DaysBefore.

@Test
public void shouldStartLoadingWhenStatusInProgressAndStartedMoreThen5DaysBefore(TestContext context) throws IOException, URISyntaxException {
    saveKbCredentials(STUB_CREDENTIALS_ID, getWiremockUrl(), STUB_CREDENTIALS_NAME, STUB_API_KEY, STUB_CUSTOMER_ID, vertx);
    OffsetDateTime dateTime = OffsetDateTime.now().minus(6, ChronoUnit.DAYS);
    HoldingsLoadingStatus statusLoadingHoldings = getStatusLoadingHoldings(1000, 500, 10, 5);
    statusLoadingHoldings.getData().getAttributes().setUpdated(dateTime.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
    saveStatus(STUB_CREDENTIALS_ID, statusLoadingHoldings, PROCESS_ID, dateTime, vertx);
    insertRetryStatus(STUB_CREDENTIALS_ID, vertx);
    runPostHoldingsWithMocks(context);
    final List<DbHoldingInfo> holdingsList = HoldingsTestUtil.getHoldings(vertx);
    assertThat(holdingsList.size(), Matchers.notNullValue());
}
Also used : HoldingsLoadingStatus(org.folio.rest.jaxrs.model.HoldingsLoadingStatus) OffsetDateTime(java.time.OffsetDateTime) DbHoldingInfo(org.folio.repository.holdings.DbHoldingInfo) Test(org.junit.Test)

Aggregations

HoldingsLoadingStatus (org.folio.rest.jaxrs.model.HoldingsLoadingStatus)13 Test (org.junit.Test)7 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)4 Async (io.vertx.ext.unit.Async)4 Tuple (io.vertx.sqlclient.Tuple)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)3 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)3 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)3 WireMock.post (com.github.tomakehurst.wiremock.client.WireMock.post)2 WireMock.stubFor (com.github.tomakehurst.wiremock.client.WireMock.stubFor)2 Handler (io.vertx.core.Handler)2 DeliveryContext (io.vertx.core.eventbus.DeliveryContext)2 TestContext (io.vertx.ext.unit.TestContext)2 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 OffsetDateTime (java.time.OffsetDateTime)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2