Search in sources :

Example 11 with RestClient

use of org.folio.rest.core.RestClient in project mod-orders by folio-org.

the class InvoiceLineServiceTest method shouldRemoveEncumbranceLinks.

@Test
void shouldRemoveEncumbranceLinks() {
    // Given
    String poLineId1 = UUID.randomUUID().toString();
    String poLineId2 = UUID.randomUUID().toString();
    String encumbrance1Id = UUID.randomUUID().toString();
    String encumbrance2Id = UUID.randomUUID().toString();
    String encumbrance3Id = UUID.randomUUID().toString();
    List<String> transactionIds = List.of(encumbrance1Id, encumbrance2Id, encumbrance3Id);
    String invoiceLineId1 = UUID.randomUUID().toString();
    InvoiceLine invoiceLine1 = new InvoiceLine().withId(invoiceLineId1).withPoLineId(poLineId1).withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance1Id))).withAdjustments(List.of(new Adjustment().withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance2Id)))));
    String invoiceLineId2 = UUID.randomUUID().toString();
    InvoiceLine invoiceLine2 = new InvoiceLine().withId(invoiceLineId2).withPoLineId(poLineId2).withAdjustments(List.of(new Adjustment().withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance3Id)))));
    List<InvoiceLine> invoiceLines = List.of(invoiceLine1, invoiceLine2);
    InvoiceLine expectedInvoiceLine1 = JsonObject.mapFrom(invoiceLine1).mapTo(InvoiceLine.class);
    expectedInvoiceLine1.getFundDistributions().get(0).setEncumbrance(null);
    expectedInvoiceLine1.getAdjustments().get(0).getFundDistributions().get(0).setEncumbrance(null);
    InvoiceLine expectedInvoiceLine2 = JsonObject.mapFrom(invoiceLine2).mapTo(InvoiceLine.class);
    expectedInvoiceLine2.getAdjustments().get(0).getFundDistributions().get(0).setEncumbrance(null);
    when(restClient.put(any(RequestEntry.class), any(InvoiceLine.class), eq(requestContextMock))).thenReturn(CompletableFuture.completedFuture(null));
    when(requestContextMock.getContext()).thenReturn(Vertx.vertx().getOrCreateContext());
    // When
    CompletableFuture<Void> result = invoiceLineService.removeEncumbranceLinks(invoiceLines, transactionIds, requestContextMock);
    assertFalse(result.isCompletedExceptionally());
    result.join();
    // Then
    verify(restClient, times(1)).put(argThat(requestEntry -> invoiceLineId1.equals(requestEntry.getPathParams().get("id"))), eq(expectedInvoiceLine1), eq(requestContextMock));
    verify(restClient, times(1)).put(argThat(requestEntry -> invoiceLineId2.equals(requestEntry.getPathParams().get("id"))), eq(expectedInvoiceLine2), eq(requestContextMock));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) RestClient(org.folio.rest.core.RestClient) BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CompletableFuture(java.util.concurrent.CompletableFuture) MockitoAnnotations(org.mockito.MockitoAnnotations) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) InvoiceLineCollection(org.folio.rest.acq.model.invoice.InvoiceLineCollection) RequestContext(org.folio.rest.core.models.RequestContext) JsonObject(io.vertx.core.json.JsonObject) InjectMocks(org.mockito.InjectMocks) Vertx(io.vertx.core.Vertx) RequestEntry(org.folio.rest.core.models.RequestEntry) Mockito.times(org.mockito.Mockito.times) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Adjustment(org.folio.rest.acq.model.invoice.Adjustment) HelperUtils.encodeQuery(org.folio.orders.utils.HelperUtils.encodeQuery) InvoiceLine(org.folio.rest.acq.model.invoice.InvoiceLine) LogManager(org.apache.logging.log4j.LogManager) Adjustment(org.folio.rest.acq.model.invoice.Adjustment) InvoiceLine(org.folio.rest.acq.model.invoice.InvoiceLine) RequestEntry(org.folio.rest.core.models.RequestEntry) Test(org.junit.jupiter.api.Test)

Example 12 with RestClient

use of org.folio.rest.core.RestClient in project mod-orders by folio-org.

the class PurchaseOrderHelperTest method testDeleteOrderLinkedToInvoiceWithError.

