Subversion Repositories DevTools

Rev

Rev 7047 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.erggroup.buildtool.utf;

import java.sql.SQLException;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.ArrayList;

import com.erggroup.buildtool.escrow.ESCROWBuild;
import com.erggroup.buildtool.ripple.BuildStandard;
import com.erggroup.buildtool.ripple.Package;
import com.erggroup.buildtool.ripple.ReleaseManager;
import com.erggroup.buildtool.ripple.RippleEngine;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.junit.Test;
import org.junit.runner.JUnitCore;

import static org.junit.Assert.*;

public class ESCROWBuildTestCase
{
    private static final Logger mLogger = LoggerFactory.getLogger(DaemonBuildTestCase.class);
    ReleaseManager              releaseManager = null;
    RippleEngine                rippleEngine   = null;

    /**
     * constructor
     */
    public ESCROWBuildTestCase()
    {
        mLogger.debug("ESCROWBuildTestCase");
        setUpEscrow();
    }

    /**
     * Test Case main line
     */
    public static void main(String[] args)
    {
        mLogger.debug("main");
        JUnitCore.main("com.erggroup.buildtool.utf.ESCROWBuildTestCase");
    }
    
    /** Subclass and override key methods so that the test can control
     *  the data being used
     */
    public class myReleaseManager extends ReleaseManagerUtf
        {
      
        public myReleaseManager(final String connectionString, final String username, final String password)
                {
                        super(connectionString, username, password);
                }

                public String queryBaselineName(int baseline) throws SQLException, Exception
                {
                        return "TIMBUKTU (TIM) > R7 7.9";
                }

                public void queryPackageVersions(RippleEngine rippleEngine, ArrayList<Package> packageCollection,
                                int baseline) throws SQLException, Exception
                {
                        /* prod_id pkg_name                pkg_version  v_ext pkg_vcs_tag
                 * 8       NotInAnyWayReproducible 1.0.0.tim    .tim  NA                                  NA
                 * 10      SolarisCentricProduct   1.0.0000.tim .tim  SolarisCentricProduct_1.0.0000.tim  \vob\SolarisCentricProduct
                 * 11      LinuxCentricProduct     1.0.0000.tim .tim  LinuxCentricProduct_1.0.0000.tim    \vob\LinuxCentricProduct
                 * 12      Win32CentricProduct     1.0.0000.tim .tim  Win32CentricProduct_1.0.0000.tim    \vob\Win32CentricProduct
                 * 13      GenericProduct          1.0.0000.tim .tim  GenericProduct_1.0.0000.tim         \vob\ToBeMovedFromHere
                 */
                 Package p = new Package(1, 8, "NotInAnyWayReproducible", "1.0.0.tim", ".tim", "NotInAnyWayReproducible.1.0.0.tim", "CC::NA::NA", 'x');
                 packageCollection.add(p);
                 p = new Package(2, 10, "SolarisCentricProduct", "1.0.0000.tim", ".tim", "SolarisCentricProduct.1.0.0000.tim", "CC::/vob/SolarisCentricProduct::SolarisCentricProduct_1.0.0000.tim", 'x');
                 packageCollection.add(p);
                 p = new Package(3, 11, "LinuxCentricProduct", "1.0.0000.tim", ".tim", "LinuxCentricProduct.1.0.0000.tim", "CC::/vob/LinuxCentricProduct::LinuxCentricProduct_1.0.0000.tim", 'x');
                 packageCollection.add(p);
                 p = new Package(4, 12, "Win32CentricProduct", "1.0.0000.tim", ".tim", "Win32CentricProduct.1.0.0000.tim", "CC::/vob/Win32CentricProduct::Win32CentricProduct_1.0.0000.tim", 'x');
                 packageCollection.add(p);
                 p = new Package(5, 13, "GenericProduct", "1.0.0000.tim", ".tim", "GenericProduct.1.0.0000.tim", "CC::/vob/ToBeMovedFromHere::GenericProduct_1.0.0000.tim", 'x');
                 packageCollection.add(p);

                /* the above products have the following dependencies which will be discovered in traverseDependencies
                 * pv_id   pkg_name, dpv.pkg_version, dpv.v_ext, dpv.pkg_vcs_tag
                 * 7     CotsWithFunnyVersion         hoopla2_x.cots   .cots CotsWithFunnyVersion_hoopla2_x.cots \vob\CotsWithFunnyVersion
                 * 9     CommonDependency             1.0.0000.tim     .tim  CommonDependency_1.0.0000.tim       \vob\CommonDependency
                 * 14    AdvisoryDependency           1.0.0000.tim     .tim  AdvisoryDependency_1.0.0000.tim     \vob\AdvisoryDependency
                 * the above packages have the following 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
                 */
                 
                   // use a ListIterator as it allows traverseDependencies to modify the packageCollection
                   for (ListIterator<Package> it = packageCollection.listIterator(); it.hasNext(); )
                   {
                     p = it.next();
                     traverseDependencies(packageCollection, p, false, it);
                   }

                   for (Iterator<Package> it = packageCollection.iterator(); it.hasNext(); )
                   {
                     p = it.next();
                     queryBuildInfo(rippleEngine, p);
                   }
                 
                        
                }
                
