Skip to content

Commit

Permalink
Implemented tests for JENKINS-26484
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsNielsen committed Feb 10, 2015
1 parent 59bc394 commit 93dd012
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 21 deletions.
3 changes: 3 additions & 0 deletions src/main/java/net/praqma/hudson/scm/CCUCMScm.java
Expand Up @@ -1197,6 +1197,9 @@ public List<String> getLoadModules() {
* @return the hLinkFeedFrom
*/
public String gethLinkFeedFrom() {
if(StringUtils.isBlank(hLinkFeedFrom)) {
return HLINK_DEFAULT;
}
return hLinkFeedFrom;
}

Expand Down
20 changes: 13 additions & 7 deletions src/test/java/net/praqma/hudson/test/CCUCMRule.java
Expand Up @@ -14,6 +14,7 @@
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;

Expand All @@ -26,7 +27,6 @@
import net.praqma.hudson.CCUCMBuildAction;
import net.praqma.hudson.scm.CCUCMScm;
import net.praqma.hudson.scm.ChangeLogEntryImpl;
import net.praqma.hudson.scm.pollingmode.BaselineCreationEnabled;
import net.praqma.hudson.scm.pollingmode.PollChildMode;
import net.praqma.hudson.scm.pollingmode.PollSelfMode;
import net.praqma.hudson.scm.pollingmode.PollSiblingMode;
Expand Down Expand Up @@ -235,7 +235,7 @@ public FreeStyleProject setupProjectWithASlave( String projectName, PollingMode
logger.info( "Setting up build for self polling, recommend:" + recommend + ", tag:" + tag + ", description:" + description );
System.out.println( "==== [Setting up ClearCase UCM project] ====" );
printInfo(projectName, mode.getPolling().getType().name(), component, stream, recommend, tag, description, mode.createBaselineEnabled(), forceDeliver, template, mode.getPromotionLevel() == null ? "ANY" : mode.getPromotionLevel().name());
FreeStyleProject project = createFreeStyleProject( "ccucm-project-" + projectName );
FreeStyleProject project = createFreeStyleProject( "ccucm-" + projectName );
DumbSlave slave = createOnlineSlave();
project.setAssignedLabel(slave.getSelfLabel());

Expand Down Expand Up @@ -320,7 +320,7 @@ public AbstractBuild build() throws ExecutionException, InterruptedException, IO
action = new EnableLoggerAction( outputDir );
}

Future<? extends Build<?, ?>> futureBuild = project.scheduleBuild2( 0, new Cause.UserCause(), action );
Future<? extends Build<?, ?>> futureBuild = project.scheduleBuild2( 0, new Cause.UserIdCause(), action );

AbstractBuild build = futureBuild.get();

Expand Down Expand Up @@ -351,7 +351,7 @@ public boolean perform( AbstractBuild<?, ?> build, Launcher launcher, BuildListe
}
}

