Skip to content
Permalink
Browse files

[JENKINS-27206] - Fixing view, adding test.

  • Loading branch information
abayer committed Jan 13, 2016
1 parent c863b59 commit aec467480ca9b130b07b3ca41da5ec5f986ffbb4
14 pom.xml
@@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.580.1</version>
<version>1.596.1</version>
</parent>

<artifactId>claim</artifactId>
@@ -68,5 +68,17 @@
<version>1.13.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-aggregator</artifactId>
<version>1.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.modules</groupId>
<artifactId>sshd</artifactId>
<version>1.6</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
@@ -24,22 +24,22 @@
alt="${b.iconColor.description}"/>
</a>
</td>
<td id="claim.build.${b.project.name}">
<a href="${rootURL}/${b.project.url}">${b.project.fullName}</a>
<td id="claim.build.${b.parent.name}">
<a href="${rootURL}/${b.parent.url}">${b.parent.fullName}</a>
<st:nbsp/>
<a href="${rootURL}/${b.url}">#${b.number}</a>
</td>
<td id="claim.date.${b.project.name}" data="${b.timestampString2}">
<td id="claim.date.${b.parent.name}" data="${b.timestampString2}">
${b.timestampString}
</td>
<j:set var="firstBad" value="${it.getFirstFail(b)}"/>
<td id="claim.firstBad.${b.project.name}" data="${firstBad.timestampString2}">
<td id="claim.firstBad.${b.parent.name}" data="${firstBad.timestampString2}">
${firstBad.timestampString}
</td>
<td id="claim.claimant.${b.project.name}">
<td id="claim.claimant.${b.parent.name}">
${it.getClaimantText(b)}
</td>
<td id="claim.desc.${b.project.name}">
<td id="claim.desc.${b.parent.name}">
${b.description}
</td>
</tr>
@@ -0,0 +1,80 @@
package hudson.plugins.claim;

import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.model.FreeStyleProject;
import hudson.model.Job;
import hudson.model.ListView;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.FailureBuilder;
import org.jvnet.hudson.test.JenkinsRule;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

public class ClaimWorkflowTest {

@Rule
public JenkinsRule j = new JenkinsRule();

private static final String JOB_NAME = "myjob";
private WorkflowJob job;
private ListView view;

@Before
public void setUp() throws Exception {

java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.FINE);

job = createFailingJobWithName(JOB_NAME);

view = new ListView("DefaultView");
j.jenkins.addView(view);
j.jenkins.setPrimaryView(view);

}

private WorkflowJob createFailingJobWithName(String jobName) throws IOException,
InterruptedException, ExecutionException {
WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, jobName);
job.setDefinition(new CpsFlowDefinition(""
+ "node {\n"
+ " catchError {\n"
+ " error('Error')\n"
+ " }\n"
+ " step([$class: 'ClaimPublisher'])\n"
+ "}"));
job.scheduleBuild2(0).get();
return job;
}

@Test
public void job_is_visible_in_claim_report() throws Exception {
// Given:
view.add(job);
//j.interactiveBreak();
// When:
HtmlPage page = j.createWebClient().goTo("claims/");
// Then:
HtmlElement element = page.getElementById("claim.build." + JOB_NAME);
assertThat(element.isDisplayed(), is(true));
}

@Test
public void job_not_present_in_default_view_is_visible_in_claim_report() throws Exception {
// When:
HtmlPage page = j.createWebClient().goTo("claims/");
// Then:
HtmlElement element = page.getElementById("claim.build." + JOB_NAME);
assertThat(element.isDisplayed(), is(true));
}

}

0 comments on commit aec4674

Please sign in to comment.