Search in sources :

Example 1 with RMAPI_HOLDINGS_STATUS_URL

use of org.folio.rest.impl.RmApiConstants.RMAPI_HOLDINGS_STATUS_URL 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 RMAPI_HOLDINGS_STATUS_URL

use of org.folio.rest.impl.RmApiConstants.RMAPI_HOLDINGS_STATUS_URL in project mod-kb-ebsco-java by folio-org.

the class DefaultLoadHoldingsImplTest method shouldRetryCreationOfSnapshotWhenItFails.

@Test
public void shouldRetryCreationOfSnapshotWhenItFails(TestContext context) throws IOException, URISyntaxException {
    setupDefaultLoadKBConfiguration();
    stubFor(post(new UrlPathPattern(new EqualToPattern(RMAPI_POST_HOLDINGS_URL), false)).willReturn(new ResponseDefinitionBuilder().withBody("").withStatus(202)));
    ResponseDefinitionBuilder failedResponse = new ResponseDefinitionBuilder().withStatus(500);
    ResponseDefinitionBuilder successfulResponse = new ResponseDefinitionBuilder().withBody(readFile(RMAPI_RESPONSE_HOLDINGS_STATUS_COMPLETED));
    mockResponseList(new UrlPathPattern(new EqualToPattern(RMAPI_HOLDINGS_STATUS_URL), false), failedResponse, successfulResponse, successfulResponse);
    Async async = context.async();
    interceptor = interceptAndStop(HOLDINGS_SERVICE_ADDRESS, SNAPSHOT_CREATED_ACTION, message -> async.complete());
    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) HoldingsLoadingStatusFactory.getStatusLoadingHoldings(org.folio.repository.holdings.status.HoldingsLoadingStatusFactory.getStatusLoadingHoldings) 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) 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) 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) HoldingsLoadingStatusFactory.getStatusCompleted(org.folio.repository.holdings.status.HoldingsLoadingStatusFactory.getStatusCompleted) MockitoAnnotations(org.mockito.MockitoAnnotations) Mockito.doAnswer(org.mockito.Mockito.doAnswer) After(org.junit.After) Spy(org.mockito.Spy) HoldingsStatusUtil.saveStatusNotStarted(org.folio.util.HoldingsStatusUtil.saveStatusNotStarted) JsonObject(io.vertx.core.json.JsonObject) KBTestUtil.clearDataFromTable(org.folio.util.KBTestUtil.clearDataFromTable) KBTestUtil.interceptAndStop(org.folio.util.KBTestUtil.interceptAndStop) HoldingsStatusAuditTestUtil(org.folio.util.HoldingsStatusAuditTestUtil) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) SC_INTERNAL_SERVER_ERROR(org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR) LoadServiceFacade(org.folio.service.holdings.LoadServiceFacade) SNAPSHOT_FAILED_ACTION(org.folio.service.holdings.HoldingConstants.SNAPSHOT_FAILED_ACTION) ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) Matchers.allOf(org.hamcrest.Matchers.allOf) CREATE_SNAPSHOT_ACTION(org.folio.service.holdings.HoldingConstants.CREATE_SNAPSHOT_ACTION) 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) 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) List(java.util.List) StringValuePattern(com.github.tomakehurst.wiremock.matching.StringValuePattern) OffsetDateTime(java.time.OffsetDateTime) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) LoadStatusAttributes(org.folio.rest.jaxrs.model.LoadStatusAttributes) 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) WireMockTestBase(org.folio.rest.impl.WireMockTestBase) HoldingsTestUtil(org.folio.util.HoldingsTestUtil) BeforeClass(org.junit.BeforeClass) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) RunWith(org.junit.runner.RunWith) CompletableFuture(java.util.concurrent.CompletableFuture) POSTGRES_TIMESTAMP_FORMATTER(org.folio.service.holdings.HoldingsServiceImpl.POSTGRES_TIMESTAMP_FORMATTER) TestUtil.mockResponseList(org.folio.test.util.TestUtil.mockResponseList) ArrayList(java.util.ArrayList) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) 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) 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) PROCESS_ID(org.folio.util.HoldingsStatusUtil.PROCESS_ID) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) 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) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) 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) HoldingsStatusUtil.saveStatus(org.folio.util.HoldingsStatusUtil.saveStatus) RetryStatusRepository(org.folio.repository.holdings.status.retry.RetryStatusRepository) HoldingsStatusAuditTestUtil.saveStatusAudit(org.folio.util.HoldingsStatusAuditTestUtil.saveStatusAudit) DateTimeFormatter(java.time.format.DateTimeFormatter) Matcher(org.hamcrest.Matcher) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) SC_CONFLICT(org.apache.http.HttpStatus.SC_CONFLICT) TestUtil.readFile(org.folio.test.util.TestUtil.readFile) RequestMethod(com.github.tomakehurst.wiremock.http.RequestMethod) Handler(io.vertx.core.Handler) SAVE_HOLDINGS_ACTION(org.folio.service.holdings.HoldingConstants.SAVE_HOLDINGS_ACTION) 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 3 with RMAPI_HOLDINGS_STATUS_URL

