Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2004-11-24 15:52:35 +0000
committerMichael Valenta2004-11-24 15:52:35 +0000
commita7de1d97517280e52ed47ad8f34c62e26356999a (patch)
tree281a166bac0de23b1ef6b8b29efe00a3a2a4702c
parent328dff37db341e375c7d3f92bac33e3e8e9b67ed (diff)
downloadeclipse.platform.team-a7de1d97517280e52ed47ad8f34c62e26356999a.tar.gz
eclipse.platform.team-a7de1d97517280e52ed47ad8f34c62e26356999a.tar.xz
eclipse.platform.team-a7de1d97517280e52ed47ad8f34c62e26356999a.zip
Improved test case validation for synchronize view contents
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/SubscriberChangeSetCollector.java19
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/AbstractSynchronizeModelProvider.java48
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeModelManager.java2
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/EclipseTest.java1
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSChangeSetTests.java32
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/SyncInfoSource.java9
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/SynchronizeViewTestAdapter.java121
7 files changed, 192 insertions, 40 deletions
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/SubscriberChangeSetCollector.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/SubscriberChangeSetCollector.java
index 0002943c1..8d065bb8c 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/SubscriberChangeSetCollector.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/SubscriberChangeSetCollector.java
@@ -15,6 +15,7 @@ import java.util.*;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.*;
import org.eclipse.team.core.ITeamStatus;
import org.eclipse.team.core.TeamException;
@@ -544,4 +545,22 @@ public class SubscriberChangeSetCollector extends ChangeSetCollector implements
protected ISyncInfoSetChangeListener getChangeSetChangeListener() {
return this;
}
+
+ /**
+ * Wait until the collector is done processing any events.
+ * This method is for testing purposes only.
+ */
+ public void waitUntilDone(IProgressMonitor monitor) {
+ monitor.worked(1);
+ // wait for the event handler to process changes.
+ while(handler.getEventHandlerJob().getState() != Job.NONE) {
+ monitor.worked(1);
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e) {
+ }
+ Policy.checkCanceled(monitor);
+ }
+ monitor.worked(1);
+ }
}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/AbstractSynchronizeModelProvider.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/AbstractSynchronizeModelProvider.java
index 62d287b7a..19e5014bd 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/AbstractSynchronizeModelProvider.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/AbstractSynchronizeModelProvider.java
@@ -61,6 +61,8 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo
private SynchronizePageActionGroup actionGroup;
private ListenerList listeners;
+
+ private static final boolean DEBUG = false;
/**
* Constructor for creating a sub-provider
@@ -441,7 +443,13 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo
ArrayList paths = new ArrayList();
for (int i = 0; i < resources.length; i++) {
IResource resource = resources[i];
- paths.add(resource.getFullPath().toString());
+ String path = resource.getFullPath().toString();
+ if (resource.getType() != IResource.FILE && path.charAt(path.length() - 1) != Path.SEPARATOR) {
+ // Include a trailing slash on folders and projects.
+ // It is used when recreating cached resources that don't exist locally
+ path += Path.SEPARATOR;
+ }
+ paths.add(path);
}
config.setProperty(configProperty, paths);
} else {
@@ -531,13 +539,17 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo
private IResource getResourceForPath(IContainer container, String path) {
IResource resource = container.findMember(path, true /* include phantoms */);
if (resource == null) {
- // The resource doesn't have an entry on the resources tree
- // but may still appear in the view so try to deduce the type
- // from the path
- if (path.endsWith(Character.toString(Path.SEPARATOR))) {
- resource = container.getFolder(new Path(null, path));
- } else {
- resource = container.getFile(new Path(null, path));
+ try {
+ // The resource doesn't have an entry on the resources tree
+ // but may still appear in the view so try to deduce the type
+ // from the path
+ if (path.endsWith(Character.toString(Path.SEPARATOR))) {
+ resource = container.getFolder(new Path(null, path));
+ } else {
+ resource = container.getFile(new Path(null, path));
+ }
+ } catch (IllegalArgumentException e) {
+ // Couldn't get a resource handle so ignore
}
}
return resource;
@@ -710,6 +722,9 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo
}
protected void addToViewer(ISynchronizeModelElement node) {
+ if (DEBUG) {
+ System.out.println("Adding model element " + node.getName()); //$NON-NLS-1$
+ }
propogateConflictState(node, false);
// Set the marker property on this node.
// There is no need to propogate this to the parents
@@ -751,7 +766,13 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo
List rootsToClear = new ArrayList();
for (int i = 0; i < nodes.length; i++) {
ISynchronizeModelElement node = nodes[i];
+ if (DEBUG) {
+ System.out.println("Removing model element " + node.getName()); //$NON-NLS-1$
+ }
ISynchronizeModelElement rootToClear = getRootToClear(node);
+ if (DEBUG && rootToClear != node) {
+ System.out.println("Removing parent element " + rootToClear.getName()); //$NON-NLS-1$
+ }
propogateConflictState(rootToClear, true /* clear the conflict */);
clearModelObjects(rootToClear);
rootsToClear.add(rootToClear);
@@ -858,6 +879,9 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo
* @param element the element to be added to the viewer
*/
protected void doAdd(ISynchronizeModelElement parent, ISynchronizeModelElement element) {
+ if (DEBUG) {
+ System.out.println("Adding view item " + element.getName()); //$NON-NLS-1$
+ }
AbstractTreeViewer viewer = (AbstractTreeViewer)getViewer();
viewer.add(parent, element);
}
@@ -868,7 +892,13 @@ public abstract class AbstractSynchronizeModelProvider implements ISynchronizeMo
*/
protected void doRemove(ISynchronizeModelElement[] elements) {
AbstractTreeViewer viewer = (AbstractTreeViewer)getViewer();
- viewer.remove(elements);
+ viewer.remove(elements);
+ if (DEBUG) {
+ for (int i = 0; i < elements.length; i++) {
+ ISynchronizeModelElement element = elements[i];
+ System.out.println("Removing view item " + element.getName()); //$NON-NLS-1$
+ }
+ }
}
/**
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeModelManager.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeModelManager.java
index 176ac6270..30d32b44f 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeModelManager.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeModelManager.java
@@ -101,7 +101,7 @@ public abstract class SynchronizeModelManager extends SynchronizePageActionGroup
* Return the provider that is currently active.
* @return the provider that is currently active
*/
- protected ISynchronizeModelProvider getActiveModelProvider() {
+ public ISynchronizeModelProvider getActiveModelProvider() {
return modelProvider;
}
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/EclipseTest.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/EclipseTest.java
index b4760a0d1..f98face54 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/EclipseTest.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/EclipseTest.java
@@ -991,6 +991,7 @@ public class EclipseTest extends ResourceTest {
// Transfer the recorded debug info to stdout
Policy.recorder.close();
System.out.println(new String(os.toByteArray()));
+ throw e;
} finally {
Policy.recorder.close();
Policy.recorder = null;
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSChangeSetTests.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSChangeSetTests.java
index 6f0ce2d31..ac07b3759 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSChangeSetTests.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSChangeSetTests.java
@@ -182,12 +182,7 @@ public class CVSChangeSetTests extends CVSSyncSubscriberTest {
* Wait until all the background handlers have settled and then return the root element in the sync view
*/
private ISynchronizeModelElement getModelRoot(Subscriber workspaceSubscriber) throws CoreException {
- SynchronizeViewTestAdapter.getCollector(workspaceSubscriber);
- ISynchronizeParticipant participant = SynchronizeViewTestAdapter.getParticipant(workspaceSubscriber);
- SubscriberParticipantPage page = (SubscriberParticipantPage)SynchronizeViewTestAdapter.getSyncViewPage(participant);
- ChangeSetModelManager manager = (ChangeSetModelManager)page.getConfiguration().getProperty(SynchronizePageConfiguration.P_MODEL_MANAGER);
- AbstractSynchronizeModelProvider provider = (AbstractSynchronizeModelProvider)manager.getActiveModelProvider();
- provider.waitUntilDone(new IProgressMonitor() {
+ IProgressMonitor eventLoopProgressMonitor = new IProgressMonitor() {
public void beginTask(String name, int totalWork) {
}
public void done() {
@@ -206,7 +201,16 @@ public class CVSChangeSetTests extends CVSSyncSubscriberTest {
public void worked(int work) {
while (Display.getCurrent().readAndDispatch()) {}
}
- });
+ };
+ SynchronizeViewTestAdapter.getCollector(workspaceSubscriber);
+ ISynchronizeParticipant participant = SynchronizeViewTestAdapter.getParticipant(workspaceSubscriber);
+ ChangeSetCapability capability = participant.getChangeSetCapability();
+ SubscriberChangeSetCollector activeManager = capability.getActiveChangeSetManager();
+ activeManager.waitUntilDone(eventLoopProgressMonitor);
+ SubscriberParticipantPage page = (SubscriberParticipantPage)SynchronizeViewTestAdapter.getSyncViewPage(participant);
+ ChangeSetModelManager manager = (ChangeSetModelManager)page.getConfiguration().getProperty(SynchronizePageConfiguration.P_MODEL_MANAGER);
+ AbstractSynchronizeModelProvider provider = (AbstractSynchronizeModelProvider)manager.getActiveModelProvider();
+ provider.waitUntilDone(eventLoopProgressMonitor);
return provider.getModelRoot();
}
@@ -288,6 +292,18 @@ public class CVSChangeSetTests extends CVSSyncSubscriberTest {
}
private void assertResourcesAreTheSame(IResource[] resources1, IResource[] resources2) {
+ if (resources1.length != resources2.length) {
+ System.out.println("Expected");
+ for (int i = 0; i < resources1.length; i++) {
+ IResource resource = resources1[i];
+ System.out.println(resource.getFullPath().toString());
+ }
+ System.out.println("Actual");
+ for (int i = 0; i < resources2.length; i++) {
+ IResource resource = resources2[i];
+ System.out.println(resource.getFullPath().toString());
+ }
+ }
assertEquals("The number of resources do not match the expected number", resources1.length, resources2.length);
for (int i = 0; i < resources1.length; i++) {
IResource resource = resources1[i];
@@ -299,7 +315,7 @@ public class CVSChangeSetTests extends CVSSyncSubscriberTest {
break;
}
}
- assertTrue("Expected resource " + resource.getFullPath().toString() + " was not presebt", found);
+ assertTrue("Expected resource " + resource.getFullPath().toString() + " was not present", found);
}
}
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/SyncInfoSource.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/SyncInfoSource.java
index d6d0cca6b..1766aa9ae 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/SyncInfoSource.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/SyncInfoSource.java
@@ -95,4 +95,13 @@ public class SyncInfoSource {
// Do nothing
}
+
+ /**
+ * Assert that the model for the subscriber matches what is being displayed.
+ * Default is to do nothing. Subclasses may override
+ * @param subscriber the subscriber
+ */
+ public void assertViewMatchesModel(Subscriber subscriber) {
+ // Default is to do nothing. Subclasses may override
+ }
}
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/SynchronizeViewTestAdapter.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/SynchronizeViewTestAdapter.java
index 5ba4458a8..416e4d1b3 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/SynchronizeViewTestAdapter.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/SynchronizeViewTestAdapter.java
@@ -12,10 +12,14 @@ package org.eclipse.team.tests.ccvs.ui;
import junit.framework.AssertionFailedError;
+import org.eclipse.compare.structuremergeviewer.IDiffContainer;
import org.eclipse.compare.structuremergeviewer.IDiffElement;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.swt.widgets.Display;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.widgets.*;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.subscribers.Subscriber;
import org.eclipse.team.core.synchronize.*;
@@ -102,6 +106,29 @@ public class SynchronizeViewTestAdapter extends SyncInfoSource {
if (participant == null) return null;
SubscriberSyncInfoCollector syncInfoCollector = participant.getSubscriberSyncInfoCollector();
EclipseTest.waitForSubscriberInputHandling(syncInfoCollector);
+ SubscriberParticipantPage page = getPage(subscriber);
+ SynchronizeModelManager manager = (SynchronizeModelManager)page.getConfiguration().getProperty(SynchronizePageConfiguration.P_MODEL_MANAGER);
+ AbstractSynchronizeModelProvider provider = (AbstractSynchronizeModelProvider)manager.getActiveModelProvider();
+ provider.waitUntilDone(new IProgressMonitor() {
+ public void beginTask(String name, int totalWork) {
+ }
+ public void done() {
+ }
+ public void internalWorked(double work) {
+ }
+ public boolean isCanceled() {
+ return false;
+ }
+ public void setCanceled(boolean value) {
+ }
+ public void setTaskName(String name) {
+ }
+ public void subTask(String name) {
+ }
+ public void worked(int work) {
+ while (Display.getCurrent().readAndDispatch()) {}
+ }
+ });
return syncInfoCollector;
}
@@ -201,6 +228,7 @@ public class SynchronizeViewTestAdapter extends SyncInfoSource {
super.refresh(subscriber, resources);
// Getting the collector waits for the subscriber input handlers
getCollector(subscriber);
+ assertViewMatchesModel(subscriber);
}
/* (non-Javadoc)
@@ -212,29 +240,10 @@ public class SynchronizeViewTestAdapter extends SyncInfoSource {
}
private SyncInfo internalGetSyncInfo(Subscriber subscriber, IResource resource) {
- try {
- SubscriberParticipant participant = getParticipant(subscriber);
- IWorkbenchPage activePage = TeamUIPlugin.getActivePage();
- ISynchronizeView view = (ISynchronizeView)activePage.showView(ISynchronizeView.VIEW_ID);
- IPage page = ((SynchronizeView)view).getPage(participant);
- if (page instanceof SubscriberParticipantPage) {
- SubscriberParticipantPage subscriberPage = (SubscriberParticipantPage)page;
- ISynchronizeModelElement root = subscriberPage.getViewerAdvisor().getModelManager().getModelRoot();
- if (root != null) {
- return findSyncInfo(root, resource);
- }
- }
- } catch (PartInitException e) {
- throw new AssertionFailedError("Cannot show sync view in active page");
- }
- return null;
+ ISynchronizeModelElement root = getModelRoot(subscriber);
+ return findSyncInfo(root, resource);
}
- /**
- * @param root
- * @param resource
- * @return
- */
private SyncInfo findSyncInfo(ISynchronizeModelElement node, IResource resource) {
if (node instanceof SyncInfoModelElement) {
SyncInfoModelElement element = (SyncInfoModelElement)node;
@@ -258,4 +267,72 @@ public class SynchronizeViewTestAdapter extends SyncInfoSource {
IPage page = ((SynchronizeView)view).getPage(participant);
return (ISynchronizePage)page;
}
+
+ public void assertViewMatchesModel(Subscriber subscriber) {
+ ISynchronizeModelElement root = getModelRoot(subscriber);
+ TreeItem[] rootItems = getTreeItems(subscriber);
+ assertMatchingTrees(root, rootItems, root.getChildren());
+ }
+
+ private ISynchronizeModelElement getModelRoot(Subscriber subscriber) {
+ SubscriberParticipantPage page = getPage(subscriber);
+ return page.getViewerAdvisor().getModelManager().getModelRoot();
+ }
+
+ private TreeItem[] getTreeItems(Subscriber subscriber) {
+ SubscriberParticipantPage page = getPage(subscriber);
+ Viewer v = page.getViewer();
+ if (v instanceof TreeViewer) {
+ TreeViewer treeViewer = (TreeViewer)v;
+ treeViewer.expandAll();
+ Tree t = (treeViewer).getTree();
+ return t.getItems();
+ }
+ throw new AssertionFailedError("The tree for " + subscriber.getName() + " could not be retrieved");
+ }
+
+ private static SubscriberParticipantPage getPage(Subscriber subscriber) {
+ try {
+ SubscriberParticipant participant = getParticipant(subscriber);
+ IWorkbenchPage activePage = TeamUIPlugin.getActivePage();
+ ISynchronizeView view = (ISynchronizeView)activePage.showView(ISynchronizeView.VIEW_ID);
+ IPage page = ((SynchronizeView)view).getPage(participant);
+ if (page instanceof SubscriberParticipantPage) {
+ SubscriberParticipantPage subscriberPage = (SubscriberParticipantPage)page;
+ return subscriberPage;
+ }
+ } catch (PartInitException e) {
+ throw new AssertionFailedError("Cannot show sync view in active page");
+ }
+ throw new AssertionFailedError("The page for " + subscriber.getName() + " could not be retrieved");
+ }
+
+ private void assertMatchingTrees(IDiffElement parent, TreeItem[] items, IDiffElement[] children) {
+ if ((items == null || items.length == 0) && (children == null || children.length == 0)) {
+ // No childen in either case so just return
+ return;
+ }
+ if (items == null || children == null || items.length != children.length) {
+ throw new AssertionFailedError("The number of children of " + parent.getName() + " is " +
+ (children == null ? 0: children.length) + " but the view has " +
+ (items == null ? 0 : items.length));
+ }
+ for (int i = 0; i < children.length; i++) {
+ IDiffElement element = children[i];
+ TreeItem foundItem = null;
+ for (int j = 0; j < items.length; j++) {
+ TreeItem item = items[j];
+ if (item.getData() == element) {
+ foundItem = item;
+ break;
+ }
+ }
+ if (foundItem == null) {
+ throw new AssertionFailedError("Element" + element.getName() + " is in the model but not in the view");
+ } else {
+ assertMatchingTrees(element, foundItem.getItems(), ((IDiffContainer)element).getChildren());
+ }
+ }
+
+ }
}

Back to the top