text:
package org.locationtech.geogig.test.integration;

import static org.locationtech.geogig.api.NodeRef.appendChild;

import java.util.Iterator;
import java.util.List;

import org.geotools.data.DataUtilities;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.locationtech.geogig.api.NodeRef;
import org.locationtech.geogig.api.ObjectId;
import org.locationtech.geogig.api.Ref;
import org.locationtech.geogig.api.RevCommit;
import org.locationtech.geogig.api.RevFeature;
import org.locationtech.geogig.api.RevFeatureBuilder;
import org.locationtech.geogig.api.RevTree;
import org.locationtech.geogig.api.plumbing.FindTreeChild;
import org.locationtech.geogig.api.plumbing.RefParse;
import org.locationtech.geogig.api.plumbing.RevObjectParse;
import org.locationtech.geogig.api.plumbing.UpdateRef;
import org.locationtech.geogig.api.plumbing.UpdateSymRef;
import org.locationtech.geogig.api.plumbing.merge.Conflict;
import org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp;
import org.locationtech.geogig.api.plumbing.merge.ReadMergeCommitMessageOp;
import org.locationtech.geogig.api.porcelain.AddOp;
import org.locationtech.geogig.api.porcelain.BranchCreateOp;
import org.locationtech.geogig.api.porcelain.CheckoutOp;
import org.locationtech.geogig.api.porcelain.CommitOp;
import org.locationtech.geogig.api.porcelain.ConfigOp;
import org.locationtech.geogig.api.porcelain.ConfigOp.ConfigAction;
import org.locationtech.geogig.api.porcelain.LogOp;
import org.locationtech.geogig.api.porcelain.MergeConflictsException;
import org.locationtech.geogig.api.porcelain.MergeOp;
import org.locationtech.geogig.api.porcelain.MergeOp.MergeReport;
import org.locationtech.geogig.api.porcelain.NothingToCommitException;
import org.locationtech.geogig.api.porcelain.PullOp;
import org.opengis.feature.Feature;
import org.opengis.feature.simple.SimpleFeatureType;

import com.google.common.base.Optional;
import com.google.common.base.Strings;
import com.google.common.base.Suppliers;

public class MergeOpTest extends RepositoryTestCase {
    @Rule
    public ExpectedException exception = ExpectedException.none();

    @Override
    protected void setUpInternal() throws Exception {
        // These values should be used during a commit to set author/committer
        // TODO: author/committer roles need to be defined better, but for
        // now they are the same thing.
        repo.command(ConfigOp.class).setAction(ConfigAction.CONFIG_SET).setName("user.name")
                .setValue("groldan").call();
        repo.command(ConfigOp.class).setAction(ConfigAction.CONFIG_SET).setName("user.email")
                .setValue("groldan@boundlessgeo.com").call();
    }