public AbstractBuild<?, ?> buildProject( AbstractProject<?, ?> project, boolean fail ) throws IOException {
public AbstractBuild<?, ?> buildProject( AbstractProject<?, ?> project, boolean fail ) throws IOException, Exception {

EnableLoggerAction action = null;
if( outputDir != null ) {
Expand All @@ -363,9 +363,15 @@ public boolean perform( AbstractBuild<?, ?> build, Launcher launcher, BuildListe
try {
build = project.scheduleBuild2(0, new Cause.UserIdCause(), action ).get();
} catch( Exception e ) {
logger.info( "Build failed(" + (fail?"on purpose":"it should not?") + "): " + e.getMessage() );
if(!fail) {
logger.log(Level.SEVERE, "Build failed...it should not!", e);
throw e;
}
logger.info( "Build failed, and it should!");
}


waitUntilNoActivityUpTo(120000);

PrintStream out = new PrintStream( new File( outputDir, "jenkins." + getSafeName( project.getDisplayName() ) + "." + build.getNumber() + ".log" ) );

out.println( "Build : " + build );
Expand All @@ -381,7 +387,7 @@ public boolean perform( AbstractBuild<?, ?> build, Launcher launcher, BuildListe
out.println( "-------------------------------------------------" );
out.println();

return project.getLastBuild();
return build;
}

public void printList( List<String> list ) {
Expand Down
22 changes: 20 additions & 2 deletions src/test/java/net/praqma/hudson/test/SystemValidator.java
Expand Up @@ -240,11 +240,16 @@ public void checkBaselineTag() {
/* Validate created baseline */
private boolean checkCreatedBaseline = false;
private Boolean createdBaselineExists;
private Boolean createdBaselineIsRecommended;

public SystemValidator validateCreatedBaseline( boolean exists ) {
public SystemValidator validateCreatedBaseline( boolean exists) {
return validateCreatedBaseline(exists, null);
}

public SystemValidator validateCreatedBaseline( boolean exists, Boolean isRecommended ) {
this.checkCreatedBaseline = true;
this.createdBaselineExists = exists;
this.createdBaselineIsRecommended = isRecommended;
return this;
}

Expand All @@ -255,12 +260,25 @@ private void checkCreatedBaseline() throws ClearCaseException {

/* Validate null check */
if( createdBaselineExists != null ) {

System.out.println( "[assert] Created baseline must " + (createdBaselineExists?"not ": "") + "be null" );
if( createdBaselineExists ) {
assertNotNull( baseline );
} else {
assertNull( baseline );
}

System.out.println( String.format( "[assert] Created baseline %s must be recommended", baseline ) );
if(createdBaselineIsRecommended != null) {
if( createdBaselineIsRecommended ) {
List<Baseline> bls = getStream().load().getRecommendedBaselines();
assertThat( baseline, is(bls.get(0)) );
} else {
List<Baseline> bls = getStream().load().getRecommendedBaselines();
assertThat( bls.size(), is(1));
assertThat( baseline, not(bls.get(0)));
}
}
}

}
Expand Down
Expand Up @@ -56,13 +56,13 @@ public void testNoOptions() throws Exception {
}

@Test
@ClearCaseUniqueVobName(name = "recommended-child")
@ClearCaseUniqueVobName(name = "rec-child")
@TestDescription(title = "Child polling", text = "baseline available", configurations = {"Recommended = true"})
public void testRecommended() throws Exception {
System.out.println("2");
Baseline baseline = getNewBaseline();

AbstractBuild<?, ?> build = initiateBuild("recommended-" + ccenv.getUniqueName(), true, false, false, false);
AbstractBuild<?, ?> build = initiateBuild("rec-" + ccenv.getUniqueName(), true, false, false, false);

//Question: Why do we not validate that the BUILT baseline in promoted??
SystemValidator validator = new SystemValidator(build)
Expand All @@ -81,7 +81,8 @@ public void testDescription() throws Exception {
Baseline baseline = getNewBaseline();

AbstractBuild<?, ?> build = initiateBuild("description-" + ccenv.getUniqueName(), false, false, true, false);



SystemValidator validator = new SystemValidator(build)
.validateBuild(Result.SUCCESS)
.validateBuildView()
Expand Down
Expand Up @@ -12,7 +12,9 @@
import net.praqma.hudson.test.SystemValidator;

import net.praqma.clearcase.test.junit.ClearCaseRule;
import net.praqma.hudson.CCUCMBuildAction;
import net.praqma.hudson.scm.pollingmode.PollSiblingMode;
import net.praqma.util.test.junit.TestDescription;


public class BaselinesFound extends BaseTestClass {
Expand All @@ -26,6 +28,13 @@ public class BaselinesFound extends BaseTestClass {
mode.setUseHyperLinkForPolling(false);
return jenkins.initiateBuild( projectName, mode, "_System@" + ccenv.getPVob(), "two_int@" + ccenv.getPVob(), recommend, tag, description, fail);
}

public AbstractBuild<?, ?> initiateBuildUsingHyperLink( String projectName, boolean recommend, boolean tag, boolean description, boolean fail ) throws Exception {
PollSiblingMode mode = new PollSiblingMode("INTIAL");
mode.setCreateBaseline(true);
mode.setUseHyperLinkForPolling(true);
return jenkins.initiateBuild( projectName, mode, "_System@" + ccenv.getPVob(), "two_int@" + ccenv.getPVob(), recommend, tag, description, fail);
}

@Test
public void basicSibling() throws Exception {
Expand All @@ -49,21 +58,52 @@ public void basicSibling() throws Exception {

@Test
public void basicSiblingUsingHlink() throws Exception {

Stream one = ccenv.context.streams.get( "one_int" );
Stream two = ccenv.context.streams.get( "two_int" );


/* The baseline that should be built */
Baseline baseline = ccenv.context.baselines.get( "model-1" );

AbstractBuild<?, ?> build = initiateBuild( "no-options-hlink" + ccenv.getUniqueName(), false, false, false, false );
AbstractBuild<?, ?> build = initiateBuildUsingHyperLink( "no-options-hlink" + ccenv.getUniqueName(), false, false, false, false );

build.getAction(CCUCMBuildAction.class).getBaseline();
/* Validate */
SystemValidator validator = new SystemValidator( build ).
validateBuild( build.getResult() ).
validateBuiltBaseline( PromotionLevel.BUILT, baseline, false ).
validateCreatedBaseline( true );
validator.validate();
}

@Test
@TestDescription(title = "Poll sibling with hyperlink", text = "poll sibling with hyperlink, build success, promote baseline and recommend")
public void basicSiblingUsingHlinkRecommend() throws Exception {

/* The baseline that should be built */
Baseline baseline = ccenv.context.baselines.get( "model-1" );

AbstractBuild<?, ?> build = initiateBuildUsingHyperLink( "hlink-recommend" + ccenv.getUniqueName(), true, false, false, false );

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

@Test
@TestDescription(title = "Poll sibling", text = "poll sibling, build fails, reject baseline, no baseline created, no recommend")
public void basicSiblingUsingHlinkDoNotRecommend() throws Exception {

/* The baseline that should be built, and rejected because of failure */
Baseline baseline = ccenv.context.baselines.get( "model-1" );

AbstractBuild<?, ?> build = initiateBuildUsingHyperLink( "hlink-no-recommend" + ccenv.getUniqueName(), true, false, false, true );

/* Validate */
SystemValidator validator = new SystemValidator( build ).
validateBuild( build.getResult() ).
validateBuiltBaseline( PromotionLevel.REJECTED, baseline, false ).
validateCreatedBaseline( false, false );
validator.validate();
}
}
Expand Up @@ -8,7 +8,6 @@
import org.junit.Rule;
import org.junit.Test;

import java.io.IOException;

/**
* @author cwolfgang
Expand All @@ -19,7 +18,7 @@ public class Story11 extends BaseTestClass {
public ClearCaseRule ccenv = new ClearCaseRule( "Story11" );

@Test
public void test() throws IOException {
public void test() throws Exception {
/* First build to create a view */
Project project = new CCUCMRule.ProjectCreator( ccenv.getUniqueName(), "_System@" + ccenv.getPVob(), "one_int@" + ccenv.getPVob() )
.setType( CCUCMRule.ProjectCreator.Type.self )
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/setup-interproject.xml
Expand Up @@ -22,7 +22,7 @@
</baselines>
</stream>

<hlink name="AlternateDeliverTarget" pvob="${pvobname}" from="one_int" to="two_int" comment="No comment"/>
<hlink type="AlternateDeliverTarget" pvob="${pvobname}" from="one_int" to="two_int" comment="No comment"/>

<view tag="${name}_two_int" stgloc="-auto">
<stream name="two_int" pvob="${pvobname}" />
Expand Down

0 comments on commit 93dd012

Please sign in to comment.