@Test
void testDeleteOrderLinkedToInvoiceWithError() {
    // given
    InvoiceLineService invoiceLineService = new InvoiceLineService(restClient);
    RestClient restClient = mock(RestClient.class, CALLS_REAL_METHODS);
    OrderInvoiceRelationService orderInvoiceRelationService = spy(new OrderInvoiceRelationService(restClient, invoiceLineService));
    // for returning non empty collection
    OrderInvoiceRelationshipCollection oirCollection = new OrderInvoiceRelationshipCollection().withOrderInvoiceRelationships(Collections.singletonList(new OrderInvoiceRelationship())).withTotalRecords(1);
    doReturn(completedFuture(oirCollection)).when(restClient).get(any(), any(), any());
    CompletableFuture<Void> future = orderInvoiceRelationService.checkOrderInvoiceRelationship(ORDER_ID, new RequestContext(ctxMock, okapiHeadersMock));
    CompletionException exception = assertThrows(CompletionException.class, future::join);
    HttpException httpException = (HttpException) exception.getCause();
    assertEquals(ErrorCodes.ORDER_RELATES_TO_INVOICE.getDescription(), httpException.getMessage());
}
Also used : OrderInvoiceRelationService(org.folio.service.orders.OrderInvoiceRelationService) OrderInvoiceRelationshipCollection(org.folio.rest.acq.model.OrderInvoiceRelationshipCollection) CompletionException(java.util.concurrent.CompletionException) RestClient(org.folio.rest.core.RestClient) OrderInvoiceRelationship(org.folio.rest.acq.model.OrderInvoiceRelationship) InvoiceLineService(org.folio.service.invoice.InvoiceLineService) HttpException(org.folio.rest.core.exceptions.HttpException) RequestContext(org.folio.rest.core.models.RequestContext) Test(org.junit.jupiter.api.Test)

Example 13 with RestClient

use of org.folio.rest.core.RestClient in project mod-orders by folio-org.

the class InventoryManagerTest method shouldCheckIfTheHoldingExistsWhenLocationIdAlwaysNewHoldingShouldBeCreated.