    @Test
    public void testMerge() throws Exception {
        // Create the following revision graph
        // o
        // |
        // o - Points 1 added
        // |\
        // | o - branch1 - Points 2 added
        // |
        // o - Points 3 added
        // |
        // o - master - HEAD - Lines 1 added
        insertAndAdd(points1);
        final RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();

        // create branch1 and checkout
        geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
        insertAndAdd(points2);
        final RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();

        // checkout master
        geogig.command(CheckoutOp.class).setSource("master").call();
        insertAndAdd(points3);
        final RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
        insertAndAdd(lines1);
        final RevCommit c4 = geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();

        // Merge branch1 into master to create the following revision graph
        // o
        // |
        // o - Points 1 added
        // |\
        // | o - branch1 - Points 2 added
        // | |
        // o | - Points 3 added
        // | |
        // o | - Lines 1 added
        // |/
        // o - master - HEAD - Merge commit

        Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
        MergeReport mergeReport = geogig.command(MergeOp.class)
                .addCommit(Suppliers.ofInstance(branch1.getObjectId()))
                .setMessage("My merge message.").call();

        RevTree mergedTree = repo.getTree(mergeReport.getMergeCommit().getTreeId());

        String path = appendChild(pointsName, points2.getIdentifier().getID());
        assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path)
                .call().isPresent());

        path = appendChild(pointsName, points1.getIdentifier().getID());
        assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path)
                .call().isPresent());

        path = appendChild(pointsName, points3.getIdentifier().getID());
        assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path)
                .call().isPresent());

        path = appendChild(linesName, lines1.getIdentifier().getID());
        assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path)
                .call().isPresent());

        Iterator<RevCommit> log = geogig.command(LogOp.class).call();

        // Merge Commit
        RevCommit logCmerge = log.next();
        assertEquals("My merge message.", logCmerge.getMessage());
        assertEquals(2, logCmerge.getParentIds().size());
        assertEquals(c4.getId(), logCmerge.getParentIds().get(0));
        assertEquals(c2.getId(), logCmerge.getParentIds().get(1));

        // Commit 4
        RevCommit logC4 = log.next();
        assertEquals(c4.getAuthor(), logC4.getAuthor());
        assertEquals(c4.getCommitter(), logC4.getCommitter());
        assertEquals(c4.getMessage(), logC4.getMessage());
        assertEquals(c4.getTreeId(), logC4.getTreeId());

        // Commit 3
        RevCommit logC3 = log.next();
        assertEquals(c3.getAuthor(), logC3.getAuthor());
        assertEquals(c3.getCommitter(), logC3.getCommitter());
        assertEquals(c3.getMessage(), logC3.getMessage());
        assertEquals(c3.getTreeId(), logC3.getTreeId());

        // Commit 2
        RevCommit logC2 = log.next();
        assertEquals(c2.getAuthor(), logC2.getAuthor());
        assertEquals(c2.getCommitter(), logC2.getCommitter());
        assertEquals(c2.getMessage(), logC2.getMessage());
        assertEquals(c2.getTreeId(), logC2.getTreeId());

        // Commit 1
        RevCommit logC1 = log.next();
        assertEquals(c1.getAuthor(), logC1.getAuthor());
        assertEquals(c1.getCommitter(), logC1.getCommitter());
        assertEquals(c1.getMessage(), logC1.getMessage());
        assertEquals(c1.getTreeId(), logC1.getTreeId());

    }

    @Test
    public void testSpecifyAuthor() throws Exception {
        // Create the following revision graph
        // o
        // |
        // o - Points 1 added
        // |\
        // | o - branch1 - Points 2 added
        // |
        // o - Points 3 added
        // |
        // o - master - HEAD - Lines 1 added
        insertAndAdd(points1);
        geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();

        // create branch1 and checkout
        geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
        insertAndAdd(points2);
        final RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();

        // checkout master
        geogig.command(CheckoutOp.class).setSource("master").call();
        insertAndAdd(points3);
        geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
        insertAndAdd(lines1);
        final RevCommit c4 = geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();

        // Merge branch1 into master to create the following revision graph
        // o
        // |
        // o - Points 1 added
        // |\
        // | o - branch1 - Points 2 added
        // | |
        // o | - Points 3 added
        // | |
        // o | - Lines 1 added
        // |/
        // o - master - HEAD - Merge commit

        Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
        geogig.command(MergeOp.class).setAuthor("Merge Author", "merge@author.com")
                .addCommit(Suppliers.ofInstance(branch1.getObjectId()))
                .setMessage("My merge message.").call();

        Iterator<RevCommit> log = geogig.command(LogOp.class).call();

        // Merge Commit
        RevCommit logCmerge = log.next();
        assertEquals("My merge message.", logCmerge.getMessage());
        assertEquals("Merge Author", logCmerge.getAuthor().getName().get());
        assertEquals("merge@author.com", logCmerge.getAuthor().getEmail().get());
        assertEquals(2, logCmerge.getParentIds().size());
        assertEquals(c4.getId(), logCmerge.getParentIds().get(0));
        assertEquals(c2.getId(), logCmerge.getParentIds().get(1));
    }

    @Test
    public void testMergeMultiple() throws Exception {
        // Create the following revision graph
        // . o
        // . |
        // . o - Points 1 added
        // . |\
        // . | o - branch1 - Points 2 added
        // . |
        // . o - Points 3 added
        // ./|
        // o | - branch 2 - Lines 1 added
        // . |
        // . o - master - HEAD - Lines 2 added
        insertAndAdd(points1);
        final RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();

        // create branch1 and checkout
        geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
        insertAndAdd(points2);
        final RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();

        // checkout master, then create branch2 and checkout
        geogig.command(CheckoutOp.class).setSource("master").call();
        insertAndAdd(points3);
        final RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
        geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch2").call();
        insertAndAdd(lines1);
        final RevCommit c4 = geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();

        geogig.command(CheckoutOp.class).setSource("master").call();
        insertAndAdd(lines2);
        final RevCommit c5 = geogig.command(CommitOp.class).setMessage("commit for " + idL2).call();

        // Merge branch1 and branch2 into master to create the following revision graph
        // . o
        // . |
        // . o - Points 1 added
        // . |\
        // . | o - branch1 - Points 2 added
        // . | |
        // . o | - Points 3 added
        // ./| |
        // o | | - branch 2 - Lines 1 added
        // | | |
        // | o | - Lines 2 added
        // .\|/
        // . o - master - HEAD - Merge commit

        Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
        Ref branch2 = geogig.command(RefParse.class).setName("branch2").call().get();
        final MergeReport mergeReport = geogig.command(MergeOp.class)
                .addCommit(Suppliers.ofInstance(branch1.getObjectId()))
                .addCommit(Suppliers.ofInstance(branch2.getObjectId()))
                .setMessage("My merge message.").call();

        RevTree mergedTree = repo.getTree(mergeReport.getMergeCommit().getTreeId());

        String path = appendChild(pointsName, points1.getIdentifier().getID());
        assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path)
                .call().isPresent());

        path = appendChild(pointsName, points2.getIdentifier().getID());
        assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path)
                .call().isPresent());

        path = appendChild(pointsName, points3.getIdentifier().getID());
        assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path)
                .call().isPresent());

        path = appendChild(linesName, lines1.getIdentifier().getID());
        assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path)
                .call().isPresent());

        path = appendChild(linesName, lines2.getIdentifier().getID());
        assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path)
                .call().isPresent());

        Iterator<RevCommit> log = geogig.command(LogOp.class).setFirstParentOnly(true).call();

        // Commit 4
        RevCommit logC4 = log.next();
        assertEquals("My merge message.", logC4.getMessage());
        assertEquals(3, logC4.getParentIds().size());
        assertEquals(c5.getId(), logC4.getParentIds().get(0));
        assertEquals(c2.getId(), logC4.getParentIds().get(1));
        assertEquals(c4.getId(), logC4.getParentIds().get(2));

        // Commit 3
        RevCommit logC3 = log.next();
        assertEquals(c5.getAuthor(), logC3.getAuthor());
        assertEquals(c5.getCommitter(), logC3.getCommitter());
        assertEquals(c5.getMessage(), logC3.getMessage());
        assertEquals(c5.getTreeId(), logC3.getTreeId());

        // Commit 2
        RevCommit logC2 = log.next();
        assertEquals(c3.getAuthor(), logC2.getAuthor());
        assertEquals(c3.getCommitter(), logC2.getCommitter());
        assertEquals(c3.getMessage(), logC2.getMessage());
        assertEquals(c3.getTreeId(), logC2.getTreeId());

        // Commit 1
        RevCommit logC1 = log.next();
        assertEquals(c1.getAuthor(), logC1.getAuthor());
        assertEquals(c1.getCommitter(), logC1.getCommitter());
        assertEquals(c1.getMessage(), logC1.getMessage());
        assertEquals(c1.getTreeId(), logC1.getTreeId());

    }

    @Test
    public void testMergeNoCommitMessage() throws Exception {
        // Create the following revision graph
        // o
        // |
        // o - Points 1 added
        // |\
        // | o - branch1 - Points 2 added
        // |
        // o - Points 3 added
        // |
        // o - master - HEAD - Lines 1 added
        insertAndAdd(points1);
        final RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();

        // create branch1 and checkout
        geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
        insertAndAdd(points2);
        final RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();

        // checkout master
        geogig.command(CheckoutOp.class).setSource("master").call();
        insertAndAdd(points3);
        final RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
        insertAndAdd(lines1);
        final RevCommit c4 = geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();

        // Merge branch1 into master to create the following revision graph
        // o
        // |
        // o - Points 1 added
        // |\
        // | o - branch1 - Points 2 added
        // | |
        // o | - Points 3 added
        // | |
        // o | - Lines 1 added
        // |/
        // o - master - HEAD - Merge commit

        Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
        final MergeReport mergeReport = geogig.command(MergeOp.class)
                .addCommit(Suppliers.ofInstance(branch1.getObjectId())).call();

        RevTree mergedTree = repo.getTree(mergeReport.getMergeCommit().getTreeId());

        String path = appendChild(pointsName, points2.getIdentifier().getID());
        assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path)
                .call().isPresent());

        path = appendChild(pointsName, points1.getIdentifier().getID());
        assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path)
                .call().isPresent());

        path = appendChild(pointsName, points3.getIdentifier().getID());
        assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path)
                .call().isPresent());

        path = appendChild(linesName, lines1.getIdentifier().getID());
        assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path)
                .call().isPresent());

        Iterator<RevCommit> log = geogig.command(LogOp.class).setFirstParentOnly(true).call();

        // Commit 4
        RevCommit logC4 = log.next();
        assertTrue(logC4.getMessage().contains("refs/heads/branch1"));
        assertEquals(2, logC4.getParentIds().size());
        assertEquals(c4.getId(), logC4.getParentIds().get(0));
        assertEquals(c2.getId(), logC4.getParentIds().get(1));

        // Commit 3
        RevCommit logC3 = log.next();
        assertEquals(c4.getAuthor(), logC3.getAuthor());
        assertEquals(c4.getCommitter(), logC3.getCommitter());
        assertEquals(c4.getMessage(), logC3.getMessage());
        assertEquals(c4.getTreeId(), logC3.getTreeId());

        // Commit 2
        RevCommit logC2 = log.next();
        assertEquals(c3.getAuthor(), logC2.getAuthor());
        assertEquals(c3.getCommitter(), logC2.getCommitter());
        assertEquals(c3.getMessage(), logC2.getMessage());
        assertEquals(c3.getTreeId(), logC2.getTreeId());

        // Commit 1
        RevCommit logC1 = log.next();
        assertEquals(c1.getAuthor(), logC1.getAuthor());
        assertEquals(c1.getCommitter(), logC1.getCommitter());
        assertEquals(c1.getMessage(), logC1.getMessage());
        assertEquals(c1.getTreeId(), logC1.getTreeId());

    }

    @Test
    public void testMergeTwice() throws Exception {
        // Create the following revision graph
        // o
        // |
        // o - Points 1 added
        // |\
        // | o - branch1 - Points 2 added
        // |
        // o - master - HEAD - Points 3 added
        insertAndAdd(points1);
        geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();

        // create branch1 and checkout
        geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
        insertAndAdd(points2);
        geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();

        // checkout master
        geogig.command(CheckoutOp.class).setSource("master").call();
        insertAndAdd(points3);
        geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();

        // Merge branch1 into master to create the following revision graph
        // o
        // |
        // o - Points 1 added
        // |\
        // | o - branch1 - Points 2 added
        // | |
        // o | - Points 3 added
        // |/
        // o - master - HEAD - Merge commit

        Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
        geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch1.getObjectId())).call();

        exception.expect(NothingToCommitException.class);
        geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch1.getObjectId())).call();
    }

    @Test
    public void testMergeFastForward() throws Exception {
        // Create the following revision graph
        // o
        // |
        // o - master - HEAD - Points 1 added
        // .\
        // . o - branch1 - Points 2 added
        insertAndAdd(points1);
        final RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();

        // create branch1 and checkout
        geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
        insertAndAdd(points2);
        final RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();

        // checkout master
        geogig.command(CheckoutOp.class).setSource("master").call();

        // Merge branch1 into master to create the following revision graph
        // o
        // |
        // o - Points 1 added
        // |
        // o - master - HEAD - branch1 - Points 2 added

        Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
        final MergeReport mergeReport = geogig.command(MergeOp.class)
                .addCommit(Suppliers.ofInstance(branch1.getObjectId())).call();

        RevTree mergedTree = repo.getTree(mergeReport.getMergeCommit().getTreeId());

        String path = appendChild(pointsName, points1.getIdentifier().getID());
        assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path)
                .call().isPresent());

        path = appendChild(pointsName, points2.getIdentifier().getID());
        assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path)
                .call().isPresent());

        Iterator<RevCommit> log = geogig.command(LogOp.class).call();

        // Commit 2
        RevCommit logC2 = log.next();
        assertEquals(c2.getAuthor(), logC2.getAuthor());
        assertEquals(c2.getCommitter(), logC2.getCommitter());
        assertEquals(c2.getMessage(), logC2.getMessage());
        assertEquals(c2.getTreeId(), logC2.getTreeId());

        // Commit 1
        RevCommit logC1 = log.next();
        assertEquals(c1.getAuthor(), logC1.getAuthor());
        assertEquals(c1.getCommitter(), logC1.getCommitter());
        assertEquals(c1.getMessage(), logC1.getMessage());
        assertEquals(c1.getTreeId(), logC1.getTreeId());

    }

    @Test
    public void testMergeFastForwardSecondCase() throws Exception {
        // Create the following revision graph
        // o - master - HEAD
        // .\
        // . o - branch1 - Points 1 added

        // create branch1 and checkout
        geogig.command(UpdateRef.class).setName(Ref.HEADS_PREFIX + "branch1")
                .setNewValue(ObjectId.NULL).call();
        geogig.command(UpdateSymRef.class).setName(Ref.HEAD)
                .setNewValue(Ref.HEADS_PREFIX + "branch1").call();
        insertAndAdd(points1);
        final RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();

        // checkout master
        geogig.command(UpdateSymRef.class).setName(Ref.HEAD)
                .setNewValue(Ref.HEADS_PREFIX + "master").call();

        // Merge branch1 into master to create the following revision graph
        // o
        // |
        // o - master - HEAD - branch1 - Points 1 added

        Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
        final MergeReport mergeReport = geogig.command(MergeOp.class)
                .addCommit(Suppliers.ofInstance(branch1.getObjectId())).call();

        RevTree mergedTree = repo.getTree(mergeReport.getMergeCommit().getTreeId());

        String path = appendChild(pointsName, points1.getIdentifier().getID());
        assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path)
                .call().isPresent());

        Iterator<RevCommit> log = geogig.command(LogOp.class).call();

        // Commit 1
        RevCommit logC1 = log.next();
        assertEquals(c1.getAuthor(), logC1.getAuthor());
        assertEquals(c1.getCommitter(), logC1.getCommitter());
        assertEquals(c1.getMessage(), logC1.getMessage());
        assertEquals(c1.getTreeId(), logC1.getTreeId());

    }

    @Test
    public void testMergeNoCommits() throws Exception {
        exception.expect(IllegalArgumentException.class);
        geogig.command(MergeOp.class).call();
    }

    @Test
    public void testMergeNullCommit() throws Exception {
        exception.expect(IllegalArgumentException.class);
        geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(ObjectId.NULL)).call();
    }

    @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());

    }

    @Test
    public void testConflictingOctopusMerge() throws Exception {
        // Create the following revision graph
        // . o
        // . |
        // . o - Points 1 added
        // . |\
        // . | o - branch1 - Points 1 modified
        // . |
        // . o - Points 2 added
        // ./|
        // o | - branch2 - Point 1 modified B
        // . |
        // . o - master - HEAD - Point 1 modified C
        insertAndAdd(points1);
        geogig.command(CommitOp.class).call();
        geogig.command(BranchCreateOp.class).setName("branch1").call();
        insertAndAdd(points2);
        geogig.command(CommitOp.class).call();
        geogig.command(BranchCreateOp.class).setName("branch2").call();
        Feature points1ModifiedC = feature(pointsType, idP1, "StringProp1_4", new Integer(3000),
                "POINT(1 3)");
        insertAndAdd(points1ModifiedC);
        geogig.command(CommitOp.class).call();
        geogig.command(CheckoutOp.class).setSource("branch1").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("branch2").call();
        Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000),
                "POINT(1 2)");
        insertAndAdd(points1ModifiedB);
        geogig.command(CommitOp.class).call();

        // Now try to merge all branches into master
        geogig.command(CheckoutOp.class).setSource("master").call();
        Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
        Ref branch2 = geogig.command(RefParse.class).setName("branch2").call().get();
        MergeOp mergeOp = geogig.command(MergeOp.class);
        mergeOp.addCommit(Suppliers.ofInstance(branch1.getObjectId()));
        mergeOp.addCommit(Suppliers.ofInstance(branch2.getObjectId()));
        try {
            mergeOp.call();
            fail();
        } catch (IllegalStateException e) {
            assertTrue(e.getMessage().contains(
                    "Cannot merge more than two commits when conflicts exist"));
        }

    }

    @Test
    public void testMergeConflictingBranchesOurs() throws Exception {
        // Create the following revision graph
        // o
        // |
        // o - Points 1 added
        // |\
        // | o - TestBranch - Points 1 modified and points 2 added
        // |
        // o - master - HEAD - Points 1 modifiedB
        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);
        insertAndAdd(points2);
        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()))
                .setOurs(true).call();

        String path = NodeRef.appendChild(pointsName, idP1);
        Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class)
                .setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
        assertTrue(revFeature.isPresent());
        assertEquals(RevFeatureBuilder.build(points1Modified), revFeature.get());
        path = NodeRef.appendChild(pointsName, idP2);
        revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path)
                .call(RevFeature.class);
        assertTrue(revFeature.isPresent());
        assertEquals(RevFeatureBuilder.build(points2), revFeature.get());
    }

    @Test
    public void testMergeConflictingBranchesTheirs() throws Exception {
        // Create the following revision graph
        // o
        // |
        // o - Points 1 added
        // |\
        // | o - TestBranch - Points 1 modified
        // |
        // o - master - HEAD - Points 1 modifiedB
        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();
        geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch.getObjectId()))
                .setTheirs(true).call();

        String path = NodeRef.appendChild(pointsName, idP1);
        Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class)
                .setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
        assertTrue(revFeature.isPresent());
        assertEquals(RevFeatureBuilder.build(points1ModifiedB), revFeature.get());
    }

    @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);
        }
    }

    @Test
    public void testNoCommitMerge() throws Exception {
        // Create the following revision graph
        // o
        // |
        // o - Points 1 added
        // |\
        // | o - branch1 - Points 2 added
        // |
        // o - master - HEAD - Points 3 added
        insertAndAdd(points1);
        geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();

        // create branch1 and checkout
        geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
        insertAndAdd(points2);
        geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();

        // checkout master
        geogig.command(CheckoutOp.class).setSource("master").call();
        insertAndAdd(points3);
        RevCommit lastCommit = geogig.command(CommitOp.class).setMessage("commit for " + idP3)
                .call();
        Ref branch = geogig.command(RefParse.class).setName("branch1").call().get();

        geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch.getObjectId()))
                .setNoCommit(true).call();

        String path = NodeRef.appendChild(pointsName, idP2);
        Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class)
                .setRefSpec(Ref.STAGE_HEAD + ":" + path).call(RevFeature.class);
        assertTrue(revFeature.isPresent());
        assertEquals(RevFeatureBuilder.build(points2), revFeature.get());
        revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path)
                .call(RevFeature.class);
        assertFalse(revFeature.isPresent());
        revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.WORK_HEAD + ":" + path)
                .call(RevFeature.class);
        assertTrue(revFeature.isPresent());
        assertEquals(RevFeatureBuilder.build(points2), revFeature.get());

        Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call();
        assertTrue(ref.isPresent());
        assertEquals(lastCommit.getId(), ref.get().getObjectId());
        ref = geogig.command(RefParse.class).setName(Ref.MERGE_HEAD).call();
        assertTrue(ref.isPresent());
        assertEquals(branch.getObjectId(), ref.get().getObjectId());

    }

    @Test
    public void testConflictingMergeInterceptor() throws Exception {
        // Create the following revision graph
        // o
        // |
        // o - Points 1 added
        // |\
        // | o - TestBranch - Points 1 modified and points 2 added
        // |
        // o - master - HEAD - Points 1 modifiedB
        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);
        insertAndAdd(points2);
        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()))
                    .call();
            fail();
        } catch (MergeConflictsException e) {
            assertTrue(e.getMessage().contains("conflict"));
        }

        try {
            geogig.command(PullOp.class).call();
            fail();
        } catch (IllegalStateException e) {
            assertEquals(e.getMessage(), "Cannot run operation while merge conflicts exist.");
        }

    }

    @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());
    }

    @Test
    public void testMergeWithFeatureMerge() throws Exception {
        // Create the following revision graph
        // o
        // |
        // o - Points 1 added
        // |\
        // | o - TestBranch - Points 1 modified and points 2 added
        // |
        // o - master - HEAD - Points 1 modifiedB
        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_1", new Integer(2000),
                "POINT(1 1)");
        insertAndAdd(points1ModifiedB);
        insertAndAdd(points2);
        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();

        String path = appendChild(pointsName, points1.getIdentifier().getID());

        Optional<RevFeature> feature = repo.command(RevObjectParse.class)
                .setRefSpec(/*
                             * mergeCommit. getId ().toString () + ":" +
                             */"WORK_HEAD" + ":" + path).call(RevFeature.class);
        assertTrue(feature.isPresent());

        Feature mergedFeature = feature(pointsType, idP1, "StringProp1_2", new Integer(2000),
                "POINT(1 1)");
        RevFeature expected = RevFeatureBuilder.build(mergedFeature);
        assertEquals(expected, feature.get());

    }

    @Test
    public void testMergeTwoBranchesWithNewFeatureType() throws Exception {
        insertAndAdd(points1);
        geogig.command(CommitOp.class).call();
        geogig.command(BranchCreateOp.class).setName("branch1").call();
        insertAndAdd(lines1);
        geogig.command(CommitOp.class).call();
        geogig.command(CheckoutOp.class).setSource("branch1").call();
        insertAndAdd(poly1);
        RevCommit commit2 = geogig.command(CommitOp.class).call();
        geogig.command(CheckoutOp.class).setSource("master").call();
        geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(commit2.getId())).call();

        Optional<NodeRef> ref = geogig.command(FindTreeChild.class).setChildPath(polyName).call();

        assertTrue(ref.isPresent());
        assertFalse(ref.get().getMetadataId().equals(ObjectId.NULL));
    }

    @Test
    public void testOctopusMerge() throws Exception {
        insertAndAdd(points1);
        RevCommit initialCommit = 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();
        geogig.command(CheckoutOp.class).setSource("branch1").call();
        ObjectId points2Id = insertAndAdd(points2);
        RevCommit branch1 = geogig.command(CommitOp.class).call();
        geogig.command(CheckoutOp.class).setSource("branch2").call();
        ObjectId points3Id = insertAndAdd(points3);
        RevCommit branch2 = geogig.command(CommitOp.class).call();
        geogig.command(CheckoutOp.class).setSource("branch3").call();
        ObjectId lines1Id = insertAndAdd(lines1);
        RevCommit branch3 = geogig.command(CommitOp.class).call();
        geogig.command(CheckoutOp.class).setSource("branch4").call();
        ObjectId lines2Id = insertAndAdd(lines2);
        RevCommit branch4 = geogig.command(CommitOp.class).call();
        geogig.command(CheckoutOp.class).setSource("branch5").call();
        ObjectId lines3Id = insertAndAdd(lines3);
        RevCommit branch5 = geogig.command(CommitOp.class).call();
        geogig.command(CheckoutOp.class).setSource("branch6").call();
        ObjectId points1Id = insertAndAdd(points1_modified);
        RevCommit branch6 = geogig.command(CommitOp.class).call();
        geogig.command(CheckoutOp.class).setSource("master").call();
        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())).call();

        Optional<NodeRef> ref = geogig.command(FindTreeChild.class)
                .setChildPath(pointsName + "/" + idP1).call();
        assertTrue(ref.isPresent());
        assertEquals(points1Id, ref.get().getNode().getObjectId());
        ref = geogig.command(FindTreeChild.class).setChildPath(pointsName + "/" + idP2).call();
        assertTrue(ref.isPresent());
        assertEquals(points2Id, ref.get().getNode().getObjectId());
        ref = geogig.command(FindTreeChild.class).setChildPath(pointsName + "/" + idP3).call();
        assertTrue(ref.isPresent());
        assertEquals(points3Id, ref.get().getNode().getObjectId());
        ref = geogig.command(FindTreeChild.class).setChildPath(linesName + "/" + idL1).call();
        assertTrue(ref.isPresent());
        assertEquals(lines1Id, ref.get().getNode().getObjectId());
        ref = geogig.command(FindTreeChild.class).setChildPath(linesName + "/" + idL2).call();
        assertTrue(ref.isPresent());
        assertEquals(lines2Id, ref.get().getNode().getObjectId());
        ref = geogig.command(FindTreeChild.class).setChildPath(linesName + "/" + idL3).call();
        assertTrue(ref.isPresent());
        assertEquals(lines3Id, ref.get().getNode().getObjectId());

        Iterator<RevCommit> log = geogig.command(LogOp.class).setFirstParentOnly(true).call();

        // MergeCommit
        RevCommit logMerge = log.next();
        assertEquals(7, logMerge.getParentIds().size());

        // Initial Commit
        RevCommit initial = log.next();
        assertEquals(initialCommit.getMessage(), initial.getMessage());
        assertEquals(initialCommit.getCommitter().getName(), initial.getCommitter().getName());
        assertEquals(initialCommit.getCommitter().getEmail(), initial.getCommitter().getEmail());
        assertEquals(initialCommit.getAuthor().getTimeZoneOffset(), initial.getAuthor()
                .getTimeZoneOffset());
        assertEquals(initialCommit.getCommitter().getTimeZoneOffset(), initial.getCommitter()
                .getTimeZoneOffset());
        assertEquals(initialCommit.getTreeId(), initial.getTreeId());
        assertEquals(initialCommit.getId(), initial.getId());

        assertFalse(log.hasNext());
    }

    @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"));
        }
    }

    @Test
    public void testOctopusMergeSameFeatureChanges() 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();
        insertAndAdd(points1_modified);
        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(points1_modified);
        RevCommit branch3 = geogig.command(CommitOp.class).call();
        geogig.command(CheckoutOp.class).setSource("master").call();
        geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch1.getId()))
                .addCommit(Suppliers.ofInstance(branch2.getId()))
                .addCommit(Suppliers.ofInstance(branch3.getId())).call();
        String path = NodeRef.appendChild(pointsName, idP1);
        Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class)
                .setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
        assertTrue(revFeature.isPresent());
        assertEquals(RevFeatureBuilder.build(points1_modified), revFeature.get());
    }

}


