Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
814 mhunt 1
package com.erggroup.buildtool.utf;
2
 
3
import com.erggroup.buildtool.daemon.BuildDaemon;
4
 
5
import com.erggroup.buildtool.daemon.BuildThread;
6
import com.erggroup.buildtool.daemon.MasterThread;
7
import com.erggroup.buildtool.daemon.SlaveThread;
8
import com.erggroup.buildtool.ripple.MutableString;
9
import com.erggroup.buildtool.ripple.Package;
10
import com.erggroup.buildtool.ripple.ReleaseManager;
11
 
12
import com.erggroup.buildtool.ripple.RippleEngine;
13
 
14
import java.io.File;
15
import java.io.FileReader;
16
import java.io.FileWriter;
17
import java.io.IOException;
18
 
19
import org.apache.log4j.Logger;
20
import org.apache.log4j.xml.DOMConfigurator;
21
 
22
import org.junit.AfterClass;
23
import org.junit.BeforeClass;
24
import org.junit.After;
25
import org.junit.Before;
26
import org.junit.Test;
27
import org.junit.runner.JUnitCore;
28
import static org.junit.Assert.*;
29
 
30
/**container of Build Daemon test methods
31
 */
32
public class DaemonBuildTestCase
33
{
34
  private static final Logger mLogger = Logger.getLogger(DaemonBuildTestCase.class);
35
 
36
  public DaemonBuildTestCase()
37
  {
38
    mLogger.debug("DaemonBuildTestCase");
39
  }
40
 
41
  /**Test Case main line
42
   */
43
  public static void main(String[] args)
44
  {
45
    DOMConfigurator.configure("utf.xml");
46
    mLogger.debug("main");
47
    JUnitCore.main( "com.erggroup.buildtool.utf.DaemonBuildTestCase" );
48
  }
49
 
50
  /**set up performed prior to any test method
51
   */
52
  @BeforeClass
53
  public static void TestCaseSetUp()
54
  {
55
    mLogger.debug("TestCaseSetUp");
56
  }
57
 
58
  /**tear down performed after test methods
59
   */
60
  @AfterClass
61
  public static void TestCaseTearDown()
62
  {
63
    mLogger.debug("TestCaseTearDown");
64
  }
65
 
66
  /**set up performed prior to each test method
67
   */
68
  @Before
69
  public void TestSetUp()
70
  {
71
    mLogger.debug("TestSetUp");
72
    ReleaseManager.mUseDatabase = false;
73
  }
74
 
75
  /**tear down performed after each test method
76
   */
77
  @After
78
  public void TestTearDown()
79
  {
80
    mLogger.debug("TestTearDown");
81
    ReleaseManager.mUseDatabase = true;
82
    ReleaseManager.mPersistedRunLevelCollection.removeAllElements();
83
  }
84
 
85
  /**test method designed primarily to test the sequence diagram spawn thread
86
   * also tests thread control out of necessity:
87
   *  1 constructs a BuildDaemon object, passing a connectionString of "unit test spawn thread"
88
   *    this utilises the following unit test hooks in the codebase:
89
   *    - BuildDaemon::BuildDaemon connectionString of "unit test spawn thread" exits while forever loop
90
   *    - BuildDaemon constructor, isActive and cleanUp made public for unit test use
91
   *    - ReleaseManager::queryReleaseConfig instantiates 2 ReleaseConfig objects
92
   *      with rcon_id's of 1 and 2, daemon_modes of 'M' and 'S' respectively, and gbebuildfilters of "unit test spawn thread"
93
   *    - MasterThread::run gbebuildfilter of "unit test spawn thread" limits method to sleep in while forever loop
94
   *    - SlaveThread::run gbebuildfilter of "unit test spawn thread" limits method to sleep in while forever loop
95
   *  2 checks the number of threads in the thread group is 3 (mainline thread + MasterThread + SlaveThread)
96
   *  3 checks isActive on the BuildDaemon object returns true when passed an rcon_id of 1
97
   *  4 checks isActive on the BuildDaemon object returns true when passed an rcon_id of 2
98
   *  5 checks isActive on the BuildDaemon object returns false when passed an rcon_id of 3
99
   *  6 calls cleanUp on the BuildDaemon object
100
   *  7 checks the number of threads in the thread group is 1 (mainline thread)
101
   *  8 checks isActive on the BuildDaemon object returns false when passed an rcon_id of 1
102
   *  9 checks isActive on the BuildDaemon object returns false when passed an rcon_id of 2
103
   * 10 checks isActive on the BuildDaemon object returns false when passed an rcon_id of 3
104
   */
105
  @Test
106
  public void TestSpawnThread()
107
  {
108
    mLogger.debug("TestSpawnThread");
109
    BuildDaemon buildDaemon = 
110
      new BuildDaemon("unit test spawn thread", "not used", "not used");
111
    assertTrue(BuildThread.mThreadGroup.activeCount() == 2 );
112
    assertTrue(buildDaemon.isActive(1));
113
    assertTrue(buildDaemon.isActive(2));
114
    assertFalse(buildDaemon.isActive(3));
115
    buildDaemon.cleanUp();
116
    assertTrue(BuildThread.mThreadGroup.activeCount() == 0);
117
    assertFalse(buildDaemon.isActive(1));
118
    assertFalse(buildDaemon.isActive(2));
119
    assertFalse(buildDaemon.isActive(3));
120
  }
121
 
122
  /**test method designed to test the sequence diagram coordinate slave thread:
123
   *  1 constructs a ReleaseManager object, passing a connectionString of "unit test coordinate slave threads"
124
   *  2 constructs a MasterThread object, passing a gbebuildfilter of "unit test coordinate slave threads"
125
   *    this utilises the following unit test hooks in the codebase:
126
   *    - MasterThread constructor made public for unit test use
127
   *    - MasterThread::run gbebuildfilter of "unit test coordinate slave threads" limits method to the sequence diagram
128
   *      interrupts the thread if, on one pass, at least one RunLevel object does not have a run level DB_WAITING
129
   *      exits the while forever loop if, on one pass, all RunLevel objects have a run level DB_WAITING
130
   *    - ReleaseManager::queryRunLevel connectionString of "unit test coordinate slave threads" instantiates 2 RunLevel objects
131
   *      initially with run levels of waiting and idle
132
   *      subsequently with run levels both waiting
133
   *  3 calls run on the MasterThread object
134
   *  4 checks its thread has been interrupted
135
   */
136
  @Test
137
  public void TestCoordinateSlaveThreads()
138
  {
139
    mLogger.debug("TestCoordinateSlaveThreads");
140
    ReleaseManager releaseManager = new ReleaseManager("unit test coordinate slave threads", "not used", "not used");
141
    MasterThread masterThread = new MasterThread(1, 1, "unit test coordinate slave threads");
142
    assertFalse(Thread.currentThread().interrupted());
143
    masterThread.run();
144
    // interrupted checks and importantly clears the interrupted status of this thread for subsequent tests
145
    assertTrue(Thread.currentThread().interrupted());
146
    assertFalse(Thread.currentThread().interrupted());
147
  }
148
 
149
  /**test method designed to test the sequence diagram generate build files
150
   * note does not test the RippleEngine:
151
   *  1 constructs a ReleaseManager object, passing a connectionString of "unit test generate build files"
152
   *  2 constructs a MasterThread object, passing a gbebuildfilter of "unit test generate build files"
153
   *    this utilises the following unit test hooks in the codebase:
154
   *    - MasterThread constructor made public for unit test use
155
   *    - MasterThread::run gbebuildfilter of "unit test generate build files" limits method to the sequence diagram
156
   *      exits the while forever loop
157
   *    - ReleaseManager::queryReleaseConfig instantiates 2 ReleaseConfig objects
158
   *      with rcon_id's of 1 and 2, daemon_modes of 'M' and 'S' respectively, and gbebuildfilters of "unit test spawn thread"
159
   *    - ReleaseManager::updateCurrentRunLevel utilises the public mPersistedRunLevelCollection
160
   *  3 calls run on the MasterThread object
161
   *  4 checks the first persisted run level is DB_ACTIVE
162
   *  5 checks the second persisted run level is DB_ACTIVE
163
   *  6 checks no further run levels were persisted
164
   */
165
  @Test
166
  public void TestGenerateBuildFiles()
167
  {
168
    mLogger.debug("TestGenerateBuildFiles");
169
    ReleaseManager releaseManager = new ReleaseManager("unit test generate build files", "not used", "not used");
170
    MasterThread masterThread = new MasterThread(1, 1, "unit test generate build files");
171
    masterThread.run();
172
    Integer persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 0 );
173
    assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_ACTIVE );
