Skip to content

Commit

Permalink
[JENKINS-27206] - Fixing view, adding test.
Browse files Browse the repository at this point in the history
  • Loading branch information
abayer committed Jan 13, 2016
1 parent c863b59 commit aec4674
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 7 deletions.
14 changes: 13 additions & 1 deletion pom.xml
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Up @@ -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>
Expand Down
80 changes: 80 additions & 0 deletions src/test/java/hudson/plugins/claim/ClaimWorkflowTest.java
@@ -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.