text:
    [context retain]
#define CGContextRelease(context) \
    [context release]
#define CGContextSetAllowsAntialiasing(context,yesOrNo) \
    [context setAllowsAntialiasing:yesOrNo]
#define CGContextBeginTransparencyLayer(context,unused) \
    [context beginTransparencyLayerWithInfo:unused]
#define CGContextEndTransparencyLayer(context) \
    [context endTransparencyLayer]
#define CGContextIsPathEmpty(context) \
    [context pathIsEmpty]
#define CGContextGetPathCurrentPoint(context) \
    [context pathCurrentPoint]
#define CGContextGetPathBoundingBox(context) \
    [context pathBoundingBox]
#define CGContextPathContainsPoint(context,point,pathMode) \
   [context pathContainsPoint:point drawingMode:pathMode]
#define CGContextBeginPath(context) \
    [context beginPath]
#define CGContextClosePath(context) \
    [context closePath]
#define CGContextMoveToPoint(context,x,y) \
    [context moveToPoint:x:y]
#define CGContextAddLineToPoint(context,x,y) \
    [context addLineToPoint:x:y]
#define CGContextAddCurveToPoint(context,cx1,cy1,cx2,cy2,x,y) \
    [context addCurveToPoint:cx1:cy1:cx2:cy2:x:y]
