Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorcletavernie2013-03-26 14:29:31 -0400
committercletavernie2013-03-26 14:29:31 -0400
commit4b80d5bffd9a039655814601a82a9ab74dbd05cf (patch)
treeebcec7137619215dfda2aad0da9742cdd5339ac7 /tests
parent71aad2ff372aa8662553059859d0025b7fb8732c (diff)
downloadorg.eclipse.papyrus-4b80d5bffd9a039655814601a82a9ab74dbd05cf.tar.gz
org.eclipse.papyrus-4b80d5bffd9a039655814601a82a9ab74dbd05cf.tar.xz
org.eclipse.papyrus-4b80d5bffd9a039655814601a82a9ab74dbd05cf.zip
290952: [CDO] Support for CDO model repository
https://bugs.eclipse.org/bugs/show_bug.cgi?id=290952 Merge the CDO tests from cdo_kepler branch to the trunk
Diffstat (limited to 'tests')
-rw-r--r--tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/tests/AbstractPapyrusCDOTest.java45
-rw-r--r--tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/util/tests/AllUtilTests.java4
-rw-r--r--tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/util/tests/CDOFunctionsTest.java108
-rw-r--r--tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/util/tests/CDOPredicatesTest.java142
-rw-r--r--tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/util/tests/JobWaiterTest.java157
-rw-r--r--tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.ui.tests/src/org/eclipse/papyrus/cdo/internal/ui/editors/tests/DawnEditorAdapterTest.java8
-rw-r--r--tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.uml.ui.tests/src/org/eclipse/papyrus/cdo/uml/internal/ui/importsources/tests/CDOPackageImportSourceTest.java8
7 files changed, 469 insertions, 3 deletions
diff --git a/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/tests/AbstractPapyrusCDOTest.java b/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/tests/AbstractPapyrusCDOTest.java
index 0a169bf397e..632c9bf226d 100644
--- a/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/tests/AbstractPapyrusCDOTest.java
+++ b/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/tests/AbstractPapyrusCDOTest.java
@@ -43,11 +43,15 @@ import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.papyrus.cdo.core.IPapyrusRepository;
import org.eclipse.papyrus.cdo.internal.core.IInternalPapyrusRepository;
import org.eclipse.papyrus.cdo.internal.core.PapyrusRepositoryManager;
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TestName;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
/**
@@ -238,4 +242,45 @@ public abstract class AbstractPapyrusCDOTest {
return result;
}
+
+ public static <T extends Number & Comparable<T>> Matcher<T> lessThan(final T max) {
+ return new BaseMatcher<T>() {
+
+ public void describeTo(Description description) {
+ description.appendText("< ").appendValue(max);
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean matches(Object item) {
+ return ((T)item).compareTo(max) < 0;
+ }
+ };
+ }
+
+ public static <T extends Number & Comparable<T>> Matcher<T> lessThanOrEqualTo(final T max) {
+ return new BaseMatcher<T>() {
+
+ public void describeTo(Description description) {
+ description.appendText("<= ").appendValue(max);
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean matches(Object item) {
+ return ((T)item).compareTo(max) <= 0;
+ }
+ };
+ }
+
+ public static <T> Matcher<Iterable<T>> hasSize(final int size) {
+ return new BaseMatcher<Iterable<T>>() {
+
+ public void describeTo(Description description) {
+ description.appendText("has size ").appendValue(size);
+ }
+
+ public boolean matches(Object item) {
+ return Iterables.size((Iterable<?>)item) == size;
+ }
+ };
+ }
}
diff --git a/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/util/tests/AllUtilTests.java b/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/util/tests/AllUtilTests.java
index 379679d1451..469f188a24d 100644
--- a/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/util/tests/AllUtilTests.java
+++ b/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/util/tests/AllUtilTests.java
@@ -17,10 +17,10 @@ import org.junit.runners.Suite.SuiteClasses;
/**
- * This is the AllExpressionsTests type. Enjoy.
+ * This is the AllUtilTests type. Enjoy.
*/
@RunWith(Suite.class)
-@SuiteClasses({ CDOPredicatesTest.class, CDOFunctionsTest.class })
+@SuiteClasses({ CDOPredicatesTest.class, CDOFunctionsTest.class, JobWaiterTest.class })
public class AllUtilTests {
public AllUtilTests() {
diff --git a/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/util/tests/CDOFunctionsTest.java b/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/util/tests/CDOFunctionsTest.java
index f3eb184b565..ef3169b243d 100644
--- a/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/util/tests/CDOFunctionsTest.java
+++ b/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/util/tests/CDOFunctionsTest.java
@@ -11,18 +11,30 @@
*****************************************************************************/
package org.eclipse.papyrus.cdo.core.util.tests;
+import static org.hamcrest.CoreMatchers.both;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertThat;
import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
+import org.eclipse.emf.cdo.eresource.CDOTextResource;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.papyrus.cdo.core.tests.AbstractPapyrusCDOTest;
import org.eclipse.papyrus.cdo.core.util.CDOFunctions;
+import org.eclipse.uml2.uml.Interface;
+import org.eclipse.uml2.uml.Model;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.UMLFactory;
import org.junit.Test;
import com.google.common.base.Function;
@@ -88,6 +100,102 @@ public class CDOFunctionsTest extends AbstractPapyrusCDOTest {
assertThat(func.toString(), containsString("adapt("));
}
+ @Test
+ public void testRootFunction() {
+ CDOTransaction transaction = createTransaction();
+
+ Resource res = transaction.createResource(getResourcePath("/folder1/foo.uml"));
+ Package package1 = UMLFactory.eINSTANCE.createPackage();
+ res.getContents().add(package1);
+ Model model1 = UMLFactory.eINSTANCE.createModel();
+ res.getContents().add(model1);
+
+ assertThat(CDOFunctions.getRoot(Model.class).apply(res), sameInstance(model1));
+ assertThat(CDOFunctions.getRoot(Interface.class).apply(res), nullValue());
+ }
+
+ @Test
+ public void testRootFunction_equals() {
+ Function<Resource, Model> func1 = CDOFunctions.getRoot(Model.class);
+ Function<Resource, Package> func2 = CDOFunctions.getRoot(Package.class);
+ Function<Resource, Package> func3 = CDOFunctions.getRoot(Package.class);
+
+ assertThat((Object)func1, not(equalTo((Object)func2)));
+ assertThat((Object)func2, not(equalTo((Object)func1)));
+ assertThat(func2 == func3, is(false));
+ assertThat(func2, equalTo(func3));
+ assertThat(func3, equalTo(func2));
+ }
+
+ @Test
+ public void testRootFunction_hashCode() {
+ Function<Resource, Model> func1 = CDOFunctions.getRoot(Model.class);
+ Function<Resource, Package> func2 = CDOFunctions.getRoot(Package.class);
+ Function<Resource, Package> func3 = CDOFunctions.getRoot(Package.class);
+
+ assertThat(func1.hashCode() == func2.hashCode(), is(Model.class.hashCode() == Package.class.hashCode()));
+ assertThat(func2.hashCode(), is(func3.hashCode()));
+ }
+
+ @Test
+ public void testRootFunction_toString() {
+ Function<Resource, Model> func = CDOFunctions.getRoot(Model.class);
+
+ assertThat(func.toString(), containsString("getRoot("));
+ }
+
+ @Test
+ public void testFolderContentsFunction_folder() {
+ CDOTransaction transaction = createTransaction();
+
+ CDOResourceFolder folder = transaction.createResourceFolder(getResourcePath("/folder1"));
+ CDOResourceNode text = transaction.createTextResource(getResourcePath("/folder1/foo.properties"));
+ CDOResource res = transaction.createResource(getResourcePath("/folder1/foo.uml"));
+
+ assertThat(CDOFunctions.getFolderContents().apply(folder), both(AbstractPapyrusCDOTest.<CDOResourceNode> hasSize(2)).and(hasItems(text, res)));
+ assertThat(CDOFunctions.getFolderContents(CDOResource.class).apply(folder), both(AbstractPapyrusCDOTest.<CDOResource> hasSize(1)).and(hasItem(res)));
+ }
+
+ @Test
+ public void testFolderContentsFunction_rootResource() {
+ CDOTransaction transaction = createTransaction();
+
+ CDOResourceFolder folder = transaction.createResourceFolder(getResourcePath("/folder1"));
+ CDOResourceNode root = transaction.getRootResource();
+
+ assertThat(CDOFunctions.getFolderContents(CDOResourceFolder.class).apply(root), both(AbstractPapyrusCDOTest.<CDOResourceFolder> hasSize(1)).and(hasItem(folder.getFolder().getFolder())));
+ }
+
+ @Test
+ public void testFolderContentsFunction_equals() {
+ Function<CDOResourceNode, Iterable<CDOResourceNode>> func1 = CDOFunctions.getFolderContents();
+ Function<CDOResourceNode, Iterable<CDOTextResource>> func2 = CDOFunctions.getFolderContents(CDOTextResource.class);
+ Function<CDOResourceNode, Iterable<CDOTextResource>> func3 = CDOFunctions.getFolderContents(CDOTextResource.class);
+
+ assertThat((Object)func1, not(equalTo((Object)func2)));
+ assertThat((Object)func2, not(equalTo((Object)func1)));
+ assertThat(func2 == func3, is(false));
+ assertThat(func2, equalTo(func3));
+ assertThat(func3, equalTo(func2));
+ }
+
+ @Test
+ public void testFolderContentsFunction_hashCode() {
+ Function<CDOResourceNode, Iterable<CDOResourceNode>> func1 = CDOFunctions.getFolderContents();
+ Function<CDOResourceNode, Iterable<CDOTextResource>> func2 = CDOFunctions.getFolderContents(CDOTextResource.class);
+ Function<CDOResourceNode, Iterable<CDOTextResource>> func3 = CDOFunctions.getFolderContents(CDOTextResource.class);
+
+ assertThat(func1.hashCode() == func2.hashCode(), is(CDOResourceNode.class.hashCode() == CDOTextResource.class.hashCode()));
+ assertThat(func2.hashCode(), is(func3.hashCode()));
+ }
+
+ @Test
+ public void testFolderContentsFunction_toString() {
+ Function<CDOResourceNode, Iterable<CDOResource>> func = CDOFunctions.getFolderContents(CDOResource.class);
+
+ assertThat(func.toString(), containsString("getFolderContents("));
+ }
+
//
// Test framework
//
diff --git a/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/util/tests/CDOPredicatesTest.java b/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/util/tests/CDOPredicatesTest.java
index 8415e78e093..23b38bc7b12 100644
--- a/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/util/tests/CDOPredicatesTest.java
+++ b/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/util/tests/CDOPredicatesTest.java
@@ -11,19 +11,29 @@
*****************************************************************************/
package org.eclipse.papyrus.cdo.core.util.tests;
+import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
+import java.util.List;
+import java.util.Set;
+
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
+import org.eclipse.emf.cdo.eresource.CDOTextResource;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.papyrus.cdo.core.tests.AbstractPapyrusCDOTest;
import org.eclipse.papyrus.cdo.core.util.CDOPredicates;
import org.junit.Test;
+import com.google.common.base.Objects;
import com.google.common.base.Predicate;
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
/**
@@ -59,6 +69,138 @@ public class CDOPredicatesTest extends AbstractPapyrusCDOTest {
assertThat(pred.apply(adapter), is(true));
}
+ @Test
+ public void testHasExtension() {
+ Predicate<CDOResourceNode> hasUML = CDOPredicates.hasExtension("uml");
+ Predicate<CDOResourceNode> hasNone = CDOPredicates.hasExtension(null);
+ CDOTransaction transaction = createTransaction();
+
+ CDOResource res1 = transaction.createResource(getResourcePath("/folder1/foo.uml"));
+ CDOResource res2 = transaction.createResource(getResourcePath("/folder1/foo.notation"));
+ assertThat(hasUML.apply(res1), is(true));
+ assertThat(hasNone.apply(res1), is(false));
+ assertThat(hasUML.apply(res2), is(false));
+ assertThat(hasNone.apply(res2), is(false));
+
+ CDOResourceFolder folder = res1.getFolder();
+ assertThat(hasUML.apply(folder), is(false));
+ assertThat(hasNone.apply(folder), is(true));
+ assertThat(hasUML.apply(transaction.getRootResource()), is(false));
+ assertThat(hasNone.apply(transaction.getRootResource()), is(true));
+ }
+
+ @Test
+ public void testHasExtension_equals() {
+ Set<Predicate<CDOResourceNode>> set1 = ImmutableSet.of( //
+ CDOPredicates.hasExtension("uml"), //
+ CDOPredicates.hasExtension("notation"), //
+ CDOPredicates.hasExtension(null));
+ Set<Predicate<CDOResourceNode>> set2 = ImmutableSet.of( //
+ CDOPredicates.hasExtension("uml"), //
+ CDOPredicates.hasExtension("notation"), //
+ CDOPredicates.hasExtension(null));
+
+ @SuppressWarnings("unchecked")
+ Set<List<Predicate<CDOResourceNode>>> product = Sets.cartesianProduct(set1, set2);
+
+ int equalPairs = 0;
+ for(List<Predicate<CDOResourceNode>> next : product) {
+ if(next.get(0).equals(next.get(1))) {
+ equalPairs++;
+ }
+ }
+
+ assertThat(equalPairs, is(3));
+ }
+
+ @Test
+ public void testHasExtension_hashCode() {
+ Set<String> set1 = ImmutableSet.of("uml", "notation", "");
+ Set<String> set2 = ImmutableSet.of("uml", "notation", "");
+
+ @SuppressWarnings("unchecked")
+ Set<List<String>> product = Sets.cartesianProduct(set1, set2);
+
+ for(List<String> next : product) {
+ String ext1 = Strings.emptyToNull(next.get(0));
+ String ext2 = Strings.emptyToNull(next.get(1));
+
+ assertThat(CDOPredicates.hasExtension(ext1).hashCode() == CDOPredicates.hasExtension(ext2).hashCode(), //
+ is(Objects.hashCode(ext1) == Objects.hashCode(ext2)));
+ }
+ }
+
+ @Test
+ public void testHasExtension_toString() {
+ assertThat(CDOPredicates.hasExtension("uml").toString(), containsString("hasExtension("));
+ assertThat(CDOPredicates.hasExtension(null).toString(), containsString("hasNoExtension("));
+ }
+
+ @Test
+ public void testHasURIPrefix() {
+ CDOTransaction transaction = createTransaction();
+ CDOResourceFolder folder = transaction.createResourceFolder(getResourcePath("/folder1"));
+ CDOResource res1 = transaction.createResource(getResourcePath("/folder1/foo.uml"));
+ CDOTextResource res2 = transaction.createTextResource(getResourcePath("/folder2/foo.properties"));
+
+ URI prefix = folder.getURI();
+ if(!prefix.hasTrailingPathSeparator()) {
+ prefix = prefix.appendSegment("");
+ }
+
+ Predicate<CDOResourceNode> pred = CDOPredicates.hasURIPrefix(prefix);
+
+ assertThat(pred.apply(folder), is(false));
+ assertThat(pred.apply(res1), is(true));
+ assertThat(pred.apply(res2), is(false));
+ }
+
+ @Test
+ public void testHasURIPrefix_equals() {
+ Set<Predicate<CDOResourceNode>> set1 = ImmutableSet.of( //
+ CDOPredicates.hasURIPrefix(URI.createURI("cdo://repo1/folder1/")), //
+ CDOPredicates.hasURIPrefix(URI.createURI("cdo://repo1/folder2/")), //
+ CDOPredicates.hasURIPrefix(URI.createURI("cdo://repo1/")));
+ Set<Predicate<CDOResourceNode>> set2 = ImmutableSet.of( //
+ CDOPredicates.hasURIPrefix(URI.createURI("cdo://repo1/folder1/")), //
+ CDOPredicates.hasURIPrefix(URI.createURI("cdo://repo1/folder2/")), //
+ CDOPredicates.hasURIPrefix(URI.createURI("cdo://repo1/")));
+
+ @SuppressWarnings("unchecked")
+ Set<List<Predicate<CDOResourceNode>>> product = Sets.cartesianProduct(set1, set2);
+
+ int equalPairs = 0;
+ for(List<Predicate<CDOResourceNode>> next : product) {
+ if(next.get(0).equals(next.get(1))) {
+ equalPairs++;
+ }
+ }
+
+ assertThat(equalPairs, is(3));
+ }
+
+ @Test
+ public void testHasURIPrefix_hashCode() {
+ Set<String> set1 = ImmutableSet.of("cdo://repo1/folder1/", "cdo://repo1/folder2/", "cdo://repo1/");
+ Set<String> set2 = ImmutableSet.of("cdo://repo1/folder1/", "cdo://repo1/folder2/", "cdo://repo1/");
+
+ @SuppressWarnings("unchecked")
+ Set<List<String>> product = Sets.cartesianProduct(set1, set2);
+
+ for(List<String> next : product) {
+ URI uri1 = URI.createURI(next.get(0));
+ URI uri2 = URI.createURI(next.get(1));
+
+ assertThat(CDOPredicates.hasURIPrefix(uri1).hashCode() == CDOPredicates.hasURIPrefix(uri2).hashCode(), //
+ is(Objects.hashCode(uri1) == Objects.hashCode(uri2)));
+ }
+ }
+
+ @Test
+ public void testHasURIPrefix_toString() {
+ assertThat(CDOPredicates.hasURIPrefix(URI.createURI("cdo://repo1/folder1/")).toString(), containsString("hasURIPrefix("));
+ }
+
//
// Test framework
//
diff --git a/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/util/tests/JobWaiterTest.java b/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/util/tests/JobWaiterTest.java
new file mode 100644
index 00000000000..a5cad7a36c1
--- /dev/null
+++ b/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.core.tests/src/org/eclipse/papyrus/cdo/core/util/tests/JobWaiterTest.java
@@ -0,0 +1,157 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.cdo.core.util.tests;
+
+import static org.eclipse.papyrus.cdo.core.tests.AbstractPapyrusCDOTest.lessThan;
+import static org.eclipse.papyrus.cdo.core.tests.AbstractPapyrusCDOTest.lessThanOrEqualTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.List;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.papyrus.cdo.core.util.JobWaiter;
+import org.junit.After;
+import org.junit.Test;
+
+import com.google.common.base.Stopwatch;
+import com.google.common.collect.Lists;
+
+
+/**
+ * This is the JobWaiterTest type. Enjoy.
+ */
+public class JobWaiterTest {
+
+ private Stopwatch watch = new Stopwatch();
+
+ private List<TestJob> jobsToClean = Lists.newArrayListWithExpectedSize(1);
+
+ @Test
+ public void testWaitForJob() throws InterruptedException {
+ Job job = new TestJob(3).start();
+
+ watch.start();
+ boolean done = JobWaiter.waitFor(job, 10, TimeUnit.SECONDS);
+ watch.stop();
+
+ assertThat(done, is(true));
+ assertThat(watch.elapsedTime(TimeUnit.SECONDS), lessThanOrEqualTo(3L));
+ }
+
+ @Test
+ public void testWaitForFamily() throws InterruptedException {
+ for(int i = 0; i < 3; i++) {
+ new TestJob(3).start();
+ }
+
+ watch.start();
+ boolean done = JobWaiter.waitFor(this, 10, TimeUnit.SECONDS);
+ watch.stop();
+
+ assertThat(done, is(true));
+ assertThat(watch.elapsedTime(TimeUnit.SECONDS), lessThanOrEqualTo(3L));
+ }
+
+ @Test
+ public void testWaitForJob_timeout() throws InterruptedException {
+ Job job = new TestJob(10).start();
+
+ watch.start();
+ boolean done = JobWaiter.waitFor(job, 3, TimeUnit.SECONDS);
+ watch.stop();
+
+ assertThat(done, is(false));
+ assertThat(watch.elapsedTime(TimeUnit.SECONDS), lessThan(5L));
+ }
+
+ @Test
+ public void testWaitForFamily_timeout() throws InterruptedException {
+ for(int i = 0; i < 3; i++) {
+ new TestJob(10).start();
+ }
+
+ watch.start();
+ boolean done = JobWaiter.waitFor(this, 3, TimeUnit.SECONDS);
+ watch.stop();
+
+ assertThat(done, is(false));
+ assertThat(watch.elapsedTime(TimeUnit.SECONDS), lessThan(5L));
+ }
+
+ //
+ // Test framework
+ //
+
+ @After
+ public void cleanUpJob() throws InterruptedException {
+ for(Job next : jobsToClean) {
+ next.cancel();
+ }
+
+ Job.getJobManager().join(this, null);
+ }
+
+ private class TestJob extends Job {
+
+ private final int iterations;
+
+ private final AtomicBoolean cancelled = new AtomicBoolean();
+
+ private Semaphore startSema = new Semaphore(0);
+
+ TestJob(int iterations) {
+ super("Test Job");
+
+ this.iterations = iterations;
+
+ jobsToClean.add(this);
+ }
+
+ @Override
+ public boolean belongsTo(Object family) {
+ return family == JobWaiterTest.this;
+ }
+
+ @Override
+ protected void canceling() {
+ cancelled.set(true);
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ startSema.release();
+
+ for(int i = iterations; (i > 0) && !cancelled.get(); i--) {
+ try {
+ Thread.sleep(1000L);
+ } catch (Exception e) {
+ // fine. Keep going
+ }
+ }
+
+ return Status.OK_STATUS;
+ }
+
+ TestJob start() throws InterruptedException {
+ schedule();
+ startSema.acquire();
+ return this;
+ }
+ }
+}
diff --git a/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.ui.tests/src/org/eclipse/papyrus/cdo/internal/ui/editors/tests/DawnEditorAdapterTest.java b/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.ui.tests/src/org/eclipse/papyrus/cdo/internal/ui/editors/tests/DawnEditorAdapterTest.java
index 8ad80e7dde0..e7b5132371a 100644
--- a/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.ui.tests/src/org/eclipse/papyrus/cdo/internal/ui/editors/tests/DawnEditorAdapterTest.java
+++ b/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.ui.tests/src/org/eclipse/papyrus/cdo/internal/ui/editors/tests/DawnEditorAdapterTest.java
@@ -17,6 +17,7 @@ import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertThat;
+import static org.junit.Assume.assumeThat;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.cdo.dawn.editors.IDawnEditor;
@@ -36,6 +37,7 @@ import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IPropertyListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartSite;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.uml2.uml.Class;
import org.junit.Before;
import org.junit.Test;
@@ -172,6 +174,12 @@ public class DawnEditorAdapterTest extends AbstractPapyrusCDOUITest {
getRepositoryExplorer().setFocus();
flushDisplayEvents();
+ // when running the tests while using some other application, the workbench
+ // window doesn't have focus, so other focus changes don't work and we
+ // get spurious test failures.
+ IWorkbenchWindow window = getWorkbenchPage().getWorkbenchWindow();
+ assumeThat(window.getShell().getDisplay().getActiveShell(), is(window.getShell()));
+
assertThat(getWorkbenchPage().getActivePart(), not((IWorkbenchPart)getEditor()));
fixture.setFocus();
diff --git a/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.uml.ui.tests/src/org/eclipse/papyrus/cdo/uml/internal/ui/importsources/tests/CDOPackageImportSourceTest.java b/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.uml.ui.tests/src/org/eclipse/papyrus/cdo/uml/internal/ui/importsources/tests/CDOPackageImportSourceTest.java
index 585c57b75d2..5f6aa87ae38 100644
--- a/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.uml.ui.tests/src/org/eclipse/papyrus/cdo/uml/internal/ui/importsources/tests/CDOPackageImportSourceTest.java
+++ b/tests/junit/extraplugins/cdo/org.eclipse.papyrus.cdo.uml.ui.tests/src/org/eclipse/papyrus/cdo/uml/internal/ui/importsources/tests/CDOPackageImportSourceTest.java
@@ -23,6 +23,7 @@ import static org.junit.Assert.fail;
import java.util.Arrays;
import java.util.List;
+import java.util.concurrent.TimeUnit;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.emf.cdo.eresource.CDOResource;
@@ -31,6 +32,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.papyrus.cdo.internal.ui.views.DIModel;
+import org.eclipse.papyrus.cdo.internal.ui.views.DIResourceQuery;
import org.eclipse.papyrus.cdo.ui.tests.AbstractPapyrusCDOUITest;
import org.eclipse.papyrus.cdo.uml.internal.ui.importsources.CDOPackageImportSource;
import org.eclipse.papyrus.infra.core.resource.AbstractBaseModel;
@@ -76,7 +78,7 @@ public class CDOPackageImportSourceTest extends AbstractPapyrusCDOUITest {
}
@Test
- public void testCreateModelHierarchyContentProvider() {
+ public void testCreateModelHierarchyContentProvider() throws InterruptedException {
IStaticContentProvider provider = fixture.getModelHierarchyContentProvider();
assertThat(provider, instanceOf(ITreeContentProvider.class));
@@ -86,6 +88,10 @@ public class CDOPackageImportSourceTest extends AbstractPapyrusCDOUITest {
ITreeContentProvider treeContent = (ITreeContentProvider)provider;
+ // trigger the asynchronous DIResourceQuery and wait for it to finish
+ treeContent.getChildren(getInternalPapyrusRepository());
+ DIResourceQuery.waitFor(getInternalPapyrusRepository().getMasterView(), 10, TimeUnit.SECONDS);
+
Object[] children = treeContent.getChildren(folder);
assertThat(Arrays.asList(children), hasItem((Object)model));
assertThat(treeContent.getParent(model), sameInstance((Object)model.getResource().getFolder()));

Back to the top