Search in sources :

Example 6 with MappingRule

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

HashMap (java.util.HashMap)6 DataImportEventPayload (org.folio.DataImportEventPayload)6 MappingRule (org.folio.rest.jaxrs.model.MappingRule)6 Test (org.junit.Test)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 Record (org.folio.rest.jaxrs.model.Record)5 JsonObject (io.vertx.core.json.JsonObject)4 HoldingsRecord (org.folio.HoldingsRecord)4 MappingProfile (org.folio.MappingProfile)4 MappingDetail (org.folio.rest.jaxrs.model.MappingDetail)4 ProfileSnapshotWrapper (org.folio.rest.jaxrs.model.ProfileSnapshotWrapper)4 Consumer (java.util.function.Consumer)3 PagingParameters (org.folio.inventory.common.api.request.PagingParameters)3 MultipleRecords (org.folio.inventory.common.domain.MultipleRecords)3 Success (org.folio.inventory.common.domain.Success)3 Item (org.folio.inventory.domain.items.Item)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Status (org.folio.inventory.domain.items.Status)2 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)2 Parameters (junitparams.Parameters)1