#define CGContextAddQuadCurveToPoint(context,cx1,cy1,x,y) \
    [context addQuadCurveToPoint:cx1:cy1:x:y]
#define CGContextAddLines(context,points,count) \
    [context addLinesWithPoints:points count:count]
#define CGContextAddRect(context,rect) \
    [context addRect:rect]
#define CGContextAddRects(context,rects,count) \
    [context addRects:rects count:count]
#define CGContextAddArc(context,x,y,radius,startRadian,endRadian,clockwise) \
    [context addArc:x:y:radius:startRadian:endRadian:clockwise]
#define CGContextAddArcToPoint(context,x1,y1,x2,y2,radius) \
    [context addArcToPoint:x1:y1:x2:y2:radius]
#define CGContextAddEllipseInRect(context,rect) \
    [context addEllipseInRect:rect]
#define CGContextAddPath(context,path) \
    [context addPath:path]
#define CGContextReplacePathWithStrokedPath(context) \
    [context replacePathWithStrokedPath]
#define CGContextSaveGState(context) \
    [context saveGState]
#define CGContextRestoreGState(context) \
    [context restoreGState]
#define CGContextGetUserSpaceToDeviceSpaceTransform(context) \
    [context userSpaceToDeviceSpaceTransform]
#define CGContextGetCTM(context) \
    [context ctm]
