Search in sources :

Example 96 with ObjectId

use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.

the class CommitOpTest method testCommitWithCustomAuthorAndCommitter.

@Test
public void testCommitWithCustomAuthorAndCommitter() throws Exception {
    try {
        geogig.command(AddOp.class).addPattern(".").call();
        geogig.command(CommitOp.class).call();
        fail("expected NothingToCommitException");
    } catch (NothingToCommitException e) {
        assertTrue(true);
    }
    ObjectId oid1 = insertAndAdd(points1);
    ObjectId oid2 = insertAndAdd(points2);
    geogig.command(AddOp.class).addPattern(".").call();
    CommitOp commitCommand = geogig.command(CommitOp.class);
    commitCommand.setAuthor("John Doe", "John@Doe.com");
    commitCommand.setCommitter("Jane Doe", "Jane@Doe.com");
    RevCommit commit = commitCommand.call();
    assertNotNull(commit);
    assertNotNull(commit.getParentIds());
    assertEquals(0, commit.getParentIds().size());
    assertFalse(commit.parentN(0).isPresent());
    assertNotNull(commit.getId());
    assertEquals("John Doe", commit.getAuthor().getName().get());
    assertEquals("John@Doe.com", commit.getAuthor().getEmail().get());
    assertEquals("Jane Doe", commit.getCommitter().getName().get());
    assertEquals("Jane@Doe.com", commit.getCommitter().getEmail().get());
    ObjectId treeId = commit.getTreeId();
    assertNotNull(treeId);
    RevTree root = repo.getTree(treeId);
    assertNotNull(root);
    Optional<Node> typeTreeId = repo.getTreeChild(root, pointsName);
    assertTrue(typeTreeId.isPresent());
    RevTree typeTree = repo.getTree(typeTreeId.get().getObjectId());
    assertNotNull(typeTree);
    String featureId = points1.getIdentifier().getID();
    Optional<Node> featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
    assertTrue(featureBlobId.isPresent());
    assertEquals(oid1, featureBlobId.get().getObjectId());
    featureId = points2.getIdentifier().getID();
    featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
    assertTrue(featureBlobId.isPresent());
    assertEquals(oid2, featureBlobId.get().getObjectId());
    ObjectId commitId = geogig.command(RevParse.class).setRefSpec(Ref.HEAD).call().get();
    assertEquals(commit.getId(), commitId);
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) RevParse(org.locationtech.geogig.api.plumbing.RevParse) NothingToCommitException(org.locationtech.geogig.api.porcelain.NothingToCommitException) Node(org.locationtech.geogig.api.Node) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 97 with ObjectId

use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.

the class CommitOpTest method testPathFiltering.

@Test
public void testPathFiltering() throws Exception {
    insertAndAdd(points1);
    insertAndAdd(points2);
    RevCommit commit = geogig.command(CommitOp.class).call();
    insertAndAdd(points3);
    insertAndAdd(lines1);
    insertAndAdd(lines2);
    insertAndAdd(lines3);
    List<String> filters = Arrays.asList("Points/Points.3", "Lines/Lines.1", "Lines/Lines.3");
    commit = geogig.command(CommitOp.class).setPathFilters(filters).call();
    assertNotNull(commit);
    assertNotNull(commit.getParentIds());
    assertEquals(1, commit.getParentIds().size());
    assertNotNull(commit.getId());
    ObjectId treeId = commit.getTreeId();
    assertNotNull(treeId);
    RevTree root = repo.getTree(treeId);
    assertNotNull(root);
    Optional<Node> typeTreeId = repo.getTreeChild(root, pointsName);
    assertTrue(typeTreeId.isPresent());
    RevTree typeTree = repo.getTree(typeTreeId.get().getObjectId());
    assertNotNull(typeTree);
    String featureId = points1.getIdentifier().getID();
    Optional<Node> featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
    assertTrue(featureBlobId.isPresent());
    featureId = points2.getIdentifier().getID();
    featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
    assertTrue(featureBlobId.isPresent());
    featureId = points3.getIdentifier().getID();
    featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
    assertTrue(featureBlobId.isPresent());
    typeTreeId = repo.getTreeChild(root, linesName);
    assertTrue(typeTreeId.isPresent());
    typeTree = repo.getTree(typeTreeId.get().getObjectId());
    assertNotNull(typeTree);
    featureId = lines1.getIdentifier().getID();
    featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(linesName, featureId));
    assertTrue(featureBlobId.isPresent());
    featureId = lines2.getIdentifier().getID();
    featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(linesName, featureId));
    assertFalse(featureBlobId.isPresent());
    featureId = lines3.getIdentifier().getID();
    featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(linesName, featureId));
    assertTrue(featureBlobId.isPresent());
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 98 with ObjectId

