Search in sources :

Example 71 with Item

use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.

the class UnknownStatusValidatorTest method itemCannotBeMarkedAsUnavailableWhenNotInAcceptableSourceStatus.

@Parameters({ "In process", "Unknown" })
@Test
public void itemCannotBeMarkedAsUnavailableWhenNotInAcceptableSourceStatus(String sourceStatus) {
    final var targetValidator = validator.getValidator(UNKNOWN);
    final var item = new Item(null, null, null, new Status(ItemStatusName.forName(sourceStatus)), null, null, null);
    final var validationFuture = targetValidator.refuseItemWhenNotInAcceptableSourceStatus(item);
    Exception e = assertThrows(Exception.class, () -> validationFuture.get(1, TimeUnit.SECONDS));
    assertThat(e.getCause().getMessage()).isEqualTo("Item is not allowed to be marked as Unknown");
}
Also used : Status(org.folio.inventory.domain.items.Status) Item(org.folio.inventory.domain.items.Item) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 72 with Item

use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.

the class ItemUtilTest method shouldReturnItemAsMappingResultRepresentation.

@Test
public void shouldReturnItemAsMappingResultRepresentation() {
    // given
    Item item = new Item(UUID.randomUUID().toString(), "2", UUID.randomUUID().toString(), new Status(AVAILABLE), UUID.randomUUID().toString(), UUID.randomUUID().toString(), null).withTemporaryLoanTypeId(UUID.randomUUID().toString()).withPermanentLocationId(UUID.randomUUID().toString()).withTemporaryLocationId(UUID.randomUUID().toString());
    // when
    String mappedResult = ItemUtil.mapToMappingResultRepresentation(item);
    JsonObject actualItemJson = new JsonObject(mappedResult);
    // then
    Assert.assertEquals(item.id, actualItemJson.getString("id"));
    Assert.assertEquals(item.getVersion(), actualItemJson.getString("_version"));
    Assert.assertEquals(item.getHoldingId(), actualItemJson.getString("holdingsRecordId"));
    Assert.assertEquals(item.getStatus().getName().value(), getNestedProperty(actualItemJson, "status", "name"));
    Assert.assertEquals(item.getMaterialTypeId(), getNestedProperty(actualItemJson, "materialType", "id"));
    Assert.assertEquals(item.getPermanentLoanTypeId(), getNestedProperty(actualItemJson, "permanentLoanType", "id"));
    Assert.assertEquals(item.getTemporaryLoanTypeId(), getNestedProperty(actualItemJson, "temporaryLoanType", "id"));
    Assert.assertEquals(item.getPermanentLocationId(), getNestedProperty(actualItemJson, "permanentLocation", "id"));
    Assert.assertEquals(item.getTemporaryLocationId(), getNestedProperty(actualItemJson, "temporaryLocation", "id"));
}
Also used : Status(org.folio.inventory.domain.items.Status) Item(org.folio.inventory.domain.items.Item) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 73 with Item

use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.

the class InProcessItemStatusValidatorTest method itemCannotBeMarkedAsInProcessWhenNotInAcceptableSourceStatus.

@Parameters({ "In process" })
@Test
public void itemCannotBeMarkedAsInProcessWhenNotInAcceptableSourceStatus(String sourceStatus) {
    final var targetValidator = validators.getValidator(IN_PROCESS);
    final var item = new Item(null, null, null, new Status(ItemStatusName.forName(sourceStatus)), null, null, null);
    final var validationFuture = targetValidator.refuseItemWhenNotInAcceptableSourceStatus(item);
    Exception e = assertThrows(Exception.class, () -> validationFuture.get(1, TimeUnit.SECONDS));
    assertThat(e.getCause().getMessage()).isEqualTo("Item is not allowed to be marked as In process");
}
Also used : Status(org.folio.inventory.domain.items.Status) Item(org.folio.inventory.domain.items.Item) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 74 with Item

use of org.folio.inventory.domain.items.Item in project mod-inventory by folio-org.