#define CGContextGetClipBoundingBox(context) \
    [context clipBoundingBox]
#define CGContextGetTextMatrix(context) \
    [context textMatrix]
#define CGContextGetInterpolationQuality(context) \
    [context interpolationQuality]
#define CGContextGetTextPosition(context) \
    [context textPosition]
#define CGContextConvertPointToDeviceSpace(context,point) \
    [context convertPointToDeviceSpace:point]
#define CGContextConvertPointToUserSpace(context,point) \
    [context convertPointToUserSpace:point]
#define CGContextConvertSizeToDeviceSpace(context,size) \
    [context convertSizeToDeviceSpace:size]
#define CGContextConvertSizeToUserSpace(context,size) \
    [context convertSizeToUserSpace:size]
#define CGContextConvertRectToDeviceSpace(context,rect) \
    [context convertRectToDeviceSpace:rect]
#define CGContextConvertRectToUserSpace(context,rect) \
    [context convertRectToUserSpace:rect]
#define CGContextSetCTM(context,matrix) \
    [context setCTM:matrix]
#define CGContextConcatCTM(context,matrix) \
    [context concatCTM:matrix]
#define CGContextTranslateCTM(context,tx,ty) \
    [context translateCTM:tx:ty]
#define CGContextScaleCTM(context,scalex,scaley) \
    [context scaleCTM:scalex:scaley]
#define CGContextRotateCTM(context,radians) \
    [context rotateCTM:radians]
#define CGContextClip(context) \
    [context clipToPath]
#define CGContextEOClip(context) \
    [context evenOddClipToPath]
#define CGContextClipToMask(context,rect,image) \
    [context clipToMask:image inRect:rect]
#define CGContextClipToRect(context,rect) \
    [context clipToRect:rect]
#define CGContextClipToRects(context,rects,count) \
    [context clipToRects:rects count:count]
#define CGContextSetStrokeColorSpace(context,colorSpace) \
    [context setStrokeColorSpace:colorSpace]
#define CGContextSetFillColorSpace(context,colorSpace) \
    [context setFillColorSpace:colorSpace]
#define CGContextSetStrokeColor(context,components) \
    [context setStrokeColorWithComponents:components]
#define CGContextSetStrokeColorWithColor(context,color) \
    [context setStrokeColor:color]
#define CGContextSetGrayStrokeColor(context,gray,alpha) \
    [context setGrayStrokeColor:gray:alpha]
#define CGContextSetRGBStrokeColor(context,r,g,b,alpha) \
    [context setRGBStrokeColor:r:g:b:alpha]
#define CGContextSetCMYKStrokeColor(context,c,m,y,k,alpha) \
    [context setCMYKStrokeColor:c:m:y:k:alpha]
#define CGContextSetFillColor(context,components) \
    [context setFillColorWithComponents:components]
#define CGContextSetFillColorWithColor(context,color) \
    [context setFillColor:color]
#define CGContextSetGrayFillColor(context,gray,alpha) \
    [context setGrayFillColor:gray:alpha]
#define CGContextSetRGBFillColor(context,r,g,b,alpha) \
    [context setRGBFillColor:r:g:b:alpha]
#define CGContextSetCMYKFillColor(context,c,m,y,k,alpha) \
    [context setCMYKFillColor:c:m:y:k:alpha]
#define CGContextSetAlpha(context,alpha) \
    [context setStrokeAndFillAlpha:alpha]
#define CGContextSetPatternPhase(context,phase) \
    [context setPatternPhase:phase]
#define CGContextSetStrokePattern(context,pattern,components) \
    [context setStrokePattern:pattern components:components]
#define CGContextSetFillPattern(context,pattern,components) \
    [context setFillPattern:pattern components:components]
#define CGContextSetTextMatrix(context,matrix) \
    [context setTextMatrix:matrix]
#define CGContextSetTextPosition(context,x,y) \
    [context setTextPosition:x:y]
#define CGContextSetCharacterSpacing(context,spacing) \
    [context setCharacterSpacing:spacing]
#define CGContextSetTextDrawingMode(context,textMode) \
    [context setTextDrawingMode:textMode]
#define CGContextSetFont(context,font) \
    [context setFont:font]
#define CGContextSetFontSize(context,size) \
    [context setFontSize:size]
#define CGContextSelectFont(context,name,size,encoding) \
    [context selectFontWithName:name size:size encoding:encoding]
#define CGContextSetShouldSmoothFonts(context,yesOrNo) \
    [context setShouldSmoothFonts:yesOrNo]
#define CGContextSetLineWidth(context,width) \
    [context setLineWidth:width]
#define CGContextSetLineCap(context,lineCap) \
    [context setLineCap:lineCap]
#define CGContextSetLineJoin(context,lineJoin) \
    [context setLineJoin:lineJoin]
#define CGContextSetMiterLimit(context,miterLimit) \
    [context setMiterLimit:miterLimit]
#define CGContextSetLineDash(context,dphase,dlengths,dcount) \
    [context setLineDashPhase:dphase lengths:dlengths count:dcount]
#define CGContextSetRenderingIntent(context,renderingIntent) \
    [context setRenderingIntent:renderingIntent]
#define CGContextSetBlendMode(context,blendMode) \
    [context setBlendMode:blendMode]
#define CGContextSetFlatness(context,flatness) \
    [context setFlatness:flatness]
#define CGContextSetInterpolationQuality(context,quality) \
    [context setInterpolationQuality:quality]
#define CGContextSetShadowWithColor(context,o,b,c) \
    [context setShadowOffset:o blur:b color:c]
#define CGContextSetShadow(context,offset,blur) \
    [context setShadowOffset:offset blur:blur]
#define CGContextSetShouldAntialias(context,yesOrNo) \
    [context setShouldAntialias:yesOrNo]
#define CGContextStrokeLineSegments(context,points,count) \
    [context strokeLineSegmentsWithPoints:points count:count]
#define CGContextStrokeRect(context,rect) \
    [context strokeRect:rect]
#define CGContextStrokeRectWithWidth(context,rect,width) \
    [context strokeRect:rect width:width]
#define CGContextStrokeEllipseInRect(context,rect) \
    [context strokeEllipseInRect:rect]
#define CGContextFillRect(context,rect) \
    [context fillRect:rect]
#define CGContextFillRects(context,rects,count) \
    [context fillRects:rects count:count]
#define CGContextFillEllipseInRect(context,rect) \
    [context fillEllipseInRect:rect]
#define CGContextDrawPath(context,pathMode) \
    [context drawPath:pathMode]
#define CGContextStrokePath(context) \
    [context strokePath]
#define CGContextFillPath(context) \
    [context fillPath]
#define CGContextEOFillPath(context) \
    [context evenOddFillPath]
#define CGContextClearRect(context,rect) \
    [context clearRect:rect]
#define CGContextShowGlyphs(context,glyphs,count) \
    [context showGlyphs:glyphs count:count]
#define CGContextShowGlyphsAtPoint(context,x,y,glyphs,count) \
    [context showGlyphs:glyphs count:count atPoint:x:y]
#define CGContextShowGlyphsWithAdvances(context,glyphs,advances,count) \
    [context showGlyphs:glyphs count:count advances:advances]
#define CGContextShowText(context,text,count) \
    [context showText:text length:count]
#define CGContextShowTextAtPoint(context,x,y,text,count) \
    [context showText:text length:count atPoint:x:y]
#define CGContextDrawShading(context,shading) \
    [context drawShading:shading]
#define CGContextDrawImage(context,rect,image) \
    [context drawImage:image inRect:rect]
#define CGContextDrawLayerAtPoint(context,point,layer) \
    [context drawLayer:layer atPoint:point]
#define CGContextDrawLayerInRect(context,rect,layer) \
    [context drawLayer:layer inRect:rect]
#define CGContextDrawPDFPage(context,page) \
    [context drawPDFPage:page]
#define CGContextFlush(context) \
    [context flush]
#define CGContextSynchronize(context) \
    [context synchronize]
#define CGContextBeginPage(context,mediaBox) \
    [context beginPage:mediaBox]
