use of org.folio.Instance in project mod-inventory by folio-org.
the class InstanceUtilTest method shouldMergeInstances.
@Test
public void shouldMergeInstances() {
Set<AlternativeTitle> alternativeTitles = new HashSet<>();
alternativeTitles.add(new AlternativeTitle().withAlternativeTitle("alt1").withAlternativeTitleTypeId("30773a27-b485-4dab-aeb6-b8c04fa3cb19"));
List<Contributor> contributors = new ArrayList<>();
contributors.add(new Contributor().withName("contributor1").withContributorNameTypeId("30773a27-b485-4dab-aeb6-b8c04fa3cb19").withContributorTypeId("30773a27-b485-4dab-aeb6-b8c04fa3cb19").withContributorTypeText("text").withPrimary(true));
Instance mapped = new Instance().withId("30773a27-b485-4dab-aeb6-b8c04fa3cb17").withHrid("in000000001").withModeOfIssuanceId("30773a27-b485-4dab-aeb6-b8c04fa3cb18").withAlternativeTitles(alternativeTitles).withContributors(contributors);
List<String> statisticalCodeIds = new ArrayList<>();
statisticalCodeIds.add("30773a27-b485-4dab-aeb6-b8c04fa3cb19");
statisticalCodeIds.add("30773a27-b485-4dab-aeb6-b8c04fa3cb18");
List<String> natureOfContentTermIds = new ArrayList<>();
statisticalCodeIds.add("30773a27-b485-4dab-aeb6-b8c04fa3cb21");
statisticalCodeIds.add("30773a27-b485-4dab-aeb6-b8c04fa3cb22");
List<InstanceRelationshipToParent> parents = new ArrayList<>();
parents.add(new InstanceRelationshipToParent("30773a27-b485-4dab-aeb6-b8c04fa3cb19", "30773a27-b485-4dab-aeb6-b8c04fa3cb23", "30773a27-b485-4dab-aeb6-b8c04fa3cb24"));
List<InstanceRelationshipToChild> children = new ArrayList<>();
children.add(new InstanceRelationshipToChild("30773a27-b485-4dab-aeb6-b8c04fa3cb19", "30773a27-b485-4dab-aeb6-b8c04fa3cb23", "30773a27-b485-4dab-aeb6-b8c04fa3cb24"));
List<String> tagList = new ArrayList<>();
tagList.add("Tag1");
tagList.add("Tag2");
org.folio.inventory.domain.instances.Instance existing = new org.folio.inventory.domain.instances.Instance("30773a27-b485-4dab-aeb6-b8c04fa3cb17", "7", "in000000001", "source", "title", "30773a27-b485-4dab-aeb6-b8c04fa3cb19");
existing.setStatisticalCodeIds(statisticalCodeIds);
existing.setDiscoverySuppress(true);
existing.setStaffSuppress(true);
existing.setPreviouslyHeld(true);
existing.setCatalogedDate("");
existing.setStatusId("30773a27-b485-4dab-aeb6-b8c04fa3cb26");
existing.setNatureOfContentTermIds(natureOfContentTermIds);
existing.setParentInstances(parents);
existing.setChildInstances(children);
existing.setTags(tagList);
org.folio.inventory.domain.instances.Instance instance = InstanceUtil.mergeFieldsWhichAreNotControlled(existing, mapped);
assertEquals("30773a27-b485-4dab-aeb6-b8c04fa3cb17", instance.getId());
assertEquals("in000000001", instance.getHrid());
assertEquals("30773a27-b485-4dab-aeb6-b8c04fa3cb18", instance.getModeOfIssuanceId());
assertEquals(contributors.get(0).getName(), instance.getContributors().get(0).name);
assertEquals(statisticalCodeIds, instance.getStatisticalCodeIds());
assertTrue(instance.getDiscoverySuppress());
assertTrue(instance.getStaffSuppress());
assertTrue(instance.getPreviouslyHeld());
assertEquals("", instance.getCatalogedDate());
assertEquals("30773a27-b485-4dab-aeb6-b8c04fa3cb26", instance.getStatusId());
assertEquals(natureOfContentTermIds, instance.getNatureOfContentTermIds());
assertNotNull(instance.getTags());
assertEquals(tagList, instance.getTags());
assertEquals("30773a27-b485-4dab-aeb6-b8c04fa3cb19", instance.getParentInstances().get(0).getId());
assertEquals("30773a27-b485-4dab-aeb6-b8c04fa3cb19", instance.getChildInstances().get(0).getId());
}
use of org.folio.Instance in project mod-inventory by folio-org.
the class MatchHoldingEventHandlerUnitTest method shouldMatchWithSubMatchByInstanceOnHandleEventPayload.
@Test
public void shouldMatchWithSubMatchByInstanceOnHandleEventPayload(TestContext testContext) throws UnsupportedEncodingException {
Async async = testContext.async();
doAnswer(ans -> {
Consumer<Success<MultipleRecords<HoldingsRecord>>> callback = ans.getArgument(2);
Success<MultipleRecords<HoldingsRecord>> result = new Success<>(new MultipleRecords<>(singletonList(createHolding()), 1));
callback.accept(result);
return null;
}).when(holdingCollection).findByCql(eq(format("hrid == \"%s\" AND instanceId == \"%s\"", HOLDING_HRID, INSTANCE_ID)), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
EventHandler eventHandler = new MatchHoldingEventHandler(mappingMetadataCache);
HashMap<String, String> context = new HashMap<>();
context.put(EntityType.INSTANCE.value(), JsonObject.mapFrom(new Instance().withId(INSTANCE_ID)).encode());
context.put(MAPPING_PARAMS, LOCATIONS_PARAMS);
context.put(RELATIONS, MATCHING_RELATIONS);
DataImportEventPayload eventPayload = createEventPayload().withContext(context);
eventHandler.handle(eventPayload).whenComplete((updatedEventPayload, throwable) -> {
testContext.assertNull(throwable);
testContext.assertEquals(1, updatedEventPayload.getEventsChain().size());
testContext.assertEquals(updatedEventPayload.getEventsChain(), singletonList(DI_SRS_MARC_BIB_RECORD_CREATED.value()));
testContext.assertEquals(DI_INVENTORY_HOLDING_MATCHED.value(), updatedEventPayload.getEventType());
async.complete();
});
}
Aggregations