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
882 mhunt 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
814 mhunt 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 );
882 mhunt 238
    assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_IDLE );
239
    persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 2 );
814 mhunt 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
882 mhunt 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
814 mhunt 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 );
882 mhunt 283
    assertTrue( persistedRunLevel.intValue() == ReleaseManager.DB_IDLE );
284
    persistedRunLevel = (Integer)ReleaseManager.mPersistedRunLevelCollection.get( 2 );
814 mhunt 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
    {
868 mhunt 411
      rippleEngine.collectMetaData();
814 mhunt 412
      rippleEngine.planRelease();
413
    }
414
    catch(Exception e)
415
    {
416
    }
417
 
418
    String ExpectedBuildFileContent = new String();
419
    MutableString buildFileContent = new MutableString();
420
    boolean moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
421
    assertTrue(moreBuildFiles);
422
 
423
    // persist the generated build file content to daemon1.xml for visibility
424
    File cwd = new File( "." );
425
    String buildFileName = new String("daemon1.xml");
426
    try
427
    {
428
      File buildFile = new File(cwd, buildFileName);
429
      FileWriter buildFileWriter = new FileWriter(buildFile);
430
      buildFileWriter.write(buildFileContent.value);
431
      buildFileWriter.close();
432
      File expectedBuildFile = new File(cwd, "expecteddaemon1.xml");
433
      FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
434
      char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
435
      expectedBuildFileReader.read(expectedBuildFileContent);
436
      expectedBuildFileReader.close();
437
      String temp = new String(expectedBuildFileContent);
438
      ExpectedBuildFileContent = temp;
439
    }
440
    catch( IOException e )
441
    {
442
      System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
443
    }
444
 
445
    assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
446
    moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
447
    assertFalse(moreBuildFiles);
448
 
449
    releaseManager = 
450
      new ReleaseManager("iteration2", "not used", "not used");
451
 
452
    // this is all the MasterThread does
453
    try
454
    {
868 mhunt 455
      rippleEngine.collectMetaData();
814 mhunt 456
      rippleEngine.planRelease();
457
    }
458
    catch(Exception e)
459
    {
460
    }
461
 
462
    moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
463
    assertTrue(moreBuildFiles);
464
 
465
    // persist the generated build file content to daemon1.xml for visibility
466
    buildFileName = new String("daemon2.xml");
467
    try
468
    {
469
      File buildFile = new File(cwd, buildFileName);
470
      FileWriter buildFileWriter = new FileWriter(buildFile);
471
      buildFileWriter.write(buildFileContent.value);
472
      buildFileWriter.close();
473
      File expectedBuildFile = new File(cwd, "expecteddaemon2.xml");
474
      FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
475
      char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
476
      expectedBuildFileReader.read(expectedBuildFileContent);
477
      expectedBuildFileReader.close();
478
      String temp = new String(expectedBuildFileContent);
479
      ExpectedBuildFileContent = temp;
480
    }
481
    catch( IOException e )
482
    {
483
      System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
484
    }
485
 
486
    assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
487
    moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
488
    assertFalse(moreBuildFiles);
489
 
490
    releaseManager = 
491
      new ReleaseManager("iteration3", "not used", "not used");
492
 
493
    // this is all the MasterThread does
494
    try
495
    {
868 mhunt 496
      rippleEngine.collectMetaData();
814 mhunt 497
      rippleEngine.planRelease();
498
    }
499
    catch(Exception e)
500
    {
501
    }
502
 
503
    moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
504
    assertTrue(moreBuildFiles);
505
 
506
    // persist the generated build file content to daemon1.xml for visibility
507
    buildFileName = new String("daemon3.xml");
508
    try
509
    {
510
      File buildFile = new File(cwd, buildFileName);
511
      FileWriter buildFileWriter = new FileWriter(buildFile);
512
      buildFileWriter.write(buildFileContent.value);
513
      buildFileWriter.close();
514
      File expectedBuildFile = new File(cwd, "expecteddaemon3.xml");
515
      FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
516
      char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
517
      expectedBuildFileReader.read(expectedBuildFileContent);
518
      expectedBuildFileReader.close();
519
      String temp = new String(expectedBuildFileContent);
520
      ExpectedBuildFileContent = temp;
521
    }
522
    catch( IOException e )
523
    {
524
      System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
525
    }
526
 
527
    assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
528
    moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
529
    assertFalse(moreBuildFiles);
530
 
531
    releaseManager = 
532
      new ReleaseManager("iteration4", "not used", "not used");
533
 
534
    // this is all the MasterThread does
535
    try