#define CGContextEndPage(context) \
    [context endPage]

// bitmap context

#define CGBitmapContextCreate(bytes,w,h,bpc,bpr,cs,bi) \
   [KGContext createWithBytes:bytes width:w height:h bitsPerComponent:bpc bytesPerRow:bpr colorSpace:cs bitmapInfo:bi]

#define CGBitmapContextGetData(self) \
   [self pixelBytes]

#define  CGBitmapContextGetWidth(self) \
   [self width]

#define  CGBitmapContextGetHeight(self) \
   [self height]

#define  CGBitmapContextGetBitsPerComponent(self) \
   [self bitsPerComponent]

#define  CGBitmapContextGetBytesPerRow(self) \
   [self bytesPerRow]

#define  CGBitmapContextGetColorSpace(self) \
   [self colorSpace]

#define  CGBitmapContextGetBitmapInfo(self) \
   [self bitmapInfo]

#define  CGBitmapContextGetBitsPerPixel(self) \
   [self bitsPerPixel]

#define  CGBitmapContextGetAlphaInfo(self) \
   [self alphaInfo]

#define  CGBitmapContextCreateImage(self) \
   [self createImage]

// CGPath
#define CGPathRelease(self) \
   [self release]

#define CGPathRetain(self) \
   [self retain]

#define CGPathEqualToPath(self,other) \
   [self isEqualToPath:other]

#define CGPathGetBoundingBox(self) \
   [self boundingBox]

#define CGPathGetCurrentPoint(self) \
   [self currentPoint]

#define CGPathIsEmpty(self) \
   [self isEmpty]

#define CGPathIsRect(self,rect) \
   [self isRect:rect]

#define CGPathApply(self,info,fn) \
   [self applyWithInfo:info function:fn]

#define CGPathCreateMutableCopy(self) \
   [self mutableCopy]

#define CGPathCreateCopy(self) \
   [self copy]

#define CGPathContainsPoint(self,xform,pt,eo) \
   [self containsPoint:pt evenOdd:eo withTransform:xform]

#define CGPathCreateMutable(void) \
   [[KGMutablePath alloc] init]

#define CGPathMoveToPoint(self,xform,x,y) \
   [self moveToPoint:CGPointMake(x,y) withTransform:xform]

#define CGPathAddLineToPoint(self,xform,x,y) \
   [self addLineToPoint:CGPointMake(x,y) withTransform:xform]

#define CGPathAddCurveToPoint(self,xform,cp1x,cp1y,cp2x,cp2y,x,y) \
   [self addCurveToControlPoint:CGPointMake(cp1x,cp1y) controlPoint:CGPointMake(cp2x,cp2y) endPoint:CGPointMake(x,y) withTransform:xform]

#define CGPathAddQuadCurveToPoint(self,xform,cpx,cpy,x,y) \
   [self addQuadCurveToControlPoint:CGPointMake(cpx,cpy) endPoint:CGPointMake(x,y) withTransform:xform]

#define CGPathCloseSubpath(self) \
   [self closeSubpath]

#define CGPathAddLines(self,xform,points,pointCount) \
   [self addLinesWithPoints:points count:pointCount withTransform:xform]

#define CGPathAddRect(self,xform,rect) \
   [self addRect:rect withTransform:xform]

#define CGPathAddRects(self,xform,rects,rectCount) \
   [self addRects:rects count:rectCount withTransform:xform]

#define CGPathAddArc(self,xform,x,y,r,startRadian,endRadian,cw) \
   [self addArcAtPoint:CGPointMake(x,y) radius:r startAngle:startRadian endAngle:endRadian clockwise:cw withTransform:xform]

#define CGPathAddArcToPoint(self,xform,tx1,ty1,tx2,ty2,radius) \
   [self addArcToPoint:CGPointMake(tx1,ty1) point:CGPointMake(tx2,ty2) radius:radius withTransform:xform]

#define CGPathAddEllipseInRect(self,xform,rect) \
   [self addEllipseInRect:rect withTransform:xform]

#define CGPathAddPath(self,xform,other) \
   [self addPath:other withTransform:xform]

// CGColor

#define CGColorRetain(self) \
   [self retain]

#define CGColorRelease(self) \
   [self release]

#define CGColorCreate(colorSpace,ccomponents) \
   [[KGColor alloc] initWithColorSpace:colorSpace components:ccomponents]

#define CGColorCreateGenericGray(gray,a) \
   [[KGColor alloc] initWithDeviceGray:gray alpha:a]

#define CGColorCreateGenericRGB(r,g,b,a) \
   [[KGColor alloc] initWithDeviceRed:r green:g blue:b alpha:a]

#define CGColorCreateGenericCMYK(c,m,y,k,a) \
   [[KGColor alloc] initWithDeviceCyan:c magenta:m yellow:y black:k alpha:a]

#define CGColorCreateWithPattern(colorSpace,pattern,ccomponents) \
   [[KGColor alloc] initWithColorSpace:colorSpace pattern:pattern components:ccomponents]

#define CGColorCreateCopy(self) \
   [self copy]

#define CGColorCreateCopyWithAlpha(self,a) \
   [self copyWithAlpha:a]

#define CGColorEqualToColor(self,other) \
   [self isEqualToColor:other]

#define CGColorGetColorSpace(self) \
   [self colorSpace]

#define CGColorGetNumberOfComponents(self) \
   [self numberOfComponents]

#define CGColorGetComponents(self) \
   [self components]

#define CGColorGetAlpha(self) \
   [self alpha]

#define CGColorGetPattern(self) \
   [self pattern]

// CGColorSpace

#define CGColorSpaceCreateDeviceRGB() \
    [[KGColorSpace alloc] initWithDeviceRGB]

#define CGColorSpaceCreateDeviceGray() \
    [[KGColorSpace alloc] initWithDeviceGray]

#define CGColorSpaceCreateDeviceCMYK() \
    [[KGColorSpace alloc] initWithDeviceCMYK]

// CGImage

#define  CGImageRetain(image) \
   [image retain]

#define  CGImageRelease(image) \
   [image release]

#define  CGImageCreate(w,h,bpc,bpp,bpr,cs,bi,dp,dec,interp,ri) \
   [[KGImage alloc] initWithWidth:w height:h bitsPerComponent:bpc bitsPerPixel:bpp bytesPerRow:bpr colorSpace:cs bitmapInfo:bi provider:dp decode:dec interpolate:interp renderingIntent:ri]

#define  CGImageMaskCreate(w,h,bpc,bpp,bpr,dp,dec,interp) \
   [[KGImage alloc] initMaskWithWidth:w height:h bitsPerComponent:bpc bitsPerPixel:bpp bytesPerRow:bpr provider:dp decode:dec interpolate:interp]

#define  CGImageCreateCopy(self) \
   [self copy]

#define  CGImageCreateCopyWithColorSpace(self,colorSpace) \
   [self copyWithColorSpace:colorSpace]

#define  CGImageCreateWithImageInRect(self,rect) \
   [self childImageInRect:rect]

#define  CGImageCreateWithJPEGDataProvider(jpegProvider,dec,interpolate, renderingIntent) \
   [[KGImage alloc] initWithJPEGDataProvider:jpegProvider decode:dec interpolate:interpolate renderingIntent:renderingIntent]

#define  CGImageCreateWithPNGDataProvider(pngProvider,dec,interpolate,renderingIntent) \
   [[KGImage alloc] initWithPNGDataProvider:pngProvider decode:dec interpolate:interpolate renderingIntent:renderingIntent]

#define  CGImageCreateWithMask(self,mask) \
   [self copyWithMask:mask]

#define  CGImageCreateWithMaskingColors(self,components) \
   [self copyWithMaskingColors:components]

#define  CGImageGetWidth(self) \
   [self width]

#define  CGImageGetHeight(self) \
   [self height]

#define  CGImageGetBitsPerComponent(self) \
   [self bitsPerComponent]

#define  CGImageGetBitsPerPixel(self) \
   [self bitsPerPixel]

#define  CGImageGetBytesPerRow(self) \
   [self bytesPerRow]

#define  CGImageGetColorSpace(self) \
   [self colorSpace]

#define  CGImageGetBitmapInfo(self) \
   [self bitmapInfo]

#define  CGImageGetDataProvider(self) \
   [self dataProvider]

#define CGImageGetDecode(self) \
   [self decode]

#define  CGImageGetShouldInterpolate(self) \
   [self shouldInterpolate]