use of org.folio.rest.impl.RmApiConstants.RMAPI_HOLDINGS_STATUS_URL 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());
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) HoldingsLoadingStatusFactory.getStatusLoadingHoldings(org.folio.repository.holdings.status.HoldingsLoadingStatusFactory.getStatusLoadingHoldings) 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) 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) 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) HoldingsLoadingStatusFactory.getStatusCompleted(org.folio.repository.holdings.status.HoldingsLoadingStatusFactory.getStatusCompleted) MockitoAnnotations(org.mockito.MockitoAnnotations) Mockito.doAnswer(org.mockito.Mockito.doAnswer) After(org.junit.After) Spy(org.mockito.Spy) HoldingsStatusUtil.saveStatusNotStarted(org.folio.util.HoldingsStatusUtil.saveStatusNotStarted) JsonObject(io.vertx.core.json.JsonObject) KBTestUtil.clearDataFromTable(org.folio.util.KBTestUtil.clearDataFromTable) KBTestUtil.interceptAndStop(org.folio.util.KBTestUtil.interceptAndStop) HoldingsStatusAuditTestUtil(org.folio.util.HoldingsStatusAuditTestUtil) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) SC_INTERNAL_SERVER_ERROR(org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR) LoadServiceFacade(org.folio.service.holdings.LoadServiceFacade) SNAPSHOT_FAILED_ACTION(org.folio.service.holdings.HoldingConstants.SNAPSHOT_FAILED_ACTION) ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) Matchers.allOf(org.hamcrest.Matchers.allOf) CREATE_SNAPSHOT_ACTION(org.folio.service.holdings.HoldingConstants.CREATE_SNAPSHOT_ACTION) 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) 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) List(java.util.List) StringValuePattern(com.github.tomakehurst.wiremock.matching.StringValuePattern) OffsetDateTime(java.time.OffsetDateTime) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) LoadStatusAttributes(org.folio.rest.jaxrs.model.LoadStatusAttributes) 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) WireMockTestBase(org.folio.rest.impl.WireMockTestBase) HoldingsTestUtil(org.folio.util.HoldingsTestUtil) BeforeClass(org.junit.BeforeClass) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) RunWith(org.junit.runner.RunWith) CompletableFuture(java.util.concurrent.CompletableFuture) POSTGRES_TIMESTAMP_FORMATTER(org.folio.service.holdings.HoldingsServiceImpl.POSTGRES_TIMESTAMP_FORMATTER) TestUtil.mockResponseList(org.folio.test.util.TestUtil.mockResponseList) ArrayList(java.util.ArrayList) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) 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) 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) PROCESS_ID(org.folio.util.HoldingsStatusUtil.PROCESS_ID) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) 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) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) 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) HoldingsStatusUtil.saveStatus(org.folio.util.HoldingsStatusUtil.saveStatus) RetryStatusRepository(org.folio.repository.holdings.status.retry.RetryStatusRepository) HoldingsStatusAuditTestUtil.saveStatusAudit(org.folio.util.HoldingsStatusAuditTestUtil.saveStatusAudit) DateTimeFormatter(java.time.format.DateTimeFormatter) Matcher(org.hamcrest.Matcher) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) SC_CONFLICT(org.apache.http.HttpStatus.SC_CONFLICT) TestUtil.readFile(org.folio.test.util.TestUtil.readFile) RequestMethod(com.github.tomakehurst.wiremock.http.RequestMethod) Handler(io.vertx.core.Handler) SAVE_HOLDINGS_ACTION(org.folio.service.holdings.HoldingConstants.SAVE_HOLDINGS_ACTION) 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 4 with RMAPI_HOLDINGS_STATUS_URL