@Test
void shouldCheckIfTheHoldingExistsWhenLocationIdAlwaysNewHoldingShouldBeCreated() throws IOException {
    String instanceId = UUID.randomUUID().toString();
    JsonObject holdingsCollection = new JsonObject(getMockData(HOLDINGS_OLD_NEW_PATH));
    String holdingIdExp = extractId(getFirstObjectFromResponse(holdingsCollection, HOLDINGS_RECORDS));
    List<JsonObject> holdings = holdingsCollection.getJsonArray(HOLDINGS_RECORDS).stream().map(o -> ((JsonObject) o)).collect(toList());
    List<String> locationIds = holdings.stream().map(holding -> holding.getString(HOLDING_PERMANENT_LOCATION_ID)).collect(toList());
    Location location = new Location().withLocationId(locationIds.get(0)).withQuantity(1).withQuantityPhysical(1);
    doReturn(completedFuture(holdingIdExp)).when(restClient).post(any(RequestEntry.class), any(JsonObject.class), eq(PostResponseType.UUID), eq(String.class), eq(requestContext));
    String holdingIdAct = inventoryManager.getOrCreateHoldingsRecord(instanceId, location, requestContext).join();
    assertThat(holdingIdAct, equalTo(holdingIdExp));
    verify(restClient, times(1)).post(any(RequestEntry.class), any(JsonObject.class), eq(PostResponseType.UUID), eq(String.class), eq(requestContext));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) TestConfig.getVertx(org.folio.TestConfig.getVertx) TestConstants(org.folio.TestConstants) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiTestSuite(org.folio.ApiTestSuite) AfterAll(org.junit.jupiter.api.AfterAll) PIECE_RECORDS_MOCK_DATA_PATH(org.folio.rest.impl.MockServer.PIECE_RECORDS_MOCK_DATA_PATH) MockitoAnnotations(org.mockito.MockitoAnnotations) CALLS_REAL_METHODS(org.mockito.Mockito.CALLS_REAL_METHODS) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) PARTIALLY_RETURNED_COLLECTION(org.folio.rest.core.exceptions.ErrorCodes.PARTIALLY_RETURNED_COLLECTION) JsonObject(io.vertx.core.json.JsonObject) OKAPI_URL(org.folio.rest.RestConstants.OKAPI_URL) Mockito.doReturn(org.mockito.Mockito.doReturn) PieceStorageService(org.folio.service.pieces.PieceStorageService) BASE_MOCK_DATA_PATH(org.folio.rest.impl.MockServer.BASE_MOCK_DATA_PATH) TestConfig.clearServiceInteractions(org.folio.TestConfig.clearServiceInteractions) HttpClientFactory(org.folio.rest.tools.client.HttpClientFactory) ConfigurationEntriesService(org.folio.service.configuration.ConfigurationEntriesService) TestConfig.mockPort(org.folio.TestConfig.mockPort) TestConfig.isVerticleNotDeployed(org.folio.TestConfig.isVerticleNotDeployed) X_OKAPI_TOKEN(org.folio.TestConstants.X_OKAPI_TOKEN) Logger(org.apache.logging.log4j.Logger) Eresource(org.folio.rest.jaxrs.model.Eresource) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) PieceCollection(org.folio.rest.jaxrs.model.PieceCollection) HttpClientInterface(org.folio.rest.tools.client.interfaces.HttpClientInterface) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) RestClient(org.folio.rest.core.RestClient) HOLDINGS_RECORDS(org.folio.service.inventory.InventoryManager.HOLDINGS_RECORDS) X_OKAPI_TENANT(org.folio.rest.impl.PurchaseOrdersApiTest.X_OKAPI_TENANT) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) TestConfig.clearVertxContext(org.folio.TestConfig.clearVertxContext) Mockito.spy(org.mockito.Mockito.spy) HelperUtils.extractId(org.folio.orders.utils.HelperUtils.extractId) INSTANCE_HOLDING(org.folio.rest.jaxrs.model.Eresource.CreateInventory.INSTANCE_HOLDING) HOLDING_PERMANENT_LOCATION_ID(org.folio.service.inventory.InventoryManager.HOLDING_PERMANENT_LOCATION_ID) TestConfig.autowireDependencies(org.folio.TestConfig.autowireDependencies) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Physical(org.folio.rest.jaxrs.model.Physical) COMP_PO_LINES_MOCK_DATA_PATH(org.folio.rest.impl.PurchaseOrderLinesApiTest.COMP_PO_LINES_MOCK_DATA_PATH) Piece(org.folio.rest.jaxrs.model.Piece) TestConfig.initSpringContext(org.folio.TestConfig.initSpringContext) RequestEntry(org.folio.rest.core.models.RequestEntry) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) PostResponseType(org.folio.rest.core.PostResponseType) ExecutionException(java.util.concurrent.ExecutionException) NOT_FOUND(org.folio.rest.RestConstants.NOT_FOUND) JsonArray(io.vertx.core.json.JsonArray) Mockito.never(org.mockito.Mockito.never) AfterEach(org.junit.jupiter.api.AfterEach) TestUtils.getMockAsJson(org.folio.TestUtils.getMockAsJson) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) TimeoutException(java.util.concurrent.TimeoutException) X_OKAPI_USER_ID(org.folio.TestConstants.X_OKAPI_USER_ID) Context(io.vertx.core.Context) HOLDINGS_BY_ID_NOT_FOUND(org.folio.rest.core.exceptions.ErrorCodes.HOLDINGS_BY_ID_NOT_FOUND) Location(org.folio.rest.jaxrs.model.Location) CompletionException(java.util.concurrent.CompletionException) UUID(java.util.UUID) HOLDINGS_OLD_NEW_PATH(org.folio.rest.impl.MockServer.HOLDINGS_OLD_NEW_PATH) Test(org.junit.jupiter.api.Test) List(java.util.List) HelperUtils.getFirstObjectFromResponse(org.folio.orders.utils.HelperUtils.getFirstObjectFromResponse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ACTIVE_ACCESS_PROVIDER_B(org.folio.TestConstants.ACTIVE_ACCESS_PROVIDER_B) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TestConfig.getFirstContextFromVertx(org.folio.TestConfig.getFirstContextFromVertx) ITEMS_RECORDS_MOCK_DATA_PATH(org.folio.rest.impl.MockServer.ITEMS_RECORDS_MOCK_DATA_PATH) ID(org.folio.service.inventory.InventoryManager.ID) HttpException(org.folio.rest.core.exceptions.HttpException) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) TestUtils.getMockData(org.folio.TestUtils.getMockData) PoLineUpdateHolder(org.folio.models.PoLineUpdateHolder) ITEM_PURCHASE_ORDER_LINE_IDENTIFIER(org.folio.service.inventory.InventoryManager.ITEM_PURCHASE_ORDER_LINE_IDENTIFIER) Title(org.folio.rest.jaxrs.model.Title) PIECE_PATH(org.folio.TestConstants.PIECE_PATH) RequestContext(org.folio.rest.core.models.RequestContext) ITEMS(org.folio.service.inventory.InventoryManager.ITEMS) IsInstanceOf(org.hamcrest.core.IsInstanceOf) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Error(org.folio.rest.jaxrs.model.Error) Collectors.toList(java.util.stream.Collectors.toList) PieceService(org.folio.service.pieces.PieceService) Bean(org.springframework.context.annotation.Bean) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) JsonObject(io.vertx.core.json.JsonObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RequestEntry(org.folio.rest.core.models.RequestEntry) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test)

