Subversion Repositories DevTools

Rev

Go to most recent revision | 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.ReleaseManager;
874 mhunt 10
import com.erggroup.buildtool.ripple.Package;
814 mhunt 11
import com.erggroup.buildtool.ripple.RippleEngine;
12
 
13
import java.io.File;
14
import java.io.FileReader;
15
import java.io.FileWriter;
16
import java.io.IOException;
874 mhunt 17
import java.util.Vector;
814 mhunt 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");
864 mhunt 142
    assertFalse(Thread.interrupted());
814 mhunt 143
    masterThread.run();
144
    // interrupted checks and importantly clears the interrupted status of this thread for subsequent tests
864 mhunt 145
    assertTrue(Thread.interrupted());
146
    assertFalse(Thread.interrupted());
814 mhunt 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");
864 mhunt 209
    assertFalse(Thread.interrupted());
814 mhunt 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
816 mhunt 224
   *  5 checks the third persisted run level is DB_WAITING
225
   *  6 checks no further run levels were persisted
814 mhunt 226
   */
227
  @Test
228
  public void TestAllowedToProceed()
229
  {
230
    mLogger.debug("TestAllowedToProceed");
231
    ReleaseManager releaseManager = new ReleaseManager("unit test allowed to proceed", "not used", "not used");
232
    MasterThread masterThread = new MasterThread(1, 1, "unit test allowed to proceed");
233
    masterThread.run();
234
    Integer persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 0 );
235
    assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_IDLE );
236
    persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 1 );
237
    assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_WAITING );
238
    boolean caughtOOB = false;
239
 
240
    try
241
    {
242
      persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 3 );
243
    }
244
    catch( ArrayIndexOutOfBoundsException e )
245
    {
246
      caughtOOB = true;
247
    }
248
 
249
    assertTrue(caughtOOB);
250
  }
251
 
252
  /**test method designed to test the sequence diagram not allowed to proceed
253
   *  1 constructs a ReleaseManager object, passing a connectionString of "unit test not allowed to proceed"
254
   *  2 constructs a MasterThread object, passing a gbebuildfilter of "unit test not allowed to proceed"
255
   *    this utilises the following unit test hooks in the codebase:
256
   *    - MasterThread constructor made public for unit test use
257
   *    - MasterThread::run gbebuildfilter of "unit test not allowed to proceed" limits method to the sequence diagram
258
   *      exits the while forever loop
259
   *    - ReleaseManager::queryReleaseConfig method returns true
260
   *    - ReleaseManager::queryRunLevelSchedule method returns false
261
   *    - ReleaseManager::updateCurrentRunLevel utilises the public mPersistedRunLevelCollection
262
   *  3 calls run on the MasterThread object
263
   *  4 checks the first persisted run level is DB_IDLE
816 mhunt 264
   *  5 checks the third persisted run level is DB_PAUSED
265
   *  6 checks no further run levels were persisted
814 mhunt 266
   * nb cannot check only one thread is running,
267
   * a Timer thread, though having run to completion, may still be "active"
268
   */
269
  @Test
270
  public void TestNotAllowedToProceed()
271
  {
272
    mLogger.debug("TestNotAllowedToProceed");
273
    ReleaseManager releaseManager = new ReleaseManager("unit test not allowed to proceed", "not used", "not used");
274
    MasterThread masterThread = new MasterThread(1, 1, "unit test not allowed to proceed");
275
    masterThread.run();
276
    Integer persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 0 );
277
    assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_IDLE );
278
    persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 1 );
279
    assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_PAUSED );
280
    boolean caughtOOB = false;
281
 
282
    try
283
    {
284
      persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 3 );
285
    }
286
    catch( ArrayIndexOutOfBoundsException e )
287
    {
288
      caughtOOB = true;
289
    }
290
 
291
    assertTrue(caughtOOB);
292
  }
293
 
