Search in sources :

Example 6 with PieceCollection

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

use of org.folio.rest.jaxrs.model.PieceCollection in project mod-orders by folio-org.

the class LocationsAndPiecesConsistencyValidatorTest method testVerifyLocationsAndPiecesConsistencyWhenTwoLocationWithHoldingAndPiecesWithHolding.

@Test
public void testVerifyLocationsAndPiecesConsistencyWhenTwoLocationWithHoldingAndPiecesWithHolding() {
    String holdingId1 = UUID.randomUUID().toString();
    String holdingId2 = UUID.randomUUID().toString();
    Location location1 = new Location().withHoldingId(holdingId1).withQuantity(1).withQuantityPhysical(1);
    Location location2 = new Location().withHoldingId(holdingId2).withQuantity(1).withQuantityPhysical(1);
    String poLineId = UUID.randomUUID().toString();
    CompositePoLine poLine = new CompositePoLine().withId(poLineId).withLocations(List.of(location1, location2));
    List<CompositePoLine> poLines = List.of(poLine);
    Piece piece1 = new Piece().withPoLineId(poLineId).withHoldingId(holdingId1).withReceivingStatus(Piece.ReceivingStatus.EXPECTED);
    Piece piece2 = new Piece().withPoLineId(poLineId).withHoldingId(holdingId2).withReceivingStatus(Piece.ReceivingStatus.EXPECTED);
    PieceCollection pieces = new PieceCollection().withPieces(List.of(piece1, piece2)).withTotalRecords(2);
    // Expect
    LocationsAndPiecesConsistencyValidator.verifyLocationsAndPiecesConsistency(poLines, pieces);
}
Also used : PieceCollection(org.folio.rest.jaxrs.model.PieceCollection) Piece(org.folio.rest.jaxrs.model.Piece) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test)

Example 8 with PieceCollection

use of org.folio.rest.jaxrs.model.PieceCollection in project mod-orders by folio-org.

the class LocationsAndPiecesConsistencyValidatorTest method testVerifyLocationsAndPiecesConsistencyWhenTwoLocationWithHoldingAndPiecesWithHoldingIdDifferenceWithPol.

@Test
public void testVerifyLocationsAndPiecesConsistencyWhenTwoLocationWithHoldingAndPiecesWithHoldingIdDifferenceWithPol() {
    String holdingId1 = UUID.randomUUID().toString();
    String holdingId2 = UUID.randomUUID().toString();
    Location location1 = new Location().withHoldingId(holdingId1).withQuantity(1).withQuantityPhysical(1);
    Location location2 = new Location().withHoldingId(holdingId2).withQuantity(1).withQuantityPhysical(1);
    String poLineId = UUID.randomUUID().toString();
    CompositePoLine poLine = new CompositePoLine().withId(poLineId).withLocations(List.of(location1, location2));
    List<CompositePoLine> poLines = List.of(poLine);
    Piece piece1 = new Piece().withPoLineId(poLineId).withHoldingId(UUID.randomUUID().toString()).withReceivingStatus(Piece.ReceivingStatus.EXPECTED);
    Piece piece2 = new Piece().withPoLineId(poLineId).withHoldingId(holdingId2).withReceivingStatus(Piece.ReceivingStatus.EXPECTED);
    PieceCollection pieces = new PieceCollection().withPieces(List.of(piece1, piece2)).withTotalRecords(2);
    // Expect
    HttpException actHttpException = assertThrows(HttpException.class, () -> LocationsAndPiecesConsistencyValidator.verifyLocationsAndPiecesConsistency(poLines, pieces), "Expected exception");
    Error actError = actHttpException.getError();
    assertEquals(PIECES_TO_BE_DELETED.getCode(), actError.getCode());
    assertEquals(VALIDATION_ERROR, actHttpException.getCode());
}
Also used : PieceCollection(org.folio.rest.jaxrs.model.PieceCollection) Piece(org.folio.rest.jaxrs.model.Piece) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Error(org.folio.rest.jaxrs.model.Error) HttpException(org.folio.rest.core.exceptions.HttpException) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test)

Aggregations

PieceCollection (org.folio.rest.jaxrs.model.PieceCollection)8 Piece (org.folio.rest.jaxrs.model.Piece)6 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)5 Location (org.folio.rest.jaxrs.model.Location)5 Test (org.junit.jupiter.api.Test)5 HttpException (org.folio.rest.core.exceptions.HttpException)4 Error (org.folio.rest.jaxrs.model.Error)3 List (java.util.List)2 Map (java.util.Map)2 RequestEntry (org.folio.rest.core.models.RequestEntry)2 Context (io.vertx.core.Context)1 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1