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");
}
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"));
}
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");
}
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));
}
Aggregations