294
  /**test method designed to test the sequence diagram exit
295
   *  1 constructs a ReleaseManager object, passing a connectionString of "unit test exit"
296
   *  2 constructs a MasterThread object, passing a gbebuildfilter of "unit test exit"
297
   *    this utilises the following unit test hooks in the codebase:
298
   *    - MasterThread constructor made public for unit test use
299
   *    - MasterThread::run gbebuildfilter of "unit test exit" limits method to the sequence diagram
300
   *    - ReleaseManager::queryReleaseConfig method returns false
301
   *    - ReleaseManager::updateCurrentRunLevel utilises the public mPersistedRunLevelCollection
302
   *  3 calls run on the MasterThread object
303
   *  4 checks the first persisted run level is DB_IDLE
304
   *  5 checks no further run levels were persisted
305
   */
306
  @Test
307
  public void TestExit()
308
  {
309
    mLogger.debug("TestExit");
310
    ReleaseManager releaseManager = new ReleaseManager("unit test exit", "not used", "not used");
311
    MasterThread masterThread = new MasterThread(1, 1, "unit test exit");
312
    masterThread.run();
313
    Integer persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 0 );
314
    assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_IDLE );
315
 
316
    boolean caughtOOB = false;
317
 
318
    try
319
    {
320
      persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 2 );
321
    }
322
    catch( ArrayIndexOutOfBoundsException e )
323
    {
324
      caughtOOB = true;
325
    }
326
 
327
    assertTrue(caughtOOB);
328
  }
329
 
330
  /**test method designed to test the sequence diagram check environment
331
   *  1 constructs a ReleaseManager object, passing a connectionString of "unit check environment"
332
   *  2 constructs a MasterThread object, passing a gbebuildfilter of "unit check environment"
333
   *    this utilises the following unit test hooks in the codebase:
334
   *    - MasterThread constructor made public for unit test use
335
   *    - MasterThread::run gbebuildfilter of "unit test check environment" limits method to the sequence diagram
336
   *      exits the while forever loop
337
   *    - MasterThread::housekeep method does not call deleteDirectory
338
   *    - MasterThread::hasSufficientDiskSpace initially returns false, then true
339
   *    - ReleaseManager::updateCurrentRunLevel utilises the public mPersistedRunLevelCollection
340
   *  3 calls run on the MasterThread object
341
   *  4 checks the first persisted run level is DB_CANNOT_CONTINUE
342
   *  5 checks the next persisted run level is DB_ACTIVE
343
   *  6 checks no further run levels were persisted
344
   */
345
  @Test
346
  public void TestCheckEnvironment()
347
  {
348
    mLogger.debug("TestCheckEnvironment");
349
    ReleaseManager releaseManager = new ReleaseManager("unit test check environment", "not used", "not used");
350
    MasterThread masterThread = new MasterThread(1, 1, "unit test check environment");
351
    masterThread.run();
352
    Integer persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 0 );
353
    assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_CANNOT_CONTINUE );
354
    persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 1 );
355
    assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_ACTIVE );
356
    boolean caughtOOB = false;
357
 
358
    try
359
    {
360
      persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 2 );
361
    }
362
    catch( ArrayIndexOutOfBoundsException e )
363
    {
364
      caughtOOB = true;
365
    }
366
 
367
    assertTrue(caughtOOB);
368
  }
369
 
370
  /**test method designed to test the ripple engine
371
   *  1 constructs a ReleaseManager object with connection string "iteration1"
372
   *  2 constructs a RippleEngine object
373
   *  3 calls planRelease on the RippleEngine object
374
   *  4 calls getFirstBuildFileContent
375
   *  5 checks it returns true
376
   *  6 writes the content to "daemon1.xml"
377
   *  7 checks the content matches the content in "expecteddaemon1.xml"
378
   *  8 calls getNextBuildFileContent
379
   *  9 checks it returns false
380
   * 10 constructs a ReleaseManager object with connection string "iteration2"
381
   * 11 calls planRelease on the RippleEngine object
382
   * 12 calls getFirstBuildFileContent
383
   * 13 checks it returns true
384
   * 14 writes the content to "daemon2.xml"
385
   * 15 checks the content matches the content in "expecteddaemon2.xml"
386
   * 16 calls getNextBuildFileContent
387
   * 17 checks it returns false
388
   * 18 steps 10 to 17 are repeated for iteration3,4,5 and 6
389
   * 19 constructs a ReleaseManager object with connection string "iteration7"
390
   * 20 calls planRelease on the RippleEngine object
391
   * 21 calls getFirstBuildFileContent
392
   * 22 checks it returns true (a benign build file content)
393
   */
