Search in sources :

Example 1 with Configuration

use of org.folio.holdingsiq.model.Configuration 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)

Example 2 with Configuration

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

the class PackageServiceImplTest method shouldReturnCachedPackage.

@Test
public void shouldReturnCachedPackage() throws IOException, URISyntaxException {
    RegexPattern getPackagePattern = new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/vendors/" + STUB_VENDOR_ID + "/packages/" + STUB_PACKAGE_ID);
    Configuration configuration = Configuration.builder().url("http://127.0.0.1:" + userMockServer.port()).customerId(STUB_CUSTOMER_ID).apiKey("API KEY").build();
    PackageServiceImpl service = new PackageServiceImpl(configuration, Vertx.vertx(), STUB_TENANT, null, null, new VertxCache<>(Vertx.vertx(), 60, "packageCache"), null);
    mockGet(getPackagePattern, CUSTOM_PACKAGE_STUB_FILE);
    PackageId packageId = PackageId.builder().packageIdPart(STUB_PACKAGE_ID).providerIdPart(STUB_VENDOR_ID).build();
    service.retrievePackage(packageId, Collections.emptyList(), true).join();
    service.retrievePackage(packageId, Collections.emptyList(), true).join();
    verify(1, getRequestedFor(new UrlPattern(getPackagePattern, true)));
}
Also used : WireMockConfiguration(com.github.tomakehurst.wiremock.core.WireMockConfiguration) Configuration(org.folio.holdingsiq.model.Configuration) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) PackageId(org.folio.holdingsiq.model.PackageId) UrlPattern(com.github.tomakehurst.wiremock.matching.UrlPattern) Test(org.junit.Test)

Example 3 with Configuration

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

the class ResourceServiceImplTest method shouldReturnCachedResource.

@Test
public void shouldReturnCachedResource() throws IOException, URISyntaxException {
    RegexPattern getResourcePattern = new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/vendors/" + STUB_VENDOR_ID + "/packages/" + STUB_PACKAGE_ID + "/titles/" + STUB_TITLE_ID);
    Configuration configuration = Configuration.builder().url("http://127.0.0.1:" + userMockServer.port()).customerId(STUB_CUSTOMER_ID).apiKey("API KEY").build();
    ResourcesServiceImpl service = new ResourcesServiceImpl(configuration, Vertx.vertx(), STUB_TENANT, null, null, new VertxCache<>(Vertx.vertx(), 60, "resourceCache"));
    mockGet(getResourcePattern, CUSTOM_RESOURCE_STUB_FILE);
    ResourceId resourceId = ResourceId.builder().packageIdPart(STUB_PACKAGE_ID).providerIdPart(STUB_VENDOR_ID).titleIdPart(STUB_TITLE_ID).build();
    service.retrieveResource(resourceId, Collections.emptyList(), true).join();
    service.retrieveResource(resourceId, Collections.emptyList(), true).join();
    verify(1, getRequestedFor(new UrlPattern(getResourcePattern, true)));
}
Also used : WireMockConfiguration(com.github.tomakehurst.wiremock.core.WireMockConfiguration) Configuration(org.folio.holdingsiq.model.Configuration) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) ResourceId(org.folio.holdingsiq.model.ResourceId) UrlPattern(com.github.tomakehurst.wiremock.matching.UrlPattern) Test(org.junit.Test)

Example 4 with Configuration

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

the class RMAPITemplateContextBuilder method build.

public RMAPITemplateContext build() {
    String tenant = okapiData.getTenant();
    Configuration configuration = converter.convert(credentials);
    final HoldingsIQService holdingsService = new HoldingsIQServiceImpl(configuration, vertx);
    final TitlesServiceImpl titlesService = new TitlesServiceImpl(configuration, vertx, okapiData.getTenant(), titleCache);
    final ProvidersServiceImpl providersService = new ProvidersServiceImpl(configuration, vertx, tenant, holdingsService, vendorCache);
    final PackageServiceImpl packagesService = new PackageServiceImpl(configuration, vertx, tenant, providersService, titlesService, packageCache, searchProperties);
    final ResourcesServiceImpl resourcesService = new ResourcesServiceImpl(configuration, vertx, tenant, providersService, packagesService, resourceCache);
    final LoadService loadService = new LoadServiceImpl(configuration, vertx);
    providersService.setPackagesService(packagesService);
    return RMAPITemplateContext.builder().configuration(configuration).okapiData(okapiData).credentialsId(credentials.getId()).credentialsName(credentials.getAttributes().getName()).holdingsService(holdingsService).packagesService(packagesService).providersService(providersService).resourcesService(resourcesService).titlesService(titlesService).loadingService(loadService).build();
}
Also used : HoldingsIQService(org.folio.holdingsiq.service.HoldingsIQService) PackageServiceImpl(org.folio.rmapi.PackageServiceImpl) LoadService(org.folio.holdingsiq.service.LoadService) Configuration(org.folio.holdingsiq.model.Configuration) LoadServiceImpl(org.folio.holdingsiq.service.impl.LoadServiceImpl) ResourcesServiceImpl(org.folio.rmapi.ResourcesServiceImpl) ProvidersServiceImpl(org.folio.rmapi.ProvidersServiceImpl) HoldingsIQServiceImpl(org.folio.holdingsiq.service.impl.HoldingsIQServiceImpl) TitlesServiceImpl(org.folio.rmapi.TitlesServiceImpl)

Example 5 with Configuration

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

the class ProviderServiceImplTest method shouldReturnCachedProviderOnSecondRequest.

@Test
public void shouldReturnCachedProviderOnSecondRequest() throws IOException, URISyntaxException {
    RegexPattern getVendorPattern = new RegexPattern("/rm/rmaccounts/" + STUB_CUSTOMER_ID + "/vendors/" + STUB_VENDOR_ID);
    Configuration configuration = Configuration.builder().url("http://127.0.0.1:" + userMockServer.port()).customerId(STUB_CUSTOMER_ID).apiKey("API KEY").build();
    ProvidersServiceImpl service = new ProvidersServiceImpl(configuration, Vertx.vertx(), STUB_TENANT, null, new VertxCache<>(Vertx.vertx(), 60, "vendorCache"));
    mockGet(getVendorPattern, VENDOR_STUB_FILE);
    service.retrieveProvider(STUB_VENDOR_ID, null, true).join();
    service.retrieveProvider(STUB_VENDOR_ID, null, true).join();
    verify(1, getRequestedFor(new UrlPattern(getVendorPattern, true)));
}
Also used : WireMockConfiguration(com.github.tomakehurst.wiremock.core.WireMockConfiguration) Configuration(org.folio.holdingsiq.model.Configuration) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) UrlPattern(com.github.tomakehurst.wiremock.matching.UrlPattern) Test(org.junit.Test)

Aggregations

Configuration (org.folio.holdingsiq.model.Configuration)7 Test (org.junit.Test)5 WireMockConfiguration (com.github.tomakehurst.wiremock.core.WireMockConfiguration)3 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)3 UrlPattern (com.github.tomakehurst.wiremock.matching.UrlPattern)3 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)2 WireMock (com.github.tomakehurst.wiremock.client.WireMock)2 WireMock.post (com.github.tomakehurst.wiremock.client.WireMock.post)2 WireMock.postRequestedFor (com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor)2 WireMock.stubFor (com.github.tomakehurst.wiremock.client.WireMock.stubFor)2 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)2 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)2 Handler (io.vertx.core.Handler)2 DeliveryContext (io.vertx.core.eventbus.DeliveryContext)2 Json (io.vertx.core.json.Json)2 Async (io.vertx.ext.unit.Async)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