[bugzilla 384447] Modifying CDO test framework to properly close the repository at tearDown and add a new Test
diff --git a/plugins/org.eclipse.mylyn.docs.intent.client.ui/src/org/eclipse/mylyn/docs/intent/client/ui/utils/IntentEditorOpener.java b/plugins/org.eclipse.mylyn.docs.intent.client.ui/src/org/eclipse/mylyn/docs/intent/client/ui/utils/IntentEditorOpener.java index d72fac3..db6a43f 100644 --- a/plugins/org.eclipse.mylyn.docs.intent.client.ui/src/org/eclipse/mylyn/docs/intent/client/ui/utils/IntentEditorOpener.java +++ b/plugins/org.eclipse.mylyn.docs.intent.client.ui/src/org/eclipse/mylyn/docs/intent/client/ui/utils/IntentEditorOpener.java
@@ -57,16 +57,17 @@ * @param readOnlyMode * indicates if the editor should be opened in readOnly mode. */ - public static void openIntentEditor(final Repository repository, boolean readOnlyMode) { + public static IntentEditor openIntentEditor(final Repository repository, boolean readOnlyMode) { try { final RepositoryAdapter repositoryAdapter = repository.createRepositoryAdapter(); openContext(repositoryAdapter, readOnlyMode); IntentDocument elementToOpen = new IntentDocumentQuery(repositoryAdapter) .getOrCreateIntentDocument(); - openIntentEditor(repositoryAdapter, elementToOpen, false, elementToOpen, false); + return openIntentEditor(repositoryAdapter, elementToOpen, false, elementToOpen, false); } catch (PartInitException e) { IntentUiLogger.logError(e); + return null; } }
diff --git a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/cdo/CDOIntegrationTest.java b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/cdo/CDOIntegrationTest.java index 0a6d4c3..ab96d90 100644 --- a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/cdo/CDOIntegrationTest.java +++ b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/cdo/CDOIntegrationTest.java
@@ -10,7 +10,10 @@ *******************************************************************************/ package org.eclipse.mylyn.docs.intent.client.ui.test.unit.cdo; +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.unit.cdo.util.AbstractIntentCDOTest; +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.common.repository.IntentRepositoryManager; import org.eclipse.mylyn.docs.intent.collab.handlers.adapters.IntentCommand; @@ -80,43 +83,44 @@ * * @throws Exception */ - // public void testRemoteChangesIntegrationInsideEditor() throws Exception { - // Local user opens an editor on an Intent document - // setUpIntentProject("myIntentProject", INTENT_ABSTRACT_RESOURCE_DOCUMENT_PATH, false); - // waitForAllOperationsInUIThread(); - // IntentEditor editor = openIntentEditor(getIntentDocument()); - // waitForAllOperationsInUIThread(); - // String initialContent = ((IntentEditorDocument)editor.getDocumentProvider().getDocument( - // editor.getEditorInput())).get(); + public void testRemoteChangesIntegrationInsideEditor() throws Exception { + // Local user opens an editor on an Intent document + setUpIntentProject("myIntentProject", INTENT_ABSTRACT_RESOURCE_DOCUMENT_PATH, false); + IntentEditor editor = IntentEditorOpener.openIntentEditor( + IntentRepositoryManager.INSTANCE.getRepository(getIntentRepositoryIdentifier()), false); + waitForAllOperationsInUIThread(); + String initialContent = ((IntentEditorDocument)editor.getDocumentProvider().getDocument( + editor.getEditorInput())).get(); - // Remote user adds an untitle chapter - // final RepositoryAdapter remoteUser = IntentRepositoryManager.INSTANCE.getRepository( - // "cdo:/myIntentProject").createRepositoryAdapter(); - // remoteUser.openSaveContext(); - // remoteUser.execute(new IntentCommand() { - // - // public void execute() { - // IntentDocument remoteIntentDocument; - // try { - // remoteIntentDocument = (IntentDocument)remoteUser - // .getOrCreateResource(IntentLocations.INTENT_INDEX).getContents().iterator() - // .next(); - // remoteIntentDocument.getChapters().add( - // IntentDocumentFactory.eINSTANCE.createIntentChapter()); - // } catch (ReadOnlyException e) { - // fail(e.getMessage()); - // } - // } - // }); - // remoteUser.save(); - // remoteUser.closeContext(); - // waitForAllOperationsInUIThread(); + // Remote user adds an untitled chapter + final RepositoryAdapter remoteUser = IntentRepositoryManager.INSTANCE.getRepository( + getIntentRepositoryIdentifier()).createRepositoryAdapter(); + remoteUser.openSaveContext(); + remoteUser.execute(new IntentCommand() { - // Local user should see the new chapter - // assertNotSame(initialContent, - // ((IntentEditorDocument)editor.getDocumentProvider().getDocument(editor.getEditorInput())) - // .get()); - // - // editor.close(false); - // } + public void execute() { + IntentDocument remoteIntentDocument; + try { + remoteIntentDocument = (IntentDocument)remoteUser + .getOrCreateResource(IntentLocations.INTENT_INDEX).getContents().iterator() + .next(); + remoteIntentDocument.getChapters().add( + IntentDocumentFactory.eINSTANCE.createIntentChapter()); + } catch (ReadOnlyException e) { + fail(e.getMessage()); + } + } + }); + remoteUser.save(); + remoteUser.closeContext(); + waitForAllOperationsInUIThread(); + + // Local user should see the new chapter + assertNotSame(initialContent, + ((IntentEditorDocument)editor.getDocumentProvider().getDocument(editor.getEditorInput())) + .get()); + // Local user's editor should not be dirty + assertFalse("Editor should not be dirty after remote changes integration", editor.isDirty()); + editor.close(false); + } }
diff --git a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/cdo/util/AbstractIntentCDOTest.java b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/cdo/util/AbstractIntentCDOTest.java index bd4a29e..f2eeaa0 100644 --- a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/cdo/util/AbstractIntentCDOTest.java +++ b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/cdo/util/AbstractIntentCDOTest.java
@@ -50,6 +50,11 @@ protected void tearDown() throws Exception { super.tearDown(); + // Delete intent repository + IntentRepositoryManager.INSTANCE.getRepository(getIntentRepositoryIdentifier()).closeSession(); + IntentRepositoryManager.INSTANCE.deleteRepository(getIntentRepositoryIdentifier()); + waitForAllOperationsInUIThread(); + // Stopping the CDOServer IntentCDORepository.stop(); } @@ -112,4 +117,5 @@ protected void additionalSetUpOperations() { } + }