1 package org.apache.maven.scm.provider.synergy.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.scm.ScmTag;
23 import org.apache.maven.scm.ScmTestCase;
24 import org.codehaus.plexus.util.Os;
25 import org.codehaus.plexus.util.cli.Commandline;
26
27 import java.io.File;
28 import java.util.LinkedList;
29 import java.util.List;
30
31
32
33
34 public class SynergyCCMTest
35 extends ScmTestCase
36 {
37
38 public void testShowTaskObjects()
39 throws Exception
40 {
41 Commandline cl = SynergyCCM.showTaskObjects( 45, "my format", "CCM_ADDR" );
42 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
43 assertCommandLine( "ccm task -show objects -f \"my format\" 45", null, cl );
44 cl = SynergyCCM.showTaskObjects( 45, null, "CCM_ADDR" );
45 assertCommandLine( "ccm task -show objects 45", null, cl );
46 }
47
48 public void testQuery()
49 throws Exception
50 {
51 Commandline cl = SynergyCCM.query( "my query", "my format", "CCM_ADDR" );
52 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
53 assertCommandLine( "ccm query -u -f \"my format\" \"my query\"", null, cl );
54 cl = SynergyCCM.query( "my query", null, "CCM_ADDR" );
55 assertCommandLine( "ccm query -u \"my query\"", null, cl );
56 }
57
58 public void testCreateBaseline()
59 throws Exception
60 {
61 Commandline cl =
62 SynergyCCM.createBaseline( "myProject~1", "theBaseline", "my_release", "my_purpose", "CCM_ADDR" );
63 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
64 assertCommandLine( "ccm baseline -create theBaseline -p myProject~1 -release my_release -purpose my_purpose",
65 null, cl );
66 }
67
68 public void testCreate()
69 throws Exception
70 {
71 File f = File.createTempFile( "test", null );
72 f.deleteOnExit();
73 List<File> list = new LinkedList<File>();
74 list.add( f );
75 Commandline cl = SynergyCCM.create( list, "test creation", "CCM_ADDR" );
76 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
77 if ( f.getCanonicalPath().indexOf( ' ' ) > -1 )
78 {
79 assertCommandLine( "ccm create -c \"test creation\" \"" + f.getCanonicalPath() + "\"", null, cl );
80 }
81 else
82 {
83 assertCommandLine( "ccm create -c \"test creation\" " + f.getCanonicalPath(), null, cl );
84 }
85 File f2 = File.createTempFile( "test", null );
86 f2.deleteOnExit();
87 list.add( f2 );
88 cl = SynergyCCM.create( list, "test creation", "CCM_ADDR" );
89 if ( f.getCanonicalPath().indexOf( ' ' ) > -1 )
90 {
91 if ( f2.getCanonicalPath().indexOf( ' ' ) > -1 )
92 {
93 assertCommandLine( "ccm create -c \"test creation\" \"" + f.getCanonicalPath() + "\" \"" +
94 f2.getCanonicalPath() + "\"", null, cl );
95 }
96 else
97 {
98 assertCommandLine(
99 "ccm create -c \"test creation\" \"" + f.getCanonicalPath() + "\" " + f2.getCanonicalPath() + "",
100 null, cl );
101 }
102 }
103 else
104 {
105 if ( f2.getCanonicalPath().indexOf( ' ' ) > -1 )
106 {
107 assertCommandLine(
108 "ccm create -c \"test creation\" " + f.getCanonicalPath() + " \"" + f2.getCanonicalPath() + "\"",
109 null, cl );
110 }
111 else
112 {
113 assertCommandLine(
114 "ccm create -c \"test creation\" " + f.getCanonicalPath() + " " + f2.getCanonicalPath(), null, cl );
115 }
116 }
117 }
118
119 public void testCreateTask()
120 throws Exception
121 {
122
123
124
125
126
127
128 if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
129 {
130 Commandline cl = SynergyCCM.createTask( "the synopsis", "release", true, "CCM_ADDR" );
131 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
132 String actual = cl.toString().replace( '\"', '\'' );
133 String expected = "ccm task -create -synopsis 'the synopsis' -release release";
134 assertTrue( "[" + actual + "] does not contain [" + expected + "]",
135 actual.indexOf( expected ) > -1 );
136
137 cl = SynergyCCM.createTask( "the synopsis", null, true, "CCM_ADDR" );
138 actual = cl.toString().replace( '\"', '\'' );
139 expected = "ccm task -create -synopsis 'the synopsis'";
140 assertTrue( "[" + actual + "] does not contain [" + expected + "]",
141 actual.indexOf( expected ) > -1 );
142 }
143 }
144
145 public void testCheckinTask()
146 throws Exception
147 {
148 Commandline cl = SynergyCCM.checkinTask( "truc", "a comment", "CCM_ADDR" );
149 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
150 assertCommandLine( "ccm task -checkin truc -comment \"a comment\"", null, cl );
151 }
152
153 public void testDelete()
154 throws Exception
155 {
156 File f = File.createTempFile( "test", null );
157 f.deleteOnExit();
158 List<File> list = new LinkedList<File>();
159 list.add( f );
160 Commandline cl = SynergyCCM.delete( list, "CCM_ADDR", true );
161 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
162 if ( f.getCanonicalPath().indexOf( ' ' ) > -1 )
163 {
164 assertCommandLine( "ccm delete -replace \"" + f.getCanonicalPath() + "\"", null, cl );
165 }
166 else
167 {
168 assertCommandLine( "ccm delete -replace " + f.getCanonicalPath(), null, cl );
169 }
170 File f2 = File.createTempFile( "test", null );
171 f2.deleteOnExit();
172 list.add( f2 );
173 cl = SynergyCCM.delete( list, "CCM_ADDR", false );
174 if ( f.getCanonicalPath().indexOf( ' ' ) > -1 )
175 {
176 if ( f2.getCanonicalPath().indexOf( ' ' ) > -1 )
177 {
178 assertCommandLine( "ccm delete \"" + f.getCanonicalPath() + "\" \"" + f2.getCanonicalPath() + "\"",
179 null, cl );
180 }
181 else
182 {
183 assertCommandLine( "ccm delete \"" + f.getCanonicalPath() + "\" " + f2.getCanonicalPath() + "", null,
184 cl );
185 }
186 }
187 else
188 {
189 if ( f2.getCanonicalPath().indexOf( ' ' ) > -1 )
190 {
191 assertCommandLine( "ccm delete " + f.getCanonicalPath() + " \"" + f2.getCanonicalPath() + "\"", null,
192 cl );
193 }
194 else
195 {
196 assertCommandLine( "ccm delete " + f.getCanonicalPath() + " " + f2.getCanonicalPath(), null, cl );
197 }
198 }
199 }
200
201 public void testReconfigure()
202 throws Exception
203 {
204 Commandline cl = SynergyCCM.reconfigure( "project~1", "CCM_ADDR" );
205 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
206 assertCommandLine( "ccm reconfigure -recurse -p project~1", null, cl );
207 }
208
209 public void testReconfigureProperties()
210 throws Exception
211 {
212 Commandline cl = SynergyCCM.reconfigureProperties( "project~1", "CCM_ADDR" );
213 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
214 assertCommandLine( "ccm reconfigure_properties -refresh project~1", null, cl );
215 }
216
217 public void testReconcileUwa()
218 throws Exception
219 {
220 Commandline cl = SynergyCCM.reconcileUwa( "project~1", "CCM_ADDR" );
221 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
222 assertCommandLine( "ccm rwa -r -uwa -p project~1", null, cl );
223 cl = SynergyCCM.reconcileUwa( null, "CCM_ADDR" );
224 assertCommandLine( "ccm rwa -r -uwa", null, cl );
225 }
226
227 public void testReconcileUdb()
228 throws Exception
229 {
230 Commandline cl = SynergyCCM.reconcileUdb( "project~1", "CCM_ADDR" );
231 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
232 assertCommandLine( "ccm rwa -r -udb -p project~1", null, cl );
233 cl = SynergyCCM.reconcileUdb( null, "CCM_ADDR" );
234 assertCommandLine( "ccm rwa -r -udb", null, cl );
235 }
236
237 public void testDir()
238 throws Exception
239 {
240 File f = File.createTempFile( "foo", null );
241 f.deleteOnExit();
242 Commandline cl = SynergyCCM.dir( f.getParentFile(), "format", "CCM_ADDR" );
243 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
244 assertEquals( f.getParentFile().getCanonicalFile(), cl.getWorkingDirectory().getCanonicalFile() );
245 assertCommandLine( "ccm dir -m -f format", f.getParentFile().getCanonicalFile(), cl );
246 }
247
248 public void testCheckoutFiles()
249 throws Exception
250 {
251 File f = File.createTempFile( "test", null );
252 f.deleteOnExit();
253 List<File> list = new LinkedList<File>();
254 list.add( f );
255 Commandline cl = SynergyCCM.checkoutFiles( list, "CCM_ADDR" );
256 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
257 if ( f.getCanonicalPath().indexOf( ' ' ) > -1 )
258 {
259 assertCommandLine( "ccm co \"" + f.getCanonicalPath() + "\"", null, cl );
260 }
261 else
262 {
263 assertCommandLine( "ccm co " + f.getCanonicalPath(), null, cl );
264 }
265 File f2 = File.createTempFile( "test", null );
266 f2.deleteOnExit();
267 list.add( f2 );
268 cl = SynergyCCM.checkoutFiles( list, "CCM_ADDR" );
269 if ( f.getCanonicalPath().indexOf( ' ' ) > -1 )
270 {
271 if ( f2.getCanonicalPath().indexOf( ' ' ) > -1 )
272 {
273 assertCommandLine( "ccm co \"" + f.getCanonicalPath() + "\" \"" + f2.getCanonicalPath() + "\"", null,
274 cl );
275 }
276 else
277 {
278 assertCommandLine( "ccm co \"" + f.getCanonicalPath() + "\" " + f2.getCanonicalPath() + "", null, cl );
279 }
280 }
281 else
282 {
283 if ( f2.getCanonicalPath().indexOf( ' ' ) > -1 )
284 {
285 assertCommandLine( "ccm co " + f.getCanonicalPath() + " \"" + f2.getCanonicalPath() + "\"", null, cl );
286 }
287 else
288 {
289 assertCommandLine( "ccm co " + f.getCanonicalPath() + " " + f2.getCanonicalPath(), null, cl );
290 }
291 }
292 }
293
294 public void testCheckoutProject()
295 throws Exception
296 {
297 Commandline cl = SynergyCCM.checkoutProject( null, "MyProject", new ScmTag( "MyVersion" ), "MyPurpose",
298 "MyRelease", "CCM_ADDR" );
299 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
300 assertCommandLine( "ccm co -subprojects -rel -t MyVersion -purpose MyPurpose -release MyRelease -p MyProject",
301 null, cl );
302 File f = File.createTempFile( "test", null );
303 f.deleteOnExit();
304 cl = SynergyCCM.checkoutProject( f.getParentFile(), "MyProject", new ScmTag( "MyVersion" ), "MyPurpose",
305 "MyRelease", "CCM_ADDR" );
306 if ( f.getCanonicalPath().indexOf( ' ' ) > -1 )
307 {
308 assertCommandLine( "ccm co -subprojects -rel -t MyVersion -purpose MyPurpose -release MyRelease -path \"" +
309 f.getParentFile().getCanonicalPath() + "\" -p MyProject", null, cl );
310 }
311 else
312 {
313 assertCommandLine( "ccm co -subprojects -rel -t MyVersion -purpose MyPurpose -release MyRelease -path " +
314 f.getParentFile().getCanonicalPath() + " -p MyProject", null, cl );
315 }
316 }
317
318 public void testCheckinProject()
319 throws Exception
320 {
321 Commandline cl = SynergyCCM.checkinProject( "MyProject", "a comment", "CCM_ADDR" );
322 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
323 assertCommandLine( "ccm ci -c \"a comment\" -p MyProject", null, cl );
324 }
325
326 public void testCheckinFiles()
327 throws Exception
328 {
329 File f = File.createTempFile( "test", null );
330 f.deleteOnExit();
331 List<File> list = new LinkedList<File>();
332 list.add( f );
333 Commandline cl = SynergyCCM.checkinFiles( list, "a comment", "CCM_ADDR" );
334 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
335 if ( f.getCanonicalPath().indexOf( ' ' ) > -1 )
336 {
337 assertCommandLine( "ccm ci -c \"a comment\" \"" + f.getCanonicalPath() + "\"", null, cl );
338 }
339 else
340 {
341 assertCommandLine( "ccm ci -c \"a comment\" " + f.getCanonicalPath(), null, cl );
342 }
343 File f2 = File.createTempFile( "test", null );
344 f2.deleteOnExit();
345 list.add( f2 );
346 cl = SynergyCCM.checkinFiles( list, "a comment", "CCM_ADDR" );
347 if ( f.getCanonicalPath().indexOf( ' ' ) > -1 )
348 {
349 if ( f2.getCanonicalPath().indexOf( ' ' ) > -1 )
350 {
351 assertCommandLine(
352 "ccm ci -c \"a comment\" \"" + f.getCanonicalPath() + "\" \"" + f2.getCanonicalPath() + "\"", null,
353 cl );
354 }
355 else
356 {
357 assertCommandLine(
358 "ccm ci -c \"a comment\" \"" + f.getCanonicalPath() + "\" " + f2.getCanonicalPath() + "", null,
359 cl );
360 }
361 }
362 else
363 {
364 if ( f2.getCanonicalPath().indexOf( ' ' ) > -1 )
365 {
366 assertCommandLine(
367 "ccm ci -c \"a comment\" " + f.getCanonicalPath() + " \"" + f2.getCanonicalPath() + "\"", null,
368 cl );
369 }
370 else
371 {
372 assertCommandLine( "ccm ci -c \"a comment\" " + f.getCanonicalPath() + " " + f2.getCanonicalPath(),
373 null, cl );
374 }
375 }
376 }
377
378 public void testSync()
379 throws Exception
380 {
381 Commandline cl = SynergyCCM.synchronize( "myProject", "CCM_ADDR" );
382 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
383 assertCommandLine( "ccm sync -r -p myProject", null, cl );
384 }
385
386 public void testShowWorkArea()
387 throws Exception
388 {
389 Commandline cl = SynergyCCM.showWorkArea( "MyProject~1", "CCM_ADDR" );
390 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
391 assertCommandLine( "ccm wa -show MyProject~1", null, cl );
392 }
393
394 public void testStart()
395 throws Exception
396 {
397 Commandline cl = SynergyCCM.start( "user", "pass", SynergyRole.BUILD_MGR );
398 assertCommandLine( "ccm start -nogui -m -q -n user -pw pass -r build_mgr", null, cl );
399 }
400
401 public void testStartRemote()
402 throws Exception
403 {
404 Commandline cl = SynergyCCM.startRemote( "user", "pass", SynergyRole.BUILD_MGR );
405 assertCommandLine( "ccm start -nogui -m -q -rc -n user -pw pass -r build_mgr", null, cl );
406 }
407
408 public void testStop()
409 throws Exception
410 {
411 Commandline cl = SynergyCCM.stop( "CCM_ADDR" );
412 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
413 assertCommandLine( "ccm stop", null, cl );
414 }
415
416 public void testDelimiter()
417 throws Exception
418 {
419 Commandline cl = SynergyCCM.delimiter( "CCM_ADDR" );
420 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
421 assertCommandLine( "ccm delimiter", null, cl );
422 }
423
424 public void testShowDefaultTask()
425 throws Exception
426 {
427 Commandline cl = SynergyCCM.showDefaultTask( "CCM_ADDR" );
428 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
429 assertCommandLine( "ccm task -default", null, cl );
430 }
431
432 public void testSetDefaultTask()
433 throws Exception
434 {
435 Commandline cl = SynergyCCM.setDefaultTask( 4711, "CCM_ADDR" );
436 assertTrue( "CCM_ADDR is not set.", assertContains( cl.getEnvironmentVariables(), "CCM_ADDR=CCM_ADDR" ) );
437 assertCommandLine( "ccm task -default 4711", null, cl );
438 }
439
440
441 public boolean assertContains( String[] array, String value )
442 {
443 for ( int i = 0; i < array.length; i++ )
444 {
445 if ( array[i].equals( value ) )
446 {
447 return true;
448 }
449 }
450 return false;
451 }
452 }