#define  CGImageGetRenderingIntent(self) \
   [self renderingIntent]

#define  CGImageIsMask(self) \
   [self isMask]

#define  CGImageGetAlphaInfo(self) \
   [self alphaInfo]

// data provider

#define CGDataProviderCreateWithData(info,data,size, releaseCallback) \
   [[KGDataProvider alloc] initWithBytes:data length:size]

#define CGDataProviderCreateWithCFData(data) \
   [[KGDataProvider alloc] initWithData:data]

// image source

#define CGImageSourceCreateWithData(data,opts) \
   [KGImageSource newImageSourceWithData:data options:opts]

#define CGImageSourceCreateImageAtIndex(self,index,opts) \
   [self createImageAtIndex:index options:opts]

// pdf document

#define CGPDFDocumentRetain(self) \
   [self retain]

#define CGPDFDocumentRelease(self) \
   [self release]

#define CGPDFDocumentCreateWithProvider(provider) \
   [[KGPDFDocument alloc] initWithDataProvider:provider]

#define CGPDFDocumentGetNumberOfPages(self) \
   [self pageCount]

#define CGPDFDocumentGetPage(self,pageNumber) \
   [self pageAtNumber:pageNumber]

// pdf page

#define CGPDFPageRetain(self) \
   [self retain]

#define CGPDFPageRelease(self) \
   [self release]

redpajama_set_name: RedPajamaGithub


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<title>Key</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="date" content="2018-04-23">
<link rel="stylesheet" type="text/css" href="../../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../../jquery/jquery-ui.css" title="Style">

JavaScript is disabled on your browser.

Skip navigation links

Overview

Package

Class

Tree

Deprecated

Index

Help

Prev Class

Next Class

Frames

No Frames

All Classes

SEARCH:
<input type="text" id="search" value=" " disabled="disabled">
<input type="reset" id="reset" value=" " disabled="disabled">

JavaScript is disabled on your browser.

Summary:

Nested |

Field |

Constr |

Method

Detail:

Field |

Constr |

Method

Package lejos.hardware

Interface Key

<map id="G" name="G">
<area shape="rect" id="node1_0" href="./Key.html" title="lejos.hardware.Key" alt="" coords="16,11,256,313"/>
<area shape="rect" id="node1" href="./Key.html" title="<TABLE>" alt="" coords="5,5,267,319"/>
</map>

public interface Key

Field Summary

Fields

Modifier and Type
Field and Description

static int
DOWN

static int
ENTER

static int
ESCAPE

static int
KEY_PRESSED

static int
KEY_PRESSED_AND_RELEASED

static int
KEY_RELEASED

static int
LEFT

static int
RIGHT

static int
UP

Method Summary

All Methods Instance Methods Abstract Methods

Modifier and Type
Method and Description

void
addKeyListener(KeyListener listener)

int
getId()

java.lang.String
getName()

boolean
isDown()

boolean
isUp()

void
simulateEvent(int event)

void
waitForPress()

void
waitForPressAndRelease()

Field Detail

UP

static final int UP

See Also:

Constant Field Values

ENTER

static final int ENTER

See Also:

Constant Field Values

DOWN

static final int DOWN

See Also:

Constant Field Values

RIGHT

static final int RIGHT

See Also:

Constant Field Values

LEFT

static final int LEFT

See Also:

Constant Field Values

ESCAPE

static final int ESCAPE

See Also:

Constant Field Values

KEY_RELEASED

static final int KEY_RELEASED

See Also:

Constant Field Values

KEY_PRESSED

static final int KEY_PRESSED

See Also:

Constant Field Values

KEY_PRESSED_AND_RELEASED

static final int KEY_PRESSED_AND_RELEASED

See Also:

Constant Field Values

Method Detail

getId

int getId()

isDown

boolean isDown()

isUp

boolean isUp()

waitForPress

void waitForPress()

waitForPressAndRelease

void waitForPressAndRelease()

addKeyListener

void addKeyListener(KeyListener listener)

simulateEvent

void simulateEvent(int event)

getName

java.lang.String getName()

Skip navigation links

Overview

Package

Class

Tree

Deprecated

Index

Help

Prev Class

Next Class

Frames

No Frames

All Classes

JavaScript is disabled on your browser.

Summary:

Nested |

Field |

Constr |

Method

Detail:

Field |

Constr |

Method


text:
package gov.nih.nci.ncicb.cadsr.bulkloader.beans.castor;

/**
 *
 * @author Ashwin Mathur
 * @version 1.0, Dec 3, 2008
 * @since
 */

public class LanguageIdentification_ISO11179 {

	private String countryIdentifier;
	private String languageIdentifier;

	public String getCountryIdentifier() {
		return countryIdentifier;
	}
	public void setCountryIdentifier(String countryIdentifier) {
		this.countryIdentifier = countryIdentifier;
	}
	public String getLanguageIdentifier() {
		return languageIdentifier;
	}
	public void setLanguageIdentifier(String languageIdentifier) {
		this.languageIdentifier = languageIdentifier;
	}

}


text:
import time

import pytest

import ray
from ray.experimental import workflow
from ray.experimental.workflow import workflow_access

@workflow.step
def identity(x):
    return x

@workflow.step
def source1():
    return "[source1]"

@workflow.step
def append1(x):
    return x + "[append1]"

@workflow.step
def append2(x):
    return x + "[append2]"

@workflow.step
def simple_sequential():
    x = source1.step()
    y = append1.step(x)
    return append2.step(y)

@workflow.step
def simple_sequential_with_input(x):
    y = append1.step(x)
    return append2.step(y)

@workflow.step
def loop_sequential(n):
    x = source1.step()
    for _ in range(n):
        x = append1.step(x)
    return append2.step(x)

@workflow.step
def nested_step(x):
    return append2.step(append1.step(x + "~[nested]~"))

@workflow.step
def nested(x):
    return nested_step.step(x)

@workflow.step
def join(x, y):
    return f"join({x}, {y})"

@workflow.step
def fork_join():
    x = source1.step()
    y = append1.step(x)
    y = identity.step(y)
    z = append2.step(x)
    return join.step(y, z)

@workflow.step
def blocking():
    time.sleep(10)
    return 314

def test_basic_workflows():
    ray.init(namespace="workflow")

    output = workflow.run(simple_sequential.step())
    assert ray.get(output) == "[source1][append1][append2]"

    output = workflow.run(simple_sequential_with_input.step("start:"))
    assert ray.get(output) == "start:[append1][append2]"

    output = workflow.run(loop_sequential.step(3))
    assert ray.get(output) == "[source1]" + "[append1]" * 3 + "[append2]"

    output = workflow.run(nested.step("nested:"))
    assert ray.get(output) == "nested:~[nested]~[append1][append2]"

    output = workflow.run(fork_join.step())
    assert ray.get(output) == "join([source1][append1], [source1][append2])"

    ray.shutdown()

def test_async_execution():
    ray.init(namespace="workflow")

    start = time.time()
    output = workflow.run(blocking.step())
    duration = time.time() - start
    assert duration < 5  # workflow.run is not blocked
    assert ray.get(output) == 314

    ray.shutdown()

@ray.remote
def deep_nested(x):
    if x >= 42:
        return x
    return deep_nested.remote(x + 1)

def _resolve_workflow_output(workflow_id: str, output: ray.ObjectRef):
    while isinstance(output, ray.ObjectRef):
        output = ray.get(output)
    return output

def test_workflow_output_resolving():
    ray.init(namespace="workflow")
    # deep nested workflow
    nested_ref = deep_nested.remote(30)
    original_func = workflow_access._resolve_workflow_output
    # replace the original function with a new function that does not
    # involving named actor
    workflow_access._resolve_workflow_output = _resolve_workflow_output
    try:
        ref = workflow_access.flatten_workflow_output("fake_workflow_id",
                                                      nested_ref)
    finally:
        # restore the function
        workflow_access._resolve_workflow_output = original_func
    assert ray.get(ref) == 42
    ray.shutdown()

def test_run_or_resume_during_running():
    ray.init(namespace="workflow")
    output = workflow.run(
        simple_sequential.step(), workflow_id="running_workflow")

    with pytest.raises(ValueError):
        workflow.run(simple_sequential.step(), workflow_id="running_workflow")
    with pytest.raises(ValueError):
        workflow.resume(workflow_id="running_workflow")

    assert ray.get(output) == "[source1][append1][append2]"
    ray.shutdown()


