Subversion Repositories DevTools

Rev

Rev 7163 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.erggroup.buildtool.utf;


import java.sql.SQLException;
import java.util.Date;
import java.util.Iterator;

import com.erggroup.buildtool.daemon.BuildDaemon;
import com.erggroup.buildtool.daemon.BuildThread;
import com.erggroup.buildtool.daemon.MasterThread;
import com.erggroup.buildtool.daemon.SlaveThread;
import com.erggroup.buildtool.ripple.BuildFile;
import com.erggroup.buildtool.ripple.BuildFile.BuildFileState;
import com.erggroup.buildtool.ripple.BuildStandard;
import com.erggroup.buildtool.ripple.ReleaseConfig;
import com.erggroup.buildtool.ripple.ReleaseManager;
import com.erggroup.buildtool.ripple.Package;
import com.erggroup.buildtool.ripple.PackageCollection;
import com.erggroup.buildtool.ripple.RippleEngine;
import com.erggroup.buildtool.ripple.RunLevelData;
import com.erggroup.buildtool.ripple.RunLevel.BuildState;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.JUnitCore;

import static org.junit.Assert.*;

/**
 * container of Build Daemon test methods
 */
public class DaemonBuildTestCase
{
    private static final Logger mLogger = LoggerFactory.getLogger(DaemonBuildTestCase.class);
    myReleaseManager            releaseManager = null;
    RippleEngine                rippleEngine   = null;
    PackageCollection testPackageCollection   = new PackageCollection();
    PackageCollection testPackageCollectionWip   = new PackageCollection();
    
    /**
     * Init the package set
     */
    public void initTestPackages(String setName)
    {
        releaseManager.initTestPackages(rippleEngine, testPackageCollection, setName);
    }

    /** Create a WIP for a package in the Release
     * This will mark it as directlyPlanned
     * @param newPvId
     * @param alias
     */
    private Package createWip(int newPvId, String alias) {

        Package wip = testPackageCollection.contains(alias);
        if (wip == null)
        {
                wip = ReleaseManager.NULL_PACKAGE;
        }
        else
        {
            wip = new Package(newPvId, wip);
            wip.mDirectlyPlanned = true;
            testPackageCollectionWip.add(wip);
        }

        return wip;
    }

    
       
    /** Subclass and override key methods so that the test can control
     *  the data being used
     */
    public class myReleaseManager extends ReleaseManagerUtf
        {
        int mAmyReleaseManager = 1;

       public myReleaseManager(final String connectionString, final String username, final String password)
                {
           super(connectionString, username, password);
           mLogger.error("Test {}", connectionString);
                }

                public myReleaseManager()
                {
                        super();
                }
                
                @Override
                public void queryPackageVersions(RippleEngine rippleEngine, PackageCollection packageCollection, int baseline) throws SQLException, Exception
                {
                 
                    //    Filter for the packages that are in the release
                    for (Iterator<Package> it = testPackageCollection.iterator(); it.hasNext(); )
                {
                    Package p = it.next();
                    if (!p.mDirectlyPlanned && p.mTestBuildInstruction == 0 && p.mForcedRippleInstruction == 0)
                    {
                        p.mIsNotReleased = false;
                        if (p.mBuildTime <= 0)
                            p.mBuildTime = 90;
                        packageCollection.add(p);
                    }
                }

                }
                
                @Override
        public void queryWips(RippleEngine rippleEngine, PackageCollection packageCollection, int baseline) throws SQLException, Exception
        {
            //    Filter for the packages that are WIPs
            for (Iterator<Package> it = testPackageCollectionWip.iterator(); it.hasNext(); )
            {
                Package p = it.next();
                if (p.mDirectlyPlanned )
                {
                    p.mIsNotReleased = true;
                    p.mDirectlyPlanned = true;
                    p.mBuildReason = BuildReason.NewVersion;
                    if (p.mBuildTime <= 0)
                        p.mBuildTime = 100;
                    packageCollection.add(p);
                }
            }

        }
                
                @Override
        public void queryTest(RippleEngine rippleEngine, PackageCollection packageCollection, int baseline) throws SQLException, Exception
        {
                    //    Filter for the packages that are TEST builds
            for (Iterator<Package> it = testPackageCollection.iterator(); it.hasNext(); )
            {
                    Package p = it.next();
                if (p.mTestBuildInstruction != 0 )
                {
                    p.mIsNotReleased = true;
                    p.mDirectlyPlanned = false;
                    p.mBuildReason = BuildReason.Test;
                    packageCollection.add(p);
                }
            }
            
        }
                
                @Override
        public void queryRipples(RippleEngine rippleEngine, PackageCollection packageCollection, int baseline) throws SQLException, Exception
        {
                    //    Filter for the packages that are forced Ripples
            for (Iterator<Package> it = testPackageCollection.iterator(); it.hasNext(); )
            {               
                    Package p = it.next();
                if (p.mForcedRippleInstruction != 0)
                {
                    p.mIsNotReleased = true;
                    p.mDirectlyPlanned = false;
                    p.mBuildReason = BuildReason.Forced;
                    p.mBuildTime = 3;
                    packageCollection.add(p);
                } 
            }
        }
                
                @Override
                public void queryReleaseConfig(final String hostname) throws SQLException, Exception
                {
                    mReleaseConfigCollection.resetData();

                    if ( mConnectionString.compareTo("unit test spawn thread") == 0)
                    {
                        mLogger.info("queryReleaseConfig 3 unit test spawn thread");
                        // specifying a gbebuildfilter of unit test is designed to invoke a benign thread for unit test purposes
                        ReleaseConfig releaseConfig = new ReleaseConfig(1,1,'M', "DummyHost1","DummyTarget1", "DummyMachtype1", "Win32");
                        mReleaseConfigCollection.add(releaseConfig);
                        releaseConfig = new ReleaseConfig(2,2,'S', "DummyHost2","DummyTarget2", "DummyMachtype2", "Linux");
                        mReleaseConfigCollection.add(releaseConfig);
                    }
                }
                
                @Override 
                public boolean queryReleaseConfig(final int rtag_id, final int rcon_id,final String machine_hostname, final char daemon_mode,  final long threadStartTime) throws SQLException, Exception
                 {
                     boolean retVal = false;

                     if ( mConnectionString.compareTo("unit test exit") != 0 )
                     {
                         retVal = true;
                     }
                     return retVal;
                 }
                 
                @Override
                 public void queryRunLevel(final int rtag_id) throws SQLException, Exception
                 {
                     if ( mConnectionString.compareTo("unit test coordinate slave threads") == 0)
                     {

                         if ( mRunLevelCollection.size() == 0)
                         {
                             // first time not all slave threads are waiting
                             RunLevelData runLevel = new RunLevelData(1, BuildState.DB_WAITING, 'S',0);
                             mRunLevelCollection.add(runLevel);
                             runLevel = new RunLevelData(2, BuildState.DB_IDLE, 'S',0);
                             mRunLevelCollection.add(runLevel);
                         }
                         else
                         {
                             // subsequent times all slave threads are waiting
                             mRunLevelCollection.clear();
                             RunLevelData runLevel = new RunLevelData(1, BuildState.DB_WAITING, 'S',0);
                             mRunLevelCollection.add(runLevel);
                             runLevel = new RunLevelData(2, BuildState.DB_WAITING, 'S',0);
                             mRunLevelCollection.add(runLevel);
                         }
                     }
                 }
                 
                 public boolean queryRunLevelSchedule(Date resumeTime, boolean recover) throws SQLException, Exception
                 {
                     boolean retVal = true;

                     if ( mConnectionString.compareTo("unit test not allowed to proceed") == 0 )
                     {
                         // schedule a 100ms max wait
                         resumeTime.setTime( resumeTime.getTime() + 100 );
                         retVal = false;
                     }
                     return retVal;
                 }
                 