use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.

the class CommitOpTest method testPathFilteringWithUnstaged.

@Test
public void testPathFilteringWithUnstaged() throws Exception {
    insertAndAdd(points1);
    insertAndAdd(points2);
    RevCommit commit = geogig.command(CommitOp.class).call();
    insertAndAdd(lines1);
    insertAndAdd(lines3);
    insert(lines2);
    insert(points3);
    List<String> filters = Arrays.asList(pointsName, linesName);
    commit = geogig.command(CommitOp.class).setPathFilters(filters).call();
    assertNotNull(commit);
    assertNotNull(commit.getParentIds());
    assertEquals(1, commit.getParentIds().size());
    assertNotNull(commit.getId());
    ObjectId treeId = commit.getTreeId();
    assertNotNull(treeId);
    RevTree root = repo.getTree(treeId);
    assertNotNull(root);
    Optional<Node> typeTreeId = repo.getTreeChild(root, pointsName);
    assertTrue(typeTreeId.isPresent());
    RevTree typeTree = repo.getTree(typeTreeId.get().getObjectId());
    assertNotNull(typeTree);
    String featureId = points1.getIdentifier().getID();
    Optional<Node> featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
    assertTrue(featureBlobId.isPresent());
    featureId = points2.getIdentifier().getID();
    featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
    assertTrue(featureBlobId.isPresent());
    featureId = points3.getIdentifier().getID();
    featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
    assertFalse(featureBlobId.isPresent());
    typeTreeId = repo.getTreeChild(root, linesName);
    assertTrue(typeTreeId.isPresent());
    typeTree = repo.getTree(typeTreeId.get().getObjectId());
    assertNotNull(typeTree);
    featureId = lines1.getIdentifier().getID();
    featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(linesName, featureId));
    assertTrue(featureBlobId.isPresent());
    featureId = lines2.getIdentifier().getID();
    featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(linesName, featureId));
    assertFalse(featureBlobId.isPresent());
    featureId = lines3.getIdentifier().getID();
    featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(linesName, featureId));
    assertTrue(featureBlobId.isPresent());
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 99 with ObjectId

use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.

the class DiffOpTest method testTreeDeletes.

@SuppressWarnings("unused")
@Test
public void testTreeDeletes() throws Exception {
    // two commits on different trees
    final ObjectId oid11 = insertAndAdd(points1);
    final ObjectId oid12 = insertAndAdd(points2);
    final ObjectId oid13 = insertAndAdd(points3);
    final RevCommit commit1 = geogig.command(CommitOp.class).setAll(true).call();
    final ObjectId oid21 = insertAndAdd(lines1);
    final ObjectId oid22 = insertAndAdd(lines2);
    final RevCommit commit2 = geogig.command(CommitOp.class).setAll(true).call();
    deleteAndAdd(points1);
    deleteAndAdd(points2);
    deleteAndAdd(points3);
    final RevCommit commit3 = geogig.command(CommitOp.class).setAll(true).call();
    List<DiffEntry> diffs;
    // filter on namespace1, no changes between commit1 and commit2
    diffOp.setOldVersion(commit1.getId());
    diffOp.setNewVersion(Ref.HEAD);
    diffOp.setFilter(pointsName);
    diffs = toList(diffOp.call());
    assertEquals(3, diffs.size());
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) RevCommit(org.locationtech.geogig.api.RevCommit) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Example 100 with ObjectId

