Skip to main content
summaryrefslogtreecommitdiffstats
blob: 42662c4c66fe287488a6a5ab0bfbfbb291460d65 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*******************************************************************************
 * Copyright (c) 2002 IBM Corporation and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 * IBM - Initial API and implementation
 ******************************************************************************/
package org.eclipse.team.tests.ccvs.core.cvsresources;

import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.team.ccvs.core.ICVSFolder;
import org.eclipse.team.ccvs.core.ICVSResource;
import org.eclipse.team.ccvs.core.ICVSRunnable;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
import org.eclipse.team.tests.ccvs.core.CVSTestSetup;
import org.eclipse.team.tests.ccvs.core.EclipseTest;

/**
 * What does this class do?
 */
public class EclipseFolderTest extends EclipseTest {
	public EclipseFolderTest() {
		super();
	}
	
	public EclipseFolderTest(String name) {
		super(name);
	}
	
	public static Test suite() {
		TestSuite suite = new TestSuite();
		suite.addTestSuite(EclipseFolderTest.class);
		return new CVSTestSetup(suite);
	}
	
	protected void assertChildrenHaveSync(IContainer root, final boolean hasSync) throws CoreException, CVSException {
		root.accept(new IResourceVisitor() {
			public boolean visit(IResource resource) throws CoreException {
				try {
					ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource);
					if(!cvsResource.isIgnored()) {
						if(resource.getType()==IResource.FILE) {
							assertTrue((cvsResource.getSyncInfo()!=null) == hasSync);
						} else {
							assertTrue((((ICVSFolder)cvsResource).getFolderSyncInfo()!=null) == hasSync);
						}
					}
				} catch(CVSException e) {
					throw new CoreException(e.getStatus());
				}
				return true;
			}
		});
	}
	
	public void testUnmanageFolder() throws CoreException, TeamException {
		IProject project = createProject("testUnmanageFolder_A", new String[] {"a.txt", "folder1/", "folder1/b.txt", "folder1/folder2/", "folder1/folder2/c.txt"});
		ICVSFolder cvsProject = CVSWorkspaceRoot.getCVSFolderFor(project);
		assertChildrenHaveSync(project, true);
		
		// test that unmanaging the project flushes sync info
		cvsProject.unmanage(null);
		assertChildrenHaveSync(project, false);
		
		final IProject projectB = createProject("testUnmanageFolder_B", new String[] {"a.txt", "folder1/", "folder1/b.txt", "folder1/folder2/", "folder1/folder2/c.txt"});
		final ICVSFolder cvsProjectB = CVSWorkspaceRoot.getCVSFolderFor(projectB);
		assertChildrenHaveSync(projectB, true);
		
		// test that unmanaging in a CVS runnable flushes too
		cvsProjectB.run(new ICVSRunnable() {
			public void run(IProgressMonitor monitor) throws CVSException {
					try {
						assertChildrenHaveSync(projectB, true);
						cvsProjectB.unmanage(null);
						assertChildrenHaveSync(projectB, false);
					} catch(CoreException e) {
						throw CVSException.wrapException(e);
					}
			}
		}, null);		
		assertChildrenHaveSync(projectB, false);
	}
}

Back to the top