Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-26818] Reproduce in unittest
  • Loading branch information
olivergondza committed May 29, 2017
1 parent 9d1739e commit ea4569d
Show file tree
Hide file tree
Showing 3 changed files with 16,528 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/main/java/hudson/plugins/sectioned_view/SectionedView.java
Expand Up @@ -60,13 +60,18 @@ public Iterable<SectionedViewSection> getSections() {
return sections;
}

public void setSections(Collection<? extends SectionedViewSection> sections) {
this.sections.clear();
this.sections.addAll(sections);
}

@DataBoundConstructor
public SectionedView(String name) {
super(name);
initSections();
}

protected void initSections() {
private void initSections() {
if (sections != null) {
// already persisted
return;
Expand Down Expand Up @@ -138,12 +143,8 @@ public static Result getResult(Job job) {
* Load view-specific properties here.
*/
@Override
protected void submit(StaplerRequest req) throws ServletException,
FormException {
if (sections == null) {
sections = new DescribableList<SectionedViewSection, Descriptor<SectionedViewSection>>(
Saveable.NOOP);
}
protected void submit(StaplerRequest req) throws ServletException, FormException {
initSections();
try {
sections.rebuildHetero(req, req.getSubmittedForm(), Hudson
.getInstance().<SectionedViewSection, Descriptor<SectionedViewSection>>getDescriptorList(SectionedViewSection.class),
Expand Down
@@ -0,0 +1,54 @@
package hudson.plugins.sectioned_view;

import static org.junit.Assert.*;

import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import hudson.tasks.junit.JUnitResultArchiver;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestBuilder;

import java.io.IOException;
import java.util.Collections;
import java.util.regex.Pattern;

/**
* @author ogondza.
*/
public class TestResultViewSectionTest {

public @Rule JenkinsRule j = new JenkinsRule();

@Test
public void showIt() throws Exception {
FreeStyleProject p = j.createFreeStyleProject("test_project");
p.getPublishersList().add(new JUnitResultArchiver("*.xml", false, null, 1));
p.getBuildersList().add(new TestBuilder() {
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
build.getWorkspace().child("result.xml").copyFrom(TestResultViewSectionTest.class.getResourceAsStream("junit-report-1472.xml"));
return true;
}
});
j.assertBuildStatus(Result.UNSTABLE, p.scheduleBuild2(0).get());
j.assertBuildStatus(Result.UNSTABLE, p.scheduleBuild2(0).get());

SectionedView sectionedView = new SectionedView("sw");
j.jenkins.addView(sectionedView);
TestResultViewSection tests = new TestResultViewSection("tests view", SectionedViewSection.Width.FULL, SectionedViewSection.Positioning.CENTER);
tests.includeRegex = ".*";
tests.includePattern = Pattern.compile(".*");
sectionedView.setSections(Collections.singletonList(tests));

String out = j.createWebClient().getPage(sectionedView).getWebResponse().getContentAsString();

assertTrue(out, out.contains("tests view"));
assertTrue(out, out.contains("test_project"));
assertTrue(out, out.contains("1 failure"));
}
}

0 comments on commit ea4569d

Please sign in to comment.