Skip to content

Commit

Permalink
[JENKINS-17067] Split up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgarnet committed Mar 15, 2013
1 parent c3e085f commit d9e5211
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 237 deletions.
@@ -0,0 +1,50 @@
package net.praqma.hudson.test.integration.enslaved;

import hudson.model.Slave;
import hudson.model.labels.LabelAtom;
import net.praqma.clearcase.test.annotations.ClearCaseUniqueVobName;
import net.praqma.clearcase.test.junit.ClearCaseRule;
import net.praqma.clearcase.ucm.entities.Stream;
import net.praqma.hudson.test.BaseTestClass;
import net.praqma.hudson.test.integration.userstories.Story06Base;
import net.praqma.junit.DescriptionRule;
import net.praqma.junit.TestDescription;
import org.junit.Rule;
import org.junit.Test;

import java.util.logging.Logger;


public class Story06WithSlaves extends Story06Base {

private static Logger logger = Logger.getLogger( Story06WithSlaves.class.getName() );

@Test
@ClearCaseUniqueVobName( name = "dip4" )
@TestDescription( title = "Story 6", text = "New baseline on dev stream. Deliver in progress from another stream, different view", configurations = { "Force deliver = true", "Poll childs", "On slave" } )
public void story06_4() throws Exception {
Stream dev1 = ccenv.context.streams.get( "one_dev" );
Stream dev2 = ccenv.context.streams.get( "two_dev" );
Slave slave = jenkins.createSlave( new LabelAtom( "ClearCaseSlave" ) );
run( dev1, dev2, ccenv.getUniqueName() + "_one_dev", ccenv.getUniqueName() + "_two_dev", slave, false );
}

@Test
@ClearCaseUniqueVobName( name = "dip5" )
@TestDescription( title = "Story 6", text = "New baseline on dev stream. Deliver in progress from same stream, different view", configurations = { "Force deliver = true", "Poll childs", "On slave" } )
public void story06_5() throws Exception {
Stream dev1 = ccenv.context.streams.get( "one_dev" );
Slave slave = jenkins.createSlave( new LabelAtom( "ClearCaseSlave" ) );
run( dev1, dev1, ccenv.getUniqueName() + "_one_dev", ccenv.getUniqueName() + "_one_dev", slave, false );
}

@Test
@ClearCaseUniqueVobName( name = "dip6" )
@TestDescription( title = "Story 6", text = "New baseline on dev stream. Deliver in progress from previous build, different view", configurations = { "Force deliver = true", "Poll childs", "On slave" } )
public void story06_6() throws Exception {
Stream dev1 = ccenv.context.streams.get( "one_dev" );
Slave slave = jenkins.createSlave( new LabelAtom( "ClearCaseSlave" ) );
run( null, dev1, null, ccenv.getUniqueName() + "_one_dev", slave, true );
}

}
@@ -1,45 +1,18 @@
package net.praqma.hudson.test.integration.userstories;

import java.io.File;

import hudson.model.*;
import hudson.model.labels.LabelAtom;
import net.praqma.clearcase.test.annotations.ClearCaseUniqueVobName;
import net.praqma.hudson.notifier.CCUCMNotifier;
import net.praqma.hudson.scm.CCUCMScm;
import net.praqma.hudson.test.BaseTestClass;
import net.praqma.hudson.test.SystemValidator;
import org.junit.Rule;
import org.junit.Test;

import net.praqma.clearcase.Deliver;
import net.praqma.clearcase.ucm.entities.Baseline;
import net.praqma.clearcase.ucm.entities.Baseline.LabelBehaviour;
import net.praqma.clearcase.ucm.entities.Project.PromotionLevel;
import net.praqma.clearcase.ucm.entities.Stream;
import net.praqma.clearcase.util.ExceptionUtils;
import net.praqma.hudson.CCUCMBuildAction;
import net.praqma.hudson.test.CCUCMRule;
import net.praqma.junit.DescriptionRule;
import net.praqma.junit.TestDescription;
import net.praqma.util.debug.Logger;

