Skip to content

Commit

Permalink
[JENKINS-14240] Test
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgarnet committed Jun 28, 2012
1 parent 685f3c3 commit 457c671
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 18 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Expand Up @@ -153,7 +153,8 @@
<configuration>
<includes>
<!-- <include>net/praqma/hudson/test/integration/child/*.java</include> -->
<include>net/praqma/hudson/test/integration/*/*.java</include>
<!-- <include>net/praqma/hudson/test/integration/*/*.java</include> -->
<include>net/praqma/hudson/test/integration/child/ActivityTest.java</include>
</includes>
</configuration>
</plugin>
Expand Down
43 changes: 26 additions & 17 deletions src/test/java/net/praqma/hudson/test/CCUCMRule.java
Expand Up @@ -6,9 +6,13 @@
import hudson.model.BuildListener;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.User;
import hudson.scm.ChangeLogSet;
import hudson.scm.ChangeLogSet.Entry;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.junit.ClassRule;
Expand All @@ -31,30 +35,15 @@
import net.praqma.clearcase.util.ExceptionUtils;
import net.praqma.hudson.CCUCMBuildAction;
import net.praqma.hudson.scm.CCUCMScm;
import net.praqma.hudson.scm.ChangeLogEntryImpl;
import net.praqma.util.debug.Logger;

import static org.junit.Assert.*;

public class CCUCMRule extends JenkinsRule {

private static Logger logger = Logger.getLogger();

/*
public String setupCC( String name, boolean installTag ) throws Exception {
//String uniqueTestVobName = "ccucm" + coolTest.uniqueTimeStamp;
String uniqueTestVobName = "ccucm_" + name + "_" + CoolTestCase.getUniqueTimestamp();
coolTest.variables.put( "vobname", uniqueTestVobName );
coolTest.variables.put( "pvobname", uniqueTestVobName + "_PVOB" );
coolTest.bootStrap();
if( installTag ) {
makeTagType();
}
return uniqueTestVobName;
}
*/


public FreeStyleProject setupProject( String projectName, String type, String component, String stream, boolean recommend, boolean tag, boolean description, boolean createBaseline ) throws Exception {

Expand Down Expand Up @@ -208,4 +197,24 @@ public void testCCUCMPolling( AbstractProject<?, ?> project ) {

assertTrue( polldir.exists() );
}

public List<User> getActivityUsers( AbstractBuild<?, ?> build ) {
ChangeLogSet<? extends Entry> ls = build.getChangeSet();

Object[] items = ls.getItems();

System.out.println( "ITEMS: " + items );

List<User> users = new ArrayList<User>();

for( Object item : items ) {
try {
users.add( ((ChangeLogEntryImpl)item).getAuthor() );
} catch( Exception e ) {

}
}

return users;
}
}
@@ -0,0 +1,87 @@
package net.praqma.hudson.test.integration.child;

import java.io.File;
import java.util.List;

import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import hudson.model.AbstractBuild;
import hudson.model.User;
import hudson.model.Result;
import net.praqma.clearcase.Environment;
import net.praqma.clearcase.exceptions.ClearCaseException;
import net.praqma.clearcase.exceptions.UCMEntityNotFoundException;
import net.praqma.clearcase.exceptions.UnableToCreateEntityException;
import net.praqma.clearcase.exceptions.UnableToGetEntityException;
import net.praqma.clearcase.exceptions.UnableToInitializeEntityException;
import net.praqma.clearcase.ucm.entities.Activity;
import net.praqma.clearcase.ucm.entities.Baseline;
import net.praqma.clearcase.ucm.entities.Stream;
import net.praqma.clearcase.ucm.entities.Baseline.LabelBehaviour;
import net.praqma.clearcase.ucm.entities.Project.PromotionLevel;
import net.praqma.clearcase.ucm.view.UCMView;
import net.praqma.clearcase.util.ExceptionUtils;
import net.praqma.hudson.test.CCUCMRule;
import net.praqma.util.debug.Logger;

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

import static org.junit.Assert.*;

public class ActivityTest {

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

@Rule
public static ClearCaseRule ccenv = new ClearCaseRule( "ccucm" );

private static Logger logger = Logger.getLogger();

public AbstractBuild<?, ?> initiateBuild( String projectName, boolean recommend, boolean tag, boolean description, boolean fail ) throws Exception {
return jenkins.initiateBuild( projectName, "child", "_System@" + ccenv.getPVob(), "one_int@" + ccenv.getPVob(), recommend, tag, description, fail, true );
}

@Test
@ClearCaseUniqueVobName( name = "activity-chglg" )
public void activityInChangelog() throws Exception {

Baseline baseline = getNewBaseline();

AbstractBuild<?, ?> build = initiateBuild( "activity-" + ccenv.getVobName(), false, false, false, false );

List<User> users = jenkins.getActivityUsers( build );

logger.debug( "Checking USERS" );
for( User user : users ) {
logger.debug( "Checking \"" + user.getDisplayName() + "\"" );
assertNotNull( user.getDisplayName() );
assertFalse( user.getDisplayName().matches( "^\\s*$" ) );
}
}

protected Baseline getNewBaseline() throws ClearCaseException {
/**/
String viewtag = ccenv.getVobName() + "_one_dev";
System.out.println( "VIEW: " + ccenv.context.views.get( viewtag ) );
File path = new File( ccenv.context.mvfs + "/" + ccenv.getVobName() + "_one_dev/" + ccenv.getVobName() );

System.out.println( "PATH: " + path );

Stream stream = Stream.get( "one_dev", ccenv.getPVob() );
Activity activity = Activity.create( "ccucm-activity", stream, ccenv.getPVob(), true, "ccucm activity", null, path );
UCMView.setActivity( activity, path, null, null );

try {
ccenv.addNewElement( ccenv.context.components.get( "Model" ), path, "test2.txt" );
} catch( ClearCaseException e ) {
ExceptionUtils.print( e, System.out, true );
}
return Baseline.create( "baseline-for-test", ccenv.context.components.get( "_System" ), path, LabelBehaviour.FULL, false );
}

}

0 comments on commit 457c671

Please sign in to comment.