174
    persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 1 );
175
    assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_ACTIVE );
176
    boolean caughtOOB = false;
177
 
178
    try
179
    {
180
      persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 2 );
181
    }
182
    catch( ArrayIndexOutOfBoundsException e )
183
    {
184
      caughtOOB = true;
185
    }
186
 
187
    assertTrue(caughtOOB);
188
  }
189
 
190
  /**test method designed to test the sequence diagram consume build files
191
   *  1 constructs a ReleaseManager object, passing a connectionString of "unit test consume build files"
192
   *  2 constructs a SlaveThread object, passing a gbebuildfilter of "unit test consume build files"
193
   *    this utilises the following unit test hooks in the codebase:
194
   *    - SlaveThread constructor made public for unit test use
195
   *    - SlaveThread::run gbebuildfilter of "unit test consume build files" limits method to the sequence diagram
196
   *      interrupts the thread if, on one pass, the current build file string is empty
197
   *      exits the while forever loop
198
   *    - ReleaseManager::queryRunLevel
199
   *      initially returns an empty current build file string
200
   *      subsequently returns a "unit test build file content" current build file string
201
   *  3 calls run on the SlaveThread object
202
   */
203
  @Test
204
  public void TestConsumeBuildFiles()
205
  {
206
    mLogger.debug("TestConsumeBuildFiles");
207
    ReleaseManager releaseManager = new ReleaseManager("unit test consume build files", "not used", "not used");
208
    SlaveThread slaveThread = new SlaveThread(1, 1, "unit test consume build files");
209
    assertFalse(Thread.currentThread().interrupted());
210
    slaveThread.run();
211
  }