import net.praqma.clearcase.exceptions.ClearCaseException;
import net.praqma.clearcase.test.junit.ClearCaseRule;

import static net.praqma.hudson.test.CCUCMRule.ProjectCreator.Type;
import java.util.logging.Logger;

public class Story06 extends BaseTestClass {

@Rule
public static ClearCaseRule ccenv = new ClearCaseRule( "ccucm-story06", "setup-story5.xml" );

@Rule
public static DescriptionRule desc = new DescriptionRule();
public class Story06 extends Story06Base {

private static Logger logger = Logger.getLogger();
private static Logger logger = Logger.getLogger( Story06.class.getName() );

//@Test
@Test
@ClearCaseUniqueVobName( name = "dip1" )
@TestDescription( title = "Story 6", text = "New baseline on dev stream. Deliver in progress from another stream, different view", configurations = { "Force deliver = true", "Poll childs" } )
public void story06_1() throws Exception {
Expand All @@ -64,122 +37,4 @@ public void story06_3() throws Exception {
run( null, dev1, null, ccenv.getUniqueName() + "_one_dev", null, true );
}

//@Test
@ClearCaseUniqueVobName( name = "dip4" )
@TestDescription( title = "Story 6", text = "New baseline on dev stream. Deliver in progress from another stream, different view", configurations = { "Force deliver = true", "Poll childs", "On slave" } )
public void story06_4() throws Exception {
Stream dev1 = ccenv.context.streams.get( "one_dev" );
Stream dev2 = ccenv.context.streams.get( "two_dev" );
Slave slave = jenkins.createSlave( new LabelAtom( "ClearCaseSlave" ) );
run( dev1, dev2, ccenv.getUniqueName() + "_one_dev", ccenv.getUniqueName() + "_two_dev", slave, false );
}

//@Test
@ClearCaseUniqueVobName( name = "dip5" )
@TestDescription( title = "Story 6", text = "New baseline on dev stream. Deliver in progress from same stream, different view", configurations = { "Force deliver = true", "Poll childs", "On slave" } )
public void story06_5() throws Exception {
Stream dev1 = ccenv.context.streams.get( "one_dev" );
Slave slave = jenkins.createSlave( new LabelAtom( "ClearCaseSlave" ) );
run( dev1, dev1, ccenv.getUniqueName() + "_one_dev", ccenv.getUniqueName() + "_one_dev", slave, false );
}

//@Test
@ClearCaseUniqueVobName( name = "dip6" )
@TestDescription( title = "Story 6", text = "New baseline on dev stream. Deliver in progress from previous build, different view", configurations = { "Force deliver = true", "Poll childs", "On slave" } )
public void story06_6() throws Exception {
Stream dev1 = ccenv.context.streams.get( "one_dev" );
Slave slave = jenkins.createSlave( new LabelAtom( "ClearCaseSlave" ) );
run( null, dev1, null, ccenv.getUniqueName() + "_one_dev", slave, true );
}

/**
*
* @param stream1 If set a new baseline will be delivered from this stream in a view
* @param streamToMakeAnotherBaseline The stream used to make the baseline found for the second build
* @param viewTag1 .... Using this view tag to create the first baseline
* @param viewTagToMakeAnotherBaseline .... Using this view tag to create the second baseline
* @param slave The slave executing the build, null if on master
* @param jenkinsWorkspace If true, the first build will not run the post build and therefore not complete the deliver
* @throws Exception
*/
public void run( Stream stream1, Stream streamToMakeAnotherBaseline, String viewTag1, String viewTagToMakeAnotherBaseline, Slave slave, boolean jenkinsWorkspace ) throws Exception {

/* First build to create a view */
Project project = new CCUCMRule.ProjectCreator( ccenv.getUniqueName(), "_System@" + ccenv.getPVob(), "one_int@" + ccenv.getPVob() )
.setType( Type.child )
.setForceDeliver( true )
.setCreateBaseline( true )
.getProject();

if( jenkinsWorkspace ) {
//project.getBuildersList().add( builder );
project.getPublishersList().remove( CCUCMNotifier.class );
( (CCUCMScm)project.getScm() ).setAddPostBuild( false );
}

AbstractBuild<?, ?> firstbuild = jenkins.buildProject( project, false, slave );

Stream target = null;
if( firstbuild != null ) {
CCUCMBuildAction preaction = jenkins.getBuildAction( firstbuild );
target = preaction.getStream();
} else {
target = Stream.get( ( (CCUCMScm)project.getScm() ).getStream() );
}

logger.debug( "Target stream is " + target );

if( !jenkinsWorkspace ) {
/* Set deliver one up and make sure the baseline is not found by polling */
Baseline bl1 = createNewContent( stream1, viewTag1, 1, PromotionLevel.BUILT );

/* Do not complete deliver */
Deliver deliver1 = new Deliver( stream1, target );
deliver1.deliver( true, false, true, false );
}

/* Setup dev 2 with new baseline */
Baseline bl2 = createNewContent( streamToMakeAnotherBaseline, viewTagToMakeAnotherBaseline, 2, null );

if( jenkinsWorkspace ) {
//project.getBuildersList().remove( builder.getClass() );
project.getPublishersList().add( new CCUCMNotifier() );

CCUCMBuildAction preaction = jenkins.getBuildAction( firstbuild );
preaction.getBaseline().setPromotionLevel( PromotionLevel.BUILT );
}

AbstractBuild<?, ?> build = jenkins.buildProject( firstbuild.getProject(), false, slave );

/* Validate */
SystemValidator validator = new SystemValidator( build );
validator.validateBuild( Result.SUCCESS ).validateBuiltBaseline( PromotionLevel.BUILT, bl2, false ).validateCreatedBaseline( true ).validate();
}

protected Baseline createNewContent( Stream stream, String viewtag, int num, PromotionLevel level ) throws ClearCaseException {
File path = null;
try {
path = ccenv.setDynamicActivity( stream, viewtag, "dip-" + stream.getShortname() );
} catch ( Exception e ) {
logger.warning( e );
path = ccenv.getDynamicPath( viewtag );
}

Baseline baseline = getNewBaseline( path, "dip" + num + ".txt", "dip" + num + "_" + stream.getShortname() );
if( level != null ) {
baseline.setPromotionLevel( level );
}

return baseline;
}

protected Baseline getNewBaseline( File path, String filename, String bname ) throws ClearCaseException {

try {
ccenv.addNewElement( ccenv.context.components.get( "Model" ), path, filename );
} catch( Exception e ) {
ExceptionUtils.print( e, System.out, true );
}
return Baseline.create( bname, ccenv.context.components.get( "_System" ), path, LabelBehaviour.FULL, false );
}
}
@@ -0,0 +1,131 @@
package net.praqma.hudson.test.integration.userstories;

import hudson.model.AbstractBuild;
import hudson.model.Project;
import hudson.model.Result;
import hudson.model.Slave;
import net.praqma.clearcase.Deliver;
import net.praqma.clearcase.exceptions.ClearCaseException;
import net.praqma.clearcase.test.junit.ClearCaseRule;
import net.praqma.clearcase.ucm.entities.Baseline;
import net.praqma.clearcase.ucm.entities.Baseline.LabelBehaviour;
import net.praqma.clearcase.ucm.entities.Project.PromotionLevel;
import net.praqma.clearcase.ucm.entities.Stream;
import net.praqma.clearcase.util.ExceptionUtils;
import net.praqma.hudson.CCUCMBuildAction;
import net.praqma.hudson.notifier.CCUCMNotifier;
import net.praqma.hudson.scm.CCUCMScm;
import net.praqma.hudson.test.BaseTestClass;
import net.praqma.hudson.test.CCUCMRule;
import net.praqma.hudson.test.SystemValidator;
import net.praqma.junit.DescriptionRule;
import org.junit.Rule;
import org.junit.Test;

import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;

import static net.praqma.hudson.test.CCUCMRule.ProjectCreator.Type;

public abstract class Story06Base extends BaseTestClass {

@Rule
public static ClearCaseRule ccenv = new ClearCaseRule( "ccucm-story06", "setup-story5.xml" );

@Rule
public static DescriptionRule desc = new DescriptionRule();

private static Logger logger = Logger.getLogger( Story06Base.class.getName() );

/**
*
* @param stream1 If set a new baseline will be delivered from this stream in a view
* @param streamToMakeAnotherBaseline The stream used to make the baseline found for the second build
* @param viewTag1 .... Using this view tag to create the first baseline
* @param viewTagToMakeAnotherBaseline .... Using this view tag to create the second baseline
* @param slave The slave executing the build, null if on master
* @param jenkinsWorkspace If true, the first build will not run the post build and therefore not complete the deliver
* @throws Exception
*/
public void run( Stream stream1, Stream streamToMakeAnotherBaseline, String viewTag1, String viewTagToMakeAnotherBaseline, Slave slave, boolean jenkinsWorkspace ) throws Exception {

/* First build to create a view */
Project project = new CCUCMRule.ProjectCreator( ccenv.getUniqueName(), "_System@" + ccenv.getPVob(), "one_int@" + ccenv.getPVob() )
.setType( Type.child )
.setForceDeliver( true )
.setCreateBaseline( true )
.getProject();

if( jenkinsWorkspace ) {
//project.getBuildersList().add( builder );
project.getPublishersList().remove( CCUCMNotifier.class );
( (CCUCMScm)project.getScm() ).setAddPostBuild( false );
}

AbstractBuild<?, ?> firstbuild = jenkins.buildProject( project, false, slave );

Stream target = null;
if( firstbuild != null ) {
CCUCMBuildAction preaction = jenkins.getBuildAction( firstbuild );
target = preaction.getStream();
} else {
target = Stream.get( ( (CCUCMScm)project.getScm() ).getStream() );
}

logger.fine( "Target stream is " + target );

if( !jenkinsWorkspace ) {
/* Set deliver one up and make sure the baseline is not found by polling */
Baseline bl1 = createNewContent( stream1, viewTag1, 1, PromotionLevel.BUILT );

/* Do not complete deliver */
Deliver deliver1 = new Deliver( stream1, target );
deliver1.deliver( true, false, true, false );
}

/* Setup dev 2 with new baseline */
Baseline bl2 = createNewContent( streamToMakeAnotherBaseline, viewTagToMakeAnotherBaseline, 2, null );

if( jenkinsWorkspace ) {
//project.getBuildersList().remove( builder.getClass() );
project.getPublishersList().add( new CCUCMNotifier() );

CCUCMBuildAction preaction = jenkins.getBuildAction( firstbuild );
preaction.getBaseline().setPromotionLevel( PromotionLevel.BUILT );
}

AbstractBuild<?, ?> build = jenkins.buildProject( firstbuild.getProject(), false, slave );

/* Validate */
SystemValidator validator = new SystemValidator( build );
validator.validateBuild( Result.SUCCESS ).validateBuiltBaseline( PromotionLevel.BUILT, bl2, false ).validateCreatedBaseline( true ).validate();
}

protected Baseline createNewContent( Stream stream, String viewtag, int num, PromotionLevel level ) throws ClearCaseException {
File path = null;
try {
path = ccenv.setDynamicActivity( stream, viewtag, "dip-" + stream.getShortname() );
} catch ( Exception e ) {
logger.log( Level.WARNING, "failed", e );
path = ccenv.getDynamicPath( viewtag );
}

Baseline baseline = getNewBaseline( path, "dip" + num + ".txt", "dip" + num + "_" + stream.getShortname() );
if( level != null ) {
baseline.setPromotionLevel( level );
}

return baseline;
}

protected Baseline getNewBaseline( File path, String filename, String bname ) throws ClearCaseException {

try {
ccenv.addNewElement( ccenv.context.components.get( "Model" ), path, filename );
} catch( Exception e ) {
ExceptionUtils.print( e, System.out, true );
}
return Baseline.create( bname, ccenv.context.components.get( "_System" ), path, LabelBehaviour.FULL, false );
}
}

0 comments on commit d9e5211

Please sign in to comment.