use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.
the class MergeOpTest method testMergeConflictingBranches.
@Test
public void testMergeConflictingBranches() throws Exception {
// Create the following revision graph
// o
// |
// o - Points 1,2 added
// |\
// | o - TestBranch - Points 1 modified, 2 removed, 3 added
// |
// o - master - HEAD - Points 1 modifiedB, 2 removed
insertAndAdd(points1, points2);
geogig.command(CommitOp.class).call();
geogig.command(BranchCreateOp.class).setName("TestBranch").call();
Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
insert(points1Modified);
delete(points2);
insert(points3);
geogig.command(AddOp.class).call();
RevCommit masterCommit = geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("TestBranch").call();
Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)");
insert(points1ModifiedB);
delete(points2);
geogig.command(AddOp.class).call();
RevCommit branchCommit = geogig.command(CommitOp.class).call();
// Now try to merge branch into master
geogig.command(CheckoutOp.class).setSource("master").call();
Ref branch = geogig.command(RefParse.class).setName("TestBranch").call().get();
try {
geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch.getObjectId())).call();
fail();
} catch (MergeConflictsException e) {
assertTrue(e.getMessage().contains("conflict"));
}
Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call();
assertTrue(ref.isPresent());
assertEquals(masterCommit.getId(), ref.get().getObjectId());
ref = geogig.command(RefParse.class).setName(Ref.MERGE_HEAD).call();
assertTrue(ref.isPresent());
assertEquals(branch.getObjectId(), ref.get().getObjectId());
String msg = geogig.command(ReadMergeCommitMessageOp.class).call();
assertFalse(Strings.isNullOrEmpty(msg));
List<Conflict> conflicts = geogig.command(ConflictsReadOp.class).call();
assertEquals(1, conflicts.size());
String path = NodeRef.appendChild(pointsName, idP1);
assertEquals(conflicts.get(0).getPath(), path);
assertEquals(conflicts.get(0).getOurs(), RevFeatureBuilder.build(points1Modified).getId());
assertEquals(conflicts.get(0).getTheirs(), RevFeatureBuilder.build(points1ModifiedB).getId());
// try to commit
try {
geogig.command(CommitOp.class).call();
fail();
} catch (IllegalStateException e) {
assertEquals(e.getMessage(), "Cannot run operation while merge conflicts exist.");
}
// solve, and commit
Feature points1Merged = feature(pointsType, idP1, "StringProp1_2", new Integer(2000), "POINT(1 1)");
insert(points1Merged);
geogig.command(AddOp.class).call();
RevCommit commit = geogig.command(CommitOp.class).call();
assertTrue(commit.getMessage().contains(idP1));
List<ObjectId> parents = commit.getParentIds();
assertEquals(2, parents.size());
assertEquals(masterCommit.getId(), parents.get(0));
assertEquals(branchCommit.getId(), parents.get(1));
Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
assertTrue(revFeature.isPresent());
assertEquals(RevFeatureBuilder.build(points1Merged), revFeature.get());
path = NodeRef.appendChild(pointsName, idP2);
revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
assertFalse(revFeature.isPresent());
path = NodeRef.appendChild(pointsName, idP3);
revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
assertTrue(revFeature.isPresent());
ref = geogig.command(RefParse.class).setName(Ref.MERGE_HEAD).call();
assertFalse(ref.isPresent());
}
use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.
the class MergeOpTest method testOursAndTheirs.
@Test
public void testOursAndTheirs() throws Exception {
insertAndAdd(points1);
geogig.command(CommitOp.class).call();
geogig.command(BranchCreateOp.class).setName("TestBranch").call();
Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
insertAndAdd(points1Modified);
geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("TestBranch").call();
Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)");
insertAndAdd(points1ModifiedB);
geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("master").call();
Ref branch = geogig.command(RefParse.class).setName("TestBranch").call().get();
try {
geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch.getObjectId())).setTheirs(true).setOurs(true).call();
fail();
} catch (IllegalArgumentException e) {
assertTrue(true);
}
}
use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.
the class MergeOpTest method testMergeWithPolygonAutoMerge.
@Test
public void testMergeWithPolygonAutoMerge() throws Exception {
String polyId = "polyId";
String polygonTypeSpec = "poly:Polygon:srid=4326";
SimpleFeatureType polygonType = DataUtilities.createType("http://geogig.polygon", "polygons", polygonTypeSpec);
Feature polygonOriginal = feature(polygonType, polyId, "POLYGON((0 0,1 0,2 0,3 0,4 0,5 0,5 1,4 1,3 1,2 1,1 1,1 0,0 0))");
insertAndAdd(polygonOriginal);
geogig.command(CommitOp.class).call();
geogig.command(BranchCreateOp.class).setName("TestBranch").call();
Feature polygonMaster = feature(polygonType, polyId, "POLYGON((0 0,1 0,2 0.2,3 0.2,4 0,5 0,5 1,4 1,3 1,2 1,1 1,1 0,0 0))");
insertAndAdd(polygonMaster);
geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("TestBranch").call();
Feature polygonBranch = feature(polygonType, polyId, "POLYGON((0 0,1 0,2 0,3 0,4 0,5 0,5 1,4 1,3 0.8,2 0.8,1 1,1 0,0 0))");
insertAndAdd(polygonBranch);
geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("master").call();
Ref branch = geogig.command(RefParse.class).setName("TestBranch").call().get();
geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch.getObjectId())).call();
Optional<RevFeature> feature = repo.command(RevObjectParse.class).setRefSpec("WORK_HEAD:polygons/polyId").call(RevFeature.class);
assertTrue(feature.isPresent());
RevFeature merged = feature.get();
Feature expected = feature(polygonType, polyId, "POLYGON((0 0,1 0,2 0.2,3 0.2,4 0,5 0,5 1,4 1,3 0.8,2 0.8,1 1,1 0,0 0))");
assertEquals(expected.getProperty("poly").getValue(), merged.getValues().get(0).get());
}
use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.
the class MergeOpTest method testOctopusMergeWithAutomerge.
@Test
public void testOctopusMergeWithAutomerge() throws Exception {
insertAndAdd(points1);
geogig.command(CommitOp.class).call();
geogig.command(BranchCreateOp.class).setName("branch1").call();
geogig.command(BranchCreateOp.class).setName("branch2").call();
geogig.command(BranchCreateOp.class).setName("branch3").call();
geogig.command(BranchCreateOp.class).setName("branch4").call();
geogig.command(BranchCreateOp.class).setName("branch5").call();
geogig.command(BranchCreateOp.class).setName("branch6").call();
Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
insertAndAdd(points1Modified);
geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("branch1").call();
insertAndAdd(points2);
RevCommit branch1 = geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("branch2").call();
insertAndAdd(points3);
RevCommit branch2 = geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("branch3").call();
insertAndAdd(lines1);
RevCommit branch3 = geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("branch4").call();
insertAndAdd(lines2);
RevCommit branch4 = geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("branch5").call();
insertAndAdd(lines3);
RevCommit branch5 = geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("branch6").call();
Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)");
insertAndAdd(points1ModifiedB);
RevCommit branch6 = geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("master").call();
MergeOp mergeOp = geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch1.getId())).addCommit(Suppliers.ofInstance(branch2.getId())).addCommit(Suppliers.ofInstance(branch3.getId())).addCommit(Suppliers.ofInstance(branch4.getId())).addCommit(Suppliers.ofInstance(branch5.getId())).addCommit(Suppliers.ofInstance(branch6.getId()));
try {
mergeOp.call();
fail();
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains("Cannot merge more than two commits when conflicts exist"));
}
}
use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.
the class GeogigAPITest method testGetFeatureFromHead.
@Test
public void testGetFeatureFromHead() throws Exception {
insertAndAdd(points1);
geogig.command(CommitOp.class).setMessage("Commit message").call();
Feature feature = geogigAPI.getFeatureFromHead(NodeRef.appendChild(pointsName, idP1));
assertNotNull(feature);
}
Aggregations