diff --git a/src/main/java/org/jenkinsci/plugins/xunit/AliasInitializer.java b/src/main/java/org/jenkinsci/plugins/xunit/AliasInitializer.java index 38aeeeb7..43e8181e 100644 --- a/src/main/java/org/jenkinsci/plugins/xunit/AliasInitializer.java +++ b/src/main/java/org/jenkinsci/plugins/xunit/AliasInitializer.java @@ -40,10 +40,10 @@ */ public class AliasInitializer { - @Initializer(before = InitMilestone.PLUGINS_STARTED) - public static void addAliases() { + @Initializer(before = InitMilestone.JOB_LOADED) + public static void init(Jenkins jenkins) { Items.XSTREAM.alias("xunit", XUnitPublisher.class); - DescriptorExtensionList> extensionList = Jenkins.getActiveInstance().getDescriptorList(TestType.class); + DescriptorExtensionList> extensionList = jenkins.getDescriptorList(TestType.class); for (Iterator> it = extensionList.iterator(); it.hasNext(); ) { Class classType = it.next().clazz; String className = getClassName(classType); diff --git a/src/main/java/org/jenkinsci/plugins/xunit/XUnitBuilder.java b/src/main/java/org/jenkinsci/plugins/xunit/XUnitBuilder.java index 10f30e09..75d85935 100644 --- a/src/main/java/org/jenkinsci/plugins/xunit/XUnitBuilder.java +++ b/src/main/java/org/jenkinsci/plugins/xunit/XUnitBuilder.java @@ -29,6 +29,7 @@ import javax.annotation.CheckForNull; +import org.jenkinsci.Symbol; import org.jenkinsci.lib.dtkit.descriptor.TestTypeDescriptor; import org.jenkinsci.lib.dtkit.type.TestType; import org.jenkinsci.plugins.xunit.threshold.FailedThreshold; @@ -37,6 +38,8 @@ import org.jenkinsci.plugins.xunit.threshold.XUnitThresholdDescriptor; import org.kohsuke.stapler.DataBoundConstructor; +import com.thoughtworks.xstream.annotations.XStreamAlias; + import hudson.DescriptorExtensionList; import hudson.Extension; import hudson.FilePath; @@ -57,20 +60,18 @@ */ public class XUnitBuilder extends Builder implements SimpleBuildStep { - private TestType[] types; + @XStreamAlias("types") + private TestType[] tools; private XUnitThreshold[] thresholds; private int thresholdMode; private ExtraConfiguration extraConfiguration; @DataBoundConstructor public XUnitBuilder(@CheckForNull TestType[] tools, @CheckForNull XUnitThreshold[] thresholds, int thresholdMode, @CheckForNull String testTimeMargin) { - this.types = (tools != null ? Arrays.copyOf(tools, tools.length) : new TestType[0]); + this.tools = (tools != null ? Arrays.copyOf(tools, tools.length) : new TestType[0]); this.thresholds = (thresholds != null ? Arrays.copyOf(thresholds, thresholds.length) : new XUnitThreshold[0]); this.thresholdMode = thresholdMode; - long longTestTimeMargin = XUnitDefaultValues.TEST_REPORT_TIME_MARGING; - if (testTimeMargin != null && testTimeMargin.trim().length() != 0) { - longTestTimeMargin = Long.parseLong(testTimeMargin); - } + long longTestTimeMargin = XUnitUtil.parsePositiveLong(testTimeMargin, XUnitDefaultValues.TEST_REPORT_TIME_MARGING); this.extraConfiguration = new ExtraConfiguration(longTestTimeMargin); } @@ -78,7 +79,7 @@ public XUnitBuilder(@CheckForNull TestType[] tools, @CheckForNull XUnitThreshold * Needed to support Snippet Generator and Workflow properly. */ public TestType[] getTools() { - return types; + return tools; } /* @@ -88,10 +89,6 @@ public String getTestTimeMargin() { return String.valueOf(getExtraConfiguration().getTestTimeMargin()); } - public TestType[] getTypes() { - return types; - } - public XUnitThreshold[] getThresholds() { return thresholds; } @@ -110,14 +107,14 @@ public ExtraConfiguration getExtraConfiguration() { @Override public void perform(final Run build, FilePath workspace, Launcher launcher, final TaskListener listener) throws InterruptedException, IOException { - XUnitProcessor xUnitProcessor = new XUnitProcessor(getTypes(), getThresholds(), getThresholdMode(), getExtraConfiguration()); + XUnitProcessor xUnitProcessor = new XUnitProcessor(getTools(), getThresholds(), getThresholdMode(), getExtraConfiguration()); xUnitProcessor.performXUnit(false, build, workspace, listener); } public boolean performDryRun(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { try { - XUnitProcessor xUnitProcessor = new XUnitProcessor(getTypes(), getThresholds(), getThresholdMode(), getExtraConfiguration()); + XUnitProcessor xUnitProcessor = new XUnitProcessor(getTools(), getThresholds(), getThresholdMode(), getExtraConfiguration()); xUnitProcessor.performXUnit(true, build, build.getWorkspace(), listener); } catch (Throwable t) { listener.getLogger().println("[ERROR] - There is an error: " + t.getCause().getMessage()); diff --git a/src/main/java/org/jenkinsci/plugins/xunit/XUnitPublisher.java b/src/main/java/org/jenkinsci/plugins/xunit/XUnitPublisher.java index 98ce844f..4758f2bb 100755 --- a/src/main/java/org/jenkinsci/plugins/xunit/XUnitPublisher.java +++ b/src/main/java/org/jenkinsci/plugins/xunit/XUnitPublisher.java @@ -68,20 +68,18 @@ */ public class XUnitPublisher extends Recorder implements DryRun, Serializable, SimpleBuildStep { - private TestType[] types; + @XStreamAlias("types") + private TestType[] tools; private XUnitThreshold[] thresholds; private int thresholdMode; private ExtraConfiguration extraConfiguration; @DataBoundConstructor public XUnitPublisher(@CheckForNull TestType[] tools, @CheckForNull XUnitThreshold[] thresholds, int thresholdMode, @CheckForNull String testTimeMargin) { - this.types = (tools != null ? Arrays.copyOf(tools, tools.length) : new TestType[0]); + this.tools = (tools != null ? Arrays.copyOf(tools, tools.length) : new TestType[0]); this.thresholds = (thresholds != null ? Arrays.copyOf(thresholds, thresholds.length) : new XUnitThreshold[0]); this.thresholdMode = thresholdMode; - long longTestTimeMargin = XUnitDefaultValues.TEST_REPORT_TIME_MARGING; - if (testTimeMargin != null && testTimeMargin.trim().length() != 0) { - longTestTimeMargin = Long.parseLong(testTimeMargin); - } + long longTestTimeMargin = XUnitUtil.parsePositiveLong(testTimeMargin, XUnitDefaultValues.TEST_REPORT_TIME_MARGING); this.extraConfiguration = new ExtraConfiguration(longTestTimeMargin); } @@ -89,7 +87,7 @@ public XUnitPublisher(@CheckForNull TestType[] tools, @CheckForNull XUnitThresho * Needed to support Snippet Generator and Workflow properly. */ public TestType[] getTools() { - return types; + return tools; } /* @@ -99,10 +97,6 @@ public String getTestTimeMargin() { return String.valueOf(getExtraConfiguration().getTestTimeMargin()); } - public TestType[] getTypes() { - return types; - } - public XUnitThreshold[] getThresholds() { return thresholds; } @@ -131,7 +125,7 @@ public Action getProjectAction(AbstractProject project) { @Override public void perform(final Run build, FilePath workspace, Launcher launcher, final TaskListener listener) throws InterruptedException, IOException { - XUnitProcessor xUnitProcessor = new XUnitProcessor(getTypes(), getThresholds(), getThresholdMode(), getExtraConfiguration()); + XUnitProcessor xUnitProcessor = new XUnitProcessor(getTools(), getThresholds(), getThresholdMode(), getExtraConfiguration()); xUnitProcessor.performXUnit(false, build, workspace, listener); } @@ -139,7 +133,7 @@ public void perform(final Run build, FilePath workspace, Launcher launcher public boolean performDryRun(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { try { - XUnitProcessor xUnitProcessor = new XUnitProcessor(getTypes(), getThresholds(), getThresholdMode(), getExtraConfiguration()); + XUnitProcessor xUnitProcessor = new XUnitProcessor(getTools(), getThresholds(), getThresholdMode(), getExtraConfiguration()); xUnitProcessor.performXUnit(true, build, build.getWorkspace(), listener); } catch (Throwable t) { listener.getLogger().println("[ERROR] - There is an error: " + t.getCause().getMessage()); diff --git a/src/main/java/org/jenkinsci/plugins/xunit/XUnitUtil.java b/src/main/java/org/jenkinsci/plugins/xunit/XUnitUtil.java new file mode 100644 index 00000000..e7869452 --- /dev/null +++ b/src/main/java/org/jenkinsci/plugins/xunit/XUnitUtil.java @@ -0,0 +1,55 @@ +/* +* The MIT License (MIT) +* +* Copyright (c) 2018, Falco Nikolas +* +* 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. +*/ +package org.jenkinsci.plugins.xunit; + +import hudson.Util; + +/* package */ final class XUnitUtil { + + private XUnitUtil() { + } + + /** + * Parses the string argument as a signed decimal {@code long}. In case the + * given value is empty or null, the default value is returned. + * + * @param value + * to parse + * @param defaultValue + * in case argument is not valid or empty or null + * @return the {@code long} represented by the argument in decimal, + * otherwise default value if argument is null, empty or invalid. + */ + public static long parsePositiveLong(String value, long defaultValue) { + long result = defaultValue; + if (Util.fixEmptyAndTrim(value) != null) { + try { + result = Math.abs(Long.parseLong(value)); + } catch (NumberFormatException e) { + // leave result valued with default value + } + } + return result; + } +} diff --git a/src/main/java/org/jenkinsci/plugins/xunit/threshold/FailedThreshold.java b/src/main/java/org/jenkinsci/plugins/xunit/threshold/FailedThreshold.java index 01d7dc9c..8ab78723 100644 --- a/src/main/java/org/jenkinsci/plugins/xunit/threshold/FailedThreshold.java +++ b/src/main/java/org/jenkinsci/plugins/xunit/threshold/FailedThreshold.java @@ -24,23 +24,20 @@ package org.jenkinsci.plugins.xunit.threshold; +import org.jenkinsci.plugins.xunit.service.XUnitLog; +import org.kohsuke.stapler.DataBoundConstructor; + import hudson.model.Result; import hudson.model.Run; import hudson.tasks.junit.TestResultAction; -import org.jenkinsci.plugins.xunit.service.XUnitLog; -import org.kohsuke.stapler.DataBoundConstructor; /** * @author Gregory Boissinot */ public class FailedThreshold extends XUnitThreshold { - public FailedThreshold() { - } - @DataBoundConstructor - public FailedThreshold(String unstableThreshold, String unstableNewThreshold, String failureThreshold, String failureNewThreshold) { - super(unstableThreshold, unstableNewThreshold, failureThreshold, failureNewThreshold); + public FailedThreshold() { } @Override diff --git a/src/main/java/org/jenkinsci/plugins/xunit/threshold/SkippedThreshold.java b/src/main/java/org/jenkinsci/plugins/xunit/threshold/SkippedThreshold.java index d510bca6..ea3ba144 100644 --- a/src/main/java/org/jenkinsci/plugins/xunit/threshold/SkippedThreshold.java +++ b/src/main/java/org/jenkinsci/plugins/xunit/threshold/SkippedThreshold.java @@ -24,23 +24,20 @@ package org.jenkinsci.plugins.xunit.threshold; +import org.jenkinsci.plugins.xunit.service.XUnitLog; +import org.kohsuke.stapler.DataBoundConstructor; + import hudson.model.Result; import hudson.model.Run; import hudson.tasks.junit.TestResultAction; -import org.jenkinsci.plugins.xunit.service.XUnitLog; -import org.kohsuke.stapler.DataBoundConstructor; /** * @author Gregory Boissinot */ public class SkippedThreshold extends XUnitThreshold { - public SkippedThreshold() { - } - @DataBoundConstructor - public SkippedThreshold(String unstableThreshold, String unstableNewThreshold, String failureThreshold, String failureNewThreshold) { - super(unstableThreshold, unstableNewThreshold, failureThreshold, failureNewThreshold); + public SkippedThreshold() { } @Override diff --git a/src/main/java/org/jenkinsci/plugins/xunit/threshold/XUnitThreshold.java b/src/main/java/org/jenkinsci/plugins/xunit/threshold/XUnitThreshold.java index 4af204b8..d9a2d1dd 100644 --- a/src/main/java/org/jenkinsci/plugins/xunit/threshold/XUnitThreshold.java +++ b/src/main/java/org/jenkinsci/plugins/xunit/threshold/XUnitThreshold.java @@ -27,9 +27,11 @@ import java.io.Serializable; import org.jenkinsci.plugins.xunit.service.XUnitLog; +import org.kohsuke.stapler.DataBoundSetter; import hudson.DescriptorExtensionList; import hudson.ExtensionPoint; +import hudson.Util; import hudson.model.Describable; import hudson.model.Descriptor; import hudson.model.Result; @@ -43,21 +45,18 @@ public abstract class XUnitThreshold implements ExtensionPoint, Serializable, Describable { private String unstableThreshold; - private String unstableNewThreshold; - private String failureThreshold; - private String failureNewThreshold; protected XUnitThreshold() { } public XUnitThreshold(String unstableThreshold, String unstableNewThreshold, String failureThreshold, String failureNewThreshold) { - this.unstableThreshold = unstableThreshold; - this.unstableNewThreshold = unstableNewThreshold; - this.failureThreshold = failureThreshold; - this.failureNewThreshold = failureNewThreshold; + this.setUnstableThreshold(unstableThreshold); + this.setUnstableNewThreshold(unstableNewThreshold); + this.setFailureThreshold(failureThreshold); + this.setFailureNewThreshold(failureNewThreshold); } @SuppressWarnings("unchecked") @@ -74,18 +73,38 @@ public String getUnstableThreshold() { return unstableThreshold; } + @DataBoundSetter + public void setUnstableThreshold(String unstableThreshold) { + this.unstableThreshold = Util.fixEmptyAndTrim(unstableThreshold); + } + public String getUnstableNewThreshold() { return unstableNewThreshold; } + @DataBoundSetter + public void setUnstableNewThreshold(String unstableNewThreshold) { + this.unstableNewThreshold = Util.fixEmptyAndTrim(unstableNewThreshold); + } + public String getFailureThreshold() { return failureThreshold; } + @DataBoundSetter + public void setFailureThreshold(String failureThreshold) { + this.failureThreshold = Util.fixEmptyAndTrim(failureThreshold); + } + public String getFailureNewThreshold() { return failureNewThreshold; } + @DataBoundSetter + public void setFailureNewThreshold(String failureNewThreshold) { + this.failureNewThreshold = Util.fixEmptyAndTrim(failureNewThreshold); + } + public abstract Result getResultThresholdNumber(XUnitLog log, Run build, TestResultAction testResultAction, @@ -100,61 +119,58 @@ public Result getResultThresholdNumber(XUnitLog log, int testCount, int newTestCount) { - String thresholdErrorMessage = "The %s number of tests for this category exceeds the specified '%s' threshold value."; if (isValid(getFailureThreshold()) && (convertToInteger(getFailureThreshold()) < testCount)) { - log.infoConsoleLogger(String.format(thresholdErrorMessage, "total", "failure")); + log.infoConsoleLogger(Messages.XUnitThreshold_thresholdErrorMessage("total", "failure")); return Result.FAILURE; } if (isValid(getFailureNewThreshold()) && (convertToInteger(getFailureNewThreshold()) < newTestCount)) { - log.infoConsoleLogger(String.format(thresholdErrorMessage, "new", "new failure")); + log.infoConsoleLogger(Messages.XUnitThreshold_thresholdErrorMessage("new", "new failure")); return Result.FAILURE; } if (isValid(getUnstableThreshold()) && (convertToInteger(getUnstableThreshold()) < testCount)) { - log.infoConsoleLogger(String.format(thresholdErrorMessage, "total", "unstable")); + log.infoConsoleLogger(Messages.XUnitThreshold_thresholdErrorMessage("total", "unstable")); return Result.UNSTABLE; } if (isValid(getUnstableNewThreshold()) && (convertToInteger(getUnstableNewThreshold()) < newTestCount)) { - log.infoConsoleLogger(String.format(thresholdErrorMessage, "new", "new unstable")); + log.infoConsoleLogger(Messages.XUnitThreshold_thresholdErrorMessage("new", "new unstable")); return Result.UNSTABLE; } return Result.SUCCESS; - } public Result getResultThresholdPercent(XUnitLog log, double testPercent, double newTestPercent) { - String thresholdErrorMessage = "The percent %s tests for this category exceeds the specified '%s' threshold percent value."; if (isValid(getFailureThreshold()) - && (convertToIntegerPercent(getFailureThreshold()) < testPercent)) { - log.infoConsoleLogger(String.format(thresholdErrorMessage, "of the total number of", "failure")); + && (convertToInteger(getFailureThreshold()) < testPercent)) { + log.infoConsoleLogger(Messages.XUnitThreshold_percentThresholdErrorMessage("of the total number of", "failure")); return Result.FAILURE; } if (isValid(getFailureNewThreshold()) - && (convertToIntegerPercent(getFailureNewThreshold()) < newTestPercent)) { - log.infoConsoleLogger(String.format(thresholdErrorMessage, "of the new number of", "new failure")); + && (convertToInteger(getFailureNewThreshold()) < newTestPercent)) { + log.infoConsoleLogger(Messages.XUnitThreshold_percentThresholdErrorMessage("of the new number of", "new failure")); return Result.FAILURE; } if (isValid(getUnstableThreshold()) - && (convertToIntegerPercent(getUnstableThreshold()) < testPercent)) { - log.infoConsoleLogger(String.format(thresholdErrorMessage, "of", "unstable")); + && (convertToInteger(getUnstableThreshold()) < testPercent)) { + log.infoConsoleLogger(Messages.XUnitThreshold_percentThresholdErrorMessage("of", "unstable")); return Result.UNSTABLE; } if (isValid(getUnstableNewThreshold()) - && (convertToIntegerPercent(getUnstableNewThreshold()) < newTestPercent)) { - log.infoConsoleLogger(String.format(thresholdErrorMessage, "of the new number of", "new unstable")); + && (convertToInteger(getUnstableNewThreshold()) < newTestPercent)) { + log.infoConsoleLogger(Messages.XUnitThreshold_percentThresholdErrorMessage("of the new number of", "new unstable")); return Result.UNSTABLE; } @@ -165,20 +181,11 @@ private int convertToInteger(String threshold) { return Integer.parseInt(threshold); } - private int convertToIntegerPercent(String threshold) { - String thresholdRemoved = threshold.replace("%", ""); - return Integer.parseInt(thresholdRemoved); - } - private boolean isValid(String threshold) { if (threshold == null) { return false; } - if (threshold.trim().length() == 0) { - return false; - } - try { Integer.parseInt(threshold); } catch (NumberFormatException nfe) { @@ -187,4 +194,5 @@ private boolean isValid(String threshold) { return true; } -} + +} \ No newline at end of file diff --git a/src/main/java/org/jenkinsci/plugins/xunit/threshold/XUnitThresholdDescriptor.java b/src/main/java/org/jenkinsci/plugins/xunit/threshold/XUnitThresholdDescriptor.java index 09dc8764..63a3155e 100644 --- a/src/main/java/org/jenkinsci/plugins/xunit/threshold/XUnitThresholdDescriptor.java +++ b/src/main/java/org/jenkinsci/plugins/xunit/threshold/XUnitThresholdDescriptor.java @@ -24,8 +24,14 @@ package org.jenkinsci.plugins.xunit.threshold; +import javax.annotation.CheckForNull; + +import org.kohsuke.stapler.QueryParameter; + import hudson.DescriptorExtensionList; +import hudson.Util; import hudson.model.Descriptor; +import hudson.util.FormValidation; import jenkins.model.Jenkins; /** @@ -51,4 +57,31 @@ public static DescriptorExtensionList - + - - - - + + @@ -65,11 +63,10 @@ THE SOFTWARE. diff --git a/src/main/resources/org/jenkinsci/plugins/xunit/XUnitPublisher/config.jelly b/src/main/resources/org/jenkinsci/plugins/xunit/XUnitPublisher/config.jelly index c282e0ed..e71e09c9 100755 --- a/src/main/resources/org/jenkinsci/plugins/xunit/XUnitPublisher/config.jelly +++ b/src/main/resources/org/jenkinsci/plugins/xunit/XUnitPublisher/config.jelly @@ -25,17 +25,15 @@ THE SOFTWARE. - + - - - - + + @@ -65,11 +63,11 @@ THE SOFTWARE.
-
diff --git a/src/main/resources/org/jenkinsci/plugins/xunit/threshold/Messages.properties b/src/main/resources/org/jenkinsci/plugins/xunit/threshold/Messages.properties index bfa66ac8..7b580481 100644 --- a/src/main/resources/org/jenkinsci/plugins/xunit/threshold/Messages.properties +++ b/src/main/resources/org/jenkinsci/plugins/xunit/threshold/Messages.properties @@ -30,3 +30,6 @@ failureNewThreshold.skippedTests=If the total number of skipped tests exceeds th thresholdHelpMessage.skippedTests=Configure the build status. A build is considered as unstable or failure \ if the new or total number of skipped tests exceeds the specified thresholds. \ +XUnitThreshold.thresholdErrorMessage=The {0} number of tests for this category exceeds the specified "{1}" threshold value. +XUnitThreshold.percentThresholdErrorMessage=The percent {0} tests for this category exceeds the specified "{1}" threshold percent value. +XUnitThresholdDescriptor.checkThreshold=Invalid threshold format for value: {0} \ No newline at end of file diff --git a/src/main/resources/util/hetero-list-readonly.jelly b/src/main/resources/util/hetero-list-readonly.jelly index acbfbcea..be04a80b 100644 --- a/src/main/resources/util/hetero-list-readonly.jelly +++ b/src/main/resources/util/hetero-list-readonly.jelly @@ -28,7 +28,7 @@ THE SOFTWARE. Outer most tag for creating a heterogeneous list, where the user can choose arbitrary number of arbitrary items from the given list of descriptors, and configure them independently. - The submission can be data-bound into List<T> where T is the common base type for the describable instances. + The submission can be data-bound into List<T> where T is the common base type for the describable instances. form name that receives an array for all the items in the heterogeneous list. diff --git a/src/main/resources/util/threshold.jelly b/src/main/resources/util/threshold.jelly index c8eb2780..1edf0727 100644 --- a/src/main/resources/util/threshold.jelly +++ b/src/main/resources/util/threshold.jelly @@ -74,6 +74,9 @@ THE SOFTWARE. + + +
-
diff --git a/src/test/java/org/jenkinsci/plugins/xunit/XUnitSerialisationTest.java b/src/test/java/org/jenkinsci/plugins/xunit/XUnitSerialisationTest.java new file mode 100644 index 00000000..9074b7a6 --- /dev/null +++ b/src/test/java/org/jenkinsci/plugins/xunit/XUnitSerialisationTest.java @@ -0,0 +1,95 @@ +/* +The MIT License (MIT) + +Copyright (c) 2018, Falco Nikolas + +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. +*/ +package org.jenkinsci.plugins.xunit; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +import org.jenkinsci.lib.dtkit.type.TestType; +import org.jenkinsci.plugins.xunit.types.JUnitType; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.JenkinsRule; +import org.jvnet.hudson.test.recipes.LocalData; + +import hudson.model.FreeStyleProject; +import hudson.model.Items; +import hudson.tasks.Builder; +import hudson.tasks.Publisher; + +public class XUnitSerialisationTest { + + @Rule + public JenkinsRule r = new JenkinsRule(); + + @BeforeClass + public static void dirtyXStreamSetup() { + // used to simulate the AliasInitializer that is not triggered by the JenkinsRule + Items.XSTREAM.alias("xunit", XUnitPublisher.class); + Items.XSTREAM.alias(JUnitType.class.getSimpleName(), JUnitType.class); + } + + @LocalData("publisher_1_103") + @Test + public void verify_publisher_compatible_before_1_103() throws Exception { + FreeStyleProject project = (FreeStyleProject) r.jenkins.getItem("foo"); + + assertThat(project.getPublishersList().size(), is(1)); + + Publisher publisher = project.getPublishersList().get(0); + assertThat(publisher, instanceOf(XUnitPublisher.class)); + + XUnitPublisher xunitPublisher = (XUnitPublisher) publisher; + assertThat(xunitPublisher.getTools().length, is(1)); + + verifyJUnitTool(xunitPublisher.getTools()[0]); + } + + @LocalData("builder_1_103") + @Test + public void verify_builder_compatible_before_1_103() throws Exception { + FreeStyleProject project = (FreeStyleProject) r.jenkins.getItem("foo"); + + assertThat(project.getBuildersList().size(), is(1)); + + Builder builders = project.getBuildersList().get(0); + assertThat(builders, instanceOf(XUnitBuilder.class)); + + XUnitBuilder xunitBuilder = (XUnitBuilder) builders; + assertThat(xunitBuilder.getTools().length, is(1)); + + verifyJUnitTool(xunitBuilder.getTools()[0]); + } + + private void verifyJUnitTool(TestType tool) { + assertThat(tool, instanceOf(JUnitType.class)); + assertThat(tool.getPattern(), is("**/target/surefire-reports/*.xml")); + assertThat(tool.isDeleteOutputFiles(), is(true)); + assertThat(tool.isFailIfNotNew(), is(false)); + assertThat(tool.isSkipNoTestFiles(), is(false)); + assertThat(tool.isStopProcessingIfError(), is(true)); + } + +} \ No newline at end of file diff --git a/src/test/java/org/jenkinsci/plugins/xunit/XUnitWorkflowTest.java b/src/test/java/org/jenkinsci/plugins/xunit/XUnitWorkflowTest.java index fc0cdc36..5c6a5b69 100644 --- a/src/test/java/org/jenkinsci/plugins/xunit/XUnitWorkflowTest.java +++ b/src/test/java/org/jenkinsci/plugins/xunit/XUnitWorkflowTest.java @@ -88,7 +88,7 @@ public void xunit() throws Exception { + "node {\n" + " xunit(testTimeMargin: '3000'," + " thresholdMode: 1," - + " thresholds: [ failed(failureNewThreshold: '', failureThreshold: '', unstableNewThreshold: '', unstableThreshold: '1') ]," + + " thresholds: [ failed(unstableThreshold: '1'), skipped() ]," + " tools: [ GoogleTest(deleteOutputFiles: false, failIfNotNew: false, pattern: 'input.xml', skipNoTestFiles: false, stopProcessingIfError: true) ]" + " )\n" + "}", true)); diff --git a/src/test/resources/org/jenkinsci/plugins/xunit/XUnitSerialisationTest/builder_1_103/jobs/foo/config.xml b/src/test/resources/org/jenkinsci/plugins/xunit/XUnitSerialisationTest/builder_1_103/jobs/foo/config.xml new file mode 100644 index 00000000..bb766692 --- /dev/null +++ b/src/test/resources/org/jenkinsci/plugins/xunit/XUnitSerialisationTest/builder_1_103/jobs/foo/config.xml @@ -0,0 +1,43 @@ + + + + + false + false + false + false + + false + + + + + **/target/surefire-reports/*.xml + false + false + true + true + + + + + + + 1 + + + + + + + + + + 1 + + 3000 + + + + + \ No newline at end of file diff --git a/src/test/resources/org/jenkinsci/plugins/xunit/XUnitSerialisationTest/publisher_1_103/jobs/foo/config.xml b/src/test/resources/org/jenkinsci/plugins/xunit/XUnitSerialisationTest/publisher_1_103/jobs/foo/config.xml new file mode 100644 index 00000000..9eaae599 --- /dev/null +++ b/src/test/resources/org/jenkinsci/plugins/xunit/XUnitSerialisationTest/publisher_1_103/jobs/foo/config.xml @@ -0,0 +1,43 @@ + + + + + false + false + false + false + + false + + + + + **/target/surefire-reports/*.xml + false + false + true + true + + + + + + + 1 + + + + + + + + + + 1 + + 3000 + + + + + \ No newline at end of file diff --git a/src/test/resources/org/jenkinsci/plugins/xunit/config.xml b/src/test/resources/org/jenkinsci/plugins/xunit/config.xml new file mode 100644 index 00000000..eb6b7020 --- /dev/null +++ b/src/test/resources/org/jenkinsci/plugins/xunit/config.xml @@ -0,0 +1,74 @@ + + + + + false + true + false + false + + false + + + + + **/target/surefire-reports/*.xml + false + false + true + true + + + + + + + 1 + + + + + + + + + + 1 + + 3000 + + + + + + + + **/target/surefire-reports/*.xml + false + false + true + true + + + + + + + 1 + + + + + + + + + + 1 + + 3000 + + + + + \ No newline at end of file