Skip to content

Commit

Permalink
[FIXED JENKINS-24006] Changes to healthScaleFactor were not actually …
Browse files Browse the repository at this point in the history
…being saved.

Ripping out the archaic manual form binding code and replacing with the modern simplified scheme.
  • Loading branch information
jglick committed Nov 6, 2014
1 parent f7e8379 commit e6416e3
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 34 deletions.
29 changes: 7 additions & 22 deletions src/main/java/hudson/tasks/junit/JUnitResultArchiver.java
Expand Up @@ -43,15 +43,14 @@
import hudson.tasks.junit.TestResultAction.Data;
import hudson.util.DescribableList;
import hudson.util.FormValidation;
import net.sf.json.JSONObject;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.types.FileSet;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
import jenkins.tasks.SimpleBuildStep;
Expand Down Expand Up @@ -208,13 +207,14 @@ public double getHealthScaleFactor() {
this.healthScaleFactor = Math.max(0.0, healthScaleFactor);
}

public DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> getTestDataPublishers() {
return testDataPublishers;
public List<? extends TestDataPublisher> getTestDataPublishers() {
return testDataPublishers == null ? Collections.<TestDataPublisher>emptyList() : testDataPublishers;
}

/** @since 1.2-beta-1 */
@DataBoundSetter public final void setTestDataPublishers(DescribableList<TestDataPublisher,Descriptor<TestDataPublisher>> testDataPublishers) {
this.testDataPublishers = testDataPublishers;
/** @since 1.2 */
@DataBoundSetter public final void setTestDataPublishers(List<? extends TestDataPublisher> testDataPublishers) {
this.testDataPublishers = new DescribableList<TestDataPublisher,Descriptor<TestDataPublisher>>(Saveable.NOOP);
this.testDataPublishers.addAll(testDataPublishers);
}

/**
Expand All @@ -237,21 +237,6 @@ public String getDisplayName() {
return Messages.JUnitResultArchiver_DisplayName();
}

@Override
public Publisher newInstance(StaplerRequest req, JSONObject formData)
throws hudson.model.Descriptor.FormException {
String testResults = formData.getString("testResults");
boolean keepLongStdio = formData.getBoolean("keepLongStdio");
DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> testDataPublishers = new DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>>(Saveable.NOOP);
try {
testDataPublishers.rebuild(req, formData, TestDataPublisher.all());
} catch (IOException e) {
throw new FormException(e,null);
}

return new JUnitResultArchiver(testResults, keepLongStdio, testDataPublishers);
}

/**
* Performs on-the-fly validation on the file mask wildcard.
*/
Expand Down
Expand Up @@ -31,7 +31,7 @@ THE SOFTWARE.
<f:textbox />
</f:entry>
<f:entry field="keepLongStdio" title="">
<f:checkbox name="keepLongStdio" checked="${instance.keepLongStdio}" title="${%Retain long standard output/error}"/>
<f:checkbox name="keepLongStdio" title="${%Retain long standard output/error}"/>
</f:entry>
<f:entry field="healthScaleFactor" title="${%Health report amplification factor}">
<f:number default="1.0" min="0" step="0.1" size="10"/>
Expand All @@ -40,17 +40,7 @@ THE SOFTWARE.
className="hudson.tasks.junit.TestDataPublisher" method="all" />
<j:if test="${testDataPublisherDescriptors.size() > 0}">
<f:entry title="Additional test report features" field="testDataPublishers">
<j:set var="testDataPublisherInstances" value="${instance.testDataPublishers}"/>
<table>
<j:forEach var="tdpd" items="${testDataPublisherDescriptors}">
<f:optionalBlock name="${tdpd.jsonSafeClassName}" help="${tdpd.helpFile}"
title="${tdpd.displayName}" checked="${testDataPublisherInstances.get(tdpd)!=null}">
<j:set var="descriptor" value="${tdpd}" />
<j:set var="instance" value="${testDataPublisherInstances.get(tdpd)}" />
<st:include from="${tdpd}" page="${tdpd.configPage}" optional="true" />
</f:optionalBlock>
</j:forEach>
</table>
<f:repeatableHeteroProperty field="testDataPublishers" hasHeader="true" oneEach="true"/>
</f:entry>
</j:if>
</j:jelly>
37 changes: 37 additions & 0 deletions src/test/java/hudson/tasks/junit/JUnitResultArchiverTest.java
Expand Up @@ -40,10 +40,14 @@
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.Descriptor;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.*;
import org.junit.Before;
Expand All @@ -53,6 +57,7 @@
import org.jvnet.hudson.test.JenkinsRule.WebClient;
import org.jvnet.hudson.test.RandomlyFails;
import org.jvnet.hudson.test.TestExtension;
import org.kohsuke.stapler.DataBoundConstructor;

public class JUnitResultArchiverTest {

Expand Down Expand Up @@ -206,4 +211,36 @@ public SimpleArchive(String pattern) {
}
}

@Test public void configRoundTrip() throws Exception {
JUnitResultArchiver a = new JUnitResultArchiver("TEST-*.xml");
a.setKeepLongStdio(true);
a.setTestDataPublishers(Collections.singletonList(new MockTestDataPublisher("testing")));
a.setHealthScaleFactor(0.77);
a = j.configRoundtrip(a);
assertEquals("TEST-*.xml", a.getTestResults());
assertTrue(a.isKeepLongStdio());
List<? extends TestDataPublisher> testDataPublishers = a.getTestDataPublishers();
assertEquals(1, testDataPublishers.size());
assertEquals(MockTestDataPublisher.class, testDataPublishers.get(0).getClass());
assertEquals("testing", ((MockTestDataPublisher) testDataPublishers.get(0)).getName());
assertEquals(0.77, a.getHealthScaleFactor(), 0.01);
}
public static class MockTestDataPublisher extends TestDataPublisher {
private final String name;
@DataBoundConstructor public MockTestDataPublisher(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override public TestResultAction.Data contributeTestData(Run<?,?> run, FilePath workspace, Launcher launcher, TaskListener listener, TestResult testResult) throws IOException, InterruptedException {
return null;
}
@TestExtension("configRoundTrip") public static class DescriptorImpl extends Descriptor<TestDataPublisher> {
@Override public String getDisplayName() {
return "MockTestDataPublisher";
}
}
}

}
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License
Copyright 2014 Jesse Glick.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:entry field="name" title="Name">
<f:textbox/>
</f:entry>
</j:jelly>

0 comments on commit e6416e3

Please sign in to comment.