use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.

the class CloneOpTest method testCloneWithTags.

@Test
public void testCloneWithTags() throws Exception {
    // Commit several features to the remote
    List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3);
    LinkedList<RevCommit> expected = new LinkedList<RevCommit>();
    List<RevTag> tags = Lists.newArrayList();
    for (Feature f : features) {
        ObjectId oId = insertAndAdd(remoteGeogig.geogig, f);
        final RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).call();
        expected.addFirst(commit);
        Optional<RevObject> childObject = remoteGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
        assertTrue(childObject.isPresent());
        RevTag tag = remoteGeogig.geogig.command(TagCreateOp.class).setCommitId(commit.getId()).setName(f.getIdentifier().getID()).call();
        tags.add(tag);
    }
    // Make sure the remote has all of the commits
    Iterator<RevCommit> logs = remoteGeogig.geogig.command(LogOp.class).call();
    List<RevCommit> logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(expected, logged);
    // Make sure the remote has all of the tags
    ImmutableList<RevTag> remoteTags = remoteGeogig.geogig.command(TagListOp.class).call();
    assertEquals(tags.size(), remoteTags.size());
    for (RevTag tag : tags) {
        assertTrue(remoteTags.contains(tag));
    }
    // Make sure the local repository has no commits prior to clone
    logs = localGeogig.geogig.command(LogOp.class).call();
    assertNotNull(logs);
    assertFalse(logs.hasNext());
    // clone from the remote
    CloneOp clone = clone();
    clone.setDepth(0);
    clone.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).call();
    // Make sure the local repository got all of the commits
    logs = localGeogig.geogig.command(LogOp.class).call();
    logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(expected, logged);
/*
         * This is commented out, since the clone operation does not clone tags yet This test
         * verifies that no errors are raised when the repo to clone contains tags, but not to
         * verify that tags are also cloned, since that is not supported
         * 
         * I leave this dommented code here, to uncomment it once tag support is implemented for the
         * clone operation
         * 
         * 
         * // Make sure the local repository got all of the tags
         * 
         * ImmutableList<RevTag> localTags = localGeogig.geogig.command(TagListOp.class).call();
         * 
         * assertEquals(tags.size(), localTags.size());
         * 
         * for (RevTag tag : tags) {
         * 
         * assertTrue(localTags.contains(tag));
         * 
         * }
         */
}
Also used : CloneOp(org.locationtech.geogig.api.porcelain.CloneOp) RevTag(org.locationtech.geogig.api.RevTag) ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) LogOp(org.locationtech.geogig.api.porcelain.LogOp) ArrayList(java.util.ArrayList) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) Feature(org.opengis.feature.Feature) LinkedList(java.util.LinkedList) TagListOp(org.locationtech.geogig.api.porcelain.TagListOp) TagCreateOp(org.locationtech.geogig.api.porcelain.TagCreateOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Aggregations

ObjectId (org.locationtech.geogig.api.ObjectId)361 Test (org.junit.Test)133 RevCommit (org.locationtech.geogig.api.RevCommit)109 NodeRef (org.locationtech.geogig.api.NodeRef)98 RevTree (org.locationtech.geogig.api.RevTree)91 RevObject (org.locationtech.geogig.api.RevObject)53 Ref (org.locationtech.geogig.api.Ref)46 Node (org.locationtech.geogig.api.Node)44 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)38 Feature (org.opengis.feature.Feature)35 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)34 LogOp (org.locationtech.geogig.api.porcelain.LogOp)28 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)27 LinkedList (java.util.LinkedList)26 ArrayList (java.util.ArrayList)25 RevFeature (org.locationtech.geogig.api.RevFeature)25 IOException (java.io.IOException)23 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)23 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)23 SymRef (org.locationtech.geogig.api.SymRef)22