[UI Tests] Adding a RepositoryListener in charge of detecting when a
remote notification is done. Updating the test framework and wait
conditions
diff --git a/plugins/org.eclipse.mylyn.docs.intent.collab/src/org/eclipse/mylyn/docs/intent/collab/handlers/impl/AbstractRepositoryObjectHandler.java b/plugins/org.eclipse.mylyn.docs.intent.collab/src/org/eclipse/mylyn/docs/intent/collab/handlers/impl/AbstractRepositoryObjectHandler.java
index c0a1184..5228d35 100644
--- a/plugins/org.eclipse.mylyn.docs.intent.collab/src/org/eclipse/mylyn/docs/intent/collab/handlers/impl/AbstractRepositoryObjectHandler.java
+++ b/plugins/org.eclipse.mylyn.docs.intent.collab/src/org/eclipse/mylyn/docs/intent/collab/handlers/impl/AbstractRepositoryObjectHandler.java
@@ -14,6 +14,10 @@
import java.util.List;
import java.util.Set;
+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.mylyn.docs.intent.collab.handlers.LockMode;
import org.eclipse.mylyn.docs.intent.collab.handlers.RepositoryClient;
import org.eclipse.mylyn.docs.intent.collab.handlers.RepositoryObjectHandler;
@@ -166,9 +170,20 @@
*
* @see org.eclipse.mylyn.docs.intent.collab.handlers.RepositoryObjectHandler#handleChangeNotification(org.eclipse.mylyn.docs.intent.collab.handlers.notification.RepositoryChangeNotification)
*/
- public void handleChangeNotification(RepositoryChangeNotification notification) {
- for (RepositoryClient client : subscribedClients) {
- client.handleChangeNotification(notification);
+ public void handleChangeNotification(final RepositoryChangeNotification notification) {
+ if (!subscribedClients.isEmpty()) {
+ Job notifyClientsJob = new Job("Notifying Intent clients") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ for (RepositoryClient client : subscribedClients) {
+ client.handleChangeNotification(notification);
+ }
+ return Status.OK_STATUS;
+ }
+
+ };
+ notifyClientsJob.schedule();
}
}
}
diff --git a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/compare/ChangeEditorUpdateTest.java b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/compare/ChangeEditorUpdateTest.java
index 9dd7b6c..7e2254c 100644
--- a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/compare/ChangeEditorUpdateTest.java
+++ b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/compare/ChangeEditorUpdateTest.java
@@ -13,7 +13,7 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.mylyn.docs.intent.client.ui.editor.IntentEditor;
import org.eclipse.mylyn.docs.intent.client.ui.editor.IntentEditorDocument;
-import org.eclipse.mylyn.docs.intent.client.ui.test.util.AbstractUITest;
+import org.eclipse.mylyn.docs.intent.client.ui.test.util.AbstractIntentUITest;
import org.eclipse.mylyn.docs.intent.core.document.IntentSection;
/**
@@ -23,7 +23,7 @@
* @author <a href="mailto:alex.lagarde@obeo.fr">Alex Lagarde</a>
* @author <a href="mailto:william.piers@obeo.fr">William Piers</a>
*/
-public class ChangeEditorUpdateTest extends AbstractUITest {
+public class ChangeEditorUpdateTest extends AbstractIntentUITest {
private static final String FAILURE_MESSAGE = "Editor update dit not occur has expected";
@@ -39,7 +39,7 @@
private static final String PREFIX_CHAPTER_2 = "\t}\n\tChapter {";
- private static String INTENT_DOCUMENT_EXAMPLE_PATH = "data/unit/documents/editorupdates/changeEditorUpdateTest.intent";
+ private static final String INTENT_DOCUMENT_EXAMPLE_PATH = "data/unit/documents/editorupdates/changeEditorUpdateTest.intent";
private IntentSection section;
diff --git a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/AbstractDemoTest.java b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/AbstractDemoTest.java
index b357278..da7cddf 100644
--- a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/AbstractDemoTest.java
+++ b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/AbstractDemoTest.java
@@ -1,57 +1,58 @@
-/*******************************************************************************
- * Copyright (c) 2011 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.mylyn.docs.intent.client.ui.test.unit.demo;
-
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.mylyn.docs.intent.client.ui.test.util.AbstractUITest;
-import org.eclipse.mylyn.docs.intent.client.ui.test.util.WorkspaceUtils;
-
-/**
- * Tests the Intent demo, part 1: navigation behavior.
- *
- * @author <a href="mailto:william.piers@obeo.fr">William Piers</a>
- */
-public abstract class AbstractDemoTest extends AbstractUITest {
-
- protected static final String TEST_COMPILER_NO_ERROR_MSG = "The compiler failed to detect errors";
-
- protected static final String TEST_COMPILER_INVALID_ERROR_MSG = "The compiler detected invalid errors";
-
- protected static final String TEST_COMPILER_NO_INFO_MSG = "The compiler failed to detect infos";
-
- protected static final String TEST_COMPILER_INVALID_INFO_MSG = "The compiler detected invalid infos";
-
- protected static final String TEST_SYNCHRONIZER_NO_WARNING_MSG = "The synchronizer failed to detect errors";
-
- protected static final String TEST_SYNCHRONIZER_INVALID_WARNING_MSG = "The synchronizer failed to detect errors";
-
- private static final String DEMO_ZIP_LOCATION = "data/unit/demo/demo.zip";
-
- private static final String BUNDLE_NAME = "org.eclipse.mylyn.docs.intent.client.ui.test";
-
- private static final String INTENT_PROJECT_NAME = "org.eclipse.emf.compare.idoc";
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.mylyn.docs.intent.client.ui.test.util.AbstractUITest#setUp()
- */
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- WorkspaceUtils.unzipAllProjects(BUNDLE_NAME, DEMO_ZIP_LOCATION, new NullProgressMonitor());
- intentProject = ResourcesPlugin.getWorkspace().getRoot().getProject(INTENT_PROJECT_NAME);
- setUpRepository(intentProject);
- waitForIndexer();
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2011 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.docs.intent.client.ui.test.unit.demo;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.mylyn.docs.intent.client.ui.test.util.AbstractIntentUITest;
+import org.eclipse.mylyn.docs.intent.client.ui.test.util.WorkspaceUtils;
+
+/**
+ * Tests the Intent demo, part 1: navigation behavior.
+ *
+ * @author <a href="mailto:william.piers@obeo.fr">William Piers</a>
+ */
+public abstract class AbstractDemoTest extends AbstractIntentUITest {
+
+ protected static final String TEST_COMPILER_NO_ERROR_MSG = "The compiler failed to detect errors";
+
+ protected static final String TEST_COMPILER_INVALID_ERROR_MSG = "The compiler detected invalid errors";
+
+ protected static final String TEST_COMPILER_NO_INFO_MSG = "The compiler failed to detect infos";
+
+ protected static final String TEST_COMPILER_INVALID_INFO_MSG = "The compiler detected invalid infos";
+
+ protected static final String TEST_SYNCHRONIZER_NO_WARNING_MSG = "The synchronizer failed to detect errors";
+
+ protected static final String TEST_SYNCHRONIZER_INVALID_WARNING_MSG = "The synchronizer failed to detect errors";
+
+ private static final String DEMO_ZIP_LOCATION = "data/unit/demo/demo.zip";
+
+ private static final String BUNDLE_NAME = "org.eclipse.mylyn.docs.intent.client.ui.test";
+
+ private static final String INTENT_PROJECT_NAME = "org.eclipse.emf.compare.idoc";
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.mylyn.docs.intent.client.ui.test.util.AbstractIntentUITest#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ WorkspaceUtils.unzipAllProjects(BUNDLE_NAME, DEMO_ZIP_LOCATION, new NullProgressMonitor());
+ intentProject = ResourcesPlugin.getWorkspace().getRoot().getProject(INTENT_PROJECT_NAME);
+ setUpRepository(intentProject);
+ registerRepositoryListener();
+ // waitForIndexer();
+ }
+
+}
diff --git a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/compilation/CompileTest.java b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/compilation/CompileTest.java
index aeb88ce..c3068a8 100644
--- a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/compilation/CompileTest.java
+++ b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/compilation/CompileTest.java
@@ -1,111 +1,119 @@
-/*******************************************************************************
- * Copyright (c) 2011 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.mylyn.docs.intent.client.ui.test.unit.demo.compilation;
-
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.mylyn.docs.intent.client.ui.editor.IntentEditor;
-import org.eclipse.mylyn.docs.intent.client.ui.editor.IntentEditorDocument;
-import org.eclipse.mylyn.docs.intent.client.ui.editor.annotation.IntentAnnotationMessageType;
-import org.eclipse.mylyn.docs.intent.client.ui.test.unit.demo.AbstractDemoTest;
-import org.eclipse.mylyn.docs.intent.client.ui.test.util.AnnotationUtils;
-
-/**
- * Tests the Intent demo, part 2: compilation behavior.
- *
- * @author <a href="mailto:william.piers@obeo.fr">William Piers</a>
- */
-public class CompileTest extends AbstractDemoTest {
-
- private static final String ERROR_TEXT_PATTERN = "nsPrefixx = \"match\";";
-
- private static final String NO_ERROR_TEXT_PATTERN = "nsPrefix = \"match\";";
-
- private static final String COMPILATION_ERROR_MESSAGE = "The feature nsPrefixx doesn't exists in EPackage";
-
- private static final String INFOS_TEXT_PATTERN = "nsURI = \"\";";
-
- private static final String NO_INFOS_TEXT_PATTERN = "nsURI = \"http://www.eclipse.org/emf/compare/match/1.1\";";
-
- private static final String COMPILATION_INFO_MESSAGE = "-The namespace URI '' is not well formed";
-
- private IntentEditor editor;
-
- private IntentEditorDocument document;
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.mylyn.docs.intent.client.ui.test.unit.demo.AbstractDemoTest#setUp()
- */
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- // Initialization : opening an editor on the document
- editor = openIntentEditor(getIntentSection(4, 1));
- document = (IntentEditorDocument)editor.getDocumentProvider().getDocument(editor.getEditorInput());
- }
-
- /**
- * Ensures that compilation errors are detected and can be fixed.
- */
- public void testCompilationErrors() {
- // Step 1 : update section by adding incorrect content
- String initialContent = document.get();
- String newContent = initialContent.replaceFirst(NO_ERROR_TEXT_PATTERN, ERROR_TEXT_PATTERN);
- document.set(newContent);
- editor.doSave(new NullProgressMonitor());
-
- waitForCompiler();
-
- // Step 2 : ensure that the compilation error has been detected
- assertTrue(TEST_COMPILER_NO_ERROR_MSG, AnnotationUtils.hasIntentAnnotation(editor,
- IntentAnnotationMessageType.COMPILER_ERROR, COMPILATION_ERROR_MESSAGE, true));
-
- // Step 3 : fix the error by resetting the content
- document.set(initialContent);
- editor.doSave(new NullProgressMonitor());
-
- waitForCompiler();
-
- // Step 4 : ensure that the compilation error no longer exists
- assertFalse(TEST_COMPILER_INVALID_ERROR_MSG, AnnotationUtils.hasIntentAnnotation(editor,
- IntentAnnotationMessageType.COMPILER_ERROR, COMPILATION_ERROR_MESSAGE, true));
- }
-
- /**
- * Ensures that compilation informations are detected and can be fixed.
- */
- public void testCompilationInfos() {
- // Step 1 : update section by adding incorrect content
- String initialContent = document.get();
- String newContent = initialContent.replaceFirst(NO_INFOS_TEXT_PATTERN, INFOS_TEXT_PATTERN);
- document.set(newContent);
- editor.doSave(new NullProgressMonitor());
-
- waitForCompiler();
-
- // Step 2 : ensure that the compilation info has been detected
- assertTrue(TEST_COMPILER_NO_INFO_MSG, AnnotationUtils.hasIntentAnnotation(editor,
- IntentAnnotationMessageType.COMPILER_INFO, COMPILATION_INFO_MESSAGE, true));
-
- // Step 3 : fix the info by resetting the content
- document.set(initialContent);
- editor.doSave(new NullProgressMonitor());
-
- waitForCompiler();
-
- // Step 4 : ensure that the compilation info no longer exists
- assertFalse(TEST_COMPILER_INVALID_INFO_MSG, AnnotationUtils.hasIntentAnnotation(editor,
- IntentAnnotationMessageType.COMPILER_INFO, COMPILATION_INFO_MESSAGE, true));
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2011 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.docs.intent.client.ui.test.unit.demo.compilation;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.mylyn.docs.intent.client.ui.editor.IntentEditor;
+import org.eclipse.mylyn.docs.intent.client.ui.editor.IntentEditorDocument;
+import org.eclipse.mylyn.docs.intent.client.ui.editor.annotation.IntentAnnotationMessageType;
+import org.eclipse.mylyn.docs.intent.client.ui.test.unit.demo.AbstractDemoTest;
+import org.eclipse.mylyn.docs.intent.client.ui.test.util.AnnotationUtils;
+
+/**
+ * Tests the Intent demo, part 2: compilation behavior.
+ *
+ * @author <a href="mailto:william.piers@obeo.fr">William Piers</a>
+ */
+public class CompileTest extends AbstractDemoTest {
+
+ private static final String ERROR_TEXT_PATTERN = "nsPrefixx = \"match\";";
+
+ private static final String NO_ERROR_TEXT_PATTERN = "nsPrefix = \"match\";";
+
+ private static final String COMPILATION_ERROR_MESSAGE = "The feature nsPrefixx doesn't exists in EPackage";
+
+ private static final String INFOS_TEXT_PATTERN = "nsURI = \"\";";
+
+ private static final String NO_INFOS_TEXT_PATTERN = "nsURI = \"http://www.eclipse.org/emf/compare/match/1.1\";";
+
+ private static final String COMPILATION_INFO_MESSAGE = "-The namespace URI '' is not well formed";
+
+ private IntentEditor editor;
+
+ private IntentEditorDocument document;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.mylyn.docs.intent.client.ui.test.unit.demo.AbstractDemoTest#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // Initialization : opening an editor on the document
+ editor = openIntentEditor(getIntentSection(4, 1));
+ document = (IntentEditorDocument)editor.getDocumentProvider().getDocument(editor.getEditorInput());
+ }
+
+ /**
+ * Ensures that compilation errors are detected and can be fixed.
+ */
+ public void testCompilationErrors() {
+ // Step 1 : update section by adding incorrect content
+ String initialContent = document.get();
+ String newContent = initialContent.replaceFirst(NO_ERROR_TEXT_PATTERN, ERROR_TEXT_PATTERN);
+ document.set(newContent);
+
+ // Step 2 : we start recording for any modification made on the repository
+ repositoryListener.startRecording();
+ // save
+ editor.doSave(new NullProgressMonitor());
+ // and wait the compiler to be notified
+ waitForCompiler();
+
+ // Step 3 : ensure that the compilation error has been detected
+ assertTrue(TEST_COMPILER_NO_ERROR_MSG, AnnotationUtils.hasIntentAnnotation(editor,
+ IntentAnnotationMessageType.COMPILER_ERROR, COMPILATION_ERROR_MESSAGE, true));
+
+ // Step 4 : fix the error by resetting the content
+ document.set(initialContent);
+ editor.doSave(new NullProgressMonitor());
+
+ waitForCompiler();
+
+ // Step 5 : ensure that the compilation error no longer exists
+ assertFalse(TEST_COMPILER_INVALID_ERROR_MSG, AnnotationUtils.hasIntentAnnotation(editor,
+ IntentAnnotationMessageType.COMPILER_ERROR, COMPILATION_ERROR_MESSAGE, true));
+ }
+
+ /**
+ * Ensures that compilation informations are detected and can be fixed.
+ */
+ public void testCompilationInfos() {
+ // Step 1 : update section by adding incorrect content
+ String initialContent = document.get();
+ String newContent = initialContent.replaceFirst(NO_INFOS_TEXT_PATTERN, INFOS_TEXT_PATTERN);
+ document.set(newContent);
+
+ // Step 2 : we start recording for any modification made on the repository
+ repositoryListener.startRecording();
+ // save
+ editor.doSave(new NullProgressMonitor());
+ // and wait the compiler to be notified
+ waitForCompiler();
+
+ // Step 2 : ensure that the compilation info has been detected
+ assertTrue(TEST_COMPILER_NO_INFO_MSG, AnnotationUtils.hasIntentAnnotation(editor,
+ IntentAnnotationMessageType.COMPILER_INFO, COMPILATION_INFO_MESSAGE, true));
+
+ // Step 3 : fix the info by resetting the content
+ document.set(initialContent);
+ repositoryListener.startRecording();
+ editor.doSave(new NullProgressMonitor());
+ waitForCompiler();
+
+ // Step 4 : ensure that the compilation info no longer exists
+ assertFalse(TEST_COMPILER_INVALID_INFO_MSG, AnnotationUtils.hasIntentAnnotation(editor,
+ IntentAnnotationMessageType.COMPILER_INFO, COMPILATION_INFO_MESSAGE, true));
+ }
+
+}
diff --git a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/synchronization/EcoreTest.java b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/synchronization/EcoreTest.java
index 6af12cf..507a983 100644
--- a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/synchronization/EcoreTest.java
+++ b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/synchronization/EcoreTest.java
@@ -1,148 +1,155 @@
-/*******************************************************************************
- * Copyright (c) 2011 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.mylyn.docs.intent.client.ui.test.unit.demo.synchronization;
-
-import java.io.IOException;
-
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EEnum;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.mylyn.docs.intent.client.ui.editor.IntentEditor;
-import org.eclipse.mylyn.docs.intent.client.ui.editor.IntentEditorDocument;
-import org.eclipse.mylyn.docs.intent.client.ui.editor.annotation.IntentAnnotation;
-import org.eclipse.mylyn.docs.intent.client.ui.editor.annotation.IntentAnnotationMessageType;
-import org.eclipse.mylyn.docs.intent.client.ui.test.unit.demo.AbstractDemoTest;
-import org.eclipse.mylyn.docs.intent.client.ui.test.util.AnnotationUtils;
-
-/**
- * Tests the Intent demo, part 3: Ecore synchronization behavior.
- *
- * @author <a href="mailto:william.piers@obeo.fr">William Piers</a>
- */
-public class EcoreTest extends AbstractDemoTest {
-
- private static final String SYNC_WARNING_MESSAGE_RIGHT = "EAttribute literal in Right has changed.<br/><b>Current Document</b> : Right<br/><b>Working Copy</b> : New";
-
- private static final String SYNC_WARNING_MESSAGE_LEFT = "EAttribute literal in Left has changed.<br/><b>Current Document</b> : Left<br/><b>Working Copy</b> : Old";
-
- private static final String SYNC_WARNING_MESSAGE_ANCESTOR = "The EEnumLiteral Ancestor is defined in the <b>Current Document</b> model<br/>but not in the <b>Working Copy</b> model.";
-
- private static final String MATCH_MODEL_URI = "platform:/resource/org.eclipse.emf.compare.match/model/match.ecore";
-
- private static final int INSERTION_INDEX = 912;
-
- private static final String NEW_LITERAL_STRING = "\n\t\t\t\teLiterals += new EEnumLiteral {\n\t\t\t\t\tname = \"Ancestor\";\n\t\t\t\t\tliteral = \"Ancestor\";\n\t\t\t\t\tvalue = \"2\";\n\t\t\t\t};";
-
- private IntentEditor editor;
-
- private IntentEditorDocument document;
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.mylyn.docs.intent.client.ui.test.unit.demo.AbstractDemoTest#setUp()
- */
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- // Initialization : opening an editor on the document
- editor = openIntentEditor(getIntentSection(4, 3, 3));
- document = (IntentEditorDocument)editor.getDocumentProvider().getDocument(editor.getEditorInput());
- }
-
- /**
- * Ensures that synchronization errors between an Ecore model and a document are detected and can be
- * fixed.
- *
- * @throws IOException
- * can happen during model saving
- */
- public void testModelChangeSynchronization() throws IOException {
- // Step 1 : modify the match.ecore model
- ResourceSet rs = new ResourceSetImpl();
- URI modelURI = URI.createURI(MATCH_MODEL_URI);
- Resource modelResource = rs.getResource(modelURI, true);
- EPackage matchPackage = (EPackage)modelResource.getContents().get(0);
- EEnum sideEnum = (EEnum)matchPackage.getEClassifier("Side");
- sideEnum.getEEnumLiteral("Left").setLiteral("Old");
- sideEnum.getEEnumLiteral("Right").setLiteral("New");
- modelResource.save(null);
-
- waitForCompiler();
- waitForSynchronizer();
-
- // Step 2 : ensure that synchronization issues are detected
- assertTrue(TEST_SYNCHRONIZER_NO_WARNING_MSG, AnnotationUtils.hasIntentAnnotation(editor,
- IntentAnnotationMessageType.SYNC_WARNING, SYNC_WARNING_MESSAGE_LEFT, true));
- assertTrue(TEST_SYNCHRONIZER_NO_WARNING_MSG, AnnotationUtils.hasIntentAnnotation(editor,
- IntentAnnotationMessageType.SYNC_WARNING, SYNC_WARNING_MESSAGE_RIGHT, true));
-
- // Step 3 : update the document
- String initialContent = document.get();
- String newContent = initialContent;
- newContent = newContent.replaceFirst("literal = \"Left\"", "literal = \"Old\"");
- newContent = newContent.replaceFirst("literal = \"Right\"", "literal = \"New\"");
- document.set(newContent);
- editor.doSave(new NullProgressMonitor());
-
- waitForCompiler();
- waitForSynchronizer();
-
- // Step 4 : ensure that synchronization issues no longer exists
- assertFalse(TEST_SYNCHRONIZER_INVALID_WARNING_MSG, AnnotationUtils.hasIntentAnnotation(editor,
- IntentAnnotationMessageType.SYNC_WARNING, SYNC_WARNING_MESSAGE_LEFT, true));
- assertFalse(TEST_SYNCHRONIZER_INVALID_WARNING_MSG, AnnotationUtils.hasIntentAnnotation(editor,
- IntentAnnotationMessageType.SYNC_WARNING, SYNC_WARNING_MESSAGE_RIGHT, true));
-
- }
-
- /**
- * Ensures that synchronization errors between a document and an Ecore model are detected and can be
- * fixed.
- *
- * @throws IOException
- * if applying fix fails
- * @throws InterruptedException
- * if comparison fails
- */
- public void testDocumentChangeSynchronization() throws IOException, InterruptedException {
- // Step 1 : make additions to the document
- String initialContent = document.get();
- String newContent = initialContent.substring(0, INSERTION_INDEX) + NEW_LITERAL_STRING
- + initialContent.substring(INSERTION_INDEX, initialContent.length());
- document.set(newContent);
- editor.doSave(new NullProgressMonitor());
-
- waitForCompiler();
- waitForSynchronizer();
-
- // Step 2 : ensure that synchronization issues are detected
- IntentAnnotation annotation = AnnotationUtils.getIntentAnnotation(editor,
- IntentAnnotationMessageType.SYNC_WARNING, SYNC_WARNING_MESSAGE_ANCESTOR, true);
- assertNotNull(TEST_SYNCHRONIZER_NO_WARNING_MSG, annotation);
-
- // Step 3 : apply quick fix
- AnnotationUtils.applyAnnotationFix(annotation);
-
- waitForCompiler();
- waitForSynchronizer();
-
- // Step 4 : ensure that synchronization issues no longer exists
- assertFalse(TEST_SYNCHRONIZER_INVALID_WARNING_MSG, AnnotationUtils.hasIntentAnnotation(editor,
- IntentAnnotationMessageType.SYNC_WARNING, SYNC_WARNING_MESSAGE_ANCESTOR, true));
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2011 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.docs.intent.client.ui.test.unit.demo.synchronization;
+
+import java.io.IOException;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EEnum;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.mylyn.docs.intent.client.ui.editor.IntentEditor;
+import org.eclipse.mylyn.docs.intent.client.ui.editor.IntentEditorDocument;
+import org.eclipse.mylyn.docs.intent.client.ui.editor.annotation.IntentAnnotation;
+import org.eclipse.mylyn.docs.intent.client.ui.editor.annotation.IntentAnnotationMessageType;
+import org.eclipse.mylyn.docs.intent.client.ui.test.unit.demo.AbstractDemoTest;
+import org.eclipse.mylyn.docs.intent.client.ui.test.util.AnnotationUtils;
+
+/**
+ * Tests the Intent demo, part 3: Ecore synchronization behavior.
+ *
+ * @author <a href="mailto:william.piers@obeo.fr">William Piers</a>
+ */
+public class EcoreTest extends AbstractDemoTest {
+
+ private static final String SYNC_WARNING_MESSAGE_RIGHT = "EAttribute literal in Right has changed.<br/><b>Current Document</b> : Right<br/><b>Working Copy</b> : New";
+
+ private static final String SYNC_WARNING_MESSAGE_LEFT = "EAttribute literal in Left has changed.<br/><b>Current Document</b> : Left<br/><b>Working Copy</b> : Old";
+
+ private static final String SYNC_WARNING_MESSAGE_ANCESTOR = "The EEnumLiteral Ancestor is defined in the <b>Current Document</b> model<br/>but not in the <b>Working Copy</b> model.";
+
+ private static final String MATCH_MODEL_URI = "platform:/resource/org.eclipse.emf.compare.match/model/match.ecore";
+
+ private static final int INSERTION_INDEX = 912;
+
+ private static final String NEW_LITERAL_STRING = "\n\t\t\t\teLiterals += new EEnumLiteral {\n\t\t\t\t\tname = \"Ancestor\";\n\t\t\t\t\tliteral = \"Ancestor\";\n\t\t\t\t\tvalue = \"2\";\n\t\t\t\t};";
+
+ private IntentEditor editor;
+
+ private IntentEditorDocument document;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.mylyn.docs.intent.client.ui.test.unit.demo.AbstractDemoTest#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // Initialization : opening an editor on the document
+ editor = openIntentEditor(getIntentSection(4, 3, 3));
+ document = (IntentEditorDocument)editor.getDocumentProvider().getDocument(editor.getEditorInput());
+ }
+
+ /**
+ * Ensures that synchronization errors between an Ecore model and a document are detected and can be
+ * fixed.
+ *
+ * @throws IOException
+ * can happen during model saving
+ */
+ public void testModelChangeSynchronization() throws IOException {
+ // Step 1 : modify the match.ecore model
+ ResourceSet rs = new ResourceSetImpl();
+ URI modelURI = URI.createURI(MATCH_MODEL_URI);
+ Resource modelResource = rs.getResource(modelURI, true);
+ EPackage matchPackage = (EPackage)modelResource.getContents().get(0);
+ EEnum sideEnum = (EEnum)matchPackage.getEClassifier("Side");
+ sideEnum.getEEnumLiteral("Left").setLiteral("Old");
+ sideEnum.getEEnumLiteral("Right").setLiteral("New");
+
+ // we start recording for any modification made on the repository
+ repositoryListener.startRecording();
+ // save the changes made on the match.ecore model
+ modelResource.save(null);
+ // and wait the synchronizer to be notified
+ waitForSynchronizer();
+
+ // Step 2 : ensure that synchronization issues are detected
+ assertTrue(TEST_SYNCHRONIZER_NO_WARNING_MSG, AnnotationUtils.hasIntentAnnotation(editor,
+ IntentAnnotationMessageType.SYNC_WARNING, SYNC_WARNING_MESSAGE_LEFT, true));
+ assertTrue(TEST_SYNCHRONIZER_NO_WARNING_MSG, AnnotationUtils.hasIntentAnnotation(editor,
+ IntentAnnotationMessageType.SYNC_WARNING, SYNC_WARNING_MESSAGE_RIGHT, true));
+
+ // Step 3 : update the document
+ String initialContent = document.get();
+ String newContent = initialContent;
+ newContent = newContent.replaceFirst("literal = \"Left\"", "literal = \"Old\"");
+ newContent = newContent.replaceFirst("literal = \"Right\"", "literal = \"New\"");
+ document.set(newContent);
+ editor.doSave(new NullProgressMonitor());
+
+ waitForCompiler();
+ waitForSynchronizer();
+
+ // Step 4 : ensure that synchronization issues no longer exists
+ assertFalse(TEST_SYNCHRONIZER_INVALID_WARNING_MSG, AnnotationUtils.hasIntentAnnotation(editor,
+ IntentAnnotationMessageType.SYNC_WARNING, SYNC_WARNING_MESSAGE_LEFT, true));
+ assertFalse(TEST_SYNCHRONIZER_INVALID_WARNING_MSG, AnnotationUtils.hasIntentAnnotation(editor,
+ IntentAnnotationMessageType.SYNC_WARNING, SYNC_WARNING_MESSAGE_RIGHT, true));
+
+ }
+
+ /**
+ * Ensures that synchronization errors between a document and an Ecore model are detected and can be
+ * fixed.
+ *
+ * @throws IOException
+ * if applying fix fails
+ * @throws InterruptedException
+ * if comparison fails
+ */
+ public void testDocumentChangeSynchronization() throws IOException, InterruptedException {
+ // Step 1 : make additions to the document
+ String initialContent = document.get();
+ String newContent = initialContent.substring(0, INSERTION_INDEX) + NEW_LITERAL_STRING
+ + initialContent.substring(INSERTION_INDEX, initialContent.length());
+ document.set(newContent);
+
+ // Step 2 : we start recording for any modification made on the repository
+ repositoryListener.startRecording();
+ // save
+ editor.doSave(new NullProgressMonitor());
+ // and wait the synchronizer and the compiler to be notified
+ waitForCompiler();
+ waitForSynchronizer();
+
+ // Step 3 : ensure that synchronization issues are detected
+ IntentAnnotation annotation = AnnotationUtils.getIntentAnnotation(editor,
+ IntentAnnotationMessageType.SYNC_WARNING, SYNC_WARNING_MESSAGE_ANCESTOR, true);
+ assertNotNull(TEST_SYNCHRONIZER_NO_WARNING_MSG, annotation);
+
+ // Step 4 : apply quick fix
+ AnnotationUtils.applyAnnotationFix(annotation);
+
+ waitForCompiler();
+ waitForSynchronizer();
+
+ // Step 5 : ensure that synchronization issues no longer exists
+ assertFalse(TEST_SYNCHRONIZER_INVALID_WARNING_MSG, AnnotationUtils.hasIntentAnnotation(editor,
+ IntentAnnotationMessageType.SYNC_WARNING, SYNC_WARNING_MESSAGE_ANCESTOR, true));
+ }
+
+}
diff --git a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/synchronization/JavaTest.java b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/synchronization/JavaTest.java
index e088fad..23d2238 100644
--- a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/synchronization/JavaTest.java
+++ b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/synchronization/JavaTest.java
@@ -1,150 +1,155 @@
-/*******************************************************************************
- * Copyright (c) 2011 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.mylyn.docs.intent.client.ui.test.unit.demo.synchronization;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.mylyn.docs.intent.client.ui.editor.IntentEditor;
-import org.eclipse.mylyn.docs.intent.client.ui.editor.IntentEditorDocument;
-import org.eclipse.mylyn.docs.intent.client.ui.editor.annotation.IntentAnnotationMessageType;
-import org.eclipse.mylyn.docs.intent.client.ui.test.unit.demo.AbstractDemoTest;
-import org.eclipse.mylyn.docs.intent.client.ui.test.util.AnnotationUtils;
-import org.eclipse.mylyn.docs.intent.parser.modelingunit.test.utils.FileToStringConverter;
-
-/**
- * Tests the Intent demo, part 4: Java synchronization behavior.
- *
- * @author <a href="mailto:william.piers@obeo.fr">William Piers</a>
- */
-public class JavaTest extends AbstractDemoTest {
-
- private static final String SYNC_WARNING_MSG = "The AcceptanceTest is defined in the <b>Working Copy</b> model<br/>but not in the <b>Current Document</b> model.";
-
- private static final int[] EDITOR_SECTION_3_7 = new int[] {3, 7,
- };
-
- private static final int[] EDITOR_SECTION_7_1 = new int[] {7, 1,
- };
-
- private static final int[] EDITOR_SECTION_7_2 = new int[] {7, 2,
- };
-
- private static final String SECTION_37_V1_FILENAME = "data/unit/demo/Section_3.7_v1";
-
- private static final String SECTION_37_V2_FILENAME = "data/unit/demo/Section_3.7_v2";
-
- private static final String SECTION_37_V3_FILENAME = "data/unit/demo/Section_3.7_v3";
-
- private static final String SECTION_72_FILENAME = "data/unit/demo/Section_7.2";
-
- private static final String JAVA_TEST_FILENAME = "data/unit/demo/PatchCreationThroughCompareDialogTest.java";
-
- /**
- * Ensures that synchronization errors between a document and java code are detected and can be fixed.
- *
- * @throws IOException
- * if an error occurs while getting test file contents
- * @throws CoreException
- * if an error occurs during file copy
- */
- public void testSynchronization() throws IOException, CoreException {
-
- // Step 1 : open the editor at 3.7
- IntentEditor editor37 = openIntentEditor(getIntentSection(EDITOR_SECTION_3_7));
- IntentEditorDocument document37 = (IntentEditorDocument)editor37.getDocumentProvider().getDocument(
- editor37.getEditorInput());
-
- // Step 2 : create a modeling unit section, check for the annotation
- document37.set(getFileContent(SECTION_37_V1_FILENAME));
- editor37.doSave(new NullProgressMonitor());
-
- waitForCompiler();
-
- assertTrue(TEST_COMPILER_NO_ERROR_MSG, AnnotationUtils.hasIntentAnnotation(editor37,
- IntentAnnotationMessageType.COMPILER_INFO,
- "-The required feature 'isTestedBy' of 'patchingDifferences' must be set", true));
- assertTrue(TEST_COMPILER_NO_ERROR_MSG, AnnotationUtils.hasIntentAnnotation(editor37,
- IntentAnnotationMessageType.COMPILER_INFO,
- "-The required feature 'accessibleThrough' of 'patchingDifferences' must be set", true));
-
- // Step 3 : update the modeling unit section, check that the last annotation disappeared
- document37.set(getFileContent(SECTION_37_V2_FILENAME));
- editor37.doSave(new NullProgressMonitor());
-
- waitForCompiler();
-
- assertFalse(TEST_COMPILER_INVALID_ERROR_MSG, AnnotationUtils.hasIntentAnnotation(editor37,
- IntentAnnotationMessageType.COMPILER_INFO,
- "-The required feature 'accessibleThrough' of 'patchingDifferences' must be set", true));
-
- // Step 4 : create a java test class
- File javaTestFile = new File(JAVA_TEST_FILENAME);
- IProject testProject = ResourcesPlugin.getWorkspace().getRoot()
- .getProject("org.eclipse.emf.compare.tests");
- IFile newJavaTestIFile = testProject
- .getFile("src/org/eclipse/emf/compare/tests/acceptance/comparedialog/patch");
- FileInputStream is = new FileInputStream(javaTestFile);
- newJavaTestIFile.create(is, false, new NullProgressMonitor());
- is.close();
- newJavaTestIFile.getParent().refreshLocal(IContainer.DEPTH_INFINITE, new NullProgressMonitor());
-
- // Step 5 : open 7.1, then check for the annotation
- IntentEditor editor71 = openIntentEditor(getIntentSection(EDITOR_SECTION_7_1));
- assertTrue(TEST_SYNCHRONIZER_NO_WARNING_MSG, AnnotationUtils.hasIntentAnnotation(editor71,
- IntentAnnotationMessageType.SYNC_WARNING, SYNC_WARNING_MSG, false));
-
- // Step 6 : fix error from 7.1 in 7.2
-
- // Step 6.1 : open 7.2
- IntentEditor editor72 = openIntentEditor(getIntentSection(EDITOR_SECTION_7_2));
- IntentEditorDocument document72 = (IntentEditorDocument)editor72.getDocumentProvider().getDocument(
- editor72.getEditorInput());
-
- // Step 6.2 : update 7.2
- document72.set(getFileContent(SECTION_72_FILENAME));
- editor72.doSave(new NullProgressMonitor());
-
- waitForCompiler();
-
- // Step 6.3 : check 7.1
- assertFalse(TEST_SYNCHRONIZER_NO_WARNING_MSG, AnnotationUtils.hasIntentAnnotation(editor71,
- IntentAnnotationMessageType.COMPILER_INFO, SYNC_WARNING_MSG, true));
-
- // Step 7 : fix error in 3.7
- document37.set(getFileContent(SECTION_37_V3_FILENAME));
- editor37.doSave(new NullProgressMonitor());
- assertFalse(TEST_COMPILER_INVALID_ERROR_MSG, AnnotationUtils.hasIntentAnnotation(editor37,
- IntentAnnotationMessageType.COMPILER_INFO,
- "-The required feature 'isTestedBy' of 'patchingDifferences' must be set", true));
- }
-
- /**
- * Return the content of the given file as String.
- *
- * @param filePath
- * the file path
- * @return the file content
- * @throws IOException
- * if the file cannot be read
- */
- private String getFileContent(String filePath) throws IOException {
- File file = new File(filePath);
- return FileToStringConverter.getFileAsString(file);
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2011 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.docs.intent.client.ui.test.unit.demo.synchronization;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.mylyn.docs.intent.client.ui.editor.IntentEditor;
+import org.eclipse.mylyn.docs.intent.client.ui.editor.IntentEditorDocument;
+import org.eclipse.mylyn.docs.intent.client.ui.editor.annotation.IntentAnnotationMessageType;
+import org.eclipse.mylyn.docs.intent.client.ui.test.unit.demo.AbstractDemoTest;
+import org.eclipse.mylyn.docs.intent.client.ui.test.util.AnnotationUtils;
+import org.eclipse.mylyn.docs.intent.parser.modelingunit.test.utils.FileToStringConverter;
+
+/**
+ * Tests the Intent demo, part 4: Java synchronization behavior.
+ *
+ * @author <a href="mailto:william.piers@obeo.fr">William Piers</a>
+ */
+public class JavaTest extends AbstractDemoTest {
+
+ private static final String SYNC_WARNING_MSG = "The AcceptanceTest is defined in the <b>Working Copy</b> model<br/>but not in the <b>Current Document</b> model.";
+
+ private static final int[] EDITOR_SECTION_3_7 = new int[] {3, 7,
+ };
+
+ private static final int[] EDITOR_SECTION_7_1 = new int[] {7, 1,
+ };
+
+ private static final int[] EDITOR_SECTION_7_2 = new int[] {7, 2,
+ };
+
+ private static final String SECTION_37_V1_FILENAME = "data/unit/demo/Section_3.7_v1";
+
+ private static final String SECTION_37_V2_FILENAME = "data/unit/demo/Section_3.7_v2";
+
+ private static final String SECTION_37_V3_FILENAME = "data/unit/demo/Section_3.7_v3";
+
+ private static final String SECTION_72_FILENAME = "data/unit/demo/Section_7.2";
+
+ private static final String JAVA_TEST_FILENAME = "data/unit/demo/PatchCreationThroughCompareDialogTest.java";
+
+ /**
+ * Ensures that synchronization errors between a document and java code are detected and can be fixed.
+ *
+ * @throws IOException
+ * if an error occurs while getting test file contents
+ * @throws CoreException
+ * if an error occurs during file copy
+ */
+ public void testSynchronization() throws IOException, CoreException {
+
+ // Step 1 : open the editor at 3.7
+ IntentEditor editor37 = openIntentEditor(getIntentSection(EDITOR_SECTION_3_7));
+ IntentEditorDocument document37 = (IntentEditorDocument)editor37.getDocumentProvider().getDocument(
+ editor37.getEditorInput());
+
+ // Step 2 : create a modeling unit section, check for the annotation
+ document37.set(getFileContent(SECTION_37_V1_FILENAME));
+
+ repositoryListener.startRecording();
+ editor37.doSave(new NullProgressMonitor());
+ waitForCompiler();
+
+ assertTrue(TEST_COMPILER_NO_ERROR_MSG, AnnotationUtils.hasIntentAnnotation(editor37,
+ IntentAnnotationMessageType.COMPILER_INFO,
+ "-The required feature 'isTestedBy' of 'patchingDifferences' must be set", true));
+ assertTrue(TEST_COMPILER_NO_ERROR_MSG, AnnotationUtils.hasIntentAnnotation(editor37,
+ IntentAnnotationMessageType.COMPILER_INFO,
+ "-The required feature 'accessibleThrough' of 'patchingDifferences' must be set", true));
+
+ // Step 3 : update the modeling unit section, check that the last annotation disappeared
+ document37.set(getFileContent(SECTION_37_V2_FILENAME));
+
+ repositoryListener.startRecording();
+ editor37.doSave(new NullProgressMonitor());
+ waitForCompiler();
+
+ assertFalse(TEST_COMPILER_INVALID_ERROR_MSG, AnnotationUtils.hasIntentAnnotation(editor37,
+ IntentAnnotationMessageType.COMPILER_INFO,
+ "-The required feature 'accessibleThrough' of 'patchingDifferences' must be set", true));
+
+ // Step 4 : create a java test class
+ repositoryListener.startRecording();
+ File javaTestFile = new File(JAVA_TEST_FILENAME);
+ IProject testProject = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject("org.eclipse.emf.compare.tests");
+ IFile newJavaTestIFile = testProject
+ .getFile("src/org/eclipse/emf/compare/tests/acceptance/comparedialog/patch");
+ FileInputStream is = new FileInputStream(javaTestFile);
+ newJavaTestIFile.create(is, false, new NullProgressMonitor());
+ is.close();
+ newJavaTestIFile.getParent().refreshLocal(IContainer.DEPTH_INFINITE, new NullProgressMonitor());
+ waitForSynchronizer();
+
+ // Step 5 : open 7.1, then check for the annotation
+ IntentEditor editor71 = openIntentEditor(getIntentSection(EDITOR_SECTION_7_1));
+ assertTrue(TEST_SYNCHRONIZER_NO_WARNING_MSG, AnnotationUtils.hasIntentAnnotation(editor71,
+ IntentAnnotationMessageType.SYNC_WARNING, SYNC_WARNING_MSG, false));
+
+ // Step 6 : fix error from 7.1 in 7.2
+
+ // Step 6.1 : open 7.2
+ IntentEditor editor72 = openIntentEditor(getIntentSection(EDITOR_SECTION_7_2));
+ IntentEditorDocument document72 = (IntentEditorDocument)editor72.getDocumentProvider().getDocument(
+ editor72.getEditorInput());
+
+ // Step 6.2 : update 7.2
+ document72.set(getFileContent(SECTION_72_FILENAME));
+
+ repositoryListener.startRecording();
+ editor72.doSave(new NullProgressMonitor());
+ waitForCompiler();
+
+ // Step 6.3 : check 7.1
+ assertFalse(TEST_SYNCHRONIZER_NO_WARNING_MSG, AnnotationUtils.hasIntentAnnotation(editor71,
+ IntentAnnotationMessageType.COMPILER_INFO, SYNC_WARNING_MSG, true));
+
+ // Step 7 : fix error in 3.7
+ document37.set(getFileContent(SECTION_37_V3_FILENAME));
+ editor37.doSave(new NullProgressMonitor());
+ assertFalse(TEST_COMPILER_INVALID_ERROR_MSG, AnnotationUtils.hasIntentAnnotation(editor37,
+ IntentAnnotationMessageType.COMPILER_INFO,
+ "-The required feature 'isTestedBy' of 'patchingDifferences' must be set", true));
+ }
+
+ /**
+ * Return the content of the given file as String.
+ *
+ * @param filePath
+ * the file path
+ * @return the file content
+ * @throws IOException
+ * if the file cannot be read
+ */
+ private String getFileContent(String filePath) throws IOException {
+ File file = new File(filePath);
+ return FileToStringConverter.getFileAsString(file);
+ }
+}
diff --git a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/project/ProjectTest.java b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/project/ProjectTest.java
index bf0e7f5..fba9abc 100644
--- a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/project/ProjectTest.java
+++ b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/project/ProjectTest.java
@@ -1,70 +1,70 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2011 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.mylyn.docs.intent.client.ui.test.unit.project;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.mylyn.docs.intent.client.ui.ide.builder.ToggleNatureAction;
-import org.eclipse.mylyn.docs.intent.client.ui.test.util.AbstractUITest;
-
-/**
- * Tests the correct behavior of Intent projects.
- *
- * @author <a href="mailto:william.piers@obeo.fr">William Piers</a>
- */
-public class ProjectTest extends AbstractUITest {
-
- /**
- * {@inheritDoc}
- *
- * @see junit.framework.TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- setUpIntentProject("intentProject", "data/unit/documents/editorupdates/changeEditorUpdateTest.intent");
- openIntentEditor();
- }
-
- /**
- * Ensures that a project can be closed.
- */
- public void testDeleteProject() {
- // already managed by tearDown()
- }
-
- /**
- * Ensures that a project can be closed.
- */
- public void testCloseProject() {
- try {
- intentProject.close(new NullProgressMonitor());
- } catch (CoreException e) {
- fail(e.getMessage());
- }
- }
-
- /**
- * Ensures that the project nature can be activated/deactivated.
- */
- public void testToggleNature() {
- ToggleNatureAction.toggleNature(intentProject);
-
- waitForAllOperationsInUIThread();
-
- ToggleNatureAction.toggleNature(intentProject);
-
- waitForAllOperationsInUIThread();
-
- openIntentEditor();
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.docs.intent.client.ui.test.unit.project;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.mylyn.docs.intent.client.ui.ide.builder.ToggleNatureAction;
+import org.eclipse.mylyn.docs.intent.client.ui.test.util.AbstractIntentUITest;
+
+/**
+ * Tests the correct behavior of Intent projects.
+ *
+ * @author <a href="mailto:william.piers@obeo.fr">William Piers</a>
+ */
+public class ProjectTest extends AbstractIntentUITest {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ setUpIntentProject("intentProject", "data/unit/documents/editorupdates/changeEditorUpdateTest.intent");
+ openIntentEditor();
+ }
+
+ /**
+ * Ensures that a project can be closed.
+ */
+ public void testDeleteProject() {
+ // already managed by tearDown()
+ }
+
+ /**
+ * Ensures that a project can be closed.
+ */
+ public void testCloseProject() {
+ try {
+ intentProject.close(new NullProgressMonitor());
+ } catch (CoreException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * Ensures that the project nature can be activated/deactivated.
+ */
+ public void testToggleNature() {
+ ToggleNatureAction.toggleNature(intentProject);
+
+ waitForAllOperationsInUIThread();
+
+ ToggleNatureAction.toggleNature(intentProject);
+
+ waitForAllOperationsInUIThread();
+
+ openIntentEditor();
+ }
+
+}
diff --git a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/scenario/IntentAbstractResourceTest.java b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/scenario/IntentAbstractResourceTest.java
index 7a59a4c..48d1ec1 100644
--- a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/scenario/IntentAbstractResourceTest.java
+++ b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/scenario/IntentAbstractResourceTest.java
@@ -1,179 +1,195 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2011 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.mylyn.docs.intent.client.ui.test.unit.scenario;
-
-import java.io.IOException;
-
-import junit.framework.AssertionFailedError;
-
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EcoreFactory;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.mylyn.docs.intent.client.ui.editor.IntentEditor;
-import org.eclipse.mylyn.docs.intent.client.ui.editor.IntentEditorDocument;
-import org.eclipse.mylyn.docs.intent.client.ui.editor.annotation.IntentAnnotationMessageType;
-import org.eclipse.mylyn.docs.intent.client.ui.test.util.AbstractUITest;
-import org.eclipse.mylyn.docs.intent.client.ui.test.util.AnnotationUtils;
-import org.eclipse.mylyn.docs.intent.collab.common.location.IntentLocations;
-
-/**
- * <p>
- * Ensures that the Abstract Resource concept works as expected.
- * </p>
- * <b> Relevant specifications </b> :
- * <ul>
- * <li>org.eclipse.mylyn.docs.intent/discussion/specs/abstractResources.textile</li>
- * </ul>
- *
- * @author <a href="mailto:alex.lagarde@obeo.fr">Alex Lagarde</a>
- */
-public class IntentAbstractResourceTest extends AbstractUITest {
- private static String INTENT_DOCUMENT_EXAMPLE_PATH = "data/unit/documents/scenario/abstract_resources.intent";
-
- private IntentEditor editor;
-
- private IntentEditorDocument document;
-
- /**
- * {@inheritDoc}
- *
- * @see junit.framework.TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- setUpIntentProject("intentProject", INTENT_DOCUMENT_EXAMPLE_PATH);
- editor = openIntentEditor();
- document = (IntentEditorDocument)editor.getDocumentProvider().getDocument(editor.getEditorInput());
- }
-
- /**
- * Ensures that abstract resources are not synchronized.
- */
- public void testAbstractResourceIsNotSynchronized() {
-
- // Step 1 : make a sample modification on modeling units, just to launch the synchronizer
- String documentContent = document.get();
- String expectedDocumentContent = documentContent.replace("myEClass", "myEClass2");
- document.set(expectedDocumentContent);
- editor.doSave(new NullProgressMonitor());
-
- waitForSynchronizer();
-
- // Step 2 : we check that no synchronization error has been detected
- assertFalse("An abstract resource should not be handled by the Intent synchronizer",
- AnnotationUtils.hasIntentAnnotation(editor, IntentAnnotationMessageType.SYNC_WARNING, "",
- false));
- }
-
- /**
- * Ensures that even if not synchronized, the abstract resources are correctly compiled.
- */
- public void testAbstractResourceIsCompiled() {
- // Step 1 : make a sample modification on modeling units, just to launch the compiler
- String documentContent = document.get();
- String expectedDocumentContent = documentContent.replace("myEClass", "myEClass2");
- document.set(expectedDocumentContent);
- editor.doSave(new NullProgressMonitor());
-
- waitForCompiler();
-
- // Step 2 : we check that the resource has correctly been compiled :
- // => no error should have been found
- assertFalse("The Abstract Resource was not correctly compiled", AnnotationUtils.hasIntentAnnotation(
- editor, IntentAnnotationMessageType.COMPILER_ERROR, "", false));
-
- // => a compiler warning should inform the end-user that the EPackage's URI and prefix are not
- // properly set
- assertTrue("The Abstract Resource was not correctly validated by Intent compiler",
- AnnotationUtils.hasIntentAnnotation(editor, IntentAnnotationMessageType.COMPILER_INFO, "URI",
- false));
- assertTrue("The Abstract Resource was not correctly validated by Intent compiler",
- AnnotationUtils.hasIntentAnnotation(editor, IntentAnnotationMessageType.COMPILER_INFO,
- "prefix", false));
-
- // => a cache of the resource should have been created inside the repository.
- Resource generatedResource = repositoryAdapter
- .getResource(IntentLocations.GENERATED_RESOURCES_FOLDER_PATH + "/abstractResource");
- assertNotNull("The Abstract Resource was not correctly generated by the compiler", generatedResource);
- assertTrue("The Abstract Resource content was not correctly generated by the compiler",
- generatedResource.getContents().iterator().next() instanceof EPackage);
- assertEquals("The Abstract Resource content was not correctly generated by the compiler",
- "myAbstractRoot", ((EPackage)generatedResource.getContents().iterator().next()).getName());
-
- }
-
- /**
- * Ensures that abstract resources are not synchronized.
- */
- public void testAbstractResourceIsSynchronizedWhenBecamingConcrete() {
-
- try {
- // Step 1 : we create a model file inside the intent project
- ResourceSet rs = new ResourceSetImpl();
- URI modelURI = URI.createURI("platform:/resource/" + intentProject.getName() + "/Model.ecore");
-
- Resource modelResource = rs.createResource(modelURI);
- modelResource.getContents().add(EcoreFactory.eINSTANCE.createEPackage());
- modelResource.save(null);
-
- // Step 2 : we make the abstract resource concrete by associating it to the created model URI
- final String resourceURIDeclaration = "\n\t\t\t\t\tURI = \"" + modelURI.toString() + "\";";
-
- String documentContent = document.get();
- String expectedDocumentContent = documentContent.replace("Resource abstractResource {",
- "Resource abstractResource {" + resourceURIDeclaration);
- document.set(expectedDocumentContent);
- editor.doSave(new NullProgressMonitor());
-
- waitForSynchronizer();
-
- // Step 3 : we check that new synchronization errors have been detected
- assertTrue("A concrete resource should be handled by the Intent synchronizer",
- AnnotationUtils.hasIntentAnnotation(editor, IntentAnnotationMessageType.SYNC_WARNING, "",
- false));
-
- // Step 4 : we make this concrete resource abstract again
- document.set(document.get().replace(resourceURIDeclaration, ""));
- editor.doSave(new NullProgressMonitor());
-
- waitForSynchronizer();
-
- // Step 5 : we check that no synchronization errors has been detected
- assertFalse("An abstract resource should not be handled by the Intent synchronizer",
- AnnotationUtils.hasIntentAnnotation(editor, IntentAnnotationMessageType.SYNC_WARNING, "",
- false));
-
- } catch (IOException e) {
- AssertionFailedError assertFailed = new AssertionFailedError(
- "Unexpected exception when creating model file : " + e.getMessage());
- assertFailed.setStackTrace(e.getStackTrace());
- throw assertFailed;
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see junit.framework.TestCase#tearDown()
- */
- @Override
- protected void tearDown() throws Exception {
- if (editor != null) {
- editor.close(false);
- }
- super.tearDown();
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.docs.intent.client.ui.test.unit.scenario;
+
+import java.io.IOException;
+
+import junit.framework.AssertionFailedError;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.mylyn.docs.intent.client.ui.editor.IntentEditor;
+import org.eclipse.mylyn.docs.intent.client.ui.editor.IntentEditorDocument;
+import org.eclipse.mylyn.docs.intent.client.ui.editor.annotation.IntentAnnotationMessageType;
+import org.eclipse.mylyn.docs.intent.client.ui.test.util.AbstractIntentUITest;
+import org.eclipse.mylyn.docs.intent.client.ui.test.util.AnnotationUtils;
+import org.eclipse.mylyn.docs.intent.collab.common.location.IntentLocations;
+
+/**
+ * <p>
+ * Ensures that the Abstract Resource concept works as expected.
+ * </p>
+ * <b> Relevant specifications </b> :
+ * <ul>
+ * <li>org.eclipse.mylyn.docs.intent/discussion/specs/abstractResources.textile</li>
+ * </ul>
+ *
+ * @author <a href="mailto:alex.lagarde@obeo.fr">Alex Lagarde</a>
+ */
+public class IntentAbstractResourceTest extends AbstractIntentUITest {
+ private static final String INTENT_DOCUMENT_EXAMPLE_PATH = "data/unit/documents/scenario/abstract_resources.intent";
+
+ private IntentEditor editor;
+
+ private IntentEditorDocument document;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // Step 1 : Generic set up
+ setUpIntentProject("intentProject", INTENT_DOCUMENT_EXAMPLE_PATH, true);
+
+ // Step 2 : open an editor on the root document
+ editor = openIntentEditor();
+ document = (IntentEditorDocument)editor.getDocumentProvider().getDocument(editor.getEditorInput());
+ }
+
+ /**
+ * Ensures that abstract resources are not synchronized.
+ */
+ public void testAbstractResourceIsNotSynchronized() {
+ // Step 1 : make a sample modification on modeling units, just to launch the synchronizer
+ String documentContent = document.get();
+ String expectedDocumentContent = documentContent.replace("myEClass", "myEClass2");
+ document.set(expectedDocumentContent);
+
+ // Step 2 : we start recording for any modification made on the repository
+ repositoryListener.startRecording();
+ // save
+ editor.doSave(new NullProgressMonitor());
+ // and wait the synchronizer to be notified
+ waitForSynchronizer();
+
+ // Step 3 : we check that no synchronization error has been detected
+ assertFalse("An abstract resource should not be handled by the Intent synchronizer",
+ AnnotationUtils.hasIntentAnnotation(editor, IntentAnnotationMessageType.SYNC_WARNING, "",
+ false));
+ }
+
+ /**
+ * Ensures that even if not synchronized, the abstract resources are correctly compiled.
+ */
+ public void testAbstractResourceIsCompiled() {
+ // Step 1 : make a sample modification on modeling units, just to launch the compiler
+ String documentContent = document.get();
+ String expectedDocumentContent = documentContent.replace("myEClass", "myEClass2");
+ document.set(expectedDocumentContent);
+
+ // Step 2 : we start recording for any modification made on the repository
+ repositoryListener.startRecording();
+ // save
+ editor.doSave(new NullProgressMonitor());
+ // and wait the compiler to be notified
+ waitForCompiler();
+
+ // Step 3 : we check that the resource has correctly been compiled :
+ // => no error should have been found
+ assertFalse("The Abstract Resource was not correctly compiled", AnnotationUtils.hasIntentAnnotation(
+ editor, IntentAnnotationMessageType.COMPILER_ERROR, "", false));
+
+ // => a compiler warning should inform the end-user that the EPackage's URI and prefix are not
+ // properly set
+ assertTrue("The Abstract Resource was not correctly validated by Intent compiler",
+ AnnotationUtils.hasIntentAnnotation(editor, IntentAnnotationMessageType.COMPILER_INFO, "URI",
+ false));
+ assertTrue("The Abstract Resource was not correctly validated by Intent compiler",
+ AnnotationUtils.hasIntentAnnotation(editor, IntentAnnotationMessageType.COMPILER_INFO,
+ "prefix", false));
+
+ // => a cache of the resource should have been created inside the repository.
+ Resource generatedResource = repositoryAdapter
+ .getResource(IntentLocations.GENERATED_RESOURCES_FOLDER_PATH + "/abstractResource");
+ assertNotNull("The Abstract Resource was not correctly generated by the compiler", generatedResource);
+ assertTrue("The Abstract Resource content was not correctly generated by the compiler",
+ generatedResource.getContents().iterator().next() instanceof EPackage);
+ assertEquals("The Abstract Resource content was not correctly generated by the compiler",
+ "myAbstractRoot", ((EPackage)generatedResource.getContents().iterator().next()).getName());
+
+ }
+
+ /**
+ * Ensures that abstract resources are not synchronized.
+ */
+ public void testAbstractResourceIsSynchronizedWhenBecamingConcrete() {
+
+ try {
+ // Step 1 : we create a model file inside the intent project
+ ResourceSet rs = new ResourceSetImpl();
+ URI modelURI = URI.createURI("platform:/resource/" + intentProject.getName() + "/Model.ecore");
+
+ Resource modelResource = rs.createResource(modelURI);
+ modelResource.getContents().add(EcoreFactory.eINSTANCE.createEPackage());
+ modelResource.save(null);
+
+ // Step 2 : we make the abstract resource concrete by associating it to the created model URI
+ final String resourceURIDeclaration = "\n\t\t\t\t\tURI = \"" + modelURI.toString() + "\";";
+
+ String documentContent = document.get();
+ String expectedDocumentContent = documentContent.replace("Resource abstractResource {",
+ "Resource abstractResource {" + resourceURIDeclaration);
+ document.set(expectedDocumentContent);
+
+ // Step 3 : we start recording for any modification made on the repository
+ repositoryListener.startRecording();
+ // save
+ editor.doSave(new NullProgressMonitor());
+ // and wait the synchronizer to be notified
+ waitForSynchronizer();
+
+ // Step 4 : we check that new synchronization errors have been detected
+ assertTrue("A concrete resource should be handled by the Intent synchronizer",
+ AnnotationUtils.hasIntentAnnotation(editor, IntentAnnotationMessageType.SYNC_WARNING, "",
+ false));
+
+ // Step 5 : we make this concrete resource abstract again
+ document.set(document.get().replace(resourceURIDeclaration, ""));
+
+ repositoryListener.startRecording();
+ editor.doSave(new NullProgressMonitor());
+ waitForSynchronizer();
+
+ // Step 6 : we check that no synchronization errors has been detected
+ assertFalse("An abstract resource should not be handled by the Intent synchronizer",
+ AnnotationUtils.hasIntentAnnotation(editor, IntentAnnotationMessageType.SYNC_WARNING, "",
+ false));
+
+ } catch (IOException e) {
+ AssertionFailedError assertFailed = new AssertionFailedError(
+ "Unexpected exception when creating model file : " + e.getMessage());
+ assertFailed.setStackTrace(e.getStackTrace());
+ throw assertFailed;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ if (editor != null) {
+ editor.close(false);
+ }
+ super.tearDown();
+ }
+}
diff --git a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/util/AbstractUITest.java b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/util/AbstractIntentUITest.java
similarity index 66%
rename from tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/util/AbstractUITest.java
rename to tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/util/AbstractIntentUITest.java
index 7eaacc6..09e817a 100644
--- a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/util/AbstractUITest.java
+++ b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/util/AbstractIntentUITest.java
@@ -12,6 +12,10 @@
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.LinkedHashSet;
+import java.util.Set;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
@@ -24,6 +28,7 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.mylyn.docs.intent.client.ui.IntentEditorActivator;
import org.eclipse.mylyn.docs.intent.client.ui.editor.IntentEditor;
@@ -32,11 +37,16 @@
import org.eclipse.mylyn.docs.intent.client.ui.ide.launcher.IntentProjectManager;
import org.eclipse.mylyn.docs.intent.client.ui.utils.IntentEditorOpener;
import org.eclipse.mylyn.docs.intent.collab.common.location.IntentLocations;
+import org.eclipse.mylyn.docs.intent.collab.handlers.RepositoryObjectHandler;
import org.eclipse.mylyn.docs.intent.collab.handlers.adapters.ReadOnlyException;
import org.eclipse.mylyn.docs.intent.collab.handlers.adapters.RepositoryAdapter;
+import org.eclipse.mylyn.docs.intent.collab.handlers.impl.ReadWriteRepositoryObjectHandlerImpl;
+import org.eclipse.mylyn.docs.intent.collab.handlers.impl.notification.typeListener.TypeNotificator;
+import org.eclipse.mylyn.docs.intent.collab.handlers.notification.Notificator;
import org.eclipse.mylyn.docs.intent.collab.repository.Repository;
import org.eclipse.mylyn.docs.intent.collab.repository.RepositoryConnectionException;
import org.eclipse.mylyn.docs.intent.collab.utils.RepositoryCreatorHolder;
+import org.eclipse.mylyn.docs.intent.core.compiler.CompilerPackage;
import org.eclipse.mylyn.docs.intent.core.document.IntentChapter;
import org.eclipse.mylyn.docs.intent.core.document.IntentDocument;
import org.eclipse.mylyn.docs.intent.core.document.IntentSection;
@@ -49,22 +59,18 @@
*
* @author <a href="mailto:alex.lagarde@obeo.fr">Alex Lagarde</a>
*/
-public abstract class AbstractUITest extends TestCase implements ILogListener {
+public abstract class AbstractIntentUITest extends TestCase implements ILogListener {
public static final String INTENT_NEW_PROJECT_WIZARD_ID = "org.eclipse.mylyn.docs.intent.client.ui.ide.wizards.NewIntentProjectWizard";
- private static final int COMPILER_DELAY = 1500;
-
- private static final int SYNCHRONIZER_DELAY = 2000;
-
- private static final int REPOSITORY_DELAY = 1000;
-
protected IProject intentProject;
protected Repository repository;
protected RepositoryAdapter repositoryAdapter;
+ protected RepositoryListenerForTests repositoryListener;
+
private IntentDocument intentDocument;
/**
@@ -88,16 +94,40 @@
*/
@Override
protected void tearDown() throws Exception {
+
+ // Step 1 : clean workspace
waitForAllOperationsInUIThread();
if (intentProject != null) {
intentProject.delete(true, true, new NullProgressMonitor());
}
IntentEditorActivator.getDefault().getLog().removeLogListener(this);
WorkspaceUtils.cleanWorkspace();
+
+ // Step 2 : setting all fields to null (to avoid memory leaks)
+ setAllFieldsToNull();
+
super.tearDown();
}
/**
+ * Creates and register an new {@link org.eclipse.mylyn.docs.intent.collab.handlers.RepositoryClient } in
+ * charge of detecting that events happened on the repository.
+ */
+ protected void registerRepositoryListener() {
+ // Step 1 : creating the handler
+ // we listen for all modifications made on the traceability index
+ RepositoryObjectHandler handler = new ReadWriteRepositoryObjectHandlerImpl(repositoryAdapter);
+ Set<EStructuralFeature> listenedFeatures = new LinkedHashSet<EStructuralFeature>();
+ listenedFeatures.addAll(CompilerPackage.eINSTANCE.getTraceabilityIndex().getEStructuralFeatures());
+ Notificator listenedElementsNotificator = new TypeNotificator(listenedFeatures);
+ handler.setNotificator(listenedElementsNotificator);
+
+ // Step 2 : creating the client
+ this.repositoryListener = new RepositoryListenerForTests();
+ repositoryListener.addRepositoryObjectHandler(handler);
+ }
+
+ /**
* Creates a new Intent project using the intent document located at the given path.
*
* @param projectName
@@ -107,6 +137,24 @@
* org.eclipse.mylyn.docs.intent.client.ui.test project).
*/
protected void setUpIntentProject(final String projectName, String intentDocumentPath) {
+ setUpIntentProject(projectName, intentDocumentPath, false);
+ }
+
+ /**
+ * Creates a new Intent project using the intent document located at the given path.
+ *
+ * @param projectName
+ * the intent project name
+ * @param intentDocumentPath
+ * the path of the intent document to use (relative to the
+ * org.eclipse.mylyn.docs.intent.client.ui.test project)
+ * @param listenForRepository
+ * indicates whether a repository listener should be registered. If you want to determine if a
+ * client has done a job (by calling {@link AbstractIntentUITest#waitForIndexer() for example}
+ * ), this must be true.
+ */
+ protected void setUpIntentProject(final String projectName, String intentDocumentPath,
+ boolean listenForRepository) {
try {
// Step 1 : getting the content of the intent document located at the given path.
File file = new File(intentDocumentPath);
@@ -134,6 +182,10 @@
) {
Thread.sleep(10);
}
+
+ // Step 3 : registering the repository listener
+ registerRepositoryListener();
+
} catch (CoreException e) {
AssertionFailedError error = new AssertionFailedError("Failed to create Intent project");
error.setStackTrace(e.getStackTrace());
@@ -269,37 +321,66 @@
/**
* Wait for synchronizer to complete work.
*/
- protected static void waitForSynchronizer() {
- try {
- Thread.sleep(SYNCHRONIZER_DELAY);
- } catch (InterruptedException e) {
- // Nothing to do
- }
+ protected void waitForSynchronizer() {
+ assertNotNull(
+ "Cannot wait for synchronizer : you need to initialize a repository listener by calling the registerRepositoryListener() method",
+ repositoryListener);
+ assertTrue("Time out : synchronizer should have handle changes but did not",
+ repositoryListener.waitForModificationOn(IntentLocations.TRACEABILITY_INFOS_INDEX_PATH));
waitForAllOperationsInUIThread();
}
/**
* Wait for repository to complete work.
*/
- protected static void waitForIndexer() {
- try {
- Thread.sleep(REPOSITORY_DELAY);
- } catch (InterruptedException e) {
- // Nothing to do
- }
+ protected void waitForIndexer() {
+ assertNotNull(
+ "Cannot wait for Indexer : you need to initialize a repository listener by calling the registerRepositoryListener() method",
+ repositoryListener);
+ assertTrue("Time out : indexer should have handle changes but did not",
+ repositoryListener.waitForModificationOn(IntentLocations.INTENT_INDEX));
waitForAllOperationsInUIThread();
}
/**
* Wait for compiler to complete work.
*/
- protected static void waitForCompiler() {
- try {
- Thread.sleep(COMPILER_DELAY);
- } catch (InterruptedException e) {
- // Nothing to do
- }
+ protected void waitForCompiler() {
+ assertNotNull(
+ "Cannot wait for compiler : you need to initialize a repository listener by calling the registerRepositoryListener() method",
+ repositoryListener);
+ assertTrue("Time out : compiler should have handle changes but did not",
+ repositoryListener.waitForModificationOn(IntentLocations.TRACEABILITY_INFOS_INDEX_PATH));
waitForAllOperationsInUIThread();
}
+ /**
+ * Sets all fields of the current test case to null (to avoid memory leaks).
+ */
+ private void setAllFieldsToNull() {
+ // For all fields defined in the current test and all its superclasses
+ for (Class<?> clazz = this.getClass(); clazz != TestCase.class; clazz = clazz.getSuperclass()) {
+ for (Field field : clazz.getDeclaredFields()) {
+ boolean isReference = !field.getType().isPrimitive();
+ try {
+ field.setAccessible(true);
+ boolean isSet = field.get(this) != null;
+ // We do not clean non set references
+ if (isReference && isSet) {
+ boolean isFinal = Modifier.isFinal(field.getModifiers());
+ // We do not clean final fields
+ if (!isFinal) {
+ // Setting the field to null
+ field.set(this, null);
+ }
+ }
+ } catch (IllegalArgumentException e) {
+ // Do nothing
+ } catch (IllegalAccessException e) {
+ // Do nothing
+ }
+ }
+ }
+ }
+
}
diff --git a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/util/RepositoryListenerForTests.java b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/util/RepositoryListenerForTests.java
new file mode 100644
index 0000000..ff9278f
--- /dev/null
+++ b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/util/RepositoryListenerForTests.java
@@ -0,0 +1,150 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.docs.intent.client.ui.test.util;
+
+import com.google.common.collect.Sets;
+
+import java.util.Set;
+
+import junit.framework.AssertionFailedError;
+
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.mylyn.docs.intent.collab.handlers.impl.AbstractRepositoryClient;
+import org.eclipse.mylyn.docs.intent.collab.handlers.notification.RepositoryChangeNotification;
+
+/**
+ * A {@link org.eclipse.mylyn.docs.intent.collab.handlers.RepositoryClient} used to detect if an event
+ * happened or not on the repository.
+ *
+ * @author <a href="mailto:alex.lagarde@obeo.fr">Alex Lagarde</a>
+ */
+public class RepositoryListenerForTests extends AbstractRepositoryClient {
+
+ /**
+ * Delay to wait before checking again that an event occurred.
+ */
+ private static final int WAITING_STEP_DELAY = 200;
+
+ /**
+ * Delay to wait before considering that an expected event never occurred.
+ */
+ private static final long TIME_OUT_DELAY = 5000;
+
+ /**
+ * The list of modified elements since the last call to
+ * {@link RepositoryListenerForTests#startRecording()}.
+ */
+ private Set<EObject> modifiedElements = Sets.newLinkedHashSet();
+
+ /**
+ * The URIs of modified resources since the last call to
+ * {@link RepositoryListenerForTests#startRecording()}.
+ */
+ private Set<URI> modifiedResourcesURI = Sets.newLinkedHashSet();
+
+ /**
+ * Indicates whether this Repository listener is recording or not.
+ */
+ private boolean isRecording;
+
+ /**
+ * Indicates whether the expected event occurred.
+ */
+ private boolean expectedEventOccured;
+
+ /**
+ * Removes all registered notifications and start listening to the repository.
+ */
+ public void startRecording() {
+ isRecording = true;
+ expectedEventOccured = false;
+ modifiedElements.clear();
+ modifiedResourcesURI.clear();
+ }
+
+ /**
+ * Waits for a modification on the intent resource located at the given path. Returns true if the
+ * modification occurred, false if it did not after a certain delay.
+ *
+ * @param resourcePath
+ * the path of the intent resource which is expected to be modified
+ * @return true if the modification occurred, false if it did not after a certain delay
+ */
+ public boolean waitForModificationOn(final String resourcePath) {
+
+ long startTime = System.currentTimeMillis();
+ boolean timeOutDetected = false;
+ try {
+ while (!resourceHasBeenModified(resourcePath) && !timeOutDetected) {
+
+ Thread.sleep(WAITING_STEP_DELAY);
+ timeOutDetected = System.currentTimeMillis() - startTime > TIME_OUT_DELAY;
+
+ }
+ Thread.sleep(WAITING_STEP_DELAY);
+ return !timeOutDetected;
+ } catch (InterruptedException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Indicates if the repository resource located at the given path has been modified since
+ * {@link RepositoryListenerForTests#startRecording()} has been called.
+ *
+ * @param resourcePath
+ * the relative path of the resource (from the root of the repository)
+ * @return true if the repository resource located at the given path has been modified since
+ * {@link RepositoryListenerForTests#startRecording()} has been called, false otherwise
+ */
+ private boolean resourceHasBeenModified(String resourcePath) {
+ if (!isRecording) {
+ throw new AssertionFailedError(
+ "The Repository listener has not started recording. Please call the startRecording() method before trying to determine which actions have been determined");
+ }
+ if (!modifiedResourcesURI.isEmpty()) {
+ URI expectedModifiedResourceURI = this.getRepositoryObjectHandler().getRepositoryAdapter()
+ .getResource(resourcePath).getURI();
+ return modifiedResourcesURI.contains(expectedModifiedResourceURI);
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.mylyn.docs.intent.collab.handlers.impl.AbstractRepositoryClient#handleChangeNotification(org.eclipse.mylyn.docs.intent.collab.handlers.notification.RepositoryChangeNotification)
+ */
+ @Override
+ public void handleChangeNotification(RepositoryChangeNotification notification) {
+ if (isRecording) {
+ // We registered the modified elements and the URI of their resource
+ modifiedElements.addAll(notification.getRightRoots());
+ for (EObject modifiedElement : notification.getRightRoots()) {
+ modifiedResourcesURI.add(modifiedElement.eResource().getURI());
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.mylyn.docs.intent.collab.handlers.impl.AbstractRepositoryClient#createNotificationJob(org.eclipse.mylyn.docs.intent.collab.handlers.notification.RepositoryChangeNotification)
+ */
+ @Override
+ protected Job createNotificationJob(RepositoryChangeNotification notification) {
+ // nothing to do, as we override handleChangeNotification this method will not be called
+ return null;
+ }
+
+}