use of org.folio.rest.impl.RmApiConstants.RMAPI_HOLDINGS_STATUS_URL in project mod-kb-ebsco-java by folio-org.

the class DefaultLoadHoldingsImplTest method shouldStopRetryingAfterMultipleFailures.

@Test
public void shouldStopRetryingAfterMultipleFailures(TestContext context) throws IOException, URISyntaxException {
    setupDefaultLoadKBConfiguration();
    mockGet(new EqualToPattern(RMAPI_HOLDINGS_STATUS_URL), RMAPI_RESPONSE_HOLDINGS_STATUS_COMPLETED);
    UrlPathPattern urlPattern = new UrlPathPattern(new EqualToPattern(RMAPI_POST_HOLDINGS_URL), false);
    stubFor(post(urlPattern).willReturn(new ResponseDefinitionBuilder().withStatus(500)));
    Async async = context.async(TEST_SNAPSHOT_RETRY_COUNT);
    interceptor = interceptAndContinue(HOLDINGS_SERVICE_ADDRESS, SNAPSHOT_FAILED_ACTION, o -> async.countDown());
    vertx.eventBus().addOutboundInterceptor(interceptor);
    postWithStatus(HOLDINGS_LOAD_BY_ID_URL, "", SC_NO_CONTENT, STUB_TOKEN_HEADER);
    async.await(TIMEOUT);
    Async retryStatusAsync = context.async();
    retryStatusRepository.findByCredentialsId(UUID.fromString(STUB_CREDENTIALS_ID), STUB_TENANT).thenAccept(status -> {
        boolean timerExists = vertx.cancelTimer(status.getTimerId());
        context.assertEquals(0, status.getRetryAttemptsLeft());
        context.assertFalse(timerExists);
        retryStatusAsync.complete();
    });
    retryStatusAsync.await(TIMEOUT);
    verify(TEST_SNAPSHOT_RETRY_COUNT, RequestPatternBuilder.newRequestPattern(RequestMethod.POST, urlPattern));
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) HoldingsLoadingStatusFactory.getStatusLoadingHoldings(org.folio.repository.holdings.status.HoldingsLoadingStatusFactory.getStatusLoadingHoldings) 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) 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) 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) HoldingsLoadingStatusFactory.getStatusCompleted(org.folio.repository.holdings.status.HoldingsLoadingStatusFactory.getStatusCompleted) MockitoAnnotations(org.mockito.MockitoAnnotations) Mockito.doAnswer(org.mockito.Mockito.doAnswer) After(org.junit.After) Spy(org.mockito.Spy) HoldingsStatusUtil.saveStatusNotStarted(org.folio.util.HoldingsStatusUtil.saveStatusNotStarted) JsonObject(io.vertx.core.json.JsonObject) KBTestUtil.clearDataFromTable(org.folio.util.KBTestUtil.clearDataFromTable) KBTestUtil.interceptAndStop(org.folio.util.KBTestUtil.interceptAndStop) HoldingsStatusAuditTestUtil(org.folio.util.HoldingsStatusAuditTestUtil) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) SC_INTERNAL_SERVER_ERROR(org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR) LoadServiceFacade(org.folio.service.holdings.LoadServiceFacade) SNAPSHOT_FAILED_ACTION(org.folio.service.holdings.HoldingConstants.SNAPSHOT_FAILED_ACTION) ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) Matchers.allOf(org.hamcrest.Matchers.allOf) CREATE_SNAPSHOT_ACTION(org.folio.service.holdings.HoldingConstants.CREATE_SNAPSHOT_ACTION) 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) 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) List(java.util.List) StringValuePattern(com.github.tomakehurst.wiremock.matching.StringValuePattern) OffsetDateTime(java.time.OffsetDateTime) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) LoadStatusAttributes(org.folio.rest.jaxrs.model.LoadStatusAttributes) 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) WireMockTestBase(org.folio.rest.impl.WireMockTestBase) HoldingsTestUtil(org.folio.util.HoldingsTestUtil) BeforeClass(org.junit.BeforeClass) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) RunWith(org.junit.runner.RunWith) CompletableFuture(java.util.concurrent.CompletableFuture) POSTGRES_TIMESTAMP_FORMATTER(org.folio.service.holdings.HoldingsServiceImpl.POSTGRES_TIMESTAMP_FORMATTER) TestUtil.mockResponseList(org.folio.test.util.TestUtil.mockResponseList) ArrayList(java.util.ArrayList) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) 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) 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) PROCESS_ID(org.folio.util.HoldingsStatusUtil.PROCESS_ID) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) 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) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) 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) HoldingsStatusUtil.saveStatus(org.folio.util.HoldingsStatusUtil.saveStatus) RetryStatusRepository(org.folio.repository.holdings.status.retry.RetryStatusRepository) HoldingsStatusAuditTestUtil.saveStatusAudit(org.folio.util.HoldingsStatusAuditTestUtil.saveStatusAudit) DateTimeFormatter(java.time.format.DateTimeFormatter) Matcher(org.hamcrest.Matcher) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) SC_CONFLICT(org.apache.http.HttpStatus.SC_CONFLICT) TestUtil.readFile(org.folio.test.util.TestUtil.readFile) RequestMethod(com.github.tomakehurst.wiremock.http.RequestMethod) Handler(io.vertx.core.Handler) SAVE_HOLDINGS_ACTION(org.folio.service.holdings.HoldingConstants.SAVE_HOLDINGS_ACTION) 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 RMAPI_HOLDINGS_STATUS_URL

