Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7e448d3d10b56fcca25e3e22937fe1c800647595 (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
127
128
129
130
131
132
133
134
135
/*******************************************************************************
 * Copyright (c) 2000, 2007 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.tests.ccvs.core.provider;

import java.io.IOException;

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

import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
import org.eclipse.team.internal.ccvs.core.CVSTag;
import org.eclipse.team.tests.ccvs.core.CVSTestSetup;
import org.eclipse.team.tests.ccvs.core.EclipseTest;

/**
 * Test the cvs watch/edit functionality
 */
public class WatchEditTest extends EclipseTest {

	/**
	 * Constructor for CVSProviderTest
	 */
	public WatchEditTest() {
		super();
	}

	/**
	 * Constructor for CVSProviderTest
	 */
	public WatchEditTest(String name) {
		super(name);
	}

	public static Test suite() {
		TestSuite suite = new TestSuite(WatchEditTest.class);
		return new CVSTestSetup(suite);
		//return new CVSTestSetup(new WatchEditTest("testReadOnly"));
	}
	
	protected boolean isFailOnSyncInfoMismatch() {
		// See  bug 198382
		return CVSTestSetup.FAIL_ON_BAD_DIFF ;
	}
	
	private void setReadOnly(boolean b) {
		CVSProviderPlugin.getPlugin().getPluginPreferences().setValue(CVSProviderPlugin.READ_ONLY, b);
	}
	
	public void testReadOnlyCheckout() throws CoreException, TeamException {
		// Create a project
		IProject project = createProject("testReadOnlyCheckout", new String[] { "changed.txt", "deleted.txt", "folder1/", "folder1/a.txt" });
		// XXX project will not be read-only at this point because "cvs add" followed by a "cvs commit" doesn't set the resource "read-only"
		IProject copy = checkoutCopy(project, "copy");
		assertReadOnly(new IResource[] {copy}, true /* isReadOnly */, true /* recurse */);
	}

	public void testEditUnedit() throws CoreException, TeamException, IOException {
		// Create a project
		IProject project = createProject("testEditUnedit", new String[] { "changed.txt", "deleted.txt", "folder1/", "folder1/a.txt" });
		// XXX project will not be read-only at this point because "cvs add" followed by a "cvs commit" doesn't set the resource "read-only"
		IProject copy = checkoutCopy(project, "copy");
		assertReadOnly(new IResource[] {copy}, true /* isReadOnly */, true /* recurse */);
		editResources(copy, new String[] {"changed.txt", "deleted.txt"});
		setContentsAndEnsureModified(copy.getFile("changed.txt"));
		deleteResources(copy, new String[] {"deleted.txt"}, false);
		uneditResources(copy, new String[] {"changed.txt", "deleted.txt"});
		assertEquals(project, copy);
	}
	
	public void testCommit() throws CoreException, TeamException {
		// Create a project
		IProject project = createProject("testCommit", new String[] { "changed.txt", "deleted.txt", "folder1/", "folder1/a.txt" });
		// XXX project will not be read-only at this point because "cvs add" followed by a "cvs commit" doesn't set the resource "read-only"
		IProject copy = checkoutCopy(project, "copy");
		editResources(copy, new String[] {"changed.txt"});
		setContentsAndEnsureModified(copy.getFile("changed.txt"));
		commitProject(copy);
		assertReadOnly(new IResource[] {copy.getFile("changed.txt")}, true /* isReadOnly */, true /* recurse */);
	}
	
	public void testEditMergeUnedit() throws CoreException, TeamException, IOException {
		// Create a project
		IProject project = createProject("testEditMergeUnedit", new String[] { "changed.txt", "deleted.txt", "folder1/", "folder1/a.txt" });
		// XXX project will not be read-only at this point because "cvs add" followed by a "cvs commit" doesn't set the resource "read-only"
		IProject copy = checkoutCopy(project, "copy");
		IProject copy2 = checkoutCopy(project, "copy2");
		// Modify the second copy and commit changes
		editResources(copy2, new String[] {"changed.txt"});
		setContentsAndEnsureModified(copy2.getFile("changed.txt"));
		commitProject(copy2);
		// Edit first copy, merge then unedit
		editResources(copy, new String[] {"changed.txt"});
		setContentsAndEnsureModified(copy.getFile("changed.txt"));
		updateProject(copy, CVSTag.DEFAULT, false);
		// XXX Update may or may not make the file read-only so it may need to be re-edited
		if (copy.getFile("changed.txt").isReadOnly()) {
			editResources(copy, new String[] {"changed.txt"});
		}
		uneditResources(copy, new String[] {"changed.txt", "deleted.txt"});
		IFile backup = copy.getFile(".#changed.txt.1.1");
		if (backup.exists()) backup.delete(true, false, null);
		assertEquals(project, copy);
	}
	
	/**
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();
		setReadOnly(true);
	}

	/**
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		super.tearDown();
		setReadOnly(false);
	}

}

Back to the top