Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9d72f84ee860dec248a8193560c40cbf8817a817 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*******************************************************************************
 * Copyright (c) 2000, 2006 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.ccvs.ui;

import java.io.IOException;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.internal.ccvs.core.ICVSFolder;
import org.eclipse.team.internal.ccvs.core.ICVSRemoteFolder;
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
import org.eclipse.team.internal.ccvs.ui.operations.CVSOperation;
import org.eclipse.team.internal.ccvs.ui.operations.CheckoutMultipleProjectsOperation;
import org.eclipse.team.internal.ccvs.ui.operations.CheckoutSingleProjectOperation;
import org.eclipse.team.tests.ccvs.core.CVSTestSetup;

public class CheckoutOperationTests extends CVSOperationTest { 

	public CheckoutOperationTests() {
	}

	public CheckoutOperationTests(String name) {
		super(name);
	}

	public static Test suite() {
		String testName = System.getProperty("eclipse.cvs.testName");
		if (testName == null) {
			TestSuite suite = new TestSuite(CheckoutOperationTests.class);
			return new CVSTestSetup(suite);
		} else {
			return new CVSTestSetup(new CheckoutOperationTests(testName));
		}
	}
	public void testSimpleCheckout() throws CoreException, TeamException, IOException {
		IProject project = createProject("testSimpleCheckout", new String[] { "changed.txt", "deleted.txt", "folder1/", "folder1/a.txt" });
		
		// move the created project so we can do a simple checkout
		project.move(new Path("moved-project"), false /* force */, DEFAULT_MONITOR);
		IProject movedProject = ResourcesPlugin.getWorkspace().getRoot().getProject("moved-project");
		
		// checkout the project to the default location		
		CVSOperation op = new CheckoutMultipleProjectsOperation(
			null /* shell */, 
			new ICVSRemoteFolder[] { (ICVSRemoteFolder)CVSWorkspaceRoot.getRemoteResourceFor(movedProject) },
			null /*target location*/);
		run(op);
		
		assertEquals(project, movedProject);
	}
	
	public void testNonRootCheckout() throws CoreException, TeamException, IOException {
		IProject project = createProject("testNonRootCheckout", new String[] { "changed.txt", "deleted.txt", "folder1/", "folder1/a.txt" });
		
		// checkout the non-root folder as a project to the default location		
		CVSOperation op = new CheckoutMultipleProjectsOperation(
			null /* shell */, 
			new ICVSRemoteFolder[] { (ICVSRemoteFolder)CVSWorkspaceRoot.getRemoteResourceFor(project.getFolder("folder1")) },
			null /*target location*/);
		run(op);
		
		IProject newProject = ResourcesPlugin.getWorkspace().getRoot().getProject("folder1");
		assertTrue(newProject.exists());
		ICVSFolder cvsFolder = CVSWorkspaceRoot.getCVSFolderFor(newProject);
		FolderSyncInfo projectInfo = cvsFolder.getFolderSyncInfo();
		assertTrue(projectInfo != null);
		ICVSFolder cvsFolder2 = CVSWorkspaceRoot.getCVSFolderFor(project.getFolder("folder1"));
		FolderSyncInfo folderInfo = cvsFolder2.getFolderSyncInfo();
		assertTrue(folderInfo != null);
		assertTrue(projectInfo.equals(folderInfo));
	}
	
	public void testMulitpleCheckout() throws CoreException, TeamException {
		IProject project1 = createProject("testNonRootCheckout1", new String[] { "file.txt", "folder1/", "folder1/a.txt" });
		IProject project2 = createProject("testNonRootCheckout2", new String[] { "file2.txt", "folder2/", "folder2/b.txt" });

		// move the created project so we can do a simple checkout
		project1.move(new Path("moved-project1"), false /* force */, DEFAULT_MONITOR);
		IProject movedProject1 = ResourcesPlugin.getWorkspace().getRoot().getProject("moved-project1");
		project2.move(new Path("moved-project2"), false /* force */, DEFAULT_MONITOR);
		IProject movedProject2 = ResourcesPlugin.getWorkspace().getRoot().getProject("moved-project2");


		// checkout the project to the default location		
		CVSOperation op = new CheckoutMultipleProjectsOperation(
			null /* shell */, 
			new ICVSRemoteFolder[] { 
				(ICVSRemoteFolder)CVSWorkspaceRoot.getRemoteResourceFor(movedProject1),
				(ICVSRemoteFolder)CVSWorkspaceRoot.getRemoteResourceFor(movedProject2)
			},
			null /*target location*/);
		run(op);
	}
	
	public void testCheckoutAs() throws TeamException, CoreException, IOException {
		IProject project = createProject("testCheckoutAs", new String[] { "changed.txt", "deleted.txt", "folder1/", "folder1/a.txt" });
		IProject copy = ResourcesPlugin.getWorkspace().getRoot().getProject(project.getName() + "-copy");
		
		// checkout the project to the default location		
		CVSOperation op = new CheckoutSingleProjectOperation(
			null /* shell */, 
			(ICVSRemoteFolder)CVSWorkspaceRoot.getRemoteResourceFor(project),
			copy,
			null /*target location*/,
			false);
		run(op);
		
		assertEquals(project, copy);
	}

}

Back to the top