use of org.locationtech.geogig.api.CommitBuilder in project GeoGig by boundlessgeo.
the class HashObjectTest method setUpInternal.
@Override
protected void setUpInternal() throws Exception {
featureType1 = RevFeatureTypeImpl.build(pointsType);
featureType2 = RevFeatureTypeImpl.build(linesType);
featureType1Duplicate = RevFeatureTypeImpl.build(pointsType);
pointFeature1 = RevFeatureBuilder.build(points1);
pointFeature2 = RevFeatureBuilder.build(points2);
pointFeature1Duplicate = RevFeatureBuilder.build(points1);
CommitBuilder b = new CommitBuilder();
b.setAuthor("groldan");
b.setAuthorEmail("groldan@boundlessgeo.com");
b.setCommitter("jdeolive");
b.setCommitterEmail("jdeolive@boundlessgeo.com");
b.setMessage("cool this works");
b.setCommitterTimestamp(1000);
b.setCommitterTimeZoneOffset(5);
ObjectId treeId = ObjectId.forString("fake tree content");
b.setTreeId(treeId);
ObjectId parentId1 = ObjectId.forString("fake parent content 1");
ObjectId parentId2 = ObjectId.forString("fake parent content 2");
List<ObjectId> parentIds = ImmutableList.of(parentId1, parentId2);
b.setParentIds(parentIds);
commit1 = b.build();
commit1Duplicate = b.build();
b.setMessage(null);
b.setAuthor(null);
b.setAuthorEmail(null);
b.setCommitterTimestamp(-1000);
b.setCommitterTimeZoneOffset(-5);
b.setParentIds(ImmutableList.of(parentId1, ObjectId.NULL));
commit2 = b.build();
Object boolArray = new boolean[] { true, false, true, true, false };
Object byteArray = new byte[] { 100, 127, -110, 26, 42 };
Object charArray = new char[] { 'a', 'b', 'c', 'd', 'e' };
Object doubleArray = new double[] { 1.5, 1.6, 1.7, 1.8 };
Object floatArray = new float[] { 1.1f, 3.14f, 6.0f, 0.0f };
Object intArray = new int[] { 5, 7, 9, 11, 32 };
Object longArray = new long[] { 100, 200, 300, 400 };
TestSerializableObject serializableObject = new TestSerializableObject();
serializableObject.words = "words to serialize";
SimpleFeatureType coverageFeatureType = DataUtilities.createType("http://geoserver.org/test", "TestType", "str:String," + "str2:String," + "bool:Boolean," + "byte:java.lang.Byte," + "doub:Double," + "bdec:java.math.BigDecimal," + "flt:Float," + "int:Integer," + "bint:java.math.BigInteger," + "boolArray:java.lang.Object," + "byteArray:java.lang.Object," + "charArray:java.lang.Object," + "doubleArray:java.lang.Object," + "floatArray:java.lang.Object," + "intArray:java.lang.Object," + "longArray:java.lang.Object," + "serialized:java.io.Serializable," + "randomClass:java.lang.Object," + "pp:Point:srid=4326," + "lng:java.lang.Long," + "uuid:java.util.UUID");
coverageRevFeatureType = RevFeatureTypeImpl.build(coverageFeatureType);
Feature coverageFeature = feature(coverageFeatureType, "TestType.Coverage.1", "StringProp1_1", null, Boolean.TRUE, Byte.valueOf("18"), new Double(100.01), new BigDecimal("1.89e1021"), new Float(12.5), new Integer(1000), new BigInteger("90000000"), boolArray, byteArray, charArray, doubleArray, floatArray, intArray, longArray, serializableObject, new SomeRandomClass(), "POINT(1 1)", new Long(800000), UUID.fromString("bd882d24-0fe9-11e1-a736-03b3c0d0d06d"));
coverageRevFeature = RevFeatureBuilder.build(coverageFeature);
hashCommand = new HashObject();
Context mockCommandLocator = mock(Context.class);
hashCommand.setContext(mockCommandLocator);
when(mockCommandLocator.command(eq(DescribeFeatureType.class))).thenReturn(new DescribeFeatureType());
}
use of org.locationtech.geogig.api.CommitBuilder in project GeoGig by boundlessgeo.
the class IndexTest method testWriteTree2.
@Test
public void testWriteTree2() throws Exception {
// insert and commit feature1_1
final ObjectId oId1_1 = insertAndAdd(points1);
final ObjectId newRepoTreeId1;
{
newRepoTreeId1 = geogig.command(WriteTree2.class).setOldRoot(tree(repo.getHead().get().getObjectId())).call();
// assertEquals(index.getDatabase().getStagedRootRef().getObjectId(), newRepoTreeId1);
RevTree newRepoTree = repo.getTree(newRepoTreeId1);
System.err.println("++++++++++ new repo tree 1: " + newRepoTreeId1 + " ++++++++++++");
// check feature1_1 is there
assertEquals(oId1_1, repo.getTreeChild(newRepoTree, appendChild(pointsName, idP1)).get().getObjectId());
}
// insert and add (stage) points2, points3, and lines1
final ObjectId oId1_2 = insertAndAdd(points2);
final ObjectId oId1_3 = insertAndAdd(points3);
final ObjectId oId2_1 = insertAndAdd(lines1);
{
// simulate a commit so the repo head points to this new tree
ObjectInserter objectInserter = repo.newObjectInserter();
List<ObjectId> parents = ImmutableList.of();
RevCommit commit = new CommitBuilder().setTreeId(newRepoTreeId1).setParentIds(parents).build();
ObjectId commitId = commit.getId();
objectInserter.insert(commit);
Optional<Ref> newHead = geogig.command(UpdateRef.class).setName("refs/heads/master").setNewValue(commitId).call();
assertTrue(newHead.isPresent());
}
final ObjectId newRepoTreeId2;
{
// write comparing the the previously generated tree instead of the repository HEAD, as
// it was not updated (no commit op was performed)
newRepoTreeId2 = geogig.command(WriteTree2.class).setOldRoot(tree(newRepoTreeId1)).call();
// assertEquals(index.getDatabase().getStagedRootRef().getObjectId(), newRepoTreeId2);
System.err.println("++++++++ new root 2:" + newRepoTreeId2 + " ++++++++++");
RevTree newRepoTree = repo.getTree(newRepoTreeId2);
// check feature1_2, feature1_2 and feature2_1
Optional<Node> treeChild;
assertNotNull(treeChild = repo.getTreeChild(newRepoTree, appendChild(pointsName, idP2)));
assertEquals(oId1_2, treeChild.get().getObjectId());
assertNotNull(treeChild = repo.getTreeChild(newRepoTree, appendChild(pointsName, idP3)));
assertEquals(oId1_3, treeChild.get().getObjectId());
assertNotNull(treeChild = repo.getTreeChild(newRepoTree, appendChild(linesName, idL1)));
assertEquals(oId2_1, treeChild.get().getObjectId());
// as well as feature1_1 from the previous commit
assertNotNull(treeChild = repo.getTreeChild(newRepoTree, appendChild(pointsName, idP1)));
assertEquals(oId1_1, treeChild.get().getObjectId());
}
{
// simulate a commit so the repo head points to this new tree
ObjectInserter objectInserter = repo.newObjectInserter();
List<ObjectId> parents = ImmutableList.of();
RevCommit commit = new CommitBuilder().setTreeId(newRepoTreeId2).setParentIds(parents).build();
ObjectId commitId = commit.getId();
objectInserter.insert(commit);
Optional<Ref> newHead = geogig.command(UpdateRef.class).setName("refs/heads/master").setNewValue(commitId).call();
assertTrue(newHead.isPresent());
}
// delete feature1_1, feature1_3, and feature2_1
assertTrue(deleteAndAdd(points1));
assertTrue(deleteAndAdd(points3));
assertTrue(deleteAndAdd(lines1));
// and insert feature2_2
final ObjectId oId2_2 = insertAndAdd(lines2);
final ObjectId newRepoTreeId3;
{
// write comparing the the previously generated tree instead of the repository HEAD, as
// it was not updated (no commit op was performed)
newRepoTreeId3 = geogig.command(WriteTree2.class).setOldRoot(tree(newRepoTreeId2)).call();
// assertEquals(index.getDatabase().getStagedRootRef().getObjectId(), newRepoTreeId3);
System.err.println("++++++++ new root 3:" + newRepoTreeId3 + " ++++++++++");
RevTree newRepoTree = repo.getTree(newRepoTreeId3);
// and check only feature1_2 and feature2_2 remain
assertFalse(repo.getTreeChild(newRepoTree, appendChild(pointsName, idP1)).isPresent());
assertFalse(repo.getTreeChild(newRepoTree, appendChild(pointsName, idP3)).isPresent());
assertFalse(repo.getTreeChild(newRepoTree, appendChild(linesName, idL3)).isPresent());
assertEquals(oId1_2, repo.getTreeChild(newRepoTree, appendChild(pointsName, idP2)).get().getObjectId());
assertEquals(oId2_2, repo.getTreeChild(newRepoTree, appendChild(linesName, idL2)).get().getObjectId());
}
}
Aggregations