DataMerger { public MergeResult<R> createMergeResult(Function<String,Boolean> permissionChecker) { MergeResult<R> mergeResult = new MergeResult<>(currentData,idToFactory); for (Triple<R> entry : mergeable) { FactoryBase<?,R> originalValue = entry.commonFactory; FactoryBase<?,R> newValue = entry.newFactory; if (newValue==null && originalValue!=null){ entry.currentFactory.internal().visitAttributesForMatch(originalValue, (name,currentAttribute, originalAttribute) -> { if (!currentAttribute.internal_mergeMatch(originalAttribute)){ mergeResult.addConflictInfo(new AttributeDiffInfo(name,entry.currentFactory.getId())); } return true; }); } if (originalValue!=null && newValue!=null){ FactoryBase<?,R> value = entry.currentFactory; value.internal().merge(originalValue, newValue, mergeResult, permissionChecker); } } return mergeResult; } DataMerger(R currentData, R commonData, R newData); MergeResult<R> createMergeResult(Function<String,Boolean> permissionChecker); MergeDiffInfo<R> mergeIntoCurrent(Function<String,Boolean> permissionChecker);  }
@Test public void test_getChangedFactories_no_change() { ExampleFactoryA exampleFactoryA = new ExampleFactoryA(); exampleFactoryA.stringAttribute.set("123"); ExampleFactoryA copy = exampleFactoryA.internal().copy(); copy.stringAttribute.set("123"); DataMerger<ExampleFactoryA> dataMerger = new DataMerger<>(exampleFactoryA, exampleFactoryA.internal().copy(), copy); MergeResult<ExampleFactoryA> mergeResult = dataMerger.createMergeResult((p) -> true); assertEquals(0,mergeResult.getMergedFactories().size()); }
@Test public void test_getChangedFactories_views() { FactoryBaseTest.XRoot previous = new FactoryBaseTest.XRoot(); FactoryBaseTest.ExampleFactoryAndViewA exampleFactoryAndViewA = new FactoryBaseTest.ExampleFactoryAndViewA(); previous.referenceAttribute.set(exampleFactoryAndViewA); FactoryBaseTest.XFactory xFactory = new FactoryBaseTest.XFactory(); previous.xFactory.set(xFactory); FactoryBaseTest.XRoot update= previous.utility().copy(); update.xFactory.set(null); DataMerger<FactoryBaseTest.XRoot> dataMerger = new DataMerger<>(previous, previous.internal().copy(), update); MergeResult<FactoryBaseTest.XRoot> mergeResult = dataMerger.createMergeResult((p) -> true); Set<FactoryBase<?,FactoryBaseTest.XRoot>> changedFactories=mergeResult.getMergedFactories(); Assertions.assertTrue(changedFactories.contains(previous)); Assertions.assertTrue(changedFactories.contains(exampleFactoryAndViewA)); }
@Test public void test_getChangedFactories_simple() { ExampleFactoryA exampleFactoryA = new ExampleFactoryA(); exampleFactoryA.stringAttribute.set("123"); ExampleFactoryA copy = exampleFactoryA.internal().copy(); copy.stringAttribute.set("qqqqq"); DataMerger<ExampleFactoryA> dataMerger = new DataMerger<>(exampleFactoryA, exampleFactoryA.internal().copy(), copy); MergeResult<ExampleFactoryA> mergeResult = dataMerger.createMergeResult((p) -> true); Set<FactoryBase<?,ExampleFactoryA>> changedFactories=mergeResult.getMergedFactories(); Assertions.assertEquals(1,changedFactories.size()); Assertions.assertTrue(changedFactories.contains(exampleFactoryA)); }
@Test public void test_getChangedFactories_simple_change_to_null() { ExampleFactoryA exampleFactoryA = new ExampleFactoryA(); exampleFactoryA.stringAttribute.set("123"); ExampleFactoryA copy = exampleFactoryA.internal().copy(); copy.stringAttribute.set(null); DataMerger<ExampleFactoryA> dataMerger = new DataMerger<>(exampleFactoryA, exampleFactoryA.internal().copy(), copy); MergeResult<ExampleFactoryA> mergeResult = dataMerger.createMergeResult((p) -> true); Set<FactoryBase<?,ExampleFactoryA>> changedFactories=mergeResult.getMergedFactories(); Assertions.assertEquals(1,changedFactories.size()); Assertions.assertTrue(changedFactories.contains(exampleFactoryA)); }
@Test public void test_objectValueAttribute_null_should_not_count_as_change() { ExampleObjectValueAttributeFactory original = new ExampleObjectValueAttributeFactory(); original.objectValueAttribute.set("123"); ExampleObjectValueAttributeFactory common = original.utility().copy(); ExampleObjectValueAttributeFactory update =original.utility().copy(); update.objectValueAttribute.set(null); DataMerger<ExampleObjectValueAttributeFactory> dataMerger = new DataMerger<>(original, common, update); MergeResult<ExampleObjectValueAttributeFactory> mergeResult = dataMerger.createMergeResult((p) -> true); Set<FactoryBase<?,ExampleObjectValueAttributeFactory>> changedFactories=mergeResult.getMergedFactories(); Assertions.assertEquals(0,changedFactories.size()); }