212
 
213
  /**test method designed to test the sequence diagram allowed to proceed
214
   *  1 constructs a ReleaseManager object, passing a connectionString of "unit test allowed to proceed"
215
   *  2 constructs a MasterThread object, passing a gbebuildfilter of "unit test allowed to proceed"
216
   *    this utilises the following unit test hooks in the codebase:
217
   *    - MasterThread constructor made public for unit test use
218
   *    - MasterThread::run gbebuildfilter of "unit test allowed to proceed" limits method to the sequence diagram
219
   *      exits the while forever loop
220
   *    - ReleaseManager::queryReleaseConfig, queryRunLevelSchedule, queryDirectedRunLevel methods return true
221
   *    - ReleaseManager::updateCurrentRunLevel utilises the public mPersistedRunLevelCollection
222
   *  3 calls run on the MasterThread object
223
   *  4 checks the first persisted run level is DB_IDLE
224
   *  5 checks the second persisted run level is DB_IDLE
225
   *  6 checks the third persisted run level is DB_WAITING
226
   *  7 checks no further run levels were persisted
227
   */
228
  @Test
229
  public void TestAllowedToProceed()
230
  {
231
    mLogger.debug("TestAllowedToProceed");
232
    ReleaseManager releaseManager = new ReleaseManager("unit test allowed to proceed", "not used", "not used");
233
    MasterThread masterThread = new MasterThread(1, 1, "unit test allowed to proceed");
234
    masterThread.run();
235
    Integer persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 0 );
