DataMerger { public MergeDiffInfo<R> mergeIntoCurrent(Function<String,Boolean> permissionChecker) { return createMergeResult(permissionChecker).executeMerge(); } 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_diff_info(){ ExampleDataA currentModel = new ExampleDataA(); currentModel.stringAttribute.set("1111111"); currentModel=currentModel.internal().finalise(); ExampleDataA originalModel = currentModel.internal().copy(); ExampleDataA newModel = currentModel.internal().copy(); newModel.stringAttribute.set("2222222"); DataMerger<ExampleDataA>dataMerger = new DataMerger<>(currentModel, originalModel, newModel); MergeDiffInfo<ExampleDataA> mergeDiff= dataMerger.mergeIntoCurrent((permission)->true); Assertions.assertTrue(mergeDiff.hasNoConflicts()); assertEquals("1111111",mergeDiff.mergeInfos.get(0).getAttributeDisplayText(mergeDiff.getPreviousRootData())); assertEquals("2222222",mergeDiff.mergeInfos.get(0).getAttributeDisplayText(mergeDiff.getNewRootData())); }
@Test public void test_diff_info_null(){ ExampleDataA currentModel = new ExampleDataA(); ExampleDataB exampleFactoryB = new ExampleDataB(); exampleFactoryB.stringAttribute.set("Factory to be deleted"); currentModel.referenceAttribute.set(exampleFactoryB); currentModel=currentModel.internal().finalise(); ExampleDataA originalModel = currentModel.internal().copy(); ExampleDataA newModel = currentModel.internal().copy(); newModel.referenceAttribute.set(null); DataMerger<ExampleDataA> dataMerger = new DataMerger<>(currentModel, originalModel, newModel); MergeDiffInfo<ExampleDataA> mergeDiff= dataMerger.mergeIntoCurrent((permission)->true); Assertions.assertTrue(mergeDiff.hasNoConflicts()); ExampleDataB exampleDataB = (ExampleDataB) mergeDiff.mergeInfos.get(0).getAttribute(mergeDiff.getPreviousRootData()).get(); Assertions.assertTrue((exampleDataB.stringAttribute.get()).equals("Factory to be deleted")); assertEquals("empty",mergeDiff.mergeInfos.get(0).getAttributeDisplayText(mergeDiff.getNewRootData())); }
@Test public void test_diff_info_mergediff_for_root(){ ExampleDataA currentModel = new ExampleDataA(); ExampleDataB exampleFactoryB = new ExampleDataB(); currentModel.referenceAttribute.set(exampleFactoryB); currentModel=currentModel.internal().finalise(); currentModel=currentModel.internal().finalise(); ExampleDataA originalModel = currentModel.internal().copy(); ExampleDataA newModel = currentModel.internal().copy(); newModel.referenceAttribute.set(null); DataMerger<ExampleDataA>dataMerger = new DataMerger<>(currentModel, originalModel, newModel); MergeDiffInfo<ExampleDataA> mergeDiff= dataMerger.mergeIntoCurrent((permission)->true); Assertions.assertTrue(mergeDiff.hasNoConflicts()); }
@Test public void test_permission_violation(){ ExampleFactoryPermission currentModel = new ExampleFactoryPermission(); currentModel.stringAttribute.set("123"); currentModel=currentModel.internal().finalise(); ExampleFactoryPermission originalModel = currentModel.internal().copy(); ExampleFactoryPermission newModel = currentModel.internal().copy(); newModel.stringAttribute.set("XXX"); DataMerger<ExampleFactoryPermission> dataMerger = new DataMerger<>(currentModel, originalModel, newModel); MergeDiffInfo<ExampleFactoryPermission> mergeDiff= dataMerger.mergeIntoCurrent((permission)->false); Assertions.assertFalse(mergeDiff.hasNoPermissionViolation()); Assertions.assertFalse(mergeDiff.successfullyMerged()); }
@Test public void test_permission_no_violation(){ ExampleFactoryPermission currentModel = new ExampleFactoryPermission(); currentModel.stringAttribute.set("123"); currentModel=currentModel.internal().finalise(); ExampleFactoryPermission originalModel = currentModel.internal().copy(); ExampleFactoryPermission newModel = currentModel.internal().copy(); newModel.stringAttribute.set("XXX"); DataMerger<ExampleFactoryPermission> dataMerger = new DataMerger<>(currentModel, originalModel, newModel); MergeDiffInfo<ExampleFactoryPermission> mergeDiff= dataMerger.mergeIntoCurrent((permission)->true); Assertions.assertTrue(mergeDiff.hasNoPermissionViolation()); Assertions.assertTrue(mergeDiff.successfullyMerged()); }