diff options
author | Michael Valenta | 2007-01-24 18:56:46 +0000 |
---|---|---|
committer | Michael Valenta | 2007-01-24 18:56:46 +0000 |
commit | b258f6e6e76d25c904dfbec138bb25935c0d501f (patch) | |
tree | 654410b2ddf838b771e46cb76717b14b63f192ae /tests/org.eclipse.team.tests.core/src | |
parent | 0fe69bb8197f6c95f4c595a1dfaf032441cc1252 (diff) | |
download | eclipse.platform.team-b258f6e6e76d25c904dfbec138bb25935c0d501f.tar.gz eclipse.platform.team-b258f6e6e76d25c904dfbec138bb25935c0d501f.tar.xz eclipse.platform.team-b258f6e6e76d25c904dfbec138bb25935c0d501f.zip |
Bug 132881 [Model Sync] Removal of element from working set doesn't update sync view
Diffstat (limited to 'tests/org.eclipse.team.tests.core/src')
4 files changed, 191 insertions, 1 deletions
diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTeamTests.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTeamTests.java index 9d207aa20..78b4da80d 100644 --- a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTeamTests.java +++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTeamTests.java @@ -14,6 +14,7 @@ import junit.framework.Test; import junit.framework.TestSuite; import org.eclipse.core.tests.resources.ResourceTest; +import org.eclipse.team.tests.core.mapping.ScopeTests; public class AllTeamTests extends ResourceTest { @@ -37,6 +38,7 @@ public class AllTeamTests extends ResourceTest { suite.addTest(RepositoryProviderTests.suite()); suite.addTest(StreamTests.suite()); suite.addTest(StorageMergerTests.suite()); + suite.addTest(ScopeTests.suite()); return suite; } } diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/mapping/ScopeBuildingTests.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/mapping/ScopeBuildingTests.java index 0a3f0b47f..69121a6df 100644 --- a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/mapping/ScopeBuildingTests.java +++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/mapping/ScopeBuildingTests.java @@ -42,7 +42,7 @@ public class ScopeBuildingTests extends TeamTest { ResourceTraversal[] traversals = mapping.getTraversals(getContext(), monitor); ((ResourceMappingScope)getScope()).addMapping(mapping, traversals); // TODO: The additional mappings and additional resources boolean will not be set - // TODO: This may bring in mappings from the resources modle provider + // TODO: This may bring in mappings from the resources model provider } } }); diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/mapping/ScopeTestSubscriber.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/mapping/ScopeTestSubscriber.java new file mode 100644 index 000000000..04fd888e7 --- /dev/null +++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/mapping/ScopeTestSubscriber.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.tests.core.mapping; + +import org.eclipse.core.resources.*; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.team.core.TeamException; +import org.eclipse.team.core.subscribers.Subscriber; +import org.eclipse.team.core.synchronize.SyncInfo; +import org.eclipse.team.core.variants.IResourceVariant; +import org.eclipse.team.core.variants.IResourceVariantComparator; + +public class ScopeTestSubscriber extends Subscriber { + + public String getName() { + return "Scope Tests"; + } + + public IResourceVariantComparator getResourceComparator() { + return new IResourceVariantComparator() { + public boolean isThreeWay() { + return false; + } + public boolean compare(IResourceVariant base, IResourceVariant remote) { + return false; + } + public boolean compare(IResource local, IResourceVariant remote) { + return false; + } + + }; + } + + public SyncInfo getSyncInfo(IResource resource) throws TeamException { + return null; + } + + public boolean isSupervised(IResource resource) throws TeamException { + return false; + } + + public IResource[] members(IResource resource) throws TeamException { + if (resource instanceof IContainer) { + IContainer c = (IContainer) resource; + try { + return c.members(); + } catch (CoreException e) { + throw TeamException.asTeamException(e); + } + } + return new IResource[0]; + } + + public void refresh(IResource[] resources, int depth, + IProgressMonitor monitor) throws TeamException { + // Nothing to do + } + + public IResource[] roots() { + return ResourcesPlugin.getWorkspace().getRoot().getProjects(); + } + +} diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/mapping/ScopeTests.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/mapping/ScopeTests.java new file mode 100644 index 000000000..7dadf28d7 --- /dev/null +++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/mapping/ScopeTests.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.tests.core.mapping; + +import junit.framework.Test; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.mapping.ResourceMapping; +import org.eclipse.core.runtime.*; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.team.core.mapping.ISynchronizationScopeManager; +import org.eclipse.team.core.subscribers.SubscriberScopeManager; +import org.eclipse.team.internal.ui.Utils; +import org.eclipse.team.tests.core.TeamTest; +import org.eclipse.ui.*; + +public class ScopeTests extends TeamTest { + + public static Test suite() { + return suite(ScopeTests.class); + } + private IProject project1, project2, project3; + private IWorkingSet workingSet; + private SubscriberScopeManager manager; + + public ScopeTests() { + super(); + } + + public ScopeTests(String name) { + super(name); + } + + protected void setUp() throws Exception { + super.setUp(); + project1 = createProject("p1", new String[]{"file.txt"}); + project2 = createProject("p2", new String[]{"file.txt"}); + project3 = createProject("p3", new String[]{"file.txt"}); + IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager(); + workingSet = manager.createWorkingSet("TestWS", new IProject[] { project1 }); + manager.addWorkingSet(workingSet); + } + + protected void tearDown() throws Exception { + super.tearDown(); + this.manager.dispose(); + project1.delete(true, null); + project2.delete(true, null); + IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager(); + manager.removeWorkingSet(workingSet); + } + + private void assertProperContainment(ISynchronizationScopeManager sm) throws OperationCanceledException, InterruptedException { + waitForManager(sm); + testProjectContainment(sm, project1); + testProjectContainment(sm, project2); + testProjectContainment(sm, project3); + } + + private void waitForManager(ISynchronizationScopeManager sm) throws OperationCanceledException, InterruptedException { + Job.getJobManager().join(sm, null); + } + + private void testProjectContainment(ISynchronizationScopeManager sm, IProject project) { + if (isInWorkingSet(project) && !isInScope(sm, project)) + fail(project.getName() + " is in the working set but not in the scope"); + if (!isInWorkingSet(project) && isInScope(sm, project)) + fail(project.getName() + " is in scope but not in the working set"); + } + + private boolean isInScope(ISynchronizationScopeManager sm, IProject project) { + return sm.getScope().contains(project); + } + + private boolean isInWorkingSet(IProject project) { + IAdaptable[] elements = workingSet.getElements(); + for (int i = 0; i < elements.length; i++) { + IAdaptable adaptable = elements[i]; + if (adaptable.equals(project)) + return true; + } + return false; + } + + private ISynchronizationScopeManager createScopeManager() throws CoreException, OperationCanceledException, InterruptedException { + ScopeTestSubscriber subscriber = new ScopeTestSubscriber(); + manager = new SubscriberScopeManager(subscriber.getName(), new ResourceMapping[] { Utils.getResourceMapping(workingSet) }, subscriber, true); + manager.initialize(new NullProgressMonitor()); + waitForManager(manager); + return manager; + } + + public void testScopeExpansion() throws CoreException, OperationCanceledException, InterruptedException { + ISynchronizationScopeManager sm = createScopeManager(); + assertProperContainment(sm); + workingSet.setElements( new IProject[] { project1, project2 }); + assertProperContainment(sm); + } + + public void testScopeContraction() throws OperationCanceledException, InterruptedException, CoreException { + workingSet.setElements( new IProject[] { project1, project2 }); + ISynchronizationScopeManager sm = createScopeManager(); + assertProperContainment(sm); + workingSet.setElements( new IProject[] { project1 }); + assertProperContainment(sm); + } + +} |