236
    assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_IDLE );
237
    persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 1 );
238
    assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_IDLE );
239
    persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 2 );
240
    assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_WAITING );
241
    boolean caughtOOB = false;
242
 
243
    try
244
    {
245
      persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 3 );
246
    }
247
    catch( ArrayIndexOutOfBoundsException e )
248
    {
249
      caughtOOB = true;
250
    }
251
 
252
    assertTrue(caughtOOB);
253
  }
254
 
255
  /**test method designed to test the sequence diagram not allowed to proceed
256
   *  1 constructs a ReleaseManager object, passing a connectionString of "unit test not allowed to proceed"
257
   *  2 constructs a MasterThread object, passing a gbebuildfilter of "unit test not allowed to proceed"
258
   *    this utilises the following unit test hooks in the codebase:
259
   *    - MasterThread constructor made public for unit test use
260
   *    - MasterThread::run gbebuildfilter of "unit test not allowed to proceed" limits method to the sequence diagram
261
   *      exits the while forever loop
262
   *    - ReleaseManager::queryReleaseConfig method returns true
263
   *    - ReleaseManager::queryRunLevelSchedule method returns false
264
   *    - ReleaseManager::updateCurrentRunLevel utilises the public mPersistedRunLevelCollection
265
   *  3 calls run on the MasterThread object
266
   *  4 checks the first persisted run level is DB_IDLE
267
   *  5 checks the second persisted run level is DB_IDLE
268
   *  6 checks the third persisted run level is DB_PAUSED
269
   *  7 checks no further run levels were persisted
270
   * nb cannot check only one thread is running,
271
   * a Timer thread, though having run to completion, may still be "active"
272
   */
273
  @Test
274
  public void TestNotAllowedToProceed()
275
  {
276
    mLogger.debug("TestNotAllowedToProceed");
277
    ReleaseManager releaseManager = new ReleaseManager("unit test not allowed to proceed", "not used", "not used");
278
    MasterThread masterThread = new MasterThread(1, 1, "unit test not allowed to proceed");
279
    masterThread.run();
280
    Integer persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 0 );
281
    assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_IDLE );
282
    persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 1 );
283
    assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_IDLE );
284
    persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 2 );
285
    assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_PAUSED );
286
    boolean caughtOOB = false;
287
 
288
    try
289
    {
290
      persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 3 );
291
    }
292
    catch( ArrayIndexOutOfBoundsException e )
293
    {
294
      caughtOOB = true;
295
    }
296
 
297
    assertTrue(caughtOOB);
298
  }
299
 
300
  /**test method designed to test the sequence diagram exit
301
   *  1 constructs a ReleaseManager object, passing a connectionString of "unit test exit"
302
   *  2 constructs a MasterThread object, passing a gbebuildfilter of "unit test exit"
303
   *    this utilises the following unit test hooks in the codebase:
304
   *    - MasterThread constructor made public for unit test use
305
   *    - MasterThread::run gbebuildfilter of "unit test exit" limits method to the sequence diagram
306
   *    - ReleaseManager::queryReleaseConfig method returns false
307
   *    - ReleaseManager::updateCurrentRunLevel utilises the public mPersistedRunLevelCollection
308
   *  3 calls run on the MasterThread object
309
   *  4 checks the first persisted run level is DB_IDLE
310
   *  5 checks no further run levels were persisted
311
   */
312
  @Test
313
  public void TestExit()
314
  {
315
    mLogger.debug("TestExit");
316
    ReleaseManager releaseManager = new ReleaseManager("unit test exit", "not used", "not used");
317
    MasterThread masterThread = new MasterThread(1, 1, "unit test exit");
318
    masterThread.run();
319
    Integer persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 0 );
