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