Search in sources :

Example 16 with RestClient

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

the class InventoryManagerTest method testShouldHandleItemRecordsIfPhysycPresentInUpdatePoLineTime.

@Test
void testShouldHandleItemRecordsIfPhysycPresentInUpdatePoLineTime() throws IOException {
    CompositePoLine reqData = getMockAsJson(COMP_PO_LINES_MOCK_DATA_PATH, "c0d08448-347b-418a-8c2f-5fb50248d67e").mapTo(CompositePoLine.class);
    String poLineId = "c0d08448-347b-418a-8c2f-5fb50248d67d";
    String itemId = "86481a22-633e-4b97-8061-0dc5fdaaeabb";
    String materialType = "1a54b431-2e4f-452d-9cae-9cee66c9a892";
    String locationId = "758258bc-ecc1-41b8-abca-f7b610822fff";
    String oldLocationId = "fcd64ce1-6995-48f0-840e-89ffa2288371";
    reqData.setId(poLineId);
    reqData.setPurchaseOrderId("9d56b621-202d-414b-9e7f-5fefe4422ab3");
    reqData.getPhysical().setMaterialType(materialType);
    reqData.getPhysical().setMaterialSupplier(ACTIVE_ACCESS_PROVIDER_B);
    reqData.getPhysical().setCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM);
    reqData.getLocations().get(0).setQuantityPhysical(1);
    reqData.getLocations().get(0).setQuantity(1);
    reqData.getCost().setQuantityPhysical(1);
    reqData.getLocations().get(0).setLocationId(locationId);
    CompositePoLine storagePoLineCom = getMockAsJson(COMP_PO_LINES_MOCK_DATA_PATH, "c0d08448-347b-418a-8c2f-5fb50248d67e").mapTo(CompositePoLine.class);
    storagePoLineCom.setAlerts(null);
    storagePoLineCom.setReportingCodes(null);
    storagePoLineCom.getLocations().get(0).setQuantityPhysical(1);
    storagePoLineCom.getLocations().get(0).setQuantity(1);
    storagePoLineCom.getCost().setQuantityPhysical(1);
    JsonObject items = new JsonObject(getMockData(ITEMS_RECORDS_MOCK_DATA_PATH + "inventoryItemsCollection.json"));
    List<JsonObject> needUpdateItems = items.getJsonArray(ITEMS).stream().map(o -> ((JsonObject) o)).filter(item -> item.getString(TestConstants.ID).equals(itemId)).map(item -> item.put(ITEM_PURCHASE_ORDER_LINE_IDENTIFIER, poLineId)).collect(toList());
    ;
    String path = PIECE_RECORDS_MOCK_DATA_PATH + String.format("pieceRecords-%s.json", poLineId);
    PieceCollection existedPieces = new JsonObject(getMockData(path)).mapTo(PieceCollection.class);
    existedPieces.getPieces().get(0).setItemId(itemId);
    existedPieces.getPieces().get(0).setFormat(Piece.Format.PHYSICAL);
    existedPieces.getPieces().get(0).setPoLineId(poLineId);
    // given
    doReturn(completedFuture(existedPieces)).when(pieceStorageService).getExpectedPiecesByLineId(poLineId, requestContext);
    doReturn(completedFuture(needUpdateItems)).when(inventoryManager).getItemRecordsByIds(Collections.singletonList(itemId), requestContext);
    doReturn(completedFuture(null)).when(inventoryManager).updateItemRecords(any(), eq(requestContext));
    doReturn(completedFuture(null)).when(restClient).put(any(RequestEntry.class), any(JsonObject.class), eq(requestContext));
    // When
    PoLineUpdateHolder poLineUpdateHolder = new PoLineUpdateHolder().withOldLocationId(oldLocationId).withNewLocationId(locationId);
    List<Piece> pieces = inventoryManager.handleItemRecords(reqData, poLineUpdateHolder, requestContext).join();
    assertEquals(1, pieces.size());
    assertEquals(itemId, pieces.get(0).getItemId());
    assertEquals(locationId, pieces.get(0).getLocationId());
}
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) PoLineUpdateHolder(org.folio.models.PoLineUpdateHolder) PieceCollection(org.folio.rest.jaxrs.model.PieceCollection) Piece(org.folio.rest.jaxrs.model.Piece) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) 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 17 with RestClient

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