320
    assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_IDLE );
321
 
322
    boolean caughtOOB = false;
323
 
324
    try
325
    {
326
      persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 2 );
327
    }
328
    catch( ArrayIndexOutOfBoundsException e )
329
    {
330
      caughtOOB = true;
331
    }
332
 
333
    assertTrue(caughtOOB);
334
  }
335
 
336
  /**test method designed to test the sequence diagram check environment
337
   *  1 constructs a ReleaseManager object, passing a connectionString of "unit check environment"
338
   *  2 constructs a MasterThread object, passing a gbebuildfilter of "unit check environment"
339
   *    this utilises the following unit test hooks in the codebase:
340
   *    - MasterThread constructor made public for unit test use
341
   *    - MasterThread::run gbebuildfilter of "unit test check environment" limits method to the sequence diagram
342
   *      exits the while forever loop
343
   *    - MasterThread::housekeep method does not call deleteDirectory
344
   *    - MasterThread::hasSufficientDiskSpace initially returns false, then true
345
   *    - ReleaseManager::updateCurrentRunLevel utilises the public mPersistedRunLevelCollection
346
   *  3 calls run on the MasterThread object
347
   *  4 checks the first persisted run level is DB_CANNOT_CONTINUE
348
   *  5 checks the next persisted run level is DB_ACTIVE
349
   *  6 checks no further run levels were persisted
350
   */
351
  @Test
352
  public void TestCheckEnvironment()
353
  {
354
    mLogger.debug("TestCheckEnvironment");
355
    ReleaseManager releaseManager = new ReleaseManager("unit test check environment", "not used", "not used");
356
    MasterThread masterThread = new MasterThread(1, 1, "unit test check environment");
357
    masterThread.run();
358
    Integer persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 0 );
359
    assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_CANNOT_CONTINUE );
360
    persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 1 );
361
    assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_ACTIVE );
362
    boolean caughtOOB = false;
363
 
364
    try
365
    {
366
      persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 2 );
367
    }
368
    catch( ArrayIndexOutOfBoundsException e )
369
    {
370
      caughtOOB = true;
371
    }
372
 
373
    assertTrue(caughtOOB);
374
  }
375
 
376
  /**test method designed to test the ripple engine
377
   *  1 constructs a ReleaseManager object with connection string "iteration1"
378
   *  2 constructs a RippleEngine object
379
   *  3 calls planRelease on the RippleEngine object
380
   *  4 calls getFirstBuildFileContent
381
   *  5 checks it returns true
382
   *  6 writes the content to "daemon1.xml"
383
   *  7 checks the content matches the content in "expecteddaemon1.xml"
384
   *  8 calls getNextBuildFileContent
385
   *  9 checks it returns false
386
   * 10 constructs a ReleaseManager object with connection string "iteration2"
387
   * 11 calls planRelease on the RippleEngine object
388
   * 12 calls getFirstBuildFileContent
389
   * 13 checks it returns true
390
   * 14 writes the content to "daemon2.xml"
391
   * 15 checks the content matches the content in "expecteddaemon2.xml"
392
   * 16 calls getNextBuildFileContent
393
   * 17 checks it returns false
394
   * 18 steps 10 to 17 are repeated for iteration3,4,5 and 6
395
   * 19 constructs a ReleaseManager object with connection string "iteration7"
396
   * 20 calls planRelease on the RippleEngine object
397
   * 21 calls getFirstBuildFileContent
398
   * 22 checks it returns true (a benign build file content)
399
   */
400
  @Test
401
  public void TestPlanRelease()