the class UpdateItemEventHandlerTest method shouldNotRequestWhenUpdatedItemHasEmptyBarcode.

@Test
public void shouldNotRequestWhenUpdatedItemHasEmptyBarcode() throws UnsupportedEncodingException {
    // given
    doAnswer(invocationOnMock -> {
        Item itemByCql = new Item(null, null, null, new Status(AVAILABLE), null, null, null);
        MultipleRecords<Item> result = new MultipleRecords<>(Collections.singletonList(itemByCql), 0);
        Consumer<Success<MultipleRecords<Item>>> successHandler = invocationOnMock.getArgument(2);
        successHandler.accept(new Success<>(result));
        return null;
    }).when(mockedItemCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
    HashMap<String, String> payloadContext = new HashMap<>();
    payloadContext.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(new Record()));
    payloadContext.put(ITEM.value(), existingItemJson.encode());
    MappingProfile mappingProfile = new MappingProfile().withId(UUID.randomUUID().toString()).withName("Prelim item from MARC").withIncomingRecordType(EntityType.MARC_BIBLIOGRAPHIC).withExistingRecordType(ITEM).withMappingDetails(new MappingDetail().withMappingFields(Arrays.asList(new MappingRule().withPath("item.status.name").withValue("\"statusExpression\"").withEnabled("true"), new MappingRule().withPath("item.permanentLoanType.id").withValue("\"permanentLoanTypeExpression\"").withEnabled("true"), new MappingRule().withPath("item.materialType.id").withValue("\"materialTypeExpression\"").withEnabled("true"))));
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_SRS_MARC_BIB_RECORD_CREATED.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(payloadContext).withCurrentNode(new ProfileSnapshotWrapper().withProfileId(actionProfile.getId()).withContentType(ACTION_PROFILE).withContent(JsonObject.mapFrom(actionProfile).getMap()).withChildSnapshotWrappers(Collections.singletonList(new ProfileSnapshotWrapper().withProfileId(mappingProfile.getId()).withContentType(MAPPING_PROFILE).withContent(JsonObject.mapFrom(mappingProfile).getMap()))));
    // when
    updateItemHandler.handle(dataImportEventPayload);
    // then
    verify(mockedItemCollection, Mockito.times(0)).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
}
Also used : Status(org.folio.inventory.domain.items.Status) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MappingRule(org.folio.rest.jaxrs.model.MappingRule) Success(org.folio.inventory.common.domain.Success) DataImportEventPayload(org.folio.DataImportEventPayload) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) Item(org.folio.inventory.domain.items.Item) MappingProfile(org.folio.MappingProfile) Consumer(java.util.function.Consumer) MappingDetail(org.folio.rest.jaxrs.model.MappingDetail) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) HoldingsRecord(org.folio.HoldingsRecord) Record(org.folio.rest.jaxrs.model.Record) Test(org.junit.Test)

Aggregations

Item (org.folio.inventory.domain.items.Item)74 Test (org.junit.Test)59 Status (org.folio.inventory.domain.items.Status)41 Parameters (junitparams.Parameters)32 JsonObject (io.vertx.core.json.JsonObject)28 PagingParameters (org.folio.inventory.common.api.request.PagingParameters)28 MultipleRecords (org.folio.inventory.common.domain.MultipleRecords)26 Success (org.folio.inventory.common.domain.Success)24 DataImportEventPayload (org.folio.DataImportEventPayload)23 HashMap (java.util.HashMap)20 Consumer (java.util.function.Consumer)20 CompletableFuture (java.util.concurrent.CompletableFuture)16 Record (org.folio.rest.jaxrs.model.Record)14 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 ItemCollection (org.folio.inventory.domain.items.ItemCollection)12 Storage (org.folio.inventory.storage.Storage)11 EventHandler (org.folio.processing.events.services.handler.EventHandler)11 List (java.util.List)9 Collectors (java.util.stream.Collectors)9 HoldingsRecord (org.folio.HoldingsRecord)9