text:
'use strict';

// Load modules

const Querystring = require('querystring');
const Boom = require('boom');
const Code = require('code');
const Hapi = require('hapi');
const Hawk = require('hawk');
const Hoek = require('hoek');
const Wreck = require('wreck');

// Declare internals

const internals = {};

// Test shortcuts

const expect = Code.expect;

exports.CLIENT_ID_TESTER = internals.CLIENT_ID_TESTER = 'clientIdTester';
exports.CLIENT_SECRET_TESTER = internals.CLIENT_SECRET_TESTER = 'clientSecretTester';

exports.V1 = internals.V1 = function (options) {

    this.options = options || {};
    this.options.signatureMethod = this.options.signatureMethod || 'HMAC-SHA1';

    this.tokens = {};

    this.server = new Hapi.Server();
    this.server.connection({ host: 'localhost' });
    this.server.route([
        {
            method: 'POST',
            path: '/temporary',
            config: {
                bind: this,
                handler: function (request, reply) {

                    if (this.options.failTemporary) {
                        return reply(Boom.badRequest());
                    }

                    const header = Hawk.utils.parseAuthorizationHeader(request.headers.authorization.replace(/OAuth/i, 'Hawk'), ['realm', 'oauth_consumer_key', 'oauth_signature_method', 'oauth_callback', 'oauth_signature', 'oauth_version', 'oauth_timestamp', 'oauth_nonce']);
                    expect(header.oauth_callback).to.exist();

                    const token = String(Object.keys(this.tokens).length + 1);
                    this.tokens[token] = {
                        authorized: false,
                        secret: 'secret',
                        callback: header.oauth_callback
                    };

                    const payload = {
                        oauth_token: token,
                        oauth_token_secret: 'secret',
                        oauth_callback_confirmed: true
                    };

                    return reply(Querystring.encode(payload)).type('application/x-www-form-urlencoded');
                }
            }
        },
        {
            method: 'GET',
            path: '/auth',
            config: {
                bind: this,
                handler: function (request, reply) {

                    const token = this.tokens[request.query.oauth_token];
                    expect(token).to.exist();

                    token.authorized = true;
                    token.verifier = '123';

                    const extra = Object.keys(request.query).length > 1 ? '&extra=true' : '';
                    return reply().redirect(unescape(token.callback) + '?oauth_token=' + request.query.oauth_token + '&oauth_verifier=' + token.verifier + extra);
                }
            }
        },
        {
            method: 'POST',
            path: '/token',
            config: {
                bind: this,
                handler: function (request, reply) {

                    if (this.options.failToken) {
                        return reply(Boom.badRequest());
                    }

                    const header = Hawk.utils.parseAuthorizationHeader(request.headers.authorization.replace(/OAuth/i, 'Hawk'), ['realm', 'oauth_consumer_key', 'oauth_token', 'oauth_signature_method', 'oauth_verifier', 'oauth_signature', 'oauth_version', 'oauth_timestamp', 'oauth_nonce']);
                    const token = this.tokens[header.oauth_token];
                    expect(token).to.exist();
                    expect(token.verifier).to.equal(header.oauth_verifier);
                    expect(token.authorized).to.equal(true);

                    const payload = {
                        oauth_token: 'final',
                        oauth_token_secret: 'secret'
                    };

                    if (header.oauth_consumer_key === 'twitter') {
                        payload.user_id = '1234567890';
                        payload.screen_name = 'Steve Stevens';
                    }

                    return reply(Querystring.encode(payload)).type('application/x-www-form-urlencoded');
                }
            }
        },
        {
            method: '*',
            path: '/resource',
            config: {
                bind: this,
                handler: function (request, reply) {

                    const header = Hawk.utils.parseAuthorizationHeader(request.headers.authorization.replace(/OAuth/i, 'Hawk'), ['realm', 'oauth_consumer_key', 'oauth_token', 'oauth_signature_method', 'oauth_verifier', 'oauth_signature', 'oauth_version', 'oauth_timestamp', 'oauth_nonce']);
                    expect(header.oauth_token).to.equal('final');

                    return reply(request.payload ? request.payload : 'some text reply');
                }
            }
        }
    ]);
};

internals.V1.prototype.start = function (callback) {

    this.server.start((err) => {

        expect(err).to.not.exist();

        this.uri = this.server.info.uri;

        return callback({
            protocol: 'oauth',
            temporary: this.server.info.uri + '/temporary',
            auth: this.server.info.uri + '/auth',
            token: this.server.info.uri + '/token',
            signatureMethod: this.options.signatureMethod
        });
    });
};

internals.V1.prototype.stop = function (callback) {

    this.server.stop(callback);
};

exports.V2 = internals.V2 = function (options) {

    options = options || {};

    this.codes = {};

    this.useParamsAuth = (options.useParamsAuth === false ? false : true);
    this.server = new Hapi.Server();
    this.server.connection({ host: 'localhost' });
    this.server.route([
        {
            method: 'GET',
            path: '/auth',
            config: {
                bind: this,
                handler: function (request, reply) {

                    const code = String(Object.keys(this.codes).length + 1);
                    this.codes[code] = {
                        redirect_uri: request.query.redirect_uri,
                        client_id: request.query.client_id
                    };

                    return reply().redirect(request.query.redirect_uri + '?code=' + code + '&state=' + request.query.state);
                }
            }
        },
        {
            method: 'POST',
            path: '/token',
            config: {
                bind: this,
                handler: function (request, reply) {

                    const code = this.codes[request.payload.code];
                    expect(code).to.exist();
                    expect(code.redirect_uri).to.equal(request.payload.redirect_uri);
                    if (this.useParamsAuth) {
                        expect(code.client_id).to.equal(request.payload.client_id);
                        expect(request.headers.authorization).to.be.undefined();
                    }
                    else {
                        const basic = new Buffer(request.headers.authorization.slice(6), 'base64').toString();
                        expect(basic).to.startWith(code.client_id);
                        expect(request.payload.client_id).to.be.undefined();
                    }

                    const payload = {
                        access_token: '456',
                        expires_in: 3600
                    };

                    if (code.client_id === 'instagram') {
                        payload.user = {
                            id: '123456789',
                            username: 'stevegraham',
                            full_name: 'Steve Graham',
                            profile_picture: 'http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg'
                        };
                    }

                    if (code.client_id === 'vk') {
                        payload.user_id = '1234567890';
                        payload.email = 'steve@example.com';
                    }

                    if (code.client_id === internals.CLIENT_ID_TESTER) {
                        expect(internals.CLIENT_SECRET_TESTER).to.equal(request.payload.client_secret);
                    }

                    if (code.client_id === 'salesforce') {
                        payload.id = 'https://login.salesforce.com/id/foo/bar';
                    }

                    return reply(payload).code(options.code || 200);
                }
            }
        }
    ]);
};

internals.V2.prototype.start = function (callback) {

    this.server.start((err) => {

        expect(err).to.not.exist();

        this.uri = this.server.info.uri;

        return callback({
            protocol: 'oauth2',
            useParamsAuth: this.useParamsAuth,
            auth: this.server.info.uri + '/auth',
            token: this.server.info.uri + '/token'
        });
    });
};

internals.V2.prototype.stop = function (callback) {

    this.server.stop(callback);
};

exports.override = function (uri, payload) {

    const override = function (method) {

        return function (dest) {

            const callback = arguments.length === 3 ? arguments[2] : arguments[1];

            if (dest.indexOf(uri) === 0) {
                if (typeof payload === 'function') {
                    return payload(dest);
                }

                if (payload instanceof Error) {
                    const statusCode = (payload && payload.output ? payload.output.statusCode : 400);
                    return Hoek.nextTick(callback)(null, { statusCode }, JSON.stringify({ message: payload.message }));
                }

                if (payload === null) {
                    return Hoek.nextTick(callback)(Boom.internal('unknown'));
                }

                return Hoek.nextTick(callback)(null, { statusCode: 200 }, typeof payload === 'string' ? payload : JSON.stringify(payload));
            }

            return internals.wreck[method].apply(null, arguments);
        };
    };

    internals.wreck = {
        get: Wreck.get.bind(Wreck),
        post: Wreck.post.bind(Wreck)
    };

    Wreck.get = override('get');
    Wreck.post = override('post');
};

exports.clear = (uri) => {

    Wreck.get = internals.wreck.get;
    Wreck.post = internals.wreck.post;
};