536
    {
868 mhunt 537
      rippleEngine.collectMetaData();
814 mhunt 538
      rippleEngine.planRelease();
539
    }
540
    catch(Exception e)
541
    {
542
    }
543
 
544
    moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
545
    assertTrue(moreBuildFiles);
546
 
547
    // persist the generated build file content to daemon1.xml for visibility
548
    buildFileName = new String("daemon4.xml");
549
    try
550
    {
551
      File buildFile = new File(cwd, buildFileName);
552
      FileWriter buildFileWriter = new FileWriter(buildFile);
553
      buildFileWriter.write(buildFileContent.value);
554
      buildFileWriter.close();
555
      File expectedBuildFile = new File(cwd, "expecteddaemon4.xml");
556
      FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
557
      char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
558
      expectedBuildFileReader.read(expectedBuildFileContent);
559
      expectedBuildFileReader.close();
560
      String temp = new String(expectedBuildFileContent);
561
      ExpectedBuildFileContent = temp;
562
    }
563
    catch( IOException e )
564
    {
565
      System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
566
    }
567
 
568
    assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
569
    moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
570
    assertFalse(moreBuildFiles);
571
 
572
    releaseManager = 
573
      new ReleaseManager("iteration5", "not used", "not used");
574
 
575
    // this is all the MasterThread does
576
    try
577
    {
868 mhunt 578
      rippleEngine.collectMetaData();
814 mhunt 579
      rippleEngine.planRelease();
580
    }
581
    catch(Exception e)
582
    {
583
    }
584
 
585
    moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
586
    assertTrue(moreBuildFiles);
587
 
588
    // persist the generated build file content to daemon1.xml for visibility
589
    buildFileName = new String("daemon5.xml");
590
    try
591
    {
592
      File buildFile = new File(cwd, buildFileName);
593
      FileWriter buildFileWriter = new FileWriter(buildFile);
594
      buildFileWriter.write(buildFileContent.value);
595
      buildFileWriter.close();
596
      File expectedBuildFile = new File(cwd, "expecteddaemon5.xml");
597
      FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
598
      char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
599
      expectedBuildFileReader.read(expectedBuildFileContent);
600
      expectedBuildFileReader.close();
601
      String temp = new String(expectedBuildFileContent);
602
      ExpectedBuildFileContent = temp;
603
    }
604
    catch( IOException e )
605
    {
606
      System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
607
    }
608
 
609
    assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
610
    moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
611
    assertFalse(moreBuildFiles);
612
 
613
    releaseManager = 
614
      new ReleaseManager("iteration6", "not used", "not used");
615
 
616
    // this is all the MasterThread does
617
    try
618
    {
868 mhunt 619
      rippleEngine.collectMetaData();
814 mhunt 620
      rippleEngine.planRelease();
621
    }
622
    catch(Exception e)
623
    {
624
    }
625
 
626
    moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
627
    assertTrue(moreBuildFiles);
628
 
629
    // persist the generated build file content to daemon1.xml for visibility
630
    buildFileName = new String("daemon6.xml");
631
    try
632
    {
633
      File buildFile = new File(cwd, buildFileName);
634
      FileWriter buildFileWriter = new FileWriter(buildFile);
635
      buildFileWriter.write(buildFileContent.value);
636
      buildFileWriter.close();
637
      File expectedBuildFile = new File(cwd, "expecteddaemon6.xml");
638
      FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
639
      char[] expectedBuildFileContent = new char[(int)expectedBuildFile.length()];
640
      expectedBuildFileReader.read(expectedBuildFileContent);
641
      expectedBuildFileReader.close();
642
      String temp = new String(expectedBuildFileContent);
643
      ExpectedBuildFileContent = temp;
644
    }
645
    catch( IOException e )
646
    {
647
      System.out.println("DaemonBuildTestCase::TestPlanRelease caught IOException");
648
    }
649
 
650
    assertTrue(buildFileContent.value.compareTo(ExpectedBuildFileContent) == 0);
651
    moreBuildFiles = rippleEngine.getNextBuildFileContent(buildFileContent);
652
    assertFalse(moreBuildFiles);
653
 
654
    releaseManager = 
655
      new ReleaseManager("iteration7", "not used", "not used");
656
 
657
    // this is all the MasterThread does
658
    try
659
    {
868 mhunt 660
      rippleEngine.collectMetaData();
814 mhunt 661
      rippleEngine.planRelease();
662
    }
663
    catch(Exception e)
664
    {
665
    }
666
 
667
    moreBuildFiles = rippleEngine.getFirstBuildFileContent(buildFileContent);
