Rev 7071 | Blame | Last modification | View Log | RSS feed
package com.erggroup.buildtool.utf;import java.sql.SQLException;import java.util.ArrayList;import java.util.Iterator;import com.erggroup.buildtool.ripple.BuildFile;import com.erggroup.buildtool.ripple.BuildFile.BuildFileState;import com.erggroup.buildtool.ripple.BuildStandard;import com.erggroup.buildtool.ripple.ReleaseManager;import com.erggroup.buildtool.ripple.Package;import com.erggroup.buildtool.ripple.RippleEngine;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 DaemonBuildTestCase2{private static final Logger mLogger = LoggerFactory.getLogger(DaemonBuildTestCase2.class);myReleaseManager releaseManager = null;RippleEngine rippleEngine = null;ArrayList<Package> testPackageCollection = new ArrayList<Package>();/*** Init the package set*/public void initTestPackages(String setName){/* A basic set of packages* All buildable*/Package p1 = createPackage(1, setName + "1");Package p2 = createPackage(2, setName + "2");Package p3 = createPackage(3, setName + "3");Package p4 = createPackage(4, setName + "4");Package p5 = createPackage(5, setName + "5");Package p6 = createPackage(6, setName + "6");Package p7 = createPackage(7, setName + "7");testPackageCollection.add(p1);testPackageCollection.add(p2);testPackageCollection.add(p3);testPackageCollection.add(p4);testPackageCollection.add(p5);testPackageCollection.add(p6);testPackageCollection.add(p7);p2.addDependency(p1);p3.addDependency(p1);p4.addDependency(p2).addDependency(p3);p5.addDependency(p2).addDependency(p4);p6.addDependency(p3).addDependency(p4);p7.addDependency(p5).addDependency(p6);}/** 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 = ReleaseManager.NULL_PACKAGE;for (Iterator<Package> it = testPackageCollection.iterator(); it.hasNext(); ){Package p = it.next();if ( p.mAlias.compareTo( alias ) == 0 ){wip = new Package(newPvId, p);wip.mDirectlyPlanned = true;testPackageCollection.add(wip);break;}}return wip;}/** Create a TEST for a package in the Release* This will mark it as test package* @param newPvId <0 - use PVID of the base package* @param alias*/private Package createTest(int newPvId, String alias) {Package wip = ReleaseManager.NULL_PACKAGE;for (Iterator<Package> it = testPackageCollection.iterator(); it.hasNext(); ){Package p = it.next();if ( p.mAlias.compareTo( alias ) == 0 ){if (newPvId < 0 )newPvId = p.mId;wip = new Package(newPvId, p);wip.mTestBuildInstruction = 1;testPackageCollection.add(wip);break;}}return wip;}/** Create a RippleRequest for a package in the Release* This will mark it as ripple request* @param alias*/private Package requestRipple(String alias) {Package wip = ReleaseManager.NULL_PACKAGE;for (Iterator<Package> it = testPackageCollection.iterator(); it.hasNext(); ){Package p = it.next();if ( p.mAlias.compareTo( alias ) == 0 ){wip = new Package(p.mId, p);wip.mForcedRippleInstruction = 1;testPackageCollection.add(wip);break;}}return wip;}/** Create a basic package**/private Package createPackage(int idx, String pName) {Package p = new Package(idx, idx * 100, pName, "1.0.0000", ".cr", pName + ".cr" , "CC::/vob/"+pName+".WIP", 'b', 'P');BuildStandard bs = new BuildStandard(rippleEngine, "Linux", "Java 1.6");p.mBuildStandardCollection.add(bs);p.mBuildTime = 100;return p;}/** Update build time for a package** @param alias* @param buildTime - Set a new build time*/private Package setBuildTime(String alias, int buildTime) {Package wip = ReleaseManager.NULL_PACKAGE;for (Iterator<Package> it = testPackageCollection.iterator(); it.hasNext(); ){Package p = it.next();if ( p.mAlias.compareTo( alias ) == 0 ){p.mBuildTime = buildTime;break;}}return wip;}/** Setup a package so that it will be detected as being rippled* Change its pvid so that consumers will see that they need to be rippled*/private Package ripplePackage(String alias) {Package wip = ReleaseManager.NULL_PACKAGE;for (Iterator<Package> it = testPackageCollection.iterator(); it.hasNext(); ){Package p = it.next();if ( p.mAlias.compareTo( alias ) == 0 ){p.mId += 10000;break;}}return wip;}/** 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);mLogger.error("Test {}", connectionString);}public myReleaseManager(){super();}@Overridepublic void queryPackageVersions(RippleEngine rippleEngine, ArrayList<Package> packageCollection, int baseline) throws SQLException, Exception{// Filter for the packages that are in the releasefor (Iterator<Package> it = testPackageCollection.iterator(); it.hasNext(); ){Package p = it.next();if (!p.mDirectlyPlanned && p.mTestBuildInstruction == 0 && p.mForcedRippleInstruction == 0){p.mIsNotReleased = false;packageCollection.add(p);}}}@Overridepublic void queryWips(RippleEngine rippleEngine, ArrayList<Package> packageCollection, int baseline) throws SQLException, Exception{// Filter for the packages that are WIPsfor (Iterator<Package> it = testPackageCollection.iterator(); it.hasNext(); ){Package p = it.next();if (p.mDirectlyPlanned ){p.mIsNotReleased = true;p.mDirectlyPlanned = true;p.mBuildReason = BuildReason.NewVersion;packageCollection.add(p);}}}@Overridepublic void queryTest(RippleEngine rippleEngine, ArrayList<Package> packageCollection, int baseline) throws SQLException, Exception{// Filter for the packages that are TEST buildsfor (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);}}}@Overridepublic void queryRipples(RippleEngine rippleEngine, ArrayList<Package> packageCollection, int baseline) throws SQLException, Exception{// Filter for the packages that are forced Ripplesfor (Iterator<Package> it = testPackageCollection.iterator(); it.hasNext(); ){Package p = it.next();if (p.mForcedRippleInstruction != 0){p.mIsNotReleased = true;p.mDirectlyPlanned = false;p.mBuildReason = BuildReason.Ripple;p.mBuildTime = 3;packageCollection.add(p);}}}}public DaemonBuildTestCase2(){mLogger.debug("DaemonBuildTestCase2");}/*** Test Case main line*/public static void main(String[] args){mLogger.debug("main");JUnitCore.main("com.erggroup.buildtool.utf.DaemonBuildTestCase2");}/*** set up performed prior to any test method*/@BeforeClasspublic static void TestCaseSetUp(){mLogger.debug("TestCaseSetUp");}/*** tear down performed after test methods*/@AfterClasspublic static void TestCaseTearDown(){mLogger.debug("TestCaseTearDown");}/*** set up performed prior to each test method*/@Beforepublic void TestSetUp(){mLogger.debug("TestSetUp");System.setProperty("vix.utf.name", "DaemonBuildTestCase2");Package.mGenericMachtype = "win32";Package.mGbeDpkg = ".";}/*** tear down performed after each test method*/@Afterpublic void TestTearDown(){mLogger.debug("TestTearDown");}/** Check the build file contents* @param expectedName - Name of the expected output file*/private void checkBuildFile(String expectedName) {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, expectedName);assertTrue(rv);}/*** Create a mesh of packages* Ripple the one at the bottom*/@Testpublic 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 testinitTestPackages("p");createWip(2000, "p1.cr");rippleEngine.planRelease(false);}catch (Exception e){}checkBuildFile("ripple1");}/*** Create a mesh of packages* Ripple the one not at the bottom*/@Testpublic void TestPlanRelease_2(){mLogger.debug("TestPlanRelease - Iteration 2");System.out.println("TestPlanRelease - Iteration 2");releaseManager = new myReleaseManager("iteration2", "not used", "not used");rippleEngine = new RippleEngine(releaseManager, 11111, true);try{rippleEngine.collectMetaData();// Generate basic test set and then tweak for this testinitTestPackages("p");createWip(2000, "p2.cr");rippleEngine.planRelease(false);}catch (Exception e){}checkBuildFile("ripple2");}/*** Create two meshes of packages* One with a longer build time ( < 20% longer)* Create a ripple in both*/@Testpublic void TestPlanRelease_3(){mLogger.debug("TestPlanRelease - Iteration 3");System.out.println("TestPlanRelease - Iteration 3");releaseManager = new myReleaseManager("iteration3", "not used", "not used");rippleEngine = new RippleEngine(releaseManager, 11111, true);try{rippleEngine.collectMetaData();// Generate basic test set and then tweak for this testinitTestPackages("p");initTestPackages("z");setBuildTime("z4.cr", 200);createWip(2000, "p1.cr");createWip(2000, "z1.cr");rippleEngine.planRelease(false);}catch (Exception e){}checkBuildFile("ripple3");}/*** Create two meshes of packages* One with a longer build time ( > 20% longer)* Create a ripple in both*/@Testpublic void TestPlanRelease_4(){mLogger.debug("TestPlanRelease - Iteration 4");System.out.println("TestPlanRelease - Iteration 4");releaseManager = new myReleaseManager("iteration4", "not used", "not used");rippleEngine = new RippleEngine(releaseManager, 11111, true);try{rippleEngine.collectMetaData();// Generate basic test set and then tweak for this testinitTestPackages("p");initTestPackages("z");setBuildTime("z4.cr", 500);createWip(2000, "p1.cr");createWip(2000, "z1.cr");rippleEngine.planRelease(false);}catch (Exception e){}checkBuildFile("ripple4");}/*** Create a mesh of packages* Create a test package* Create a WIP* Test should be built first*/@Testpublic void TestPlanRelease_5(){String tName = "ripple5";mLogger.debug("TestPlanRelease {}", tName);System.out.println("TestPlanRelease " + tName);releaseManager = new myReleaseManager(tName, "not used", "not used");rippleEngine = new RippleEngine(releaseManager, 11111, true);try{rippleEngine.collectMetaData();// Generate basic test set and then tweak for this testinitTestPackages("p");createWip (2000, "p1.cr");createTest(3333, "p5.cr");createTest(-1 , "p4.cr");rippleEngine.planRelease(false);}catch (Exception e){}checkBuildFile(tName);}/*** Create a mesh of packages* Request a ripple (daemon Instruction)*/@Testpublic void TestPlanRelease_6(){String tName = "ripple6";mLogger.debug("TestPlanRelease {}", tName);System.out.println("TestPlanRelease " + tName);releaseManager = new myReleaseManager(tName, "not used", "not used");rippleEngine = new RippleEngine(releaseManager, 11111, true);try{rippleEngine.collectMetaData();// Generate basic test set and then tweak for this testinitTestPackages("p");requestRipple("p5.cr");rippleEngine.planRelease(false);}catch (Exception e){}checkBuildFile(tName);}/*** Create a mesh of packages* Create a circular dependency* Create a WIP to 'fix' the circular dependency*/@Testpublic void TestPlanRelease_7(){String tName = "ripple7";mLogger.debug("TestPlanRelease {}", tName);System.out.println("TestPlanRelease " + tName);releaseManager = new myReleaseManager(tName, "not used", "not used");rippleEngine = new RippleEngine(releaseManager, 11111, true);try{rippleEngine.collectMetaData();// Generate basic test set and then tweak for this test/* A basic set of packages*/Package p1 = createPackage(1, "p1");Package p2 = createPackage(2, "p2");Package p3 = createPackage(3, "p3");Package p4 = createPackage(4, "p4");testPackageCollection.add(p1);testPackageCollection.add(p2);testPackageCollection.add(p3);testPackageCollection.add(p4);// Create circular dependencyp2.addDependency(p1);p3.addDependency(p2);p4.addDependency(p3);p1.addDependency(p4);Package p1fixed = createWip(400, "p1.cr");p1fixed.resetDependencies();testPackageCollection.add(p1fixed);rippleEngine.planRelease(false);}catch (Exception e){}checkBuildFile(tName);}/*** Create a mesh of packages* Create a dependencies* Create a WIP to 'create' a circular dependency** Should build WIP, then it will have a hissy fit on the next planning session*/@Testpublic void TestPlanRelease_8(){String tName = "ripple8";mLogger.debug("TestPlanRelease {}", tName);System.out.println("TestPlanRelease " + tName);releaseManager = new myReleaseManager(tName, "not used", "not used");rippleEngine = new RippleEngine(releaseManager, 11111, true);try{rippleEngine.collectMetaData();// Generate basic test set and then tweak for this test/* A basic set of packages*/Package p1 = createPackage(1, "p1");Package p2 = createPackage(2, "p2");Package p3 = createPackage(3, "p3");Package p4 = createPackage(4, "p4");testPackageCollection.add(p1);testPackageCollection.add(p2);testPackageCollection.add(p3);testPackageCollection.add(p4);// Create dependencyp2.addDependency(p1);p3.addDependency(p2);p4.addDependency(p3);Package p1Broken = createWip(400, "p1.cr");p1Broken.resetDependencies().addDependency(p4);rippleEngine.planRelease(false);}catch (Exception e){}checkBuildFile(tName);}/*** Create a WIP that will fail applyPV* Expect it to be rejected* Expect an email*/@Testpublic void TestPlanRelease_9(){String tName = "ripple9";mLogger.debug("TestPlanRelease {}", tName);System.out.println("TestPlanRelease " + tName);releaseManager = new myReleaseManager(tName, "not used", "not used");rippleEngine = new RippleEngine(releaseManager, 11111, true);try{rippleEngine.collectMetaData();// Generate basic test set and then tweak for this test/* A basic set of packages*/Package p1 = createPackage(1, "p1");Package p2 = createPackage(2, "p2");Package p3 = createPackage(3, "p3");Package p4 = createPackage(4, "p4");testPackageCollection.add(p1);testPackageCollection.add(p2);testPackageCollection.add(p3);testPackageCollection.add(p4);p2.addDependency(p1);Package p1Broken = createWip(400, "p1.cr");p1Broken.mVersion = "BadVersion";// Create a ripple, so we get some outputrequestRipple("p4.cr");rippleEngine.planRelease(false);}catch (Exception e){}checkBuildFile(tName);}/*** Create a mesh of packages* Mark bottom as being rippled*/@Testpublic void TestPlanRelease_99(){String tName = "ripple99";mLogger.debug("TestPlanRelease {}", tName);System.out.println("TestPlanRelease " + tName);releaseManager = new myReleaseManager(tName, "not used", "not used");rippleEngine = new RippleEngine(releaseManager, 11111, true);try{rippleEngine.collectMetaData();// Generate basic test set and then tweak for this testinitTestPackages("p");ripplePackage("p1.cr");rippleEngine.planRelease(false);}catch (Exception e){}checkBuildFile(tName);}}