diff options
author | lgoubet | 2018-06-05 10:29:54 +0000 |
---|---|---|
committer | lgoubet | 2018-06-05 10:30:37 +0000 |
commit | fcaf8f7f72e5caa23e1e511a603430413c21b8ab (patch) | |
tree | 7b9a9f4e9201ba6c4710f3765e5e1e47c6d045ac | |
parent | e5f2114530046be50ef7d85cd595dbd37fc58e42 (diff) | |
download | org.eclipse.emf.compare-fcaf8f7f72e5caa23e1e511a603430413c21b8ab.tar.gz org.eclipse.emf.compare-fcaf8f7f72e5caa23e1e511a603430413c21b8ab.tar.xz org.eclipse.emf.compare-fcaf8f7f72e5caa23e1e511a603430413c21b8ab.zip |
Introduce test for merges with multiple ancestors
Bug: 535200
Change-Id: I38f54baa9ce655fee60b1ed86ee850693e9555f1
9 files changed, 142 insertions, 1 deletions
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitMerge.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitMerge.java index a9670377c..803b6f44c 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitMerge.java +++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/annotations/GitMerge.java @@ -21,6 +21,7 @@ import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitTestSupport; import org.eclipse.jgit.api.MergeResult; import org.eclipse.jgit.api.Status; import org.eclipse.jgit.lib.Repository; +import org.junit.Test.None; /** * Annotation used to test the merge of models. @@ -80,4 +81,12 @@ public @interface GitMerge { */ String remote(); + /** + * Optionally specify an exception that is expected to be thrown by the test. The test will fail if this + * exception is not thrown. + * + * @return The expected exception thrown by this test. + */ + Class<? extends Throwable> expected() default None.class; + } diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/AbstractGitOperationStatement.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/AbstractGitOperationStatement.java index c22f82de4..1f54db079 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/AbstractGitOperationStatement.java +++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/AbstractGitOperationStatement.java @@ -11,6 +11,8 @@ *******************************************************************************/ package org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.statements; +import static org.junit.Assert.fail; + import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.egit.core.Activator; @@ -19,6 +21,7 @@ import org.eclipse.emf.compare.ide.ui.tests.framework.EMFCompareTestConfiguratio import org.eclipse.emf.compare.ide.ui.tests.framework.ResolutionStrategyID; import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitMergeStrategyID; import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitTestSupport; +import org.junit.Test.None; import org.junit.runners.model.FrameworkMethod; /** @@ -71,6 +74,7 @@ public abstract class AbstractGitOperationStatement extends AbstractGitStatement setEMFComparePreferences(); String from = InternalGitTestSupport.normalizeBranch(getCheckoutedBranch()); String to = InternalGitTestSupport.normalizeBranch(getOtherBranch()); + Class<? extends Throwable> expected = getExpectedException(); GitTestSupport gitTestsSupport = new GitTestSupport(); try { @@ -79,6 +83,15 @@ public abstract class AbstractGitOperationStatement extends AbstractGitStatement callGitOperation(gitTestsSupport, from, to); Object[] parameters = createParameters(test.getMethod(), gitTestsSupport); test.invokeExplosively(testObject, parameters); + if (expected != None.class) { + fail("Expected exception : " + expected.getName()); //$NON-NLS-1$ + } + } catch (Throwable e) { + if (expected.isAssignableFrom(e.getClass())) { + // success + } else { + throw e; + } } finally { restoreEMFComparePreferences(); gitTestsSupport.tearDown(); @@ -102,6 +115,15 @@ public abstract class AbstractGitOperationStatement extends AbstractGitStatement protected abstract String getOtherBranch(); /** + * Returns the exception that is expected to be thrown by this test. + * + * @return The exception that is expected to be thrown by this test. + */ + protected Class<? extends Throwable> getExpectedException() { + return None.class; + } + + /** * Call the Git operation used in for the test. This method have to be sub-classed by clients to call the * correct operation. * diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitMergeStatement.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitMergeStatement.java index 657d411ce..3068d5c85 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitMergeStatement.java +++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git.framework/src/org/eclipse/emf/compare/ide/ui/tests/git/framework/internal/statements/GitMergeStatement.java @@ -63,4 +63,10 @@ public class GitMergeStatement extends AbstractGitOperationStatement { return merge.remote(); } + @Override + protected Class<? extends Throwable> getExpectedException() { + GitMerge merge = test.getAnnotation(GitMerge.class); + return merge.expected(); + } + } diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/MultipleAncestorsTest.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/MultipleAncestorsTest.java new file mode 100644 index 000000000..8d5d56e50 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/MultipleAncestorsTest.java @@ -0,0 +1,103 @@ +package org.eclipse.emf.compare.ide.ui.tests.merge; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.eclipse.core.resources.IProject; +import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitTestRunner; +import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitInput; +import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitMerge; +import org.eclipse.jgit.api.Status; +import org.eclipse.jgit.api.errors.JGitInternalException; +import org.junit.runner.RunWith; + +@RunWith(GitTestRunner.class) +@SuppressWarnings({"nls", }) +public class MultipleAncestorsTest { + + /** + * Three people modifying two 4 models: 1 model for each person and 1 "index" model that links the 4 + * together. + * <p> + * Each person is modifying a single ecore file, everyone on their own branch. However, they're all + * merging to and from the same branch. There should never be a conflicting merge, but there will be + * multiple ancestors for the merges. + * </p> + */ + @GitInput("data/multipleancestors/complex.merge.zip") + @GitMerge(local = "assemblage", remote = "arthur") + public void testComplexMerge(Status status, List<IProject> projects) { + assertEquals(1, projects.size()); + assertFilesExist(projects.get(0), "index.ecore", "Arthur.ecore", "Laurent.ecore", "Stephane.ecore"); + assertTrue(status.getConflicting().isEmpty()); + assertTrue(status.isClean()); + } + + /** + * Two people modifying two models in their own branch, merging to and from master. + * <p> + * The two persons are modifying the same model files, but they're only creating "textual" conflicts (as + * opposed to model conflicts). These are automatically mergeable through EMF Compare and this merge + * should just finish correctly. + * </p> + */ + @GitInput("data/multipleancestors/library.binaryecore.multiple.ancestors.conflicts.zip") + @GitMerge(local = "master", remote = "Stephane") + public void testLibraryTextualConflicts(Status status, List<IProject> projects) { + assertEquals(1, projects.size()); + assertFilesExist(projects.get(0), "library.ecore", "types.ecore"); + assertTrue(status.getConflicting().isEmpty()); + assertTrue(status.isClean()); + } + + /** + * Two people modifying two models in their own branch, merging to and from master, and using an + * "assembly" branch to test before merging towards master. + * <p> + * The two persons have created a conflict in a previous merge, and have merged in such a way that there + * is now a conflict in the two commits that need to be used to create a base ancestor. JGit cannot handle + * that case and the merge is impossible. + * </p> + */ + @GitInput("data/multipleancestors/conflict.base.ancestor.zip") + @GitMerge(local = "assemblage", remote = "arthur", expected = JGitInternalException.class) + public void testModelAndTextualConflictInBaseCommits(Status status, List<IProject> projects) { + assertEquals(1, projects.size()); + assertFilesExist(projects.get(0), "library.uml", "types.uml"); + assertTrue(status.getConflicting().isEmpty()); + assertTrue(status.isClean()); + } + + /** + * Two people modifying two models in their own branch, merging to and from master. + * <p> + * The two persons are modifying different files and will not have conflictual differences with each + * other. This merge will go correctly. + * </p> + */ + @GitInput("data/multipleancestors/library.binaryecore.multiple.ancestors.no.conflict.different.files.zip") + @GitMerge(local = "master", remote = "Stephane") + public void testLibraryNoConflicts(Status status, List<IProject> projects) { + assertEquals(1, projects.size()); + assertFilesExist(projects.get(0), "library.ecore", "types.ecore"); + assertTrue(status.getConflicting().isEmpty()); + assertTrue(status.isClean()); + } + + /** + * Asserts that all given files exist in the given project. + * + * @param project + * project + * @param files + * files that need to exist in the project + */ + protected void assertFilesExist(IProject project, String... files) { + for (String file : files) { + assertTrue(file + " does not exist.", project.getFile(file).exists()); + } + } + +} diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/data/multipleancestors/complex.merge.zip b/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/data/multipleancestors/complex.merge.zip Binary files differnew file mode 100644 index 000000000..fefa41efc --- /dev/null +++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/data/multipleancestors/complex.merge.zip diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/data/multipleancestors/conflict.base.ancestor.zip b/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/data/multipleancestors/conflict.base.ancestor.zip Binary files differnew file mode 100644 index 000000000..8f2b4a2bd --- /dev/null +++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/data/multipleancestors/conflict.base.ancestor.zip diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/data/multipleancestors/library.binaryecore.multiple.ancestors.conflicts.zip b/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/data/multipleancestors/library.binaryecore.multiple.ancestors.conflicts.zip Binary files differnew file mode 100644 index 000000000..65dbaa01c --- /dev/null +++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/data/multipleancestors/library.binaryecore.multiple.ancestors.conflicts.zip diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/data/multipleancestors/library.binaryecore.multiple.ancestors.no.conflict.different.files.zip b/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/data/multipleancestors/library.binaryecore.multiple.ancestors.no.conflict.different.files.zip Binary files differnew file mode 100644 index 000000000..f3b396dd3 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/merge/data/multipleancestors/library.binaryecore.multiple.ancestors.no.conflict.different.files.zip diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/suite/GitTests.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/suite/GitTests.java index 312b31393..19cb4bf5e 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/suite/GitTests.java +++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.git/src/org/eclipse/emf/compare/ide/ui/tests/suite/GitTests.java @@ -17,6 +17,7 @@ import org.eclipse.emf.compare.ide.ui.tests.merge.AdditiveMergeTests; import org.eclipse.emf.compare.ide.ui.tests.merge.DirCacheResourceVariantTreeProviderTest; import org.eclipse.emf.compare.ide.ui.tests.merge.EMFResourceMappingMergerPreMergeTest; import org.eclipse.emf.compare.ide.ui.tests.merge.GitResourceVariantTreeSubscriberTest; +import org.eclipse.emf.compare.ide.ui.tests.merge.MultipleAncestorsTest; import org.eclipse.emf.compare.ide.ui.tests.merge.ResourceVariantTest; import org.eclipse.emf.compare.ide.ui.tests.merge.TreeWalkResourceVariantTreeProviderTest; import org.eclipse.emf.compare.ide.ui.tests.unit.GitLogicalModelTest; @@ -57,7 +58,7 @@ import org.junit.runners.Suite.SuiteClasses; // StrategyRecursiveModelTest.class, // StrategyRecursiveModelWithDeepProjectTest.class, ThreadedModelResolverResolutionTest.class, TreeWalkResourceVariantTreeProviderTest.class, - EMFResourceMappingMergerPreMergeTest.class }) + EMFResourceMappingMergerPreMergeTest.class, MultipleAncestorsTest.class, }) public class GitTests { @BeforeClass |