                  /**called only in escrow mode
                   * if checkCollection is true, checks the pv_id is in the packageCollection
                   * if checkCollection is false, or the pv_id is not in the collection
                   * 1 traverses the pv_id package dependencies
                   *   select dpv.pv_id, p.pkg_name, dpv.pkg_version, dpv.v_ext
                   *   from release_manager.package_versions pv, release_manager.package_dependencies pd, release_manager.package_versions dpv, release_manager.packages p
                   *   where pv.pv_id = <pv_id> and pd.pv_id=pv.pv_id and dpv.pv_id=pd.dpv_id and p.pkg_id=dpv.pkg_id
                   *   order by pv.pv_id;
                   * 2 for each dpv.pv_id in the resultset
                   *     call traverseDependencies( packageCollection, dpv.pv_id, true )
                   *     if the pv_id is not in the collection, add it
                   *   
                   */
                public void traverseDependencies(ArrayList<Package> packageCollection, Package pkg, 
                                                     boolean checkCollection, 
                                                     ListIterator<Package> listIterator) throws SQLException, Exception
                  {
                    mLogger.debug("traverseDependencies " + checkCollection);
                    boolean pvIdInCollection = false;
                    
                    if ( checkCollection )
                    {
                      for (Iterator<Package> it = packageCollection.iterator(); it.hasNext(); )
                      {
                        Package p = it.next();
                        
                        if ( p.mId == pkg.mId )
                        {
                          pvIdInCollection = true;
                          break;
                        }
                      }
                    }
                    
                    if ( !pvIdInCollection )
                    {
                      ArrayList<Package> resultset = new ArrayList<Package>();

                        
                         /* 7      CotsWithFunnyVersion
                          * 8      NotInAnyWayReproducible
                          * 9      CommonDependency 
                     * 10      SolarisCentricProduct
                     * 11      LinuxCentricProduct
                     * 13      GenericProduct
                     * 14      AdvisoryDependency         
                     */
                        if ( pkg.mId == 8 || pkg.mId == 10 || pkg.mId == 13 )
                        {
                          Package p = new Package(1, 9, "CommonDependency", "1.0.0000.tim", ".tim", "CommonDependency.1.0.0000.tim", "CC::/vob/CommonDependency::CommonDependency_1.0.0000.tim", 'x');
                          resultset.add(p);
                          pkg.mDependencyCollection.add(p.mAlias);
                        }
                        else if ( pkg.mId == 9 )
                        {
                          Package p = new Package(2, 7, "CotsWithFunnyVersion", "hoopla2_x.cots", ".cots", "CotsWithFunnyVersion.hoopla2_x.cots", "CC::/vob/CotsWithFunnyVersion::CotsWithFunnyVersion_hoopla2_x.cots", 'x');
                          resultset.add(p);
                          pkg.mDependencyCollection.add(p.mAlias);
                        }
                        else if ( pkg.mId == 11 )
                        {
                          Package p = new Package(3, 14, "AdvisoryDependency", "1.0.0000.tim", ".tim", "AdvisoryDependency.1.0.0000.tim", "CC::/vob/AdvisoryDependency::AdvisoryDependency_1.0.0000.tim", 'x');
                          resultset.add(p);
                          pkg.mDependencyCollection.add(p.mAlias);
                        }

                      
                      for (Iterator<Package> it = resultset.iterator(); it.hasNext(); )
                      {
                        Package r = it.next();
                        traverseDependencies(packageCollection, r, true, listIterator);
                        
                        pvIdInCollection = false;
                        
                        for (Iterator<Package> it2 = packageCollection.iterator(); it2.hasNext(); )
                        {
                          Package p = it2.next();
                          
                          if ( p.mId == r.mId )
                          {
                            pvIdInCollection = true;
                            break;
                          }
                        }
                        
                        if (!pvIdInCollection)
                        {
                          // insert the Package immediately before the next Package returned by next
                          // this does not change the next Package (if any) to be returned by next
                          listIterator.add(r);
                        }
                       
                      }
                    }
                  }