the class InventoryManagerTest method shouldCheckIfTheHoldingExistsWhenLocationIdSpecifiedAndIfNotExistThenCreateNewHoldingReturnHoldingId.

@Test
void shouldCheckIfTheHoldingExistsWhenLocationIdSpecifiedAndIfNotExistThenCreateNewHoldingReturnHoldingId() 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);
    JsonObject holdingsRecJson = new JsonObject();
    holdingsRecJson.put(HOLDING_INSTANCE_ID, instanceId);
    holdingsRecJson.put(HOLDING_PERMANENT_LOCATION_ID, locationIds.get(0));
    JsonObject emptyHoldingCollection = new JsonObject().put(HOLDINGS_RECORDS, new JsonArray());
    doReturn(completedFuture(emptyHoldingCollection)).when(restClient).getAsJsonObject(any(RequestEntry.class), eq(requestContext));
    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) JsonArray(io.vertx.core.json.JsonArray) 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 18 with RestClient

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

the class InventoryManagerTest method shouldReturnHoldingsByInstanceIdAndLocationIdIfTheyExist.

@Test
void shouldReturnHoldingsByInstanceIdAndLocationIdIfTheyExist() 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));
    JsonObject actHoldings = inventoryManager.getFirstHoldingRecord(instanceId, locationIds.get(0), requestContext).get();
    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 19 with RestClient

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

the class InventoryManagerTest method shouldTrowExceptionHoldingsByIdsIfNotAllOfThemExist.

@Test
void shouldTrowExceptionHoldingsByIdsIfNotAllOfThemExist() 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());
    holdingIds.add(UUID.randomUUID().toString());
    doReturn(completedFuture(holdingsCollection)).when(restClient).getAsJsonObject(any(RequestEntry.class), eq(requestContext));
    CompletableFuture<List<JsonObject>> resultFuture = inventoryManager.getHoldingsByIds(holdingIds, requestContext);
    ExecutionException executionException = assertThrows(ExecutionException.class, resultFuture::get);
    assertThat(executionException.getCause(), IsInstanceOf.instanceOf(HttpException.class));
    HttpException httpException = (HttpException) executionException.getCause();
    assertEquals(404, httpException.getCode());
    assertEquals(PARTIALLY_RETURNED_COLLECTION.toError().getCode(), httpException.getError().getCode());
}
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) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) HttpException(org.folio.rest.core.exceptions.HttpException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RequestEntry(org.folio.rest.core.models.RequestEntry) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test)

Example 20 with RestClient

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

the class InvoiceCancelServiceTest method setupPoLineQuery.

