Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 64b194f3f5090947a0f2332c5ed7692777b15b0d (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
/*******************************************************************************
 * 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.core.compatible;
import java.util.Date;
import java.util.GregorianCalendar;

import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.team.tests.ccvs.core.JUnitTestCase;

public class BasicTest extends JUnitTestCase {
	SameResultEnv env1;
	SameResultEnv env2;
	
	public BasicTest(String arg) {
		super(arg);
		env1 = new SameResultEnv(arg + "-checkout1");
		env2 = new SameResultEnv(arg + "-checkout2");
	}
	
	public BasicTest() {
		this("BasicTest");
	}

	public static void main(String[] args) {	
		run(BasicTest.class);
	}

	public static Test suite() {
		TestSuite suite = new TestSuite(BasicTest.class);
		return new CompatibleTestSetup(suite);
		//return new CompatibleTestSetup(new BasicTest("testReadOnly"));
	}
	public void setUp() throws Exception {
		env1.setUp();
		env2.setUp();

		// Set the project to the content we need ...
		env1.magicSetUpRepo("proj2",new String[]{"a.txt","f1/b.txt","f1/c.txt"});
		env2.deleteFile("proj2");
	}
	
	public void tearDown() throws Exception {
		env1.tearDown();
		env2.tearDown();
	}
	
	public void testAdd() throws Exception {
		
		env1.execute("co",EMPTY_ARGS,new String[]{"proj2"});
		env1.writeToFile("proj2/d.txt",new String[]{"The file to be added","next"});
		env1.mkdirs("proj2/f2/f3");
		env1.mkdirs("proj2/f4/f5");
		env1.writeToFile("proj2/f4/f5/e.txt", new String[]{"Another file to be added","next"});
		
		env1.execute("add",EMPTY_ARGS,new String[]{"d.txt"},"proj2");
		env1.execute("add",EMPTY_ARGS,new String[]{"f2","f2/f3"},"proj2");
		env1.execute("add",EMPTY_ARGS,new String[]{"f4"},"proj2");
		env1.execute("add",EMPTY_ARGS,new String[]{"f4/f5"},"proj2");
		env1.execute("add",EMPTY_ARGS,new String[]{"f4/f5/e.txt"},"proj2");
		env1.execute("ci",new String[]{"-m","TestMessage"},new String[]{"proj2"});

		// Check the stuff out somewhere else to acctually check, that
		// the file has been accepted
		env2.execute("co",EMPTY_ARGS,new String[]{"proj2"});		
	}

	public void testAddUpdate() throws Exception {
		
		env1.execute("co",EMPTY_ARGS,new String[]{"proj2"});
		env2.execute("co",EMPTY_ARGS,new String[]{"proj2"});		

		env1.writeToFile("proj2/d.txt",new String[]{"The file to be added","next"});
		env1.mkdirs("proj2/f2/f3");
		env1.mkdirs("proj2/f4/f5");
		env1.writeToFile("proj2/f4/f5/e.txt", new String[]{"Another file to be added","next"});
		
		env1.execute("add",EMPTY_ARGS,new String[]{"d.txt"},"proj2");
		env1.execute("add",EMPTY_ARGS,new String[]{"f2","f2/f3"},"proj2");
		env1.execute("add",EMPTY_ARGS,new String[]{"f4"},"proj2");
		env1.execute("add",EMPTY_ARGS,new String[]{"f4/f5"},"proj2");
		env1.execute("add",EMPTY_ARGS,new String[]{"f4/f5/e.txt"},"proj2");
		env1.execute("ci",new String[]{"-m","TestMessage"},new String[]{"proj2"});

		env2.execute("update",EMPTY_ARGS,new String[]{"proj2"});		

	}

	public void testRemove() throws Exception {
		
		env1.execute("co",EMPTY_ARGS,new String[]{"proj2"});
		env1.deleteFile("proj2/a.txt");
		env1.deleteFile("proj2/f1/c.txt");
		
		env1.execute("remove",EMPTY_ARGS,new String[]{"a.txt"},"proj2");
		env1.execute("remove",EMPTY_ARGS,new String[]{"f1/c.txt"},"proj2");
		env1.execute("ci",new String[]{"-m","TestMessage"},new String[]{"proj2"});

		// Check the stuff out somewhere else to acctually check, that
		// the file has been accepted
		env2.execute("co",EMPTY_ARGS,new String[]{"proj2"});		
	}
	
	public void testRemoveRecusive() throws Exception {
		
		env1.execute("co",EMPTY_ARGS,new String[]{"proj2"});
		env2.execute("co",EMPTY_ARGS,new String[]{"proj2"});		

		env1.deleteFile("proj2/a.txt");
		env1.deleteFile("proj2/f1/c.txt");
		
		env1.execute("remove",EMPTY_ARGS,new String[0],"proj2");
		env1.execute("ci",new String[]{"-m","TestMessage"},new String[]{"proj2"});

		// Check the stuff out somewhere else to acctually check, that
		// the file has been accepted
		env2.execute("update",EMPTY_ARGS,new String[]{"proj2"});		
	}
	
	public void testRoundRewrite() throws Exception {
				
		// Download content in two locations
		env1.execute("co",EMPTY_ARGS,new String[]{"proj2"},"");
		env2.execute("co",EMPTY_ARGS,new String[]{"proj2"},"");
		
		// change the file "proj1/folder1/c.txt" in env1 check it in
		// on the server
		env1.appendToFile("proj2/f1/c.txt", new String[] { "AppendIt" });
		env1.execute("ci",new String[]{"-m","TestMessage"},new String[]{"proj2"},"");
		
		// assure that the file is different in env1 and env2
		// try {
		//	assertEqualsArrays(env1.readFromFile("proj2/f1/c.txt"),
		//				   	   env2.readFromFile("proj2/f1/c.txt"));
		//	throw new IllegalArgumentException("This is a failed Assertion");
		// } catch (AssertionFailedError e) {}
		
		// update env2 and make sure the changes are there
		env2.execute("update",EMPTY_ARGS,new String[]{"proj2"},"");
		// assertEqualsArrays(env1.readFromFile("proj2/f1/c.txt"),
		//				   env2.readFromFile("proj2/f1/c.txt"));
	}
	
	public void testUpdateMinusN() throws Exception {	
		String[] fileContent1;
		
		fileContent1 = new String[]{"RandomNumber", Math.random() + ""};
		
		env1.execute("co",EMPTY_ARGS,new String[]{"proj2"});
		env2.execute("co",EMPTY_ARGS,new String[]{"proj2"});
		
		env1.writeToFile("proj1/folder1/c.txt",fileContent1);
		
		env1.execute("ci",new String[]{"-n"},new String[]{"-m","TestMessage"},new String[]{"proj2"},"");
		env2.execute("update",EMPTY_ARGS,new String[]{"proj2"});		
	}
	
	public void testStatus() throws Exception {
		
		env1.execute("co",EMPTY_ARGS,new String[]{"proj2"});
		env1.execute("status",EMPTY_ARGS,new String[]{"proj2"});
		
		env1.deleteFile("proj2/a.txt");
		env1.deleteFile("proj2/f1/c.txt");
		env1.appendToFile("proj2/f1/b.txt",new String[] { "AppendIt" });

		env1.execute("status",EMPTY_ARGS,new String[]{"proj2"});
		env1.execute("status",EMPTY_ARGS,new String[0],"proj2");

		env1.createRandomFile("proj2/d.txt");

		env1.execute("status",EMPTY_ARGS,new String[0],"proj2");
		env1.execute("status",EMPTY_ARGS,new String[]{"f1/b.txt"},"proj2");
		// env1.execute("status",localOptions,new String[]{"d.txt"},"proj2");
	}

	public void testLog() throws Exception {
		
		env1.execute("co",EMPTY_ARGS,new String[]{"proj2"});
		env1.execute("log",EMPTY_ARGS,new String[]{"proj2"});
		
		env1.deleteFile("proj2/a.txt");
		env1.deleteFile("proj2/f1/c.txt");
		env1.appendToFile("proj2/f1/b.txt",new String[] { "AppendIt" });

		env1.execute("log",EMPTY_ARGS,new String[]{"proj2"});
		env1.execute("log",EMPTY_ARGS,new String[0],"proj2");

		env1.createRandomFile("proj2/d.txt");

		env1.execute("log",EMPTY_ARGS,new String[0],"proj2");
		env1.execute("log",EMPTY_ARGS,new String[]{"f1/b.txt"},"proj2");
	
	}	
	
	public void testBranchTag() throws Exception {
		
		env1.execute("co",EMPTY_ARGS,new String[]{"proj2"});
		env1.execute("tag",new String[]{"-b"},new String[]{"tag1","proj2"});
		
		env1.deleteFile("proj2/a.txt");
		env1.deleteFile("proj2/f1/c.txt");
		env1.appendToFile("proj2/f1/b.txt",new String[] { "AppendIt" });

		env1.execute("tag",new String[]{"-b"},new String[]{"tag2","proj2"});

		env1.createRandomFile("proj2/d.txt");
		
		env1.deleteFile("proj2");
		
		// Try an commit and an add in the two different streams
		env1.execute("co",new String[]{"-r","tag1"},new String[]{"proj2"});
		env1.appendToFile("proj2/f1/b.txt", new String[] { "AppendItTwo" });
		env1.createRandomFile("proj2/d.txt");
		env1.execute("add",new String[0],new String[]{"d.txt"},"proj2");
		env1.execute("ci",new String[]{"-m","branch"},new String[]{"proj2"});
		env1.deleteFile("proj2");
		env1.execute("co",new String[]{"-r","tag1"},new String[]{"proj2"});

		env2.execute("co",new String[]{"-r","tag2"},new String[]{"proj2"});
		env2.appendToFile("proj2/f1/b.txt", new String[] { "AppendItThree" });
		env2.createRandomFile("proj2/d.txt");
		env2.execute("add",new String[0],new String[]{"d.txt"},"proj2");
		env2.execute("ci",new String[]{"-m","branch"},new String[]{"proj2"});	
		env2.deleteFile("proj2");
		env2.execute("co",new String[]{"-r","tag2"},new String[]{"proj2"});
	}
		
	public void testBranchingWithLocalChanges() throws Exception {
		// Try to branch of a workspace with local changes
		env1.execute("co",EMPTY_ARGS,new String[]{"proj2"});
		JUnitTestCase.waitMsec(1500);
		env1.appendToFile("proj2/f1/b.txt",new String[] { "AppendIt" });
		env1.execute("tag",new String[]{"-b"},new String[]{"branch-with-changes","proj2"});
		env1.execute("update",new String[]{"-r", "branch-with-changes"},new String[]{"proj2"});
	}

	public void testTag() throws Exception {
		
		env1.execute("co",EMPTY_ARGS,new String[]{"proj2"});
		env1.execute("tag",EMPTY_ARGS,new String[]{"tag1","proj2"});
		
		env1.deleteFile("proj2/a.txt");
		env1.deleteFile("proj2/f1/c.txt");
		env1.appendToFile("proj2/f1/b.txt",new String[] { "AppendIt" });

		env1.execute("tag",EMPTY_ARGS,new String[]{"tag2","proj2"});
		env1.execute("tag",EMPTY_ARGS,new String[]{"tag2"},"proj2");

		env1.createRandomFile("proj2/d.txt");

		env1.execute("tag",EMPTY_ARGS,new String[]{"tag3"},"proj2");
		env1.execute("tag",EMPTY_ARGS,new String[]{"tag3","f1/b.txt"},"proj2");
		
		env1.deleteFile("proj2");
		env1.execute("co",new String[]{"-r","tag1"},new String[]{"proj2"});
		env1.deleteFile("proj2");
		env1.execute("co",new String[]{"-r","tag2"},new String[]{"proj2"});
		env1.deleteFile("proj2");
		env1.execute("co",new String[]{"-r","tag3"},new String[]{"proj2"});
		
		// env1.execute("tag",localOptions,new String[]{"d.txt"},"proj2");
		
		env1.execute("update", new String[]{"-r","tag1"}, new String[]{"proj2"});
		env1.execute("update", new String[]{"-r","tag2"}, new String[]{"proj2"});
		env1.execute("update", new String[]{"-r","tag3"}, new String[]{"proj2"});
		env1.execute("update", new String[]{"-A"}, new String[]{"proj2"});
	}
	
	public void testRTag() throws Exception {
		
		// Checkout and tag the project
		env1.execute("co",EMPTY_ARGS,new String[]{"proj2"});
		env1.execute("tag",EMPTY_ARGS,new String[]{"tag1","proj2"});
		env1.deleteFile("proj2");
		
		// Use rtag to tag the above tag as both a version and a branch
		env1.execute("rtag",new String[]{"-r", "tag1"},new String[]{"rtag1","proj2"});
		env1.execute("rtag",new String[]{"-b", "-r", "tag1"},new String[]{"btag1","proj2"});
		
		// Checkout the version and branch
		env1.deleteFile("proj2");
		env1.execute("co",new String[]{"-r","rtag1"},new String[]{"proj2"});
		env1.deleteFile("proj2");
		env1.execute("co",new String[]{"-r","btag1"},new String[]{"proj2"});
	}
	
	public void testPrune() throws Exception {
				
		// Download content in two locations
		env1.execute("co",EMPTY_ARGS,new String[]{"proj2"},"");
		env2.execute("co",EMPTY_ARGS,new String[]{"proj2"},"");
		
		// change the file "proj1/folder1/c.txt" in env1 check it in
		// on the server
		env1.deleteFile("proj2/f1/b.txt");
		env1.deleteFile("proj2/f1/c.txt");
		env1.execute("remove",EMPTY_ARGS,new String[0],"proj2");
		
		env1.execute("ci",new String[]{"-m","TestMessage"},new String[]{"proj2"},"");
		env1.execute("update",new String[]{"-P"},new String[]{"proj2"},"");
		
		// update env2 and make sure the changes are there
		env2.execute("update",new String[]{"-P"},new String[]{"proj2"},"");

	}
	
	public void testPrune2() throws Exception {
				
		// Download content in two locations
		env1.execute("co",EMPTY_ARGS,new String[]{"proj2"},"");
		env2.execute("co",EMPTY_ARGS,new String[]{"proj2"},"");
		
		// change the file "proj1/folder1/c.txt" in env1 check it in
		// on the server
		env1.deleteFile("proj2/f1/b.txt");
		env1.deleteFile("proj2/f1/c.txt");
		env1.execute("remove",EMPTY_ARGS,new String[0],"proj2");
		
		env1.execute("ci",new String[]{"-m","TestMessage"},new String[]{"proj2"},"");
		env1.execute("update",new String[]{"-P"},new String[]{},"proj2");
		
		// update env2 and make sure the changes are there
		env2.execute("update",new String[]{"-P"},new String[]{},"proj2");

	}
	
	public void testAdmin() throws Exception {
				
		env1.execute("co",EMPTY_ARGS,new String[]{"proj2"},"");
		
		env1.execute("admin",new String[]{"-kb"},new String[]{"proj2/f1/b.txt"},"");
		env1.execute("update",EMPTY_ARGS,new String[]{"proj2"},"");
		
		env2.execute("co",EMPTY_ARGS,new String[]{"proj2"},"");
	}

	public void testDiff() throws Exception {
		
		env1.execute("co",EMPTY_ARGS,new String[]{"proj2"});
		env1.execute("diff",EMPTY_ARGS,new String[]{"proj2"});
		
		env1.setIgnoreExceptions(true);
		
		env1.appendToFile("proj2/f1/c.txt",new String[] {"AppendIt2" });
		env1.appendToFile("proj2/f1/b.txt",new String[] { "AppendIt" });
		
		env1.execute("diff",EMPTY_ARGS,new String[]{"proj2"});
		env1.execute("diff",EMPTY_ARGS,new String[0],"proj2");
		
		env1.createRandomFile("proj2/d.txt");

		env1.execute("diff",EMPTY_ARGS,new String[0],"proj2");
		env1.execute("diff",EMPTY_ARGS,new String[]{"f1/b.txt"},"proj2");
		// env1.execute("diff",localOptions,new String[]{"d.txt"},"proj2");

		env1.setIgnoreExceptions(false);
	}

	public void testReadOnly() throws Exception {
		
		// Checkout a read-only copy
		env1.execute("co",new String[]{"-r"},EMPTY_ARGS,new String[]{"proj2"},"");
		// Checkout and modify a writable copy
		env2.execute("co",new String[]{},EMPTY_ARGS,new String[]{"proj2"},"");
		env2.appendToFile("proj2/f1/c.txt",new String[] {"AppendIt2" });
		// Update the read only copy
		env1.execute("update",new String[] {"-r"},EMPTY_ARGS,new String[]{"proj2"},"");
		
		// Update the read-only copy to writable
		env1.execute("update",new String[] {},EMPTY_ARGS,new String[]{"proj2"},"");
	}
	
	public void testQuestionables() throws Exception {			
		env1.execute("co",EMPTY_ARGS,new String[]{"proj2"},"");
		env1.writeToFile("proj2/f2/d.txt", new String[]{"content"});
		env1.writeToFile("proj2/f3/f4/d.txt", new String[]{"content"});	
		env1.writeToFile("proj2/f5/f6/f7/d.txt", new String[]{"content"});	
		env1.execute("add",new String[0],new String[]{"f3"},"proj2");
		env1.execute("add",new String[0],new String[]{"f3/f4"},"proj2");
		env1.execute("update",new String[0],new String[]{"."},"proj2");
	}
	
	public void testImportWrappers() throws Exception {
		// Make the project empty
		env1.magicSetUpRepo("proj3",new String[]{"NoImportant.txt"});
		env2.deleteFile("proj3");
		
		// Create resouces and import them with the 
		// special wrapper
		env1.createRandomFile(new String[]{"a.txt","a.class","a.xxx"},"proj3");
		env1.execute("import",
					new String[]{"-W","*.txt -k 'kv'","-W","*.class -k 'b'","-I","*.xxx","-m","msg"},
					new String[]{"proj3","aTag","bTag"},
					"proj3");
		
		// download the server-version	
		env2.execute("co",EMPTY_ARGS,new String[]{"proj3"},"");
	}
	
	public void testImportIgnores() throws Exception {
		// Make the project empty
		env1.magicSetUpRepo("proj3",new String[]{"NoImportant.txt"});
		env2.deleteFile("proj3");
		
		// Create resouces and import them with the 
		// special wrapper
		env1.createRandomFile(new String[]{"a.txt","a.class","a.xxx"},"proj3");
		env1.execute("import",
					new String[]{"-I","*.xxx","-m","msg"},
					new String[]{"proj3","aTag","bTag"},
					"proj3");
		
		// download the server-version	
		env2.execute("co",EMPTY_ARGS,new String[]{"proj3"},"");
	}
	
	private String toGMTString(Date d) {
		return d.toGMTString();
	}
	
	public void testDate() throws Exception {
		
		// IMPOTANT:
		// Do not make tests with relative dates, because the times coming back form the server will 
		// sometimes differ from the reference-client to the eclipse-client due to the time-delay in calling

		Date beforeChange;
		Date firstChange;
		Date secondChange;
		
		env1.execute("co",new String[0],new String[]{"proj2"});
		
		// Change the file "a.txt" and record the times you are doing that at
		waitMsec(1100); // here we wait for the import to finish
		beforeChange = GregorianCalendar.getInstance().getTime();

		waitMsec(1100);
	
		env1.appendToFile("proj2/a.txt",new String[] { "AppendIt" });
		env1.execute("ci",new String[]{"-m","msg"},new String[]{"proj2"});
		firstChange = GregorianCalendar.getInstance().getTime();

		waitMsec(1100);
			
		env1.appendToFile("proj2/a.txt",new String[] { "AppendIt2" });
		env1.appendToFile("proj2/f1/b.txt",new String[] { "AppendIt2" });
		env1.execute("ci",new String[]{"-m","msg"},new String[]{"proj2"});
		secondChange = GregorianCalendar.getInstance().getTime();

		waitMsec(1100);		

		env1.deleteFile("proj2");
		
		// Now check the project at different times out
		env1.execute("co",new String[]{"-D",toGMTString(beforeChange)},new String[]{"proj2"});
		env1.deleteFile("proj2");
		
		env1.execute("co",new String[]{"-D",toGMTString(firstChange)},new String[]{"proj2"});
		env1.deleteFile("proj2");
		
		env1.execute("co",new String[]{"-D",toGMTString(secondChange)},new String[]{"proj2"});
		env1.deleteFile("proj2");
		
		// Now do some updates to look if update -D works
		env1.execute("co",new String[0],new String[]{"proj2"});
		env1.execute("update",new String[]{"-D",toGMTString(beforeChange)},new String[]{"proj2"});
		env1.execute("update",new String[]{"-D",toGMTString(firstChange)},new String[]{"proj2"});
		env1.execute("update",new String[]{"-D",toGMTString(secondChange)},new String[]{"proj2"});

		// We look if the parameter -a is working
		env1.execute("update",new String[]{"-D",toGMTString(beforeChange),"-A"},new String[]{"proj2"});
		env1.execute("update",new String[]{"-D",toGMTString(secondChange)},new String[]{"proj2"});
		env1.deleteFile("proj2");
		
		// We get try to merge changes from different dates
		env1.execute("co",new String[0],new String[]{"proj2"});
		env1.appendToFile("proj2/a.txt", new String[] { "This is the world ..." });
		env1.execute("update",new String[]{"-D",toGMTString(beforeChange)},new String[]{"proj2"});
		env1.appendToFile("proj2/a.txt", new String[] {"... which constantly changes" });
		env1.execute("update",new String[]{"-A"},new String[]{"proj2"});
		// Change something to be able to commit
		env1.appendToFile("proj2/a.txt", new String[] { "... and the changes are approved" });
		env1.execute("ci",new String[]{"-m","msg"},new String[]{"proj2"});
		
	}
}

Back to the top