use of org.folio.rest.impl.RmApiConstants.RMAPI_HOLDINGS_STATUS_URL in project mod-kb-ebsco-java by folio-org.

the class DefaultLoadServiceFacadeTest 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));
    HoldingsLoadStatus status = readJsonFile("responses/rmapi/holdings/status/get-status-completed.json", HoldingsLoadStatus.class).toBuilder().created(now).build();
    mockGetWithBody(new EqualToPattern(RMAPI_HOLDINGS_STATUS_URL), Json.encode(status));
    mockPostHoldings();
    interceptor = interceptAndStop(HOLDINGS_SERVICE_ADDRESS, SNAPSHOT_CREATED_ACTION, message -> async.complete());
    vertx.eventBus().addOutboundInterceptor(interceptor);
    loadServiceFacade.createSnapshot(new ConfigurationMessage(configuration, STUB_CREDENTIALS_ID, STUB_TENANT));
    async.await(TIMEOUT);
    WireMock.verify(0, postRequestedFor(new UrlPathPattern(new EqualToPattern(RMAPI_POST_HOLDINGS_URL), false)));
}
Also used : RMAPI_POST_HOLDINGS_URL(org.folio.rest.impl.RmApiConstants.RMAPI_POST_HOLDINGS_URL) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) WireMockTestBase(org.folio.rest.impl.WireMockTestBase) Json(io.vertx.core.json.Json) KbCredentialsTestUtil.saveKbCredentials(org.folio.util.KbCredentialsTestUtil.saveKbCredentials) URISyntaxException(java.net.URISyntaxException) LocalDateTime(java.time.LocalDateTime) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) RMAPI_HOLDINGS_STATUS_URL(org.folio.rest.impl.RmApiConstants.RMAPI_HOLDINGS_STATUS_URL) LoadHoldingsMessage(org.folio.service.holdings.message.LoadHoldingsMessage) WireMock.postRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor) DefaultLoadServiceFacade(org.folio.service.holdings.DefaultLoadServiceFacade) TestUtil.mockResponseList(org.folio.test.util.TestUtil.mockResponseList) WireMock(com.github.tomakehurst.wiremock.client.WireMock) After(org.junit.After) HoldingsStatusUtil.saveStatusNotStarted(org.folio.util.HoldingsStatusUtil.saveStatusNotStarted) HoldingsRetryStatusTestUtil.insertRetryStatus(org.folio.util.HoldingsRetryStatusTestUtil.insertRetryStatus) 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) 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) ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) HOLDINGS_STATUS_TIME_FORMATTER(org.folio.service.holdings.AbstractLoadServiceFacade.HOLDINGS_STATUS_TIME_FORMATTER) HoldingsLoadStatus(org.folio.holdingsiq.model.HoldingsLoadStatus) SNAPSHOT_CREATED_ACTION(org.folio.service.holdings.HoldingConstants.SNAPSHOT_CREATED_ACTION) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) STUB_TENANT(org.folio.test.util.TestUtil.STUB_TENANT) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) TestUtil.readJsonFile(org.folio.test.util.TestUtil.readJsonFile) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) HOLDINGS_SERVICE_ADDRESS(org.folio.service.holdings.HoldingConstants.HOLDINGS_SERVICE_ADDRESS) STUB_CREDENTIALS_NAME(org.folio.util.KbCredentialsTestUtil.STUB_CREDENTIALS_NAME) KB_CREDENTIALS_TABLE_NAME(org.folio.repository.kbcredentials.KbCredentialsTableConstants.KB_CREDENTIALS_TABLE_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) Configuration(org.folio.holdingsiq.model.Configuration) Handler(io.vertx.core.Handler) 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) HoldingsLoadStatus(org.folio.holdingsiq.model.HoldingsLoadStatus) Test(org.junit.Test)