private void setupPoLineQuery(List<PoLine> poLines) {
    String poLineIdsQuery = poLines.stream().map(PoLine::getId).collect(joining(" or "));
    String poLineQuery = "paymentStatus==(\"Awaiting Payment\" OR \"Partially Paid\" OR \"Fully Paid\") AND id==(" + poLineIdsQuery + ")";
    PoLineCollection poLineCollection = new PoLineCollection().withPoLines(poLines).withTotalRecords(poLines.size());
    RequestEntry requestEntry = new RequestEntry("/orders/order-lines").withQuery(poLineQuery).withOffset(0).withLimit(Integer.MAX_VALUE);
    doReturn(completedFuture(poLineCollection)).when(restClient).get(argThat(re -> sameRequestEntry(requestEntry, re)), eq(requestContextMock), eq(PoLineCollection.class));
}
Also used : INVOICE_MOCK_DATA_PATH(org.folio.TestMockDataConstants.INVOICE_MOCK_DATA_PATH) BeforeEach(org.junit.jupiter.api.BeforeEach) TransactionType(org.folio.rest.acq.model.finance.Transaction.TransactionType) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) PurchaseOrder(org.folio.rest.acq.model.orders.PurchaseOrder) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) PoLine(org.folio.rest.acq.model.orders.PoLine) OrderLineService(org.folio.services.order.OrderLineService) VOUCHERS_STORAGE(org.folio.invoices.utils.ResourcePathResolver.VOUCHERS_STORAGE) INVOICE_TRANSACTION_SUMMARIES(org.folio.invoices.utils.ResourcePathResolver.INVOICE_TRANSACTION_SUMMARIES) Mockito.argThat(org.mockito.Mockito.argThat) TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) MOCK_CREDITS_LIST(org.folio.TestMockDataConstants.MOCK_CREDITS_LIST) Collections.singletonList(java.util.Collections.singletonList) VOUCHER_MOCK_DATA_PATH(org.folio.TestMockDataConstants.VOUCHER_MOCK_DATA_PATH) HttpException(org.folio.invoices.rest.exceptions.HttpException) Voucher(org.folio.rest.jaxrs.model.Voucher) InvoiceTransactionSummaryService(org.folio.services.finance.transaction.InvoiceTransactionSummaryService) VoucherCommandService(org.folio.services.voucher.VoucherCommandService) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) InvoiceTransactionSummary(org.folio.rest.acq.model.finance.InvoiceTransactionSummary) JsonObject(io.vertx.core.json.JsonObject) Method(java.lang.reflect.Method) ERROR_UNRELEASING_ENCUMBRANCES(org.folio.invoices.utils.ErrorCodes.ERROR_UNRELEASING_ENCUMBRANCES) Mockito.doReturn(org.mockito.Mockito.doReturn) RELEASED(org.folio.rest.acq.model.finance.Encumbrance.Status.RELEASED) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) ORDER_TRANSACTION_SUMMARIES(org.folio.invoices.utils.ResourcePathResolver.ORDER_TRANSACTION_SUMMARIES) CompletionException(java.util.concurrent.CompletionException) MOCK_ENCUMBRANCES_LIST(org.folio.TestMockDataConstants.MOCK_ENCUMBRANCES_LIST) UUID(java.util.UUID) Collectors.joining(java.util.stream.Collectors.joining) Test(org.junit.jupiter.api.Test) CompletableFuture.failedFuture(java.util.concurrent.CompletableFuture.failedFuture) List(java.util.List) FINANCE_TRANSACTIONS(org.folio.invoices.utils.ResourcePathResolver.FINANCE_TRANSACTIONS) PENDING(org.folio.rest.acq.model.finance.Encumbrance.Status.PENDING) PurchaseOrderCollection(org.folio.rest.acq.model.orders.PurchaseOrderCollection) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) UNRELEASED(org.folio.rest.acq.model.finance.Encumbrance.Status.UNRELEASED) WorkflowStatus(org.folio.rest.acq.model.orders.PurchaseOrder.WorkflowStatus) Invoice(org.folio.rest.jaxrs.model.Invoice) MOCK_PAYMENTS_LIST(org.folio.TestMockDataConstants.MOCK_PAYMENTS_LIST) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) RestClient(org.folio.rest.core.RestClient) EncumbranceService(org.folio.services.finance.transaction.EncumbranceService) CANNOT_CANCEL_INVOICE(org.folio.invoices.utils.ErrorCodes.CANNOT_CANCEL_INVOICE) PoLineCollection(org.folio.rest.acq.model.orders.PoLineCollection) CompletableFuture(java.util.concurrent.CompletableFuture) Transaction(org.folio.rest.acq.model.finance.Transaction) VoucherCollection(org.folio.rest.jaxrs.model.VoucherCollection) InvoiceLineCollection(org.folio.rest.jaxrs.model.InvoiceLineCollection) Answer(org.mockito.stubbing.Answer) OrderTransactionSummary(org.folio.rest.acq.model.finance.OrderTransactionSummary) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RequestContext(org.folio.rest.core.models.RequestContext) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) BaseTransactionService(org.folio.services.finance.transaction.BaseTransactionService) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) MOCK_PENDING_PAYMENTS_LIST(org.folio.TestMockDataConstants.MOCK_PENDING_PAYMENTS_LIST) OrderService(org.folio.services.order.OrderService) ResourcePathResolver.resourcesPath(org.folio.invoices.utils.ResourcePathResolver.resourcesPath) Files(java.nio.file.Files) VoucherRetrieveService(org.folio.services.voucher.VoucherRetrieveService) Vertx(io.vertx.core.Vertx) RequestEntry(org.folio.rest.core.models.RequestEntry) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Collectors.toList(java.util.stream.Collectors.toList) Paths(java.nio.file.Paths) INVOICE_LINES_LIST_PATH(org.folio.TestMockDataConstants.INVOICE_LINES_LIST_PATH) OrderTransactionSummaryService(org.folio.services.finance.transaction.OrderTransactionSummaryService) PoLineCollection(org.folio.rest.acq.model.orders.PoLineCollection) RequestEntry(org.folio.rest.core.models.RequestEntry)

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