394
  @Test
395
  public void TestPlanRelease()
396
  {
397
    mLogger.debug("TestPlanRelease");
398
    ReleaseManager releaseManager = 
399
      new ReleaseManager("iteration1", "not used", "not used");
400
 
401
    RippleEngine rippleEngine = new RippleEngine(releaseManager, 11111, true);
402
    // this is all the MasterThread does
403
    try
404
    {
868 mhunt 405
      rippleEngine.collectMetaData();
814 mhunt 406
      rippleEngine.planRelease();
407
    }
408
    catch(Exception e)
409
    {
410
    }
411
 
412
    String ExpectedBuildFileContent = new String();
413
    MutableString buildFileContent = new MutableString();
414
    boolean moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
415
    assertTrue(moreBuildFiles);
416
 
417
    // persist the generated build file content to daemon1.xml for visibility
418
    File cwd = new File( "." );
419
    String buildFileName = new String("daemon1.xml");
420
    try
421
    {
422
      File buildFile = new File(cwd, buildFileName);
423
      FileWriter buildFileWriter = new FileWriter(buildFile);
424
      buildFileWriter.write(buildFileContent.value);
425
      buildFileWriter.close();
426
      File expectedBuildFile = new File(cwd, "expecteddaemon1.xml");
427
      FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
428
      char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
429
      expectedBuildFileReader.read(expectedBuildFileContent);
430
      expectedBuildFileReader.close();
431
      String temp = new String(expectedBuildFileContent);
432
      ExpectedBuildFileContent = temp;
433
    }
434
    catch( IOException e )
435
    {
436
      System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
437
    }
438
 
439
    assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
440
    moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
441
    assertFalse(moreBuildFiles);
442
 
443
    releaseManager = 
444
      new ReleaseManager("iteration2", "not used", "not used");
445
 
446
    // this is all the MasterThread does
447
    try
448
    {
868 mhunt 449
      rippleEngine.collectMetaData();
814 mhunt 450
      rippleEngine.planRelease();
451
    }
452
    catch(Exception e)
453
    {
454
    }
455
 
456
    moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
457
    assertTrue(moreBuildFiles);
458
 
459
    // persist the generated build file content to daemon1.xml for visibility
460
    buildFileName = new String("daemon2.xml");
461
    try
462
    {
463
      File buildFile = new File(cwd, buildFileName);
464
      FileWriter buildFileWriter = new FileWriter(buildFile);
465
      buildFileWriter.write(buildFileContent.value);
466
      buildFileWriter.close();
467
      File expectedBuildFile = new File(cwd, "expecteddaemon2.xml");
468
      FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
469
      char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
470
      expectedBuildFileReader.read(expectedBuildFileContent);
471
      expectedBuildFileReader.close();
472
      String temp = new String(expectedBuildFileContent);
473
      ExpectedBuildFileContent = temp;
474
    }
475
    catch( IOException e )
476
    {
477
      System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
478
    }
479
 
480
    assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
481
    moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
482
    assertFalse(moreBuildFiles);
483
 
484
    releaseManager = 
485
      new ReleaseManager("iteration3", "not used", "not used");
486
 
487
    // this is all the MasterThread does
488
    try
489
    {
868 mhunt 490
      rippleEngine.collectMetaData();
814 mhunt 491
      rippleEngine.planRelease();
492
    }
493
    catch(Exception e)
494
    {
495
    }
496
 
497
    moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
498
    assertTrue(moreBuildFiles);
499
 
500
    // persist the generated build file content to daemon1.xml for visibility
501
    buildFileName = new String("daemon3.xml");
502
    try
503
    {
504
      File buildFile = new File(cwd, buildFileName);
505
      FileWriter buildFileWriter = new FileWriter(buildFile);
506
      buildFileWriter.write(buildFileContent.value);
507
      buildFileWriter.close();
508
      File expectedBuildFile = new File(cwd, "expecteddaemon3.xml");
509
      FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
510
      char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
511
      expectedBuildFileReader.read(expectedBuildFileContent);
512
      expectedBuildFileReader.close();
513
      String temp = new String(expectedBuildFileContent);
514
      ExpectedBuildFileContent = temp;
515
    }
516
    catch( IOException e )
517
    {
518
      System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
519
    }
520
 
521
    assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
522
    moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
523
    assertFalse(moreBuildFiles);
524
 
525
    releaseManager = 
526
      new ReleaseManager("iteration4", "not used", "not used");
527
 
528
    // this is all the MasterThread does
529
    try
530
    {
868 mhunt 531
      rippleEngine.collectMetaData();
814 mhunt 532
      rippleEngine.planRelease();
533
    }
534
    catch(Exception e)
535
    {
536
    }
537
 
538
    moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
539
    assertTrue(moreBuildFiles);
540
 
541
    // persist the generated build file content to daemon1.xml for visibility
542
    buildFileName = new String("daemon4.xml");
543
    try
544
    {
545
      File buildFile = new File(cwd, buildFileName);
546
      FileWriter buildFileWriter = new FileWriter(buildFile);
547
      buildFileWriter.write(buildFileContent.value);
548
      buildFileWriter.close();
549
      File expectedBuildFile = new File(cwd, "expecteddaemon4.xml");
550
      FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
551
      char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
552
      expectedBuildFileReader.read(expectedBuildFileContent);
553
      expectedBuildFileReader.close();
554
      String temp = new String(expectedBuildFileContent);
555
      ExpectedBuildFileContent = temp;
556
    }
557
    catch( IOException e )
558
    {
559
      System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
560
    }
561
 
562
    assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
563
    moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
564
    assertFalse(moreBuildFiles);
565
 
566
    releaseManager = 
567
      new ReleaseManager("iteration5", "not used", "not used");
568
 
569
    // this is all the MasterThread does
570
    try
571
    {
868 mhunt 572
      rippleEngine.collectMetaData();
814 mhunt 573
      rippleEngine.planRelease();
574
    }
575
    catch(Exception e)
576
    {
577
    }
578
 
579
    moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
580
    assertTrue(moreBuildFiles);
581
 
582
    // persist the generated build file content to daemon1.xml for visibility
583
    buildFileName = new String("daemon5.xml");
584
    try
585
    {
586
      File buildFile = new File(cwd, buildFileName);
587
      FileWriter buildFileWriter = new FileWriter(buildFile);
588
      buildFileWriter.write(buildFileContent.value);
589
      buildFileWriter.close();
590
      File expectedBuildFile = new File(cwd, "expecteddaemon5.xml");
591
      FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
592
      char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
593
      expectedBuildFileReader.read(expectedBuildFileContent);
594
      expectedBuildFileReader.close();
595
      String temp = new String(expectedBuildFileContent);
596
      ExpectedBuildFileContent = temp;
597
    }
598
    catch( IOException e )
599
    {
600
      System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
601
    }
602
 
603
    assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
604
    moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
605
    assertFalse(moreBuildFiles);
606
 
607
    releaseManager = 
608
      new ReleaseManager("iteration6", "not used", "not used");
609
 
610
    // this is all the MasterThread does
611
    try
612
    {
868 mhunt 613
      rippleEngine.collectMetaData();
814 mhunt 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
    {
868 mhunt 654
      rippleEngine.collectMetaData();
814 mhunt 655
      rippleEngine.planRelease();
656
    }
657
    catch(Exception e)
658
    {
659
    }
660
 
661
    moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
662
    assertTrue(moreBuildFiles);
663
  }
874 mhunt 664
 
665
  /**test method designed to test ripple field limits
666
   *  1 tests applyPV returns 1 for package with version a.b.1.2.0
667
   */
668
  @Test
669
  public void TestRippleFieldLimits()
670
  {
671
    ReleaseManager rm = new ReleaseManager();
672
    // for test purposes, p.mId will contain the return value of applyPV
673
    // test applyPV returns 1 and leaves mVersion alone
674
    Package p = new Package(rm, "a.b.1.2.0", 255, 255, 255, 255);
675
    assertTrue( p.getId() == 1 );
676
    assertTrue( p.getVersion().compareTo( "a.b.1.2.0" ) == 0);
677
 
678
    // test applyPV returns 2 and leaves mVersion alone
679
    p = new Package( rm, "1.0.0000", 0, 0, 0, 0 );
680
    assertTrue( p.getId() == 2 );
681
    assertTrue( p.getVersion().compareTo( "1.0.0000" ) == 0);
682
 
683
    // test applyPV returns 2 and leaves mVersion alone
684
    p = new Package( rm, "1.0.0009", 0, 0, 0, 9 );
685
    assertTrue( p.getId() == 2 );
686
    assertTrue( p.getVersion().compareTo( "1.0.0009" ) == 0);
687
 
688
    // test applyPV returns 2 and leaves mVersion alone
689
    p = new Package( rm, "1.0.9000", 0, 0, 9, 0 );
690
    assertTrue( p.getId() == 2 );
691
    assertTrue( p.getVersion().compareTo( "1.0.9000" ) == 0);
692
 
693
    // test applyPV returns 2 and leaves mVersion alone
694
    p = new Package( rm, "1.9.0000", 0, 9, 0, 0 );
695
    assertTrue( p.getId() == 2 );
696
    assertTrue( p.getVersion().compareTo( "1.9.0000" ) == 0);
697
 
698
    // test applyPV returns 2 and leaves mVersion alone
699
    p = new Package( rm, "1.0.0000", 1, 0, 0, 0 );
700
    assertTrue( p.getId() == 2 );
701
    assertTrue( p.getVersion().compareTo( "1.0.0000" ) == 0);
702
 
703
    // test applyPV returns 2 and leaves mVersion alone - wince style limits
704
    p = new Package( rm, "9.9.9000", 9, 9, 9, 0 );
705
    assertTrue( p.getId() == 2 );
706
    assertTrue( p.getVersion().compareTo( "9.9.9000" ) == 0);
707
 
708
    // test applyPV returns 0 and sets mVersion from 8.8.8000 to 8.8.9000
709
    p = new Package( rm, "8.8.8000", 9, 9, 9, 0 );
710
    assertTrue( p.getId() == 0 );
711
    assertTrue( p.getVersion().compareTo( "8.8.9000" ) == 0);
712
 
713
    // test applyPV returns 0 and sets mVersion from 8.8.9000 to 8.9.0000
714
    p = new Package( rm, "8.8.9000", 9, 9, 9, 0 );
715
    assertTrue( p.getId() == 0 );
716
    assertTrue( p.getVersion().compareTo( "8.9.0000" ) == 0);
717
 
718
    // test applyPV returns 0 and sets mVersion from 8.9.9000 to 9.0.0000
719
    p = new Package( rm, "8.9.9000", 9, 9, 9, 0 );
720
    assertTrue( p.getId() == 0 );
721
    assertTrue( p.getVersion().compareTo( "9.0.0000" ) == 0);
722
 
723
    // test applyPV returns 2 and leaves mVersion alone - mos style limits
724
    p = new Package( rm, "99.99.0000", 99, 99, 0, 0 );
725
    assertTrue( p.getId() == 2 );
726
    assertTrue( p.getVersion().compareTo( "99.99.0000" ) == 0);
727
 
728
    // test applyPV returns 0 and sets mVersion from 98.98.0000 to 98.99.0000
729
    p = new Package( rm, "98.98.0000", 99, 99, 0, 0 );
730
    assertTrue( p.getId() == 0 );
731
    assertTrue( p.getVersion().compareTo( "98.99.0000" ) == 0);
732
 
733
    // test applyPV returns 0 and sets mVersion from 98.99.0000 to 99.0.0000
734
    p = new Package( rm, "98.99.0000", 99, 99, 0, 0 );
735
    assertTrue( p.getId() == 0 );
736
    assertTrue( p.getVersion().compareTo( "99.0.0000" ) == 0);
737
 
738
  }
814 mhunt 739
}