402
  {
403
    mLogger.debug("TestPlanRelease");
404
    ReleaseManager releaseManager = 
405
      new ReleaseManager("iteration1", "not used", "not used");
406
 
407
    RippleEngine rippleEngine = new RippleEngine(releaseManager, 11111, true);
408
    // this is all the MasterThread does
409
    try
410
    {
411
      rippleEngine.planRelease();
412
    }
413
    catch(Exception e)
414
    {
415
    }
416
 
417
    String ExpectedBuildFileContent = new String();
418
    MutableString buildFileContent = new MutableString();
419
    boolean moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
420
    assertTrue(moreBuildFiles);
421
 
422
    // persist the generated build file content to daemon1.xml for visibility
423
    File cwd = new File( "." );
424
    String buildFileName = new String("daemon1.xml");
425
    try
426
    {
427
      File buildFile = new File(cwd, buildFileName);
428
      FileWriter buildFileWriter = new FileWriter(buildFile);
429
      buildFileWriter.write(buildFileContent.value);
430
      buildFileWriter.close();
431
      File expectedBuildFile = new File(cwd, "expecteddaemon1.xml");
432
      FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
433
      char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
434
      expectedBuildFileReader.read(expectedBuildFileContent);
435
      expectedBuildFileReader.close();
436
      String temp = new String(expectedBuildFileContent);
437
      ExpectedBuildFileContent = temp;
438
    }
439
    catch( IOException e )
440
    {
441
      System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
442
    }
443
 
444
    assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
445
    moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
446
    assertFalse(moreBuildFiles);
447
 
448
    releaseManager = 
449
      new ReleaseManager("iteration2", "not used", "not used");
450
 
451
    // this is all the MasterThread does
452
    try
453
    {
454
      rippleEngine.planRelease();
455
    }
456
    catch(Exception e)
457
    {
458
    }
459
 
460
    moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
461
    assertTrue(moreBuildFiles);
462
 
463
    // persist the generated build file content to daemon1.xml for visibility
464
    buildFileName = new String("daemon2.xml");
465
    try
466
    {
467
      File buildFile = new File(cwd, buildFileName);
468
      FileWriter buildFileWriter = new FileWriter(buildFile);
469
      buildFileWriter.write(buildFileContent.value);
470
      buildFileWriter.close();
471
      File expectedBuildFile = new File(cwd, "expecteddaemon2.xml");
472
      FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
473
      char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
474
      expectedBuildFileReader.read(expectedBuildFileContent);
475
      expectedBuildFileReader.close();
476
      String temp = new String(expectedBuildFileContent);
477
      ExpectedBuildFileContent = temp;
478
    }
479
    catch( IOException e )
480
    {
481
      System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
482
    }
483
 
484
    assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
485
    moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
486
    assertFalse(moreBuildFiles);
487
 
488
    releaseManager = 
489
      new ReleaseManager("iteration3", "not used", "not used");
490
 
491
    // this is all the MasterThread does
492
    try
493
    {
494
      rippleEngine.planRelease();
495
    }
496
    catch(Exception e)
497
    {
498
    }
499
 
500
    moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
501
    assertTrue(moreBuildFiles);
502
 
503
    // persist the generated build file content to daemon1.xml for visibility
504
    buildFileName = new String("daemon3.xml");
505
    try
506
    {
507
      File buildFile = new File(cwd, buildFileName);
508
      FileWriter buildFileWriter = new FileWriter(buildFile);
509
      buildFileWriter.write(buildFileContent.value);
510
      buildFileWriter.close();
511
      File expectedBuildFile = new File(cwd, "expecteddaemon3.xml");
512
      FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
513
      char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
514
      expectedBuildFileReader.read(expectedBuildFileContent);
515
      expectedBuildFileReader.close();
516
      String temp = new String(expectedBuildFileContent);
517
      ExpectedBuildFileContent = temp;
518
    }
519
    catch( IOException e )
520
    {
521
      System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
522
    }
523
 
524
    assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
525
    moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
526
    assertFalse(moreBuildFiles);
527
 
528
    releaseManager = 
529
      new ReleaseManager("iteration4", "not used", "not used");
530
 
531
    // this is all the MasterThread does
532
    try
533
    {
534
      rippleEngine.planRelease();
535
    }
536
    catch(Exception e)
537
    {
538
    }
539
 
540
    moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
541
    assertTrue(moreBuildFiles);
542
 
543
    // persist the generated build file content to daemon1.xml for visibility
544
    buildFileName = new String("daemon4.xml");
545
    try
546
    {
547
      File buildFile = new File(cwd, buildFileName);
548
      FileWriter buildFileWriter = new FileWriter(buildFile);
549
      buildFileWriter.write(buildFileContent.value);
550
      buildFileWriter.close();
551
      File expectedBuildFile = new File(cwd, "expecteddaemon4.xml");
552
      FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
553
      char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
554
      expectedBuildFileReader.read(expectedBuildFileContent);
555
      expectedBuildFileReader.close();
556
      String temp = new String(expectedBuildFileContent);
557
      ExpectedBuildFileContent = temp;
558
    }
559
    catch( IOException e )
560
    {
561
      System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
562
    }
563
 
564
    assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
565
    moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
566
    assertFalse(moreBuildFiles);
567
 
568
    releaseManager = 
569
      new ReleaseManager("iteration5", "not used", "not used");
570
 
571
    // this is all the MasterThread does
572
    try
573
    {
574
      rippleEngine.planRelease();
575
    }
576
    catch(Exception e)
577
    {
578
    }
579
 
580
    moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
581
    assertTrue(moreBuildFiles);
582
 
583
    // persist the generated build file content to daemon1.xml for visibility
584
    buildFileName = new String("daemon5.xml");
585
    try
586
    {
587
      File buildFile = new File(cwd, buildFileName);
588
      FileWriter buildFileWriter = new FileWriter(buildFile);
589
      buildFileWriter.write(buildFileContent.value);
590
      buildFileWriter.close();
591
      File expectedBuildFile = new File(cwd, "expecteddaemon5.xml");
592
      FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
593
      char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
594
      expectedBuildFileReader.read(expectedBuildFileContent);
595
      expectedBuildFileReader.close();
596
      String temp = new String(expectedBuildFileContent);
597
      ExpectedBuildFileContent = temp;
598
    }
599
    catch( IOException e )
600
    {
601
      System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
602
    }
603
 
604
    assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
605
    moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
606
    assertFalse(moreBuildFiles);
607
 
608
    releaseManager = 
609
      new ReleaseManager("iteration6", "not used", "not used");
610
 
611
    // this is all the MasterThread does
612
    try
613
    {
614
      rippleEngine.planRelease();
615
    }
616
    catch(Exception e)
617
    {
618
    }
619
 
620
    moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
621
    assertTrue(moreBuildFiles);
622
 
623
    // persist the generated build file content to daemon1.xml for visibility
624
    buildFileName = new String("daemon6.xml");
625
    try
626
    {
627
      File buildFile = new File(cwd, buildFileName);
628
      FileWriter buildFileWriter = new FileWriter(buildFile);
629
      buildFileWriter.write(buildFileContent.value);
630
      buildFileWriter.close();
631
      File expectedBuildFile = new File(cwd, "expecteddaemon6.xml");
632
      FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
633
      char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
634
      expectedBuildFileReader.read(expectedBuildFileContent);
635
      expectedBuildFileReader.close();
636
      String temp = new String(expectedBuildFileContent);
637
      ExpectedBuildFileContent = temp;
638
    }
639
    catch( IOException e )
640
    {
641
      System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
642
    }
643
 
644
    assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
645
    moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
646
    assertFalse(moreBuildFiles);
647
 
648
    releaseManager = 
649
      new ReleaseManager("iteration7", "not used", "not used");
650
 
651
    // this is all the MasterThread does
652
    try
653
    {
654
      rippleEngine.planRelease();
655
    }
656
    catch(Exception e)
657
    {
658
    }
659
 
660
    moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
661
    assertTrue(moreBuildFiles);
662
  }
663
}