@Test public void testNoConflictIfSameDiff() throws Exception { Geometry oldGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); Geometry newGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 35, 30 30),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom); assertFalse(diff.conflicts(diff2)); }
@Test public void testNoConflictIfSameDiff() throws Exception { Geometry oldGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); Geometry newGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 35, 30 30),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom); assertFalse(diff.conflicts(diff2)); }
@Test public void testConflictEditedSamePoint() throws Exception { Geometry oldGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); Geometry newGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 48 32, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); Geometry newGeom2 = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 41 33, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom2); assertTrue(diff.conflicts(diff2)); }
@Test public void testConflictEditedSamePoint() throws Exception { Geometry oldGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); Geometry newGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 48 32, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); Geometry newGeom2 = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 41 33, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom2); assertTrue(diff.conflicts(diff2)); }
@Test public void testConflict() throws Exception { Geometry oldGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); Geometry newGeom = new WKTReader() .read("MULTILINESTRING ((40 40, 20 45),(20 35, 45 10, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); Geometry newGeom2 = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 41 33, 25 25),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom2); assertTrue(diff.conflicts(diff2)); }
@Test public void testConflict() throws Exception { Geometry oldGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); Geometry newGeom = new WKTReader() .read("MULTILINESTRING ((40 40, 20 45),(20 35, 45 10, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); Geometry newGeom2 = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 41 33, 25 25),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom2); assertTrue(diff.conflicts(diff2)); }
@Test public void testNoConflictIfSameDiff2() throws Exception { String wkt = "MULTIPOLYGON (((-75.0740073 38.6938098, -75.0739683 38.6935296, " + "-75.0745695 38.6934786, -75.0745824 38.6935715, -75.0741091 38.6936117, " + "-75.0741352 38.6937989, -75.0740073 38.6938098)))"; Geometry oldGeom = new WKTReader().read(wkt); Geometry newGeom = new WKTReader().read(wkt); assertTrue(oldGeom.equalsExact(newGeom)); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom); assertFalse(diff.conflicts(diff2)); } }
@Test public void testNoConflictIfSameDiff2() throws Exception { String wkt = "MULTIPOLYGON (((-75.0740073 38.6938098, -75.0739683 38.6935296, " + "-75.0745695 38.6934786, -75.0745824 38.6935715, -75.0741091 38.6936117, " + "-75.0741352 38.6937989, -75.0740073 38.6938098)))"; Geometry oldGeom = new WKTReader().read(wkt); Geometry newGeom = new WKTReader().read(wkt); assertTrue(oldGeom.equalsExact(newGeom)); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom); assertFalse(diff.conflicts(diff2)); } }
@Test public void testConflictPatcheable() throws Exception { Geometry oldGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); Geometry newGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 35, 30 30),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); Geometry newGeom2 = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 31 6, 10 30, 20 35))"); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom2); // it's a conflict for the sake of merging branches assertTrue(diff.conflicts(diff2)); // yet can be merged for the sake of applying a patch assertTrue(diff2.canBeAppliedOn(newGeom)); Geometry merged = diff2.applyOn(newGeom); assertNotNull(merged); assertEquals( "MULTILINESTRING ((40 40, 20 45, 45 35, 30 30), (20 35, 45 10, 31 6, 10 30, 20 35))", merged.toText()); }
@Test public void testNoConflictAddingPoints() throws Exception { Geometry oldGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); Geometry newGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 10 10, 20 45, 45 30, 30 30),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); Geometry newGeom2 = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 31 6, 10 30, 20 35))"); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom2); // the diff is conflicting assertTrue(diff.conflicts(diff2)); // yet it can be applied for patching assertTrue(diff2.canBeAppliedOn(newGeom)); Geometry merged = diff2.applyOn(newGeom); assertNotNull(merged); assertEquals( "MULTILINESTRING ((40 40, 10 10, 20 45, 45 30, 30 30), (20 35, 45 10, 31 6, 10 30, 20 35))", merged.toText()); }
@Test public void testConflictPatcheable() throws Exception { Geometry oldGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); Geometry newGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 35, 30 30),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); Geometry newGeom2 = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 31 6, 10 30, 20 35))"); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom2); // it's a conflict for the sake of merging branches assertTrue(diff.conflicts(diff2)); // yet can be merged for the sake of applying a patch assertTrue(diff2.canBeAppliedOn(newGeom)); Geometry merged = diff2.applyOn(newGeom); assertNotNull(merged); assertEquals( "MULTILINESTRING ((40 40, 20 45, 45 35, 30 30), (20 35, 45 10, 31 6, 10 30, 20 35))", merged.toText()); }
@Test public void testNoConflictAddingPoints() throws Exception { Geometry oldGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); Geometry newGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 10 10, 20 45, 45 30, 30 30),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); Geometry newGeom2 = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 31 6, 10 30, 20 35))"); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom2); // the diff is conflicting assertTrue(diff.conflicts(diff2)); // yet it can be applied for patching assertTrue(diff2.canBeAppliedOn(newGeom)); Geometry merged = diff2.applyOn(newGeom); assertNotNull(merged); assertEquals( "MULTILINESTRING ((40 40, 10 10, 20 45, 45 30, 30 30), (20 35, 45 10, 31 6, 10 30, 20 35))", merged.toText()); }
@Test public void testConflictRemovingPoints() throws Exception { Geometry oldGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); Geometry newGeom = new WKTReader() .read("MULTILINESTRING ((40 40, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); Geometry newGeom2 = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 31 6, 10 30, 20 35))"); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom2); // the diff reports a conflict assertTrue(diff.conflicts(diff2)); // yet it can be applied for patching assertTrue(diff2.canBeAppliedOn(newGeom)); Geometry merged = diff2.applyOn(newGeom); assertNotNull(merged); Geometry expected = new WKTReader().read( "MULTILINESTRING ((40 40, 45 30, 40 40), (20 35, 45 10, 31 6, 10 30, 20 35))"); assertEquals(expected, merged); }
@Test public void testConflictRemovingPoints() throws Exception { Geometry oldGeom = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); Geometry newGeom = new WKTReader() .read("MULTILINESTRING ((40 40, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))"); GeometryAttributeDiff diff = new GeometryAttributeDiff(oldGeom, newGeom); Geometry newGeom2 = new WKTReader().read( "MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 31 6, 10 30, 20 35))"); GeometryAttributeDiff diff2 = new GeometryAttributeDiff(oldGeom, newGeom2); // the diff reports a conflict assertTrue(diff.conflicts(diff2)); // yet it can be applied for patching assertTrue(diff2.canBeAppliedOn(newGeom)); Geometry merged = diff2.applyOn(newGeom); assertNotNull(merged); Geometry expected = new WKTReader().read( "MULTILINESTRING ((40 40, 45 30, 40 40), (20 35, 45 10, 31 6, 10 30, 20 35))"); assertEquals(expected, merged); }