Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2004-09-23 18:32:18 +0000
committerMichael Valenta2004-09-23 18:32:18 +0000
commitc26e28e9ea98b59d55d9c8293763ad1aaac6516a (patch)
tree832fa5c0bfda92f726eaecdda7ac27db785d50dd
parent62e7329944fbf06a691a3b3e0984ab3fe0c62505 (diff)
downloadeclipse.platform.team-c26e28e9ea98b59d55d9c8293763ad1aaac6516a.tar.gz
eclipse.platform.team-c26e28e9ea98b59d55d9c8293763ad1aaac6516a.tar.xz
eclipse.platform.team-c26e28e9ea98b59d55d9c8293763ad1aaac6516a.zip
Initial test case for commit sets
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/EclipseTest.java9
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSChangeSetTests.java175
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSSyncSubscriberTest.java9
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/SynchronizeViewTestAdapter.java12
4 files changed, 192 insertions, 13 deletions
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 10297fa4d..412a0655c 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
@@ -258,13 +258,18 @@ public class EclipseTest extends EclipseWorkspaceTest {
return resources;
}
+ protected void commitResources(IResource[] resources, int depth) throws TeamException, CoreException {
+ commitResources(resources, depth, "");
+ }
+
/*
* Commit the provided resources which must all be in the same project
*/
- protected void commitResources(IResource[] resources, int depth) throws TeamException, CoreException {
+ protected void commitResources(IResource[] resources, int depth, String message) throws TeamException, CoreException {
if (resources.length == 0) return;
- executeHeadless(new CommitOperation(null, resources, new Command.LocalOption[] { Commit.makeArgumentOption(Command.MESSAGE_OPTION, "") }));
+ executeHeadless(new CommitOperation(null, resources, new Command.LocalOption[] { Commit.makeArgumentOption(Command.MESSAGE_OPTION, message) }));
}
+
/**
* Commit the resources from an existing container to the CVS repository
*/
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
new file mode 100644
index 000000000..c71fdb45b
--- /dev/null
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSChangeSetTests.java
@@ -0,0 +1,175 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.tests.ccvs.core.subscriber;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Test;
+
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
+import org.eclipse.core.resources.*;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.subscribers.Subscriber;
+import org.eclipse.team.internal.ccvs.core.CVSTag;
+import org.eclipse.team.internal.ccvs.ui.subscriber.ChangeLogDiffNode;
+import org.eclipse.team.internal.ccvs.ui.subscriber.ChangeLogModelManager;
+import org.eclipse.team.internal.ui.synchronize.*;
+import org.eclipse.team.tests.ccvs.ui.SynchronizeViewTestAdapter;
+import org.eclipse.team.ui.synchronize.ISynchronizeModelElement;
+import org.eclipse.team.ui.synchronize.ISynchronizeParticipant;
+import org.eclipse.ui.PartInitException;
+
+/**
+ * Tests the change set mode of the synchronize view
+ */
+public class CVSChangeSetTests extends CVSSyncSubscriberTest {
+
+ public static Test suite() {
+ return suite(CVSChangeSetTests.class);
+ }
+
+ public CVSChangeSetTests() {
+ super();
+ }
+
+ public CVSChangeSetTests(String name) {
+ super(name);
+ }
+
+ private void assertIncomingChangesInSets(IFile[][] files, String[] messages) throws CoreException {
+ // Get the workspace subscriber which also creates a participant and page in the sync view
+ Subscriber workspaceSubscriber = getWorkspaceSubscriber();
+ enableCommitSets(workspaceSubscriber);
+ refresh(workspaceSubscriber);
+ ISynchronizeModelElement root = getModelRoot(workspaceSubscriber);
+ for (int i = 0; i < messages.length; i++) {
+ String message = messages[i];
+ ChangeLogDiffNode node = getCommitSetFor(root, message);
+ assertNotNull("The commit set for '" + message + "' is not in the sync view", node);
+ List filesInSet = new ArrayList();
+ getFileChildren(node, filesInSet);
+ assertTrue("The number of files in the set do not match the expected number", files[i].length == filesInSet.size());
+ for (int j = 0; j < files[i].length; j++) {
+ IFile file = files[i][j];
+ assertTrue("File " + file.getFullPath() + " is not in the set", filesInSet.contains(file));
+ }
+ }
+ }
+
+ /**
+ * Adds IFiles to the list
+ */
+ private void getFileChildren(ISynchronizeModelElement node, List list) {
+ IResource resource = node.getResource();
+ if (resource != null && resource.getType() == IResource.FILE) {
+ list.add(resource);
+ }
+ IDiffElement[] children = node.getChildren();
+ for (int i = 0; i < children.length; i++) {
+ IDiffElement child = children[i];
+ getFileChildren((ISynchronizeModelElement)child, list);
+ }
+ return;
+ }
+
+ private ChangeLogDiffNode getCommitSetFor(ISynchronizeModelElement root, String message) {
+ IDiffElement[] children = root.getChildren();
+ for (int i = 0; i < children.length; i++) {
+ IDiffElement element = children[i];
+ if (element instanceof ChangeLogDiffNode) {
+ ChangeLogDiffNode node = (ChangeLogDiffNode)element;
+ if (node.getComment().getComment().equals(message)) {
+ return node;
+ }
+ }
+ }
+ return null;
+ }
+
+ private void refresh(Subscriber workspaceSubscriber) throws TeamException {
+ workspaceSubscriber.refresh(workspaceSubscriber.roots(), IResource.DEPTH_INFINITE, DEFAULT_MONITOR);
+ }
+
+ private void enableCommitSets(Subscriber workspaceSubscriber) throws PartInitException {
+ ISynchronizeParticipant participant = SynchronizeViewTestAdapter.getParticipant(workspaceSubscriber);
+ SubscriberParticipantPage page = (SubscriberParticipantPage)SynchronizeViewTestAdapter.getSyncViewPage(participant);
+ ChangeLogModelManager manager = (ChangeLogModelManager)page.getConfiguration().getProperty(SynchronizePageConfiguration.P_MODEL_MANAGER);
+ manager.setCommitSetsEnabled(true);
+ }
+
+ /*
+ * 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);
+ ChangeLogModelManager manager = (ChangeLogModelManager)page.getConfiguration().getProperty(SynchronizePageConfiguration.P_MODEL_MANAGER);
+ AbstractSynchronizeModelProvider provider = (AbstractSynchronizeModelProvider)manager.getActiveModelProvider();
+ provider.waitForUpdateHandler(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 provider.getModelRoot();
+ }
+
+ public void testSimpleCommit() throws CoreException {
+ IProject project = createProject(new String[] { "file1.txt", "file2.txt", "folder1/", "folder1/a.txt", "folder1/b.txt"});
+
+ // Modify a file in a copy
+ IProject copy = checkoutCopy(project, CVSTag.DEFAULT);
+ setContentsAndEnsureModified(copy.getFile("file1.txt"));
+ String message1 = "Commit 1";
+ commitResources(new IResource[] {copy}, IResource.DEPTH_INFINITE, message1);
+ assertIncomingChangesInSets(new IFile[][] {{ project.getFile("file1.txt") }}, new String[] {message1});
+
+ // Modify the copy some more
+ setContentsAndEnsureModified(copy.getFile("file2.txt"));
+ setContentsAndEnsureModified(copy.getFile("folder1/a.txt"));
+ String message2 = "Commit 2";
+ commitResources(new IResource[] {copy}, IResource.DEPTH_INFINITE, message2);
+ assertIncomingChangesInSets(new IFile[][] {
+ { project.getFile("file1.txt") },
+ { project.getFile("file2.txt"), project.getFile("folder1/a.txt") }
+ }, new String[] {message1, message2});
+
+ // Modify the copy some more
+ setContentsAndEnsureModified(copy.getFile("file2.txt"));
+ String message3 = "Commit 3";
+ commitResources(new IResource[] {copy}, IResource.DEPTH_INFINITE, message3);
+ assertIncomingChangesInSets(new IFile[][] {
+ { project.getFile("file1.txt") },
+ { project.getFile("folder1/a.txt") },
+ { project.getFile("file2.txt")}
+ }, new String[] {message1, message2, message3});
+ }
+
+}
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSSyncSubscriberTest.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSSyncSubscriberTest.java
index ebf364fd9..4abdbc0a4 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSSyncSubscriberTest.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSSyncSubscriberTest.java
@@ -113,10 +113,6 @@ public abstract class CVSSyncSubscriberTest extends EclipseTest {
return getSyncInfoSource().getSyncInfo(subscriber, resource);
}
- /**
- * @param changes
- * @param resources
- */
protected void assertSyncChangesMatch(ISubscriberChangeEvent[] changes, IResource[] resources) {
// First, ensure that all the resources appear in the delta
for (int i = 0; i < resources.length; i++) {
@@ -190,11 +186,6 @@ public abstract class CVSSyncSubscriberTest extends EclipseTest {
return (IResource[]) affected.toArray(new IResource[affected.size()]);
}
- /**
- * @param resources
- * @param condition
- * @return
- */
protected IResource[] collectAncestors(IResource[] resources, ResourceCondition condition) throws CoreException, TeamException {
Set affected = new HashSet();
for (int i = 0; i < resources.length; i++) {
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 b7e2f7064..af25bd586 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
@@ -36,6 +36,7 @@ import org.eclipse.team.internal.ui.synchronize.SynchronizeView;
import org.eclipse.team.tests.ccvs.core.EclipseTest;
import org.eclipse.team.tests.ccvs.core.subscriber.SyncInfoSource;
import org.eclipse.team.ui.TeamUI;
+import org.eclipse.team.ui.synchronize.*;
import org.eclipse.team.ui.synchronize.ISynchronizeManager;
import org.eclipse.team.ui.synchronize.ISynchronizeParticipant;
import org.eclipse.team.ui.synchronize.ISynchronizeParticipantReference;
@@ -92,7 +93,7 @@ public class SynchronizeViewTestAdapter extends SyncInfoSource {
return info;
}
- private SubscriberParticipant getParticipant(Subscriber subscriber) {
+ public static SubscriberParticipant getParticipant(Subscriber subscriber) {
// show the sync view
ISynchronizeParticipantReference[] participants = TeamUI.getSynchronizeManager().getSynchronizeParticipants();
for (int i = 0; i < participants.length; i++) {
@@ -111,7 +112,7 @@ public class SynchronizeViewTestAdapter extends SyncInfoSource {
return null;
}
- private SubscriberSyncInfoCollector getCollector(Subscriber subscriber) {
+ public static SubscriberSyncInfoCollector getCollector(Subscriber subscriber) {
SubscriberParticipant participant = getParticipant(subscriber);
if (participant == null) return null;
SubscriberSyncInfoCollector syncInfoCollector = participant.getSubscriberSyncInfoCollector();
@@ -247,4 +248,11 @@ public class SynchronizeViewTestAdapter extends SyncInfoSource {
}
return null;
}
+
+ public static ISynchronizePage getSyncViewPage(ISynchronizeParticipant participant) throws PartInitException {
+ IWorkbenchPage activePage = TeamUIPlugin.getActivePage();
+ ISynchronizeView view = (ISynchronizeView)activePage.showView(ISynchronizeView.VIEW_ID);
+ IPage page = ((SynchronizeView)view).getPage(participant);
+ return (ISynchronizePage)page;
+ }
}

Back to the top