Aggregations

ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)7 WireMock.post (com.github.tomakehurst.wiremock.client.WireMock.post)7 WireMock.stubFor (com.github.tomakehurst.wiremock.client.WireMock.stubFor)7 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)7 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)7 Handler (io.vertx.core.Handler)7 DeliveryContext (io.vertx.core.eventbus.DeliveryContext)7 Async (io.vertx.ext.unit.Async)7 TestContext (io.vertx.ext.unit.TestContext)7 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)7 IOException (java.io.IOException)7 URISyntaxException (java.net.URISyntaxException)7 KB_CREDENTIALS_TABLE_NAME (org.folio.repository.kbcredentials.KbCredentialsTableConstants.KB_CREDENTIALS_TABLE_NAME)7 RMAPI_HOLDINGS_STATUS_URL (org.folio.rest.impl.RmApiConstants.RMAPI_HOLDINGS_STATUS_URL)7 RMAPI_POST_HOLDINGS_URL (org.folio.rest.impl.RmApiConstants.RMAPI_POST_HOLDINGS_URL)7 WireMockTestBase (org.folio.rest.impl.WireMockTestBase)7 HOLDINGS_SERVICE_ADDRESS (org.folio.service.holdings.HoldingConstants.HOLDINGS_SERVICE_ADDRESS)7 SNAPSHOT_CREATED_ACTION (org.folio.service.holdings.HoldingConstants.SNAPSHOT_CREATED_ACTION)7 LoadHoldingsMessage (org.folio.service.holdings.message.LoadHoldingsMessage)7 TestUtil.mockResponseList (org.folio.test.util.TestUtil.mockResponseList)7