668
    assertTrue(moreBuildFiles);
669
  }
874 mhunt 670
 
671
  /**test method designed to test ripple field limits
672
   *  1 tests applyPV returns 1 for package with version a.b.1.2.0
673
   */
674
  @Test
675
  public void TestRippleFieldLimits()
676
  {
677
    ReleaseManager rm = new ReleaseManager();
678
    // for test purposes, p.mId will contain the return value of applyPV
679
    // test applyPV returns 1 and leaves mVersion alone
680
    Package p = new Package(rm, "a.b.1.2.0", 255, 255, 255, 255);
681
    assertTrue( p.getId() == 1 );
682
    assertTrue( p.getVersion().compareTo( "a.b.1.2.0" ) == 0);
683
 
684
    // test applyPV returns 2 and leaves mVersion alone
685
    p = new Package( rm, "1.0.0000", 0, 0, 0, 0 );
686
    assertTrue( p.getId() == 2 );
687
    assertTrue( p.getVersion().compareTo( "1.0.0000" ) == 0);
688
 
689
    // test applyPV returns 2 and leaves mVersion alone
690
    p = new Package( rm, "1.0.0009", 0, 0, 0, 9 );
691
    assertTrue( p.getId() == 2 );
692
    assertTrue( p.getVersion().compareTo( "1.0.0009" ) == 0);
693
 
694
    // test applyPV returns 2 and leaves mVersion alone
695
    p = new Package( rm, "1.0.9000", 0, 0, 9, 0 );
696
    assertTrue( p.getId() == 2 );
697
    assertTrue( p.getVersion().compareTo( "1.0.9000" ) == 0);
698
 
699
    // test applyPV returns 2 and leaves mVersion alone
700
    p = new Package( rm, "1.9.0000", 0, 9, 0, 0 );
701
    assertTrue( p.getId() == 2 );
702
    assertTrue( p.getVersion().compareTo( "1.9.0000" ) == 0);
703
 
704
    // test applyPV returns 2 and leaves mVersion alone
705
    p = new Package( rm, "1.0.0000", 1, 0, 0, 0 );
706
    assertTrue( p.getId() == 2 );
707
    assertTrue( p.getVersion().compareTo( "1.0.0000" ) == 0);
708
 
709
    // test applyPV returns 2 and leaves mVersion alone - wince style limits
710
    p = new Package( rm, "9.9.9000", 9, 9, 9, 0 );
711
    assertTrue( p.getId() == 2 );
712
    assertTrue( p.getVersion().compareTo( "9.9.9000" ) == 0);
713
 
714
    // test applyPV returns 0 and sets mVersion from 8.8.8000 to 8.8.9000
715
    p = new Package( rm, "8.8.8000", 9, 9, 9, 0 );
716
    assertTrue( p.getId() == 0 );
717
    assertTrue( p.getVersion().compareTo( "8.8.9000" ) == 0);
718
 
719
    // test applyPV returns 0 and sets mVersion from 8.8.9000 to 8.9.0000
720
    p = new Package( rm, "8.8.9000", 9, 9, 9, 0 );
721
    assertTrue( p.getId() == 0 );
722
    assertTrue( p.getVersion().compareTo( "8.9.0000" ) == 0);
723
 
724
    // test applyPV returns 0 and sets mVersion from 8.9.9000 to 9.0.0000
725
    p = new Package( rm, "8.9.9000", 9, 9, 9, 0 );
726
    assertTrue( p.getId() == 0 );
727
    assertTrue( p.getVersion().compareTo( "9.0.0000" ) == 0);
728
 
729
    // test applyPV returns 2 and leaves mVersion alone - mos style limits
730
    p = new Package( rm, "99.99.0000", 99, 99, 0, 0 );
731
    assertTrue( p.getId() == 2 );
732
    assertTrue( p.getVersion().compareTo( "99.99.0000" ) == 0);
733
 
734
    // test applyPV returns 0 and sets mVersion from 98.98.0000 to 98.99.0000
735
    p = new Package( rm, "98.98.0000", 99, 99, 0, 0 );
736
    assertTrue( p.getId() == 0 );
737
    assertTrue( p.getVersion().compareTo( "98.99.0000" ) == 0);
738
 
739
    // test applyPV returns 0 and sets mVersion from 98.99.0000 to 99.0.0000
740
    p = new Package( rm, "98.99.0000", 99, 99, 0, 0 );
741
    assertTrue( p.getId() == 0 );
742
    assertTrue( p.getVersion().compareTo( "99.0.0000" ) == 0);
743
 
744
  }
814 mhunt 745
}