Skip to content

Commit

Permalink
[JENKINS-14806] Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgarnet committed Aug 15, 2012
1 parent 5e0af3f commit b4282c3
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 26 deletions.
39 changes: 13 additions & 26 deletions src/main/java/net/praqma/hudson/scm/CCUCMScm.java
Expand Up @@ -91,11 +91,7 @@
/**
* is responsible for everything regarding Hudsons connection to ClearCase
* pre-build. This class defines all the files required by the user. The
* information can be entered on the config page.
*
* @author Troels Selch
* @author Margit Bennetzen
*
* information can be entered on the config page.
*/
public class CCUCMScm extends SCM {

Expand Down Expand Up @@ -912,29 +908,20 @@ public boolean accept( File file, String name ) {
Logger.addAppender( app );
this.rutil = new RemoteUtil( Logger.getLoggerSettings( app.getMinimumLevel() ), app );

logger.info( "Total number of states: " + ccucm.size() );
logger.debug( "THE STATES: " + ccucm.stringify() );
List<State> states = ccucm.getStates( jobName );
/* This is only interesting if there're any states */
logger.debug( "I got " + states.size() + " number of states for " + jobName );
if( states.size() > 0 ) {
for( State s : states ) {
try {
logger.debug( "Checking " + s.getJobNumber() );
Integer bnum = s.getJobNumber();
Object o = project.getBuildByNumber( bnum );
Build<?, ?> bld = (Build<?, ?>) o;
if( bld.hasntStartedYet() ) {
logger.debug( s.getJobNumber() + " is still waiting in queue or building, no need for polling" );
Logger.removeAppender( app );
return p;
}
} catch( Exception e ) {
logger.debug( "The state " + s.getJobNumber() + " threw " + e.getMessage() );
}
/* Interrupt polling if: */
if( this.getMultisitePolling() ) {
/* multisite polling and a build is in progress */
if( project.isBuilding() ) {
logger.debug( "A build already building - cancelling poll" );
return PollingResult.NO_CHANGES;
}
} else {
/* not multisite polling and a the project is already in queue */
if( project.isInQueue() ) {
logger.debug( "A build already in queue - cancelling poll" );
return PollingResult.NO_CHANGES;
}
}


boolean createdByThisPoll = false;
State state = null;
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/net/praqma/hudson/test/CCUCMRule.java
Expand Up @@ -82,6 +82,32 @@ public FreeStyleProject setupProject( String projectName, String type, String co
return project;
}

public CCUCMScm getCCUCM( String type, String component, String stream, String promotionLevel, boolean recommend, boolean tag, boolean description, boolean createBaseline, boolean forceDeliver, String template ) {
System.out.println( "==== [Setting up ClearCase UCM project] ====" );
System.out.println( " * Stream : " + stream );
System.out.println( " * Component : " + component );
System.out.println( " * Level : " + promotionLevel );
System.out.println( " * Polling : " + type );
System.out.println( " * Recommend : " + recommend );
System.out.println( " * Tag : " + tag );
System.out.println( " * Description : " + description );
System.out.println( " * Create baseline: " + createBaseline );
System.out.println( " * Template : " + template );
System.out.println( " * Force deliver : " + forceDeliver );
System.out.println( "============================================" );

CCUCMScm scm = new CCUCMScm( component, promotionLevel, "ALL", false, type, stream, "successful", createBaseline, template, forceDeliver, recommend, tag, description, "" );

return scm;
}

public FreeStyleProject createProject( String name, CCUCMScm ccucm ) throws IOException {
FreeStyleProject project = createFreeStyleProject( name );
project.setScm( ccucm );

return project;
}

public CCUCMScm getScm() {
return this.scm;
}
Expand Down
@@ -0,0 +1,56 @@
package net.praqma.hudson.test.integration.userstories;

import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.modules.junit4.PowerMockRunner;

import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import net.praqma.clearcase.ucm.entities.Baseline;
import net.praqma.clearcase.ucm.entities.Project.PromotionLevel;
import net.praqma.hudson.scm.CCUCMScm;
import net.praqma.hudson.test.CCUCMRule;
import net.praqma.hudson.test.SystemValidator;
import net.praqma.junit.DescriptionRule;
import net.praqma.junit.TestDescription;

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

@RunWith( PowerMockRunner.class )
public class JENKINS14806 {

@ClassRule
public static CCUCMRule jenkins = new CCUCMRule();

@Rule
public static ClearCaseRule ccenv = new ClearCaseRule( "JENKINS-14806", "setup-JENKINS-14806.xml" );

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

@Test
@TestDescription( title = "JENKINS-14806", text = "Multisite polling finds the same baseline times", configurations = { "ClearCase multisite = true" } )
public void jenkins13944() throws Exception {

CCUCMScm ccucm = jenkins.getCCUCM( "child", "_System@" + ccenv.getPVob(), "one_int@" + ccenv.getPVob(), "INITIAL", false, false, false, false, true, "[project]_[date]_[time]" );
CCUCMScm ccucmspy = Mockito.spy( ccucm );

/* Behaviour */
PowerMockito.doReturn( true ).when( ccucmspy ).getMultisitePolling();

FreeStyleProject project = jenkins.createProject( ccenv.getUniqueName(), ccucmspy );

/* First build to create a view */
AbstractBuild<?, ?> build = jenkins.buildProject( project, false );
Baseline baseline = ccenv.context.baselines.get( "model-1" );
new SystemValidator( build ).validateBuild( Result.SUCCESS ).validateBuiltBaseline( PromotionLevel.BUILT, baseline, false ).validate();
}


}
30 changes: 30 additions & 0 deletions src/test/resources/setup-JENKINS-14806.xml
@@ -0,0 +1,30 @@
<ccenvs xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="src/test/resources/setup-basic.xml"/>
<xi:include href="src/test/resources/setup-jenkins-project.xml"/>

<ccenv name="JENKINS 14806">

<context mvfs="m:\" linux="/view" view="${name}_one_dev" vob="${vobname}"/>

<activity comment="" headline="Adding initial files into components" in="one_int" name="initial_files" pvob="${pvobname}" />

<setactivity activity="initial_files" pvob="${pvobname}" />

<!-- Add element -->
<add file="Model/model.h" content="#1" />
<baseline name="model-1" label="full" comment="" component="_System" pvob="${pvobname}" />

<!-- Second -->
<checkout comment="" file="Model/model.h" />
<content file="Model/model.h" content="#2" />
<checkin file="Model/model.h" />
<baseline name="model-2" label="full" comment="" component="_System" pvob="${pvobname}" />

<!-- Third -->
<checkout comment="" file="Model/model.h" />
<content file="Model/model.h" content="#3" />
<checkin file="Model/model.h" />
<baseline name="model-3" label="full" comment="" component="_System" pvob="${pvobname}" />

</ccenv>
</ccenvs>

0 comments on commit b4282c3

Please sign in to comment.