Example 14 with RestClient

use of org.folio.rest.core.RestClient in project mod-orders by folio-org.

the class InventoryManagerTest method shouldReturnHoldingsByIdsIfTheyExist.

@Test
void shouldReturnHoldingsByIdsIfTheyExist() throws IOException, ExecutionException, InterruptedException {
    JsonObject holdingsCollection = new JsonObject(getMockData(HOLDINGS_OLD_NEW_PATH));
    List<JsonObject> holdings = holdingsCollection.getJsonArray("holdingsRecords").stream().map(o -> ((JsonObject) o)).collect(toList());
    List<String> holdingIds = holdings.stream().map(holding -> holding.getString(ID)).collect(toList());
    doReturn(completedFuture(holdingsCollection)).when(restClient).getAsJsonObject(any(RequestEntry.class), eq(requestContext));
    List<JsonObject> actHoldings = inventoryManager.getHoldingsByIds(holdingIds, requestContext).get();
    assertThat(actHoldings.size(), equalTo(holdings.size()));
    verify(restClient, times(1)).getAsJsonObject(any(RequestEntry.class), eq(requestContext));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) TestConfig.getVertx(org.folio.TestConfig.getVertx) TestConstants(org.folio.TestConstants) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiTestSuite(org.folio.ApiTestSuite) AfterAll(org.junit.jupiter.api.AfterAll) PIECE_RECORDS_MOCK_DATA_PATH(org.folio.rest.impl.MockServer.PIECE_RECORDS_MOCK_DATA_PATH) MockitoAnnotations(org.mockito.MockitoAnnotations) CALLS_REAL_METHODS(org.mockito.Mockito.CALLS_REAL_METHODS) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) PARTIALLY_RETURNED_COLLECTION(org.folio.rest.core.exceptions.ErrorCodes.PARTIALLY_RETURNED_COLLECTION) JsonObject(io.vertx.core.json.JsonObject) OKAPI_URL(org.folio.rest.RestConstants.OKAPI_URL) Mockito.doReturn(org.mockito.Mockito.doReturn) PieceStorageService(org.folio.service.pieces.PieceStorageService) BASE_MOCK_DATA_PATH(org.folio.rest.impl.MockServer.BASE_MOCK_DATA_PATH) TestConfig.clearServiceInteractions(org.folio.TestConfig.clearServiceInteractions) HttpClientFactory(org.folio.rest.tools.client.HttpClientFactory) ConfigurationEntriesService(org.folio.service.configuration.ConfigurationEntriesService) TestConfig.mockPort(org.folio.TestConfig.mockPort) TestConfig.isVerticleNotDeployed(org.folio.TestConfig.isVerticleNotDeployed) X_OKAPI_TOKEN(org.folio.TestConstants.X_OKAPI_TOKEN) Logger(org.apache.logging.log4j.Logger) Eresource(org.folio.rest.jaxrs.model.Eresource) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) PieceCollection(org.folio.rest.jaxrs.model.PieceCollection) HttpClientInterface(org.folio.rest.tools.client.interfaces.HttpClientInterface) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) RestClient(org.folio.rest.core.RestClient) HOLDINGS_RECORDS(org.folio.service.inventory.InventoryManager.HOLDINGS_RECORDS) X_OKAPI_TENANT(org.folio.rest.impl.PurchaseOrdersApiTest.X_OKAPI_TENANT) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) TestConfig.clearVertxContext(org.folio.TestConfig.clearVertxContext) Mockito.spy(org.mockito.Mockito.spy) HelperUtils.extractId(org.folio.orders.utils.HelperUtils.extractId) INSTANCE_HOLDING(org.folio.rest.jaxrs.model.Eresource.CreateInventory.INSTANCE_HOLDING) HOLDING_PERMANENT_LOCATION_ID(org.folio.service.inventory.InventoryManager.HOLDING_PERMANENT_LOCATION_ID) TestConfig.autowireDependencies(org.folio.TestConfig.autowireDependencies) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Physical(org.folio.rest.jaxrs.model.Physical) COMP_PO_LINES_MOCK_DATA_PATH(org.folio.rest.impl.PurchaseOrderLinesApiTest.COMP_PO_LINES_MOCK_DATA_PATH) Piece(org.folio.rest.jaxrs.model.Piece) TestConfig.initSpringContext(org.folio.TestConfig.initSpringContext) RequestEntry(org.folio.rest.core.models.RequestEntry) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) PostResponseType(org.folio.rest.core.PostResponseType) ExecutionException(java.util.concurrent.ExecutionException) NOT_FOUND(org.folio.rest.RestConstants.NOT_FOUND) JsonArray(io.vertx.core.json.JsonArray) Mockito.never(org.mockito.Mockito.never) AfterEach(org.junit.jupiter.api.AfterEach) TestUtils.getMockAsJson(org.folio.TestUtils.getMockAsJson) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) TimeoutException(java.util.concurrent.TimeoutException) X_OKAPI_USER_ID(org.folio.TestConstants.X_OKAPI_USER_ID) Context(io.vertx.core.Context) HOLDINGS_BY_ID_NOT_FOUND(org.folio.rest.core.exceptions.ErrorCodes.HOLDINGS_BY_ID_NOT_FOUND) Location(org.folio.rest.jaxrs.model.Location) CompletionException(java.util.concurrent.CompletionException) UUID(java.util.UUID) HOLDINGS_OLD_NEW_PATH(org.folio.rest.impl.MockServer.HOLDINGS_OLD_NEW_PATH) Test(org.junit.jupiter.api.Test) List(java.util.List) HelperUtils.getFirstObjectFromResponse(org.folio.orders.utils.HelperUtils.getFirstObjectFromResponse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ACTIVE_ACCESS_PROVIDER_B(org.folio.TestConstants.ACTIVE_ACCESS_PROVIDER_B) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TestConfig.getFirstContextFromVertx(org.folio.TestConfig.getFirstContextFromVertx) ITEMS_RECORDS_MOCK_DATA_PATH(org.folio.rest.impl.MockServer.ITEMS_RECORDS_MOCK_DATA_PATH) ID(org.folio.service.inventory.InventoryManager.ID) HttpException(org.folio.rest.core.exceptions.HttpException) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) TestUtils.getMockData(org.folio.TestUtils.getMockData) PoLineUpdateHolder(org.folio.models.PoLineUpdateHolder) ITEM_PURCHASE_ORDER_LINE_IDENTIFIER(org.folio.service.inventory.InventoryManager.ITEM_PURCHASE_ORDER_LINE_IDENTIFIER) Title(org.folio.rest.jaxrs.model.Title) PIECE_PATH(org.folio.TestConstants.PIECE_PATH) RequestContext(org.folio.rest.core.models.RequestContext) ITEMS(org.folio.service.inventory.InventoryManager.ITEMS) IsInstanceOf(org.hamcrest.core.IsInstanceOf) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Error(org.folio.rest.jaxrs.model.Error) Collectors.toList(java.util.stream.Collectors.toList) PieceService(org.folio.service.pieces.PieceService) Bean(org.springframework.context.annotation.Bean) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) JsonObject(io.vertx.core.json.JsonObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RequestEntry(org.folio.rest.core.models.RequestEntry) Test(org.junit.jupiter.api.Test)

Example 15 with RestClient

use of org.folio.rest.core.RestClient in project mod-orders by folio-org.

the class InventoryManagerTest method shouldReturnHoldingsByInstanceIdAndLocationIdsIfTheyExist.

@Test
void shouldReturnHoldingsByInstanceIdAndLocationIdsIfTheyExist() throws IOException, ExecutionException, InterruptedException {
    String instanceId = UUID.randomUUID().toString();
    JsonObject holdingsCollection = new JsonObject(getMockData(HOLDINGS_OLD_NEW_PATH));
    List<JsonObject> holdings = holdingsCollection.getJsonArray("holdingsRecords").stream().map(o -> ((JsonObject) o)).collect(toList());
    List<String> locationIds = holdings.stream().map(holding -> holding.getString(HOLDING_PERMANENT_LOCATION_ID)).collect(toList());
    doReturn(completedFuture(holdingsCollection)).when(restClient).getAsJsonObject(any(RequestEntry.class), eq(requestContext));
    List<JsonObject> actHoldings = inventoryManager.getHoldingRecords(instanceId, locationIds, requestContext).get();
    assertThat(actHoldings.size(), equalTo(holdings.size()));
    verify(restClient, times(2)).getAsJsonObject(any(RequestEntry.class), eq(requestContext));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) TestConfig.getVertx(org.folio.TestConfig.getVertx) TestConstants(org.folio.TestConstants) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiTestSuite(org.folio.ApiTestSuite) AfterAll(org.junit.jupiter.api.AfterAll) PIECE_RECORDS_MOCK_DATA_PATH(org.folio.rest.impl.MockServer.PIECE_RECORDS_MOCK_DATA_PATH) MockitoAnnotations(org.mockito.MockitoAnnotations) CALLS_REAL_METHODS(org.mockito.Mockito.CALLS_REAL_METHODS) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) PARTIALLY_RETURNED_COLLECTION(org.folio.rest.core.exceptions.ErrorCodes.PARTIALLY_RETURNED_COLLECTION) JsonObject(io.vertx.core.json.JsonObject) OKAPI_URL(org.folio.rest.RestConstants.OKAPI_URL) Mockito.doReturn(org.mockito.Mockito.doReturn) PieceStorageService(org.folio.service.pieces.PieceStorageService) BASE_MOCK_DATA_PATH(org.folio.rest.impl.MockServer.BASE_MOCK_DATA_PATH) TestConfig.clearServiceInteractions(org.folio.TestConfig.clearServiceInteractions) HttpClientFactory(org.folio.rest.tools.client.HttpClientFactory) ConfigurationEntriesService(org.folio.service.configuration.ConfigurationEntriesService) TestConfig.mockPort(org.folio.TestConfig.mockPort) TestConfig.isVerticleNotDeployed(org.folio.TestConfig.isVerticleNotDeployed) X_OKAPI_TOKEN(org.folio.TestConstants.X_OKAPI_TOKEN) Logger(org.apache.logging.log4j.Logger) Eresource(org.folio.rest.jaxrs.model.Eresource) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) PieceCollection(org.folio.rest.jaxrs.model.PieceCollection) HttpClientInterface(org.folio.rest.tools.client.interfaces.HttpClientInterface) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) RestClient(org.folio.rest.core.RestClient) HOLDINGS_RECORDS(org.folio.service.inventory.InventoryManager.HOLDINGS_RECORDS) X_OKAPI_TENANT(org.folio.rest.impl.PurchaseOrdersApiTest.X_OKAPI_TENANT) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) TestConfig.clearVertxContext(org.folio.TestConfig.clearVertxContext) Mockito.spy(org.mockito.Mockito.spy) HelperUtils.extractId(org.folio.orders.utils.HelperUtils.extractId) INSTANCE_HOLDING(org.folio.rest.jaxrs.model.Eresource.CreateInventory.INSTANCE_HOLDING) HOLDING_PERMANENT_LOCATION_ID(org.folio.service.inventory.InventoryManager.HOLDING_PERMANENT_LOCATION_ID) TestConfig.autowireDependencies(org.folio.TestConfig.autowireDependencies) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Physical(org.folio.rest.jaxrs.model.Physical) COMP_PO_LINES_MOCK_DATA_PATH(org.folio.rest.impl.PurchaseOrderLinesApiTest.COMP_PO_LINES_MOCK_DATA_PATH) Piece(org.folio.rest.jaxrs.model.Piece) TestConfig.initSpringContext(org.folio.TestConfig.initSpringContext) RequestEntry(org.folio.rest.core.models.RequestEntry) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) PostResponseType(org.folio.rest.core.PostResponseType) ExecutionException(java.util.concurrent.ExecutionException) NOT_FOUND(org.folio.rest.RestConstants.NOT_FOUND) JsonArray(io.vertx.core.json.JsonArray) Mockito.never(org.mockito.Mockito.never) AfterEach(org.junit.jupiter.api.AfterEach) TestUtils.getMockAsJson(org.folio.TestUtils.getMockAsJson) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) TimeoutException(java.util.concurrent.TimeoutException) X_OKAPI_USER_ID(org.folio.TestConstants.X_OKAPI_USER_ID) Context(io.vertx.core.Context) HOLDINGS_BY_ID_NOT_FOUND(org.folio.rest.core.exceptions.ErrorCodes.HOLDINGS_BY_ID_NOT_FOUND) Location(org.folio.rest.jaxrs.model.Location) CompletionException(java.util.concurrent.CompletionException) UUID(java.util.UUID) HOLDINGS_OLD_NEW_PATH(org.folio.rest.impl.MockServer.HOLDINGS_OLD_NEW_PATH) Test(org.junit.jupiter.api.Test) List(java.util.List) HelperUtils.getFirstObjectFromResponse(org.folio.orders.utils.HelperUtils.getFirstObjectFromResponse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ACTIVE_ACCESS_PROVIDER_B(org.folio.TestConstants.ACTIVE_ACCESS_PROVIDER_B) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TestConfig.getFirstContextFromVertx(org.folio.TestConfig.getFirstContextFromVertx) ITEMS_RECORDS_MOCK_DATA_PATH(org.folio.rest.impl.MockServer.ITEMS_RECORDS_MOCK_DATA_PATH) ID(org.folio.service.inventory.InventoryManager.ID) HttpException(org.folio.rest.core.exceptions.HttpException) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) TestUtils.getMockData(org.folio.TestUtils.getMockData) PoLineUpdateHolder(org.folio.models.PoLineUpdateHolder) ITEM_PURCHASE_ORDER_LINE_IDENTIFIER(org.folio.service.inventory.InventoryManager.ITEM_PURCHASE_ORDER_LINE_IDENTIFIER) Title(org.folio.rest.jaxrs.model.Title) PIECE_PATH(org.folio.TestConstants.PIECE_PATH) RequestContext(org.folio.rest.core.models.RequestContext) ITEMS(org.folio.service.inventory.InventoryManager.ITEMS) IsInstanceOf(org.hamcrest.core.IsInstanceOf) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Error(org.folio.rest.jaxrs.model.Error) Collectors.toList(java.util.stream.Collectors.toList) PieceService(org.folio.service.pieces.PieceService) Bean(org.springframework.context.annotation.Bean) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) JsonObject(io.vertx.core.json.JsonObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RequestEntry(org.folio.rest.core.models.RequestEntry) Test(org.junit.jupiter.api.Test)

Aggregations

RestClient (org.folio.rest.core.RestClient)26 RequestContext (org.folio.rest.core.models.RequestContext)26 Test (org.junit.jupiter.api.Test)25 JsonObject (io.vertx.core.json.JsonObject)23 BeforeEach (org.junit.jupiter.api.BeforeEach)23 List (java.util.List)22 CompletableFuture (java.util.concurrent.CompletableFuture)21 Collectors.toList (java.util.stream.Collectors.toList)21 IOException (java.io.IOException)20 RequestEntry (org.folio.rest.core.models.RequestEntry)18 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)18 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)18 Mockito.verify (org.mockito.Mockito.verify)18 UUID (java.util.UUID)17 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)17 CompletionException (java.util.concurrent.CompletionException)17 Mockito.doReturn (org.mockito.Mockito.doReturn)17 Mockito.times (org.mockito.Mockito.times)17 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)16 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)16