                /**called only in escrow mode to add build info to the Package
                   * select bm.bm_name, bsa.bsa_name
                   * from release_manager.package_versions pv, release_manager.package_build_info pbi, release_manager.build_machines bm, release_manager.build_standards_addendum bsa
                   * where pv.pv_id = <p.pv_id> and pbi.pv_id=pv.pv_id and bm.bm_id=pbi.bm_id and bsa.bsa_id=pbi.bsa_id
                   * order by pv.pv_id;
                   */
                  private void queryBuildInfo(RippleEngine rippleEngine, Package p) throws SQLException, Exception
                  {
                    mLogger.debug("queryBuildInfo");
                    
                      mLogger.info("queryBuildInfo !mUseDatabase");
                      
                      if (p.mId == 7)
                      {
                        BuildStandard bs = new BuildStandard(rippleEngine,"Solaris", "Debug");
                        p.mBuildStandardCollection.add(bs);
                      }
                      else if (p.mId == 9)
                      {
                        BuildStandard 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);
                      }
                      else if (p.mId == 10)
                      {
                        BuildStandard bs = new BuildStandard(rippleEngine, "Solaris", "Java 1.4");
                        p.mBuildStandardCollection.add(bs);
                      }
                      else if (p.mId == 11)
                      {
                        BuildStandard bs = new BuildStandard(rippleEngine, "Linux", "Production and Debug");
                        p.mBuildStandardCollection.add(bs);
                      }
                      else if (p.mId == 12)
                      {
                        BuildStandard bs = new BuildStandard(rippleEngine, "Win32", "Java 1.6");
                        p.mBuildStandardCollection.add(bs);
                      }
                      else if (p.mId == 13)
                      {
                        BuildStandard bs = new BuildStandard(rippleEngine, "Generic", "Java 1.4");
                        p.mBuildStandardCollection.add(bs);
                      }
                      else if (p.mId == 14)
                      {
                        BuildStandard bs = new BuildStandard(rippleEngine, "Linux", "Debug");
                        p.mBuildStandardCollection.add(bs);
                      }
                      
                    }
                   
                }
                

    /** Setup and Run the Escrow
     *  The tests will be the results of the escrow run
     */
    public void setUpEscrow()
    {
       mLogger.debug("TestESCROWBuild");
        
        
        //      Construct a Release Manager and Ripple Builder
        //      Run the Escrow Engine
        //
        releaseManager = new myReleaseManager("not used", "not used", "not used");
        releaseManager.mUseDatabase = false;
        rippleEngine = new RippleEngine(releaseManager, 99999, false);
        ESCROWBuild.generateEscrowFiles(rippleEngine, "build"); 
    }
    
    @Test
    public void TestEscrowBuildFiles()
    {
        //      Examine the results
        //
        boolean rv1 = Utilities.checkBuildfiles("build1.xml");
        boolean rv2 = Utilities.checkBuildfiles("build2.xml");
        boolean rv3 = Utilities.checkBuildfiles("build3.xml");

        //  Test assertions - after all files have been processed
        //
        assertTrue(rv1);
        assertTrue(rv2);
        assertTrue(rv3);
    }
    
    @Test
    public void TestEscrowDataFiles()
    {
        // Examine the other escrow files
        boolean rv4 = Utilities.checkBuildfiles("escrow_set_up");
        boolean rv5 = Utilities.checkBuildfiles("raw_data.csv");
        
        assertTrue(rv4);
        assertTrue(rv5);
    }

        
}