                 /** Build a single package collection
                     * It will be split up when requested by the classes under test 
                     * 
                     * @param packageCollection
                     */
                    private void initTestPackages(RippleEngine rippleEngine, PackageCollection packageCollection, String setName)
                    {
                        packageCollection.clear();

                        /* a highly unlikely set of packages
                         * planned info
                         * pv_id pkg_id pkg_name                     v_ext pkg_vcs_tag                            change_type
                         * 0     76     UncommonDependency           .tim  0.TIM.WIP \vob\UncommonDependency           P
                         * 1     1011   DependencyMissingFromRelease .tim  1.TIM.WIP \vob\DependencyMissingFromRelease M
                         * 2     34     CommonDependency             .tim  2.TIM.WIP \vob\CommonDependency             M
                         * 3     908    SolarisCentricProduct        .tim  3.TIM.WIP \vob\SolarisCentricProduct        N
                         * 4     6      GenericProduct               .tim  4.TIM.WIP \vob\GenericProduct               P
                         * 5     11     Product                      .tim  5.TIM.WIP \vob\Product                      M
                         * 6     113    UnfinishedProduct            .tim  6.TIM.WIP \vob\UnfinishedProduct            M
                         * 25    45     Banana                       .tim  B.TIM.WIP \vob\Banana                       M
                         */
                 Package p;
                        
                         if ( setName.compareTo("iteration1") == 0 )
                         {
                           p = new Package(76, 0, "UncommonDependency", "1.0.0000", ".tim", "UncommonDependency.tim", "CC::/vob/UncommonDependency::0.TIM.WIP", 'b', 'P');
                           //p.mDirectlyPlanned = true;
                           packageCollection.add(p);
                         }

                     p = new Package(1011, 1, "DependencyMissingFromRelease", "1.0.0000", ".tim", "DependencyMissingFromRelease.tim", "CC::/vob/DependencyMissingFromRelease::1.TIM.WIP", 'b', 'M');
                     //p.mDirectlyPlanned = true;
                     packageCollection.add(p);

                         
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0 )
                         {
                           p = new Package(34, 2, "CommonDependency", "1.0.0000", ".tim", "CommonDependency.tim", "CC::/vob/CommonDependency::2.TIM.WIP", 'b', 'M');
                           //p.mDirectlyPlanned = true;
                           packageCollection.add(p);
                         }
                         
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0 )
                         {
                           p = new Package(908, 3, "SolarisCentricProduct", "1.0.0000", ".tim", "SolarisCentricProduct.tim", "CC::/vob/SolarisCentricProduct::3.TIM.WIP", 'b', 'N');
                           //p.mDirectlyPlanned = true;
                           packageCollection.add(p);
                         }
                         
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0
                           || setName.compareTo("iteration4") == 0 )
                         {
                           p = new Package(6, 4, "GenericProduct", "1.0.0000", ".tim", "GenericProduct.tim", "CC::/vob/GenericProduct::4.TIM.WIP", 'b', 'P');
                           //p.mDirectlyPlanned = true;
                           packageCollection.add(p);
                         }
                         
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0
                           || setName.compareTo("iteration4") == 0
                           || setName.compareTo("iteration5") == 0 )
                         {
                           p = new Package(11, 5, "Product", "1.0.0000", ".tim", "Product.tim", "CC::/vob/Product::5.TIM.WIP", 'b', 'M');
                           //p.mDirectlyPlanned = true;
                           packageCollection.add(p);
                         }
                        
                         p = new Package(113, 6, "UnfinishedProduct", "1.0.0000", ".tim", "UnfinishedProduct.tim", "CC::/vob/UnfinishedProduct::6.TIM.WIP", 'b', 'M');
                         //p.mDirectlyPlanned = true;
                         packageCollection.add(p);
                         
                         if ( setName.compareTo("iteration1") == 0 )
                         {
                           p = new Package(45, 25, "Banana", "1.0.0000", ".tim", "Banana.tim", "CC::B.TIM.WIP/vob/Banana", 'b', 'M');
                           //p.mDirectlyPlanned = true;
                           packageCollection.add(p);
                         }
                         
                        /* planned dependencies
                         * pv_id pkg_name                     v_ext
                         * 1     NotInTheRelease              .cots
                         * 2     CotsWithFunnyVersion         .cots
                         * 2     UncommonDependency           .tim
                         * 3     CommonDependency             .tim
                         * 4     CommonDependency             .tim
                         * 5     UncommonDependency           .tim
                         * 25    Car                          .tim
                         */
                         p = findPackage(1, packageCollection);
                         p.addDependency("NotInTheRelease.cots", -1);
                         
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0 )
                         {
                           p = findPackage(2, packageCollection);
                           p.addDependency("CotsWithFunnyVersion.cots", 7);
                           p.addDependency("UncommonDependency.tim", 0);
                         }
                         
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0 )
                         {
                           p = findPackage(3, packageCollection);
                           p.addDependency("CommonDependency.tim", 2);
                         }
                         
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0
                           || setName.compareTo("iteration4") == 0 )
                         {
                           p = findPackage(4, packageCollection);
                           p.addDependency("CommonDependency.tim", 2);
                         }
                         
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0
                           || setName.compareTo("iteration4") == 0
                           || setName.compareTo("iteration5") == 0 )
                         {
                           p = findPackage(5, packageCollection);
                           p.addDependency("UncommonDependency.tim", 0);
                         }
                         
                         if ( setName.compareTo("iteration1") == 0 )
                         {
                           p = findPackage(25, packageCollection);
                           p.addDependency("Car.tim", 24);
                         }
                         
                         
                         
                        /* planned build info
                         * pv_id bm_name bsa_name
                         * 0     Linux   Java 1.6
                         * 1     Linux   Debug
                         * 2     Linux   Debug
                         * 2     Solaris Production
                         * 2     Win32   Production and Debug
                         * 3     Solaris Java 1.4
                         * 4     Generic Java 1.5
                         * 5     Linux   Java 1.6
                         * 5     Win32   Java 1.6
                         * 25    Linux   Java 1.6
                         */
                         if ( setName.compareTo("iteration1") == 0 )
                         {
                           p = findPackage(0, packageCollection);
                           BuildStandard bs = new BuildStandard(rippleEngine, "Linux", "Java 1.6");
                           p.mBuildStandardCollection.add(bs);
                         }
                         
                         p = findPackage(1, packageCollection);
                         BuildStandard bs = new BuildStandard(rippleEngine, "Linux", "Debug");
                         p.mBuildStandardCollection.add(bs);
                         
                         if ( setName.compareTo("iteration1") == 0 || setName.compareTo("iteration2") == 0 )
                         {
                           p = findPackage(2, packageCollection);
                           bs = new BuildStandard(rippleEngine, "Linux", "Debug");
                           p.mBuildStandardCollection.add(bs);
                           bs = new BuildStandard(rippleEngine, "Solaris","Production");
                           p.mBuildStandardCollection.add(bs);
                           bs = new BuildStandard(rippleEngine, "Win32", "Production and Debug");
                           p.mBuildStandardCollection.add(bs);
                         }
                         
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0 )
                         {
                           p = findPackage(3, packageCollection);
                           bs = new BuildStandard(rippleEngine, "Solaris", "Java 1.4");
                           p.mBuildStandardCollection.add(bs);
                         }
                         
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0
                           || setName.compareTo("iteration4") == 0 )
                         {
                           p = findPackage(4, packageCollection);
                           bs = new BuildStandard(rippleEngine, "Generic", "Java 1.5");
                           p.mBuildStandardCollection.add(bs);
                         }
                         
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0
                           || setName.compareTo("iteration4") == 0
                           || setName.compareTo("iteration5") == 0 )
                         {
                           p = findPackage(5, packageCollection);
                           bs = new BuildStandard(rippleEngine, "Linux", "Java 1.6");
                           p.mBuildStandardCollection.add(bs);
                           bs = new BuildStandard(rippleEngine, "Win32", "Java 1.6");
                           p.mBuildStandardCollection.add(bs);
                         }
                         
                         if ( setName.compareTo("iteration1") == 0 )
                         {
                           p = findPackage(25, packageCollection);
                           bs = new BuildStandard(rippleEngine, "Linux", "Java 1.6");
                           p.mBuildStandardCollection.add(bs);
                         }

                         /* planned unit test info
                         * pv_id test_type_name
                         * 2     Manual Test
                         * 2     Interactive Test
                         * 2     Integration Test
                         * 5     Autobuild UTF
                         */
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0
                           || setName.compareTo("iteration4") == 0
                           || setName.compareTo("iteration5") == 0 )
                         {
                           p = findPackage(5, packageCollection);
                           p.mHasAutomatedUnitTests = true;
                         }
                         
                        /* planned build failure info
                         * pv_id user_email
                         * 3     jimmyfishcake@vixtechnology.com
                         * 3     rayhaddock@vixtechnology.com
                         * 5     timbutdim@vixtechnology.com
                         */
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0 )
                         {
                           p = findPackage(3, packageCollection);
                           p.addEmail("jimmyfishcake@vixtechnology.com");
                           p.addEmail("rayhaddock@vixtechnology.com");
                         }
                         
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0
                           || setName.compareTo("iteration4") == 0
                           || setName.compareTo("iteration5") == 0 )
                         {
                           p = findPackage(5, packageCollection);
                           p.addEmail("timbutdim@vixtechnology.com");
                         }
                         
                        /* planned advisory ripple info
                         * pv_id
                         * 0
                         */
                         if ( setName.compareTo("iteration1") == 0 )
                         {
                           p = findPackage(0, packageCollection);
                           p.mAdvisoryRipple = true;
                         }
                         
                        /* released info
                         * pv_id pkg_id pkg_name                     pkg_version      v_ext pkg_vcs_tag                                                    ripple_field
                         * 7     8      CotsWithFunnyVersion         hoopla2_x.cots   .cots CotsWithFunnyVersion_hoopla2_x.cots \vob\CotsWithFunnyVersion
                         * 8     17     NotInAnyWayReproducible      1.0.0.tim        .tim  NA                                  NA
                         * 9     34     CommonDependency             1.0.0000.tim     .tim  CommonDependency_1.0.0000.tim       \vob\CommonDependency
                         * 10    908    SolarisCentricProduct        1.0.0000.tim     .tim  SolarisCentricProduct_1.0.0000.tim  \vob\SolarisCentricProduct m
                         * 11    16     LinuxCentricProduct          1.0.0000.tim     .tim  LinuxCentricProduct_1.0.0000.tim    \vob\LinuxCentricProduct
                         * 12    312    Win32CentricProduct          1.0.0000.tim     .tim  Win32CentricProduct_1.0.0000.tim    \vob\Win32CentricProduct
                         * 13    6      GenericProduct               1.0.0000.tim     .tim  GenericProduct_1.0.0000.tim         \vob\ToBeMovedFromHere     M
                         * 14    81     AdvisoryDependency           1.0.0000.tim     .tim  AdvisoryDependency_1.0.0000.tim     \vob\AdvisoryDependency
                         * 15    1      MergedProduct                1.0.0000.tim     .tim  MergedProduct_1.0.0000.tim          \vob\MergedProduct         m
                         * 22    45     Banana                       1.1.0000.tim     .tim  Banana_1.1.0000.tim                 \vob\Banana
                         * 23    18     Aardvark                     1.1.1000.tim     .tim  Aardvark_1.1.1000.tim               \vob\Aardvark
                         * 24    227    Car                          1.0.10000.tim    .tim  Car_1.0.10000.tim                   \vob\Car
                         */
                         if ( setName.compareTo("iteration1") != 0 )
                         {
                           p = new Package(76, 0, "UncommonDependency", "0.0.1000.tim", ".tim", "UncommonDependency.tim", "CC::/vob/UncommonDependency::UncommonDependency_0.0.1000.tim", 'x');
                           Package plannedPackage = findPackage(p.mAlias, packageCollection);
                           
                           if ( plannedPackage == NULL_PACKAGE )
                           {
                             packageCollection.add(p);
                           }
                           else
                           {
                             plannedPackage.mVersion = "0.0.1000";
                           }
                         }

                         if ( setName.compareTo("iteration1") != 0 
                           && setName.compareTo("iteration2") != 0
                           && setName.compareTo("iteration3") != 0 )
                         {
                           p = new Package(908, 3, "SolarisCentricProduct", "1.1.0000.tim", ".tim", "SolarisCentricProduct.tim", "CC::/vob/SolarisCentricProduct::SolarisCentricProduct_1.1.0000.tim", 'm');
                           Package plannedPackage = findPackage(p.mAlias, packageCollection);
                           
                           if ( plannedPackage == NULL_PACKAGE )
                           {
                             packageCollection.add(p);
                           }
                           else
                           {
                             plannedPackage.mVersion = "1.1.0000";
                           }
                         }
                        
                         if ( setName.compareTo("iteration1") != 0 
                           && setName.compareTo("iteration2") != 0
                           && setName.compareTo("iteration3") != 0
                           && setName.compareTo("iteration4") != 0 )
                         {
                           p = new Package(6, 4, "GenericProduct", "1.0.1000.tim", ".tim", "GenericProduct.tim", "CC::/vob/GenericProduct::GenericProduct_1.0.1000.tim", 'M');
                           Package plannedPackage = findPackage(p.mAlias, packageCollection);
                           
                           if ( plannedPackage == NULL_PACKAGE )
                           {
                             packageCollection.add(p);
                           }
                           else
                           {
                             plannedPackage.mVersion = "1.0.1000";
                           }
                         }
                         
                         if ( setName.compareTo("iteration1") != 0 
                           && setName.compareTo("iteration2") != 0
                           && setName.compareTo("iteration3") != 0
                           && setName.compareTo("iteration4") != 0
                           && setName.compareTo("iteration5") != 0 )
                         {
                           p = new Package(11, 5, "Product", "1.0.0000.tim", ".tim", "Product.tim", "CC::/vob/Product::Product_1.0.0000.tim", 'M');
                           Package plannedPackage = findPackage(p.mAlias, packageCollection);
                           
                           if ( plannedPackage == NULL_PACKAGE )
                           {
                             packageCollection.add(p);
                           }
                           else
                           {
                             plannedPackage.mVersion = "1.0.0000";
                           }
                         }
                        
                         p = new Package(8, 7, "CotsWithFunnyVersion", "hoopla2_x.cots", ".cots", "CotsWithFunnyVersion.cots", "CC::/vob/CotsWithFunnyVersion::CotsWithFunnyVersion_hoopla2_x", 'x');
                         Package plannedPackage = findPackage(p.mAlias, packageCollection);
                         
                         if ( plannedPackage == NULL_PACKAGE )
                         {
                           packageCollection.add(p);
                         }
                         else
                         {
                           plannedPackage.mVersion = "hoopla2_x";
                         }
                         
                         p = new Package(17, 8, "NotInAnyWayReproducible", "1.0.0.tim", ".tim", "NotInAnyWayReproducible.tim", "CC::NA::NA", 'x');
                         plannedPackage = findPackage(p.mAlias, packageCollection);
                        
                         if ( plannedPackage == NULL_PACKAGE )
                         {
                           packageCollection.add(p);
                         }
                         else
                         {
                           plannedPackage.mVersion = "1.0.0";
                         }

                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0 )
                         {
                           p = new Package(908, 10, "SolarisCentricProduct", "1.0.0000.tim", ".tim", "SolarisCentricProduct.tim", "CC::/vob/SolarisCentricProduct::SolarisCentricProduct_1.0.0000.tim", 'm');
                           plannedPackage = findPackage(p.mAlias, packageCollection);
                          
                           if ( plannedPackage == NULL_PACKAGE )
                           {
                             packageCollection.add(p);
                           }
                           else
                           {
                             plannedPackage.mVersion = "1.0.0000";
                           }
                         }
                        
                         p = new Package(16, 11, "LinuxCentricProduct", "1.0.0000.tim", ".tim", "LinuxCentricProduct.tim", "CC::/vob/LinuxCentricProduct::LinuxCentricProduct_1.0.0000.tim", 'x');
                         plannedPackage = findPackage(p.mAlias, packageCollection);
                        
                         if ( plannedPackage == NULL_PACKAGE )
                         {
                           packageCollection.add(p);
                         }
                         else
                         {
                           plannedPackage.mVersion = "1.0.0000";
                         }
                        
                         p = new Package(312, 12, "Win32CentricProduct", "1.0.0000.tim", ".tim", "Win32CentricProduct.tim", "CC::/vob/Win32CentricProduct::Win32CentricProduct_1.0.0000.tim", 'x');
                         plannedPackage = findPackage(p.mAlias, packageCollection);
                        
                         if ( plannedPackage == NULL_PACKAGE )
                         {
                           packageCollection.add(p);
                         }
                         else
                         {
                           plannedPackage.mVersion = "1.0.0000";
                         }
                        
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0
                           || setName.compareTo("iteration4") == 0 )
                         {
                           p = new Package(6, 13, "GenericProduct", "1.0.0000.tim", ".tim", "GenericProduct.tim", "CC::/vob/ToBeMovedFromHere::GenericProduct_1.0.0000.tim", 'M');
                           plannedPackage = findPackage(p.mAlias, packageCollection);

                        
                         if ( plannedPackage == NULL_PACKAGE )
                         {
                           packageCollection.add(p);
                         }
                         else
                         {
                           plannedPackage.mVersion = "1.0.0000";
                         }
                 }      
                         
                         p = new Package(81, 14, "AdvisoryDependency", "1.0.0000.tim", ".tim", "AdvisoryDependency.tim", "CC::/vob/AdvisoryDependency::AdvisoryDependency_1.0.0000.tim", 'x');
                         plannedPackage = findPackage(p.mAlias, packageCollection);
                        
                         if ( plannedPackage == NULL_PACKAGE )
                         {
                           packageCollection.add(p);
                         }
                         else
                         {
                           plannedPackage.mVersion = "1.0.0000";
                         }
                         
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0
                           || setName.compareTo("iteration4") == 0
                           || setName.compareTo("iteration5") == 0
                           || setName.compareTo("iteration6") == 0 )
                         {
                           p = new Package(1, 15, "MergedProduct", "1.0.0000.tim", ".tim", "MergedProduct.tim", "CC::/vob/MergedProduct::MergedProduct_1.0.0000.tim", 'm');
                           p.mBuildTime = 9990;
                           plannedPackage = findPackage(p.mAlias, packageCollection);
                         }
                         else
                         {
                           p = new Package(1, 16, "MergedProduct", "1.0.0000.tim", ".tim", "MergedProduct.tim", "CC::/vob/MergedProduct::MergedProduct_1.0.0000.tim", 'm');
                           p.mBuildTime = 9990;
                           plannedPackage = findPackage(p.mAlias, packageCollection);
                         }
                        
                         if ( plannedPackage == NULL_PACKAGE )
                         {
                           packageCollection.add(p);
                         }
                         else
                         {
                           plannedPackage.mVersion = "1.0.0000";
                         }
                         
                         if ( setName.compareTo("iteration1") == 0 )
                         {
                           p = new Package(45, 22, "Banana", "1.1.0000.tim", ".tim", "Banana.tim", "CC::/vob/Banana::Banana_1.1.0000.tim", 'x');
                           plannedPackage = findPackage(p.mAlias, packageCollection);
                          
                           if ( plannedPackage == NULL_PACKAGE )
                           {
                             packageCollection.add(p);
                           }
                           else
                           {
                             plannedPackage.mVersion = "1.1.0000";
                           }
                  
                           p = new Package(18, 23, "Aardvark", "1.1.1000.tim", ".tim", "Aardvark.tim", "CC::/vob/Aardvark::Aardvark_1.1.1000.tim", 'x');
                           plannedPackage = findPackage(p.mAlias, packageCollection);
                          
                           if ( plannedPackage == NULL_PACKAGE )
                           {
                             packageCollection.add(p);
                           }
                           else
                           {
                             plannedPackage.mVersion = "1.1.1000";
                           }
                           
                           p = new Package(227, 24, "Car", "1.0.10000.tim", ".tim", "Car.tim", "CC::/vob/Car::Car_1.0.10000.tim", 'x');
                           plannedPackage = findPackage(p.mAlias, packageCollection);
                          
                           if ( plannedPackage == NULL_PACKAGE )
                           {
                             packageCollection.add(p);
                           }
                           else
                           {
                             plannedPackage.mVersion = "1.0.10000";
                           }
                         }

                         if ( setName.compareTo("iteration1") != 0 
                           && setName.compareTo("iteration2") != 0 )
                         {
                           p = new Package(34, 2, "CommonDependency", "2.0.0000.tim", ".tim", "CommonDependency.tim", "CC::/vob/CommonDependency::CommonDependency_2.0.0000.tim", 'x');
                           plannedPackage = findPackage(p.mAlias, packageCollection);
                           
                           if ( plannedPackage == NULL_PACKAGE )
                           {
                             packageCollection.add(p);
                           }
                           else
                           {
                             plannedPackage.mVersion = "2.0.0000";
                           }
                         }           
                         
                         if ( setName.compareTo("iteration1") == 0 || setName.compareTo("iteration2") == 0 )
                         {
                             p = new Package(34, 9, "CommonDependency", "1.0.0000.tim", ".tim", "CommonDependency.tim", "CC::/vob/CommonDependency::CommonDependency_1.0.0000.tim", 'x');
                             plannedPackage = findPackage(p.mAlias, packageCollection);

                             if ( plannedPackage == NULL_PACKAGE )
                             {
                                 packageCollection.add(p);
                             }
                             else
                             {
                                 plannedPackage.mVersion = "1.0.0000";
                             }
                         }
                         
                         /* released dependencies
                         * pv_id dpv_id pkg_name                     v_ext
                         * 8     9      CommonDependency             .tim
                         * 9     7      CotsWithFunnyVersion         .cots
                         * 10    9      CommonDependency             .tim
                         * 11    44     AdvisoryDependency           .tim
                         * 13    9      CommonDependency             .tim
                         * 15    99     CommonDependency             .tim
                         * 23    22     Banana                       .tim
                         * 24    23     Aardvark                     .tim
                         */
                         if ( setName.compareTo("iteration1") != 0 
                           && setName.compareTo("iteration2") != 0 )
                         {
                           p = findPackage(2, packageCollection);
                           p.addDependency("CotsWithFunnyVersion.cots",7);
                           p.addDependency("UncommonDependency.tim",0);
                         }
                         
                         if ( setName.compareTo("iteration1") != 0 
                           && setName.compareTo("iteration2") != 0
                           && setName.compareTo("iteration3") != 0 )
                         {
                           p = findPackage(3, packageCollection);
                           p.addDependency("CommonDependency.tim",2);
                         }

                         if ( setName.compareTo("iteration1") != 0 
                           && setName.compareTo("iteration2") != 0
                           && setName.compareTo("iteration3") != 0
                           && setName.compareTo("iteration4") != 0 )
                         {
                           p = findPackage(4, packageCollection);
                           p.addDependency("CommonDependency.tim",2);
                         }
                         
                         if ( setName.compareTo("iteration1") != 0 
                           && setName.compareTo("iteration2") != 0
                           && setName.compareTo("iteration3") != 0
                           && setName.compareTo("iteration4") != 0
                           && setName.compareTo("iteration5") != 0 )
                         {
                           p = findPackage(5, packageCollection);
                           p.addDependency("UncommonDependency.tim",0);
                         }

                         p = findPackage(8, packageCollection);
                         p.addDependency("CommonDependency.tim",9);
                         
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0 )
                         {
                           p = findPackage(9, packageCollection);
                           p.addDependency("CotsWithFunnyVersion.cots",7);
                         }
                         
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0 )
                         {
                           p = findPackage(10, packageCollection);
                           p.addDependency("CommonDependency.tim",9);
                         }
                         
                         p = findPackage(11, packageCollection);
                         p.addDependency("AdvisoryDependency.tim",44);
                         
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0
                           || setName.compareTo("iteration4") == 0 )
                         {
                           p = findPackage(13, packageCollection);
                           p.addDependency("CommonDependency.tim",9);
                         }
                         
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0
                           || setName.compareTo("iteration4") == 0
                           || setName.compareTo("iteration5") == 0
                           || setName.compareTo("iteration6") == 0 )
                         {
                           p = findPackage(15, packageCollection);
                           p.addDependency("CommonDependency.tim",99); // PVID not in the release
                         }
                         else
                         {
                           p = findPackage(16, packageCollection);
                           p.addDependency("CommonDependency.tim",2);
                         }
                         
                         if ( setName.compareTo("iteration1") == 0 )
                         {
                           p = findPackage(23, packageCollection);
                           p.addDependency("Banana.tim", 22);
                  
                           p = findPackage(24, packageCollection);
                           p.addDependency("Aardvark.tim", 23);
                         }

                        /* released build info
                         * pv_id bm_name bsa_name
                         * 7     Solaris Debug
                         * 9     Linux   Debug
                         * 9     Solaris Debug
                         * 9     Win32   Production
                         * 10    Solaris Java 1.4
                         * 11    Linux   Production and Debug
                         * 12    Win32   Java 1.6
                         * 13    Generic Java 1.4
                         * 14    Linux   Debug
                         * 15    Linux   Debug
                         * 22    Linux   Java 1.6
                         * 23    Linux   Java 1.6
                         * 24    Linux   Java 1.6
                         */
                         if ( setName.compareTo("iteration1") != 0 )
                         {
                           p = findPackage(0, packageCollection);
                           bs = new BuildStandard(rippleEngine, "Linux", "Java 1.6");
                           p.mBuildStandardCollection.add(bs);
                         }
                         
                         if ( setName.compareTo("iteration1") != 0 
                           && setName.compareTo("iteration2") != 0 )
                         {
                           p = findPackage(2, packageCollection);
                           bs = new BuildStandard(rippleEngine, "Linux", "Debug");
                           p.mBuildStandardCollection.add(bs);
                           bs = new BuildStandard(rippleEngine, "Solaris", "Production");
                           p.mBuildStandardCollection.add(bs);
                           bs = new BuildStandard(rippleEngine, "Win32", "Production and Debug");
                           p.mBuildStandardCollection.add(bs);
                         }
                         
                         if ( setName.compareTo("iteration1") != 0 
                           && setName.compareTo("iteration2") != 0
                           && setName.compareTo("iteration3") != 0 )
                         {
                           p = findPackage(3, packageCollection);
                           bs = new BuildStandard(rippleEngine, "Solaris", "Java 1.4");
                           p.mBuildStandardCollection.add(bs);
                         }

                         if ( setName.compareTo("iteration1") != 0 
                           && setName.compareTo("iteration2") != 0
                           && setName.compareTo("iteration3") != 0
                           && setName.compareTo("iteration4") != 0 )
                         {
                           p = findPackage(4, packageCollection);
                           bs = new BuildStandard(rippleEngine, "Generic", "Java 1.5");
                           p.mBuildStandardCollection.add(bs);
                         }
                        
                         if ( setName.compareTo("iteration1") != 0 
                           && setName.compareTo("iteration2") != 0
                           && setName.compareTo("iteration3") != 0
                           && setName.compareTo("iteration4") != 0
                           && setName.compareTo("iteration5") != 0 )
                         {
                           p = findPackage(5, packageCollection);
                           bs = new BuildStandard(rippleEngine, "Linux", "Java 1.6");
                           p.mBuildStandardCollection.add(bs);
                           bs = new BuildStandard(rippleEngine, "Win32", "Java 1.6");
                           p.mBuildStandardCollection.add(bs);
                         }

                         p = findPackage(7, packageCollection);
                         bs = new BuildStandard(rippleEngine, "Solaris", "Debug");
                         p.mBuildStandardCollection.add(bs);
                         
                         if ( setName.compareTo("iteration1") == 0 || setName.compareTo("iteration2") == 0 )
                         {
                           p = findPackage(9, packageCollection);
                           bs = new BuildStandard(rippleEngine, "Linux", "Debug");
                           p.mBuildStandardCollection.add(bs);
                           bs = new BuildStandard(rippleEngine, "Solaris", "Debug");
                           p.mBuildStandardCollection.add(bs);
                           bs = new BuildStandard(rippleEngine, "Win32", "Production");
                           p.mBuildStandardCollection.add(bs);
                         }
                         
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0 )
                         {
                           p = findPackage(10, packageCollection);
                           bs = new BuildStandard(rippleEngine, "Solaris", "Java 1.4");
                           p.mBuildStandardCollection.add(bs);
                         }
                         
                         p = findPackage(11, packageCollection);
                         bs = new BuildStandard(rippleEngine, "Linux", "Production and Debug");
                         p.mBuildStandardCollection.add(bs);

                         p = findPackage(12, packageCollection);
                         bs = new BuildStandard(rippleEngine, "Win32", "Java 1.6");
                         p.mBuildStandardCollection.add(bs);

                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0
                           || setName.compareTo("iteration4") == 0 )
                         {
                           p = findPackage(13, packageCollection);
                           bs = new BuildStandard(rippleEngine, "Generic", "Java 1.4");
                           p.mBuildStandardCollection.add(bs);
                         }

                         p = findPackage(14, packageCollection);
                         bs = new BuildStandard(rippleEngine, "Linux", "Debug");
                         p.mBuildStandardCollection.add(bs);
                         
                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0
                           || setName.compareTo("iteration4") == 0
                           || setName.compareTo("iteration5") == 0
                           || setName.compareTo("iteration6") == 0 )
                         {
                           p = findPackage(15, packageCollection);
                           bs = new BuildStandard(rippleEngine, "Linux", "Debug");
                           p.mBuildStandardCollection.add(bs);
                         }
                         else
                         {
                           p = findPackage(16, packageCollection);
                           bs = new BuildStandard(rippleEngine, "Linux", "Debug");
                           p.mBuildStandardCollection.add(bs);
                         }        
                 
                         if ( setName.compareTo("iteration1") == 0 )
                         {
                           p = findPackage(22, packageCollection);
                           bs = new BuildStandard(rippleEngine, "Linux", "Java 1.6");
                           p.mBuildStandardCollection.add(bs);
                  
                           p = findPackage(23, packageCollection);
                           bs = new BuildStandard(rippleEngine, "Linux", "Java 1.6");
                           p.mBuildStandardCollection.add(bs);
                  
                           p = findPackage(24, packageCollection);
                           bs = new BuildStandard(rippleEngine, "Solaris", "Java 1.6");
                           p.mBuildStandardCollection.add(bs);
                         }

                         /* released package unit test info
                         * pv_id tt.test_type_name
                         * 9     Manual Test
                         * 9     Interactive Test
                         * 9     Integration Test
                         * 11    Autobuild UTF
                         */
                         if ( setName.compareTo("iteration1") != 0 
                           && setName.compareTo("iteration2") != 0
                           && setName.compareTo("iteration3") != 0
                           && setName.compareTo("iteration4") != 0
                           && setName.compareTo("iteration5") != 0 )
                         {
                           p = findPackage(5, packageCollection);
                           p.mHasAutomatedUnitTests = true;
                         }

                         p = findPackage(11, packageCollection);
                         p.mHasAutomatedUnitTests = true;
                         
                        /* released build failure email info
                         * pv_id user_email
                         * 10    jimmyfishcake@vixtechnology.com
                         */
                         if ( setName.compareTo("iteration1") != 0 
                           && setName.compareTo("iteration2") != 0
                           && setName.compareTo("iteration3") != 0 )
                         {
                           p = findPackage(3, packageCollection);
                           p.addEmail("jimmyfishcake@vixtechnology.com");
                           p.addEmail("rayhaddock@vixtechnology.com");
                         }

                         if ( setName.compareTo("iteration1") != 0 
                           && setName.compareTo("iteration2") != 0
                           && setName.compareTo("iteration3") != 0
                           && setName.compareTo("iteration4") != 0
                           && setName.compareTo("iteration5") != 0 )
                         {
                           p = findPackage(5, packageCollection);
                           p.addEmail("timbutdim@vixtechnology.com");
                         }

                         if ( setName.compareTo("iteration1") == 0 
                           || setName.compareTo("iteration2") == 0
                           || setName.compareTo("iteration3") == 0 )
                         {
                           p = findPackage(10, packageCollection);
                           p.addEmail("jimmyfishcake@vixtechnology.com");
                         }
                         
                        /* released advisory ripple info
                         * pv_id
                         * 14
                         */
                         if ( setName.compareTo("iteration1") != 0 )
                         {
                           p = findPackage(0, packageCollection);
                           p.mAdvisoryRipple = true;
                         }

                         p = findPackage(14, packageCollection);
                         p.mAdvisoryRipple = true;
                         
                         // Insert sequence for later sorting
                         Package.setSequence(packageCollection);
                
                    }
        }


    public DaemonBuildTestCase()
    {
        mLogger.debug("DaemonBuildTestCase");
    }

    /**
     * Test Case main line
     */
    public static void main(String[] args)
    {
        mLogger.debug("main");
        JUnitCore.main("com.erggroup.buildtool.utf.DaemonBuildTestCase");
    }

    /**
     * set up performed prior to any test method
     */
    @BeforeClass
    public static void TestCaseSetUp()
    {
        mLogger.debug("TestCaseSetUp");
    }

    /**
     * tear down performed after test methods
     */
    @AfterClass
    public static void TestCaseTearDown()
    {
        mLogger.debug("TestCaseTearDown");
    }

    /**
     * set up performed prior to each test method
     */
    @Before
    public void TestSetUp()
    {
        mLogger.debug("TestSetUp");
        System.setProperty("vix.utf.name", "DaemonBuildTestCase");
        Package.mGenericMachtype = "win32";
        Package.mGbeDpkg = ".";
    }

    /**
     * tear down performed after each test method
     */
    @After
    public void TestTearDown()
    {
        mLogger.debug("TestTearDown");
    }

    /**
     * test method designed primarily to test the sequence diagram spawn thread
     * also tests thread control out of necessity:
     * 1 constructs a BuildDaemon object, passing a connectionString of "unit test spawn thread"
     * this utilises the following unit test hooks in the codebase:
     * - BuildDaemon::BuildDaemon connectionString of "unit test spawn thread" exits while forever loop
     * - BuildDaemon constructor, isActive and cleanUp made public for unit test use
     * - ReleaseManager::queryReleaseConfig instantiates 2 ReleaseConfig objects
     * with rcon_id's of 1 and 2, daemon_modes of 'M' and 'S' respectively, and gbebuildfilters of
     * "unit test spawn thread"
     * - MasterThread::run gbebuildfilter of "unit test spawn thread" limits method to sleep in while forever loop
     * - SlaveThread::run gbebuildfilter of "unit test spawn thread" limits method to sleep in while forever loop
     * 2 checks the number of threads in the thread group is 3 (mainline thread + MasterThread + SlaveThread)
     * 3 checks isActive on the BuildDaemon object returns true when passed an rcon_id of 1
     * 4 checks isActive on the BuildDaemon object returns true when passed an rcon_id of 2
     * 5 checks isActive on the BuildDaemon object returns false when passed an rcon_id of 3
     * 6 calls cleanUp on the BuildDaemon object
     * 7 checks the number of threads in the thread group is 1 (mainline thread)
     * 8 checks isActive on the BuildDaemon object returns false when passed an rcon_id of 1
     * 9 checks isActive on the BuildDaemon object returns false when passed an rcon_id of 2
     * 10 checks isActive on the BuildDaemon object returns false when passed an rcon_id of 3
     */
    @Test
    public void TestSpawnThread()
    {
        mLogger.debug("TestSpawnThread");
        int tcount;
        releaseManager = new myReleaseManager("unit test spawn thread", "not used", "not used");
        BuildDaemon buildDaemon = new BuildDaemon(releaseManager);
        tcount = BuildThread.mThreadGroup.activeCount();
        System.out.println("TestSpawnThread. tCount:" + tcount);
        assertTrue(tcount == 2);
        assertTrue(buildDaemon.isActive(1));
        assertTrue(buildDaemon.isActive(2));
        assertFalse(buildDaemon.isActive(3));
        buildDaemon.cleanUp();
        tcount = BuildThread.mThreadGroup.activeCount();
        System.out.println("TestSpawnThread Cleanup. tCount:" + tcount);
        assertTrue(tcount == 0);
        assertFalse(buildDaemon.isActive(1));
        assertFalse(buildDaemon.isActive(2));
        assertFalse(buildDaemon.isActive(3));
    }

    /**
     * test method designed to test the sequence diagram coordinate slave thread:
     * 1 constructs a ReleaseManager object, passing a connectionString of "unit test coordinate slave threads"
     * 2 constructs a MasterThread object, passing a gbebuildfilter of "unit test coordinate slave threads"
     * this utilises the following unit test hooks in the codebase:
     * - MasterThread constructor made public for unit test use
     * - MasterThread::run gbebuildfilter of "unit test coordinate slave threads" limits method to the sequence diagram
     * interrupts the thread if, on one pass, at least one RunLevel object does not have a run level DB_WAITING
     * exits the while forever loop if, on one pass, all RunLevel objects have a run level DB_WAITING
     * - ReleaseManager::queryRunLevel connectionString of "unit test coordinate slave threads" instantiates 2 RunLevel
     * objects
     * initially with run levels of waiting and idle
     * subsequently with run levels both waiting
     * 3 calls run on the MasterThread object
     * 4 checks its thread has been interrupted
     */
    @Test
    public void TestCoordinateSlaveThreads()
    {
        mLogger.debug("TestCoordinateSlaveThreads");
        ReleaseManager releaseManager = new myReleaseManager("unit test coordinate slave threads", "not used", "not used");
        MasterThread masterThread = new MasterThread(1, 1, releaseManager ,"unit test coordinate slave threads");
        assertFalse(Thread.interrupted());
        masterThread.run();
        // interrupted checks and importantly clears the interrupted status of this thread for subsequent tests
        assertTrue(Thread.interrupted());
        assertFalse(Thread.interrupted());
    }

    /**
     * test method designed to test the sequence diagram generate build files
     * note does not test the RippleEngine:
     * 1 constructs a ReleaseManager object, passing a connectionString of "unit test generate build files"
     * 2 constructs a MasterThread object, passing a gbebuildfilter of "unit test generate build files"
     * this utilises the following unit test hooks in the codebase:
     * - MasterThread constructor made public for unit test use
     * - MasterThread::run gbebuildfilter of "unit test generate build files" limits method to the sequence diagram
     * exits the while forever loop
     * - ReleaseManager::queryReleaseConfig instantiates 2 ReleaseConfig objects
     * with rcon_id's of 1 and 2, daemon_modes of 'M' and 'S' respectively, and gbebuildfilters of
     * "unit test spawn thread"
     * - ReleaseManager::updateCurrentRunLevel utilises the public mPersistedRunLevelCollection
     * 3 calls run on the MasterThread object
     * 4 checks the first persisted run level is DB_ACTIVE
     * 5 checks the second persisted run level is DB_ACTIVE
     * 6 checks no further run levels were persisted
     */
    @Test
    public void TestGenerateBuildFiles()
    {
        mLogger.debug("TestGenerateBuildFiles");
        myReleaseManager releaseManager = new myReleaseManager("unit test generate build files", "not used", "not used");
        MasterThread masterThread = new MasterThread(1, 1, releaseManager, "unit test generate build files");
        masterThread.run();
        assertTrue(RunLevelData.isAt(BuildState.DB_ACTIVE, releaseManager.mPersistedRunLevelCollection.get(0)));
        assertTrue(RunLevelData.isAt(BuildState.DB_ACTIVE, releaseManager.mPersistedRunLevelCollection.get(1)));
        assertTrue( releaseManager.mPersistedRunLevelCollection.size() == 2);
    }

    /**
     * test method designed to test the sequence diagram consume build files
     * 1 constructs a ReleaseManager object, passing a connectionString of "unit test consume build files"
     * 2 constructs a SlaveThread object, passing a gbebuildfilter of "unit test consume build files"
     * this utilises the following unit test hooks in the codebase:
     * - SlaveThread constructor made public for unit test use
     * - SlaveThread::run gbebuildfilter of "unit test consume build files" limits method to the sequence diagram
     * interrupts the thread if, on one pass, the current build file string is empty
     * exits the while forever loop
     * - ReleaseManager::queryRunLevel
     * initially returns an empty current build file string
     * subsequently returns a "unit test build file content" current build file string
     * 3 calls run on the SlaveThread object
     */
     @Test
    public void TestConsumeBuildFiles()
    {
        mLogger.debug("TestConsumeBuildFiles");
        ReleaseManager releaseManager = new myReleaseManager("unit test consume build files", "not used", "not used");
        SlaveThread slaveThread = new SlaveThread(1, 1, releaseManager, "unit test consume build files");
        assertFalse(Thread.interrupted());
        slaveThread.run();
    }

    /**
     * test method designed to test the sequence diagram allowed to proceed
     * 1 constructs a ReleaseManager object, passing a connectionString of "unit test allowed to proceed"
     * 2 constructs a MasterThread object, passing a gbebuildfilter of "unit test allowed to proceed"
     * this utilises the following unit test hooks in the codebase:
     * - MasterThread constructor made public for unit test use
     * - MasterThread::run gbebuildfilter of "unit test allowed to proceed" limits method to the sequence diagram
     * exits the while forever loop
     * - ReleaseManager::queryReleaseConfig, queryRunLevelSchedule, queryDirectedRunLevel methods return true
     * - ReleaseManager::updateCurrentRunLevel utilises the public mPersistedRunLevelCollection
     * 3 calls run on the MasterThread object
     * 4 checks the first persisted run level is DB_IDLE
     * 5 checks the second persisted run level is DB_IDLE
     * 6 checks the third persisted run level is DB_WAITING
     * 7 checks no further run levels were persisted
     */
    @Test
    public void TestAllowedToProceed()
    {
        mLogger.debug("TestAllowedToProceed");
        myReleaseManager releaseManager = new myReleaseManager("unit test allowed to proceed", "not used", "not used");
        MasterThread masterThread = new MasterThread(1, 1, releaseManager, "unit test allowed to proceed");
        masterThread.run();
        
        assertTrue( RunLevelData.isAt(BuildState.DB_IDLE, releaseManager.mPersistedRunLevelCollection.get(0)));
        assertTrue( releaseManager.mPersistedRunLevelCollection.size() == 1);
    }

    /**
     * test method designed to test the sequence diagram not allowed to proceed
     * 1 constructs a ReleaseManager object, passing a connectionString of "unit test not allowed to proceed"
     * 2 constructs a MasterThread object, passing a gbebuildfilter of "unit test not allowed to proceed"
     * this utilises the following unit test hooks in the codebase:
     * - MasterThread constructor made public for unit test use
     * - MasterThread::run gbebuildfilter of "unit test not allowed to proceed" limits method to the sequence diagram
     *   exits the while forever loop
     * - ReleaseManager::queryReleaseConfig method returns true
     * - ReleaseManager::queryRunLevelSchedule method returns false
     * - ReleaseManager::updateCurrentRunLevel utilises the public mPersistedRunLevelCollection
     * 3 calls run on the MasterThread object
     * 4 checks the first persisted run level is DB_IDLE
     * 5 checks the second persisted run level is DB_IDLE
     * 6 checks the third persisted run level is DB_PAUSED
     * 7 checks no further run levels were persisted
     * nb cannot check only one thread is running,
     * a Timer thread, though having run to completion, may still be "active"
     */
    @Test
    public void TestNotAllowedToProceed()
    {
        mLogger.debug("TestNotAllowedToProceed");
        myReleaseManager releaseManager = new myReleaseManager("unit test not allowed to proceed", "not used", "not used");
        MasterThread masterThread = new MasterThread(1, 1, releaseManager, "unit test not allowed to proceed");
        masterThread.run();
        
        assertTrue(RunLevelData.isAt(BuildState.DB_IDLE, releaseManager.mPersistedRunLevelCollection.get(0)));
        assertTrue(RunLevelData.isAt(BuildState.DB_PAUSED, releaseManager.mPersistedRunLevelCollection.get(1)));
        assertTrue( releaseManager.mPersistedRunLevelCollection.size() == 2);
    }

    /**
     * test method designed to test the sequence diagram exit
     * 1 constructs a ReleaseManager object, passing a connectionString of "unit test exit"
     * 2 constructs a MasterThread object, passing a gbebuildfilter of "unit test exit"
     * this utilises the following unit test hooks in the codebase:
     * - MasterThread constructor made public for unit test use
     * - MasterThread::run gbebuildfilter of "unit test exit" limits method to the sequence diagram
     * - ReleaseManager::queryReleaseConfig method returns false
     * - ReleaseManager::updateCurrentRunLevel utilises the public mPersistedRunLevelCollection
     * 3 calls run on the MasterThread object
     * 4 checks the first persisted run level is DB_IDLE
     * 5 checks no further run levels were persisted
     */
    @Test
    public void TestExit()
    {
        mLogger.debug("TestExit");
        myReleaseManager releaseManager = new myReleaseManager("unit test exit", "not used", "not used");
        MasterThread masterThread = new MasterThread(1, 1, releaseManager, "unit test exit");
        masterThread.run();
        
        assertTrue(RunLevelData.isAt(BuildState.DB_IDLE, releaseManager.mPersistedRunLevelCollection.get(0)));
        assertTrue( releaseManager.mPersistedRunLevelCollection.size() == 1);
    }

    /**
     * test method designed to test the sequence diagram check environment
     * 1 constructs a ReleaseManager object, passing a connectionString of "unit check environment"
     * 2 constructs a MasterThread object, passing a gbebuildfilter of "unit check environment"
     * this utilises the following unit test hooks in the codebase:
     * - MasterThread constructor made public for unit test use
     * - MasterThread::run gbebuildfilter of "unit test check environment" limits method to the sequence diagram
     * exits the while forever loop
     * - MasterThread::housekeep method does not call deleteDirectory
     * - MasterThread::hasSufficientDiskSpace initially returns false, then true
     * - ReleaseManager::updateCurrentRunLevel utilises the public mPersistedRunLevelCollection
     * 3 calls run on the MasterThread object
     * 4 checks the first persisted run level is DB_CANNOT_CONTINUE
     * 5 checks the next persisted run level is DB_ACTIVE
     * 6 checks no further run levels were persisted
     */
    @Test
    public void TestCheckEnvironment()
    {
        mLogger.debug("TestCheckEnvironment");
        myReleaseManager releaseManager = new myReleaseManager("unit test check environment", "not used", "not used");
        MasterThread masterThread = new MasterThread(1, 1, releaseManager, "unit test check environment");
        masterThread.run();
        assertTrue(RunLevelData.isAt(BuildState.DB_CANNOT_CONTINUE, releaseManager.mPersistedRunLevelCollection.get(0)));
        assertTrue(RunLevelData.isAt(BuildState.DB_ACTIVE, releaseManager.mPersistedRunLevelCollection.get(1)));
        assertTrue( releaseManager.mPersistedRunLevelCollection.size() == 2);
    }

    /**
     * I'm guessing as to the function of this test
     * Test for:
     *      Circular dependencies
     *      Build Dependency not in the release
     *      Package has no build environment
     *      Package not built for configured platforms
     *      A package is selected to be built
     * 
     */
    @Test
    public void TestPlanRelease_1()
    {
        mLogger.debug("TestPlanRelease - Iteration 1");
        System.out.println("TestPlanRelease - Iteration 1");
        releaseManager = new myReleaseManager("iteration1", "not used", "not used");
        rippleEngine = new RippleEngine(releaseManager, 11111, true);
        
        try
        {
            rippleEngine.collectMetaData();
            
            //  Generate basic test set and then tweak for this test
            initTestPackages(releaseManager.mConnectionString);
            createWip(1000, "UncommonDependency.tim");
            createWip(1001, "DependencyMissingFromRelease.tim");
            createWip(1002, "CommonDependency.tim");
            createWip(1003, "SolarisCentricProduct.tim");
            createWip(1004, "GenericProduct.tim");
            createWip(1005, "Product.tim");
            createWip(1006, "UnfinishedProduct.tim");
            createWip(1007, "Banana.tim");
            
            rippleEngine.planRelease(false);
        }
        catch (Exception e)
        {
        }

        boolean rv;
        BuildFile buildFile;

        buildFile = rippleEngine.getFirstBuildFileContent();
        assertTrue(buildFile != null);
        assertTrue(buildFile.state != BuildFileState.Dummy);
        assertTrue(buildFile.state != BuildFileState.Empty);

        rv = Utilities.checkBuildfile(buildFile.content, "daemon1");
        assertTrue(rv);
        
        buildFile = rippleEngine.getNextBuildFileContent();
        assertTrue(buildFile != null);
        assertTrue(buildFile.state == BuildFileState.Empty);
    }
    
    @Test
    public void TestPlanRelease_2()
    {
        //
        System.out.println("TestPlanRelease - Iteration 2");
        releaseManager = new myReleaseManager("iteration2", "not used", "not used");
        rippleEngine = new RippleEngine(releaseManager, 11111, true);

        // this is all the MasterThread does
        try
        {
            rippleEngine.collectMetaData();
            initTestPackages(releaseManager.mConnectionString);

            createWip(1001, "DependencyMissingFromRelease.tim");
            createWip(1002, "CommonDependency.tim");
            createWip(1003, "SolarisCentricProduct.tim");
            createWip(1004, "GenericProduct.tim");
            createWip(1005, "Product.tim");
            createWip(1006, "UnfinishedProduct.tim");
            createWip(1007, "Banana.tim");
            
            rippleEngine.planRelease(false);
        }
        catch (Exception e)
        {
        }

        boolean rv;
        BuildFile buildFile;
        
        buildFile = rippleEngine.getFirstBuildFileContent();
        assertTrue(buildFile != null);
        assertTrue(buildFile.state != BuildFileState.Dummy);
        assertTrue(buildFile.state != BuildFileState.Empty);

        rv = Utilities.checkBuildfile(buildFile.content, "daemon2");
        assertTrue(rv);

        buildFile = rippleEngine.getNextBuildFileContent();
        assertTrue(buildFile != null);
        assertTrue(buildFile.state == BuildFileState.Empty);
    }
    
    @Test
    public void TestPlanRelease_3()
    {
        //
        System.out.println("TestPlanRelease - Iteration 3");
        releaseManager = new myReleaseManager("iteration3", "not used", "not used");
        rippleEngine = new RippleEngine(releaseManager, 11111, true);
        
        // this is all the MasterThread does
        try
        {
            rippleEngine.collectMetaData();
            initTestPackages(releaseManager.mConnectionString);
            
            createWip(1001, "DependencyMissingFromRelease.tim");
            createWip(1003, "SolarisCentricProduct.tim");
            createWip(1004, "GenericProduct.tim");
            createWip(1005, "Product.tim");
            createWip(1006, "UnfinishedProduct.tim");

            rippleEngine.planRelease(false);
        }
        catch (Exception e)
        {
        }

        boolean rv;
        BuildFile buildFile;
        
        buildFile = rippleEngine.getFirstBuildFileContent();
        assertTrue(buildFile != null);
        assertTrue(buildFile.state != BuildFileState.Dummy);
        assertTrue(buildFile.state != BuildFileState.Empty);

        rv = Utilities.checkBuildfile(buildFile.content, "daemon3");
        assertTrue(rv);

        buildFile = rippleEngine.getNextBuildFileContent();
        assertTrue(buildFile != null);
        assertTrue(buildFile.state == BuildFileState.Empty);
    }
    
    @Test
    public void TestPlanRelease_4()
    {

        // 
        System.out.println("TestPlanRelease - Iteration 4");
        releaseManager = new myReleaseManager("iteration4", "not used", "not used");
        rippleEngine = new RippleEngine(releaseManager, 11111, true);

        // this is all the MasterThread does
        try
        {
            rippleEngine.collectMetaData();
            
            initTestPackages(releaseManager.mConnectionString);
            createWip(1001, "DependencyMissingFromRelease.tim");
            createWip(1004, "GenericProduct.tim");
            createWip(1005, "Product.tim");
            createWip(1006, "UnfinishedProduct.tim");
            
            rippleEngine.planRelease(false);
        }
        catch (Exception e)
        {
        }

        boolean rv;
        BuildFile buildFile;
        
        buildFile = rippleEngine.getFirstBuildFileContent();
        assertTrue(buildFile != null);
        assertTrue(buildFile.state != BuildFileState.Dummy);
        assertTrue(buildFile.state != BuildFileState.Empty);

        rv = Utilities.checkBuildfile(buildFile.content, "daemon4");
        assertTrue(rv)
        ;
        buildFile = rippleEngine.getNextBuildFileContent();
        assertTrue(buildFile != null);
        assertTrue(buildFile.state == BuildFileState.Empty);
    }
    
    @Test
    public void TestPlanRelease_5()
    {

        //
        System.out.println("TestPlanRelease - Iteration 5");
        releaseManager = new myReleaseManager("iteration5", "not used", "not used");
        rippleEngine = new RippleEngine(releaseManager, 11111, true);

        // this is all the MasterThread does
        try
        {
            rippleEngine.collectMetaData();
            
            initTestPackages(releaseManager.mConnectionString);
            createWip(1001, "DependencyMissingFromRelease.tim");
            createWip(1005, "Product.tim");
            createWip(1006, "UnfinishedProduct.tim");
            
            rippleEngine.planRelease(false);
        }
        catch (Exception e)
        {
        }

        boolean rv;
        BuildFile buildFile;
        
        buildFile = rippleEngine.getFirstBuildFileContent();
        assertTrue(buildFile != null);
        assertTrue(buildFile.state != BuildFileState.Dummy);
        assertTrue(buildFile.state != BuildFileState.Empty);

        rv = Utilities.checkBuildfile(buildFile.content, "daemon5");
        assertTrue(rv);
        
        buildFile = rippleEngine.getNextBuildFileContent();
        assertTrue(buildFile != null);
        assertTrue(buildFile.state == BuildFileState.Empty);
    }
    
    @Test
    public void TestPlanRelease_6()
    {

        //
        System.out.println("TestPlanRelease - Iteration 6");
        releaseManager = new myReleaseManager("iteration6", "not used", "not used");
        rippleEngine = new RippleEngine(releaseManager, 11111, true);

        // this is all the MasterThread does
        try
        {
            rippleEngine.collectMetaData();
            
            initTestPackages(releaseManager.mConnectionString);
            createWip(1001, "DependencyMissingFromRelease.tim");
            createWip(1006, "UnfinishedProduct.tim");
            
            rippleEngine.planRelease(false);
        }
        catch (Exception e)
        {
        }

        boolean rv;
        BuildFile buildFile;
        
        buildFile = rippleEngine.getFirstBuildFileContent();
        assertTrue(buildFile != null);
        assertTrue(buildFile.state != BuildFileState.Dummy);
        assertTrue(buildFile.state != BuildFileState.Empty);

        rv = Utilities.checkBuildfile(buildFile.content, "daemon6");
        assertTrue(rv);
        
        buildFile = rippleEngine.getNextBuildFileContent();
        assertTrue(buildFile != null);
        assertTrue(buildFile.state == BuildFileState.Empty);
    }
    
    @Test
    public void TestPlanRelease_7()
    {

        //
        System.out.println("TestPlanRelease - Iteration 7");
        releaseManager = new myReleaseManager("iteration7", "not used", "not used");
        rippleEngine = new RippleEngine(releaseManager, 11111, true);

        // this is all the MasterThread does
        try
        {
            rippleEngine.collectMetaData();
            
            initTestPackages(releaseManager.mConnectionString);
            createWip(1001, "DependencyMissingFromRelease.tim");
            createWip(1006, "UnfinishedProduct.tim");

            rippleEngine.planRelease(false);
        }
        catch (Exception e)
        {
        }
        
        boolean rv;
        BuildFile buildFile;
        
        buildFile = rippleEngine.getFirstBuildFileContent();
        assertTrue(buildFile != null);
        assertTrue(buildFile.state == BuildFileState.Dummy);

        rv = Utilities.checkBuildfile(buildFile.content, "daemon7");
        assertTrue(rv);
        
        buildFile = rippleEngine.getNextBuildFileContent();
        assertTrue(buildFile != null);
        assertTrue(buildFile.state == BuildFileState.Empty);
    }

}