diff --git a/test/src/test/groovy/jenkins/model/BuildDiscarderTest.groovy b/test/src/test/groovy/jenkins/model/BuildDiscarderTest.groovy deleted file mode 100644 index 891cb0ac60a4bf3426c0eb80eda5bb8412eb6be6..0000000000000000000000000000000000000000 --- a/test/src/test/groovy/jenkins/model/BuildDiscarderTest.groovy +++ /dev/null @@ -1,49 +0,0 @@ -package jenkins.model - -import hudson.model.AbstractProject -import hudson.tasks.LogRotator -import org.junit.Rule -import org.junit.Test -import org.jvnet.hudson.test.Issue -import org.jvnet.hudson.test.JenkinsRule -import org.jvnet.hudson.test.recipes.LocalData - -import javax.xml.transform.Source -import javax.xml.transform.stream.StreamSource - -/** - * @author Kohsuke Kawaguchi - */ -public class BuildDiscarderTest { - - @Rule - public JenkinsRule j = new JenkinsRule() - - @Test - @Issue("JENKINS-16979") - @LocalData - void compatibility() { - AbstractProject p = j.jenkins.getItem("foo") - verifyLogRotatorSanity(p) - - // now persist in the new format - p.save() - def xml = p.configFile.asString() - - // make sure this new format roundtrips by itself - p.buildDiscarder = null - p.updateByXml((Source)new StreamSource(new StringReader(xml))) - verifyLogRotatorSanity(p) - - // another sanity check - assert xml.contains("") - } - - private static void verifyLogRotatorSanity(AbstractProject p) { - LogRotator d = p.buildDiscarder - assert d.daysToKeep == 4 - assert d.numToKeep == 3 - assert d.artifactDaysToKeep == 2 - assert d.artifactNumToKeep == 1 - } -} diff --git a/test/src/test/java/jenkins/model/BuildDiscarderPropertyTest.java b/test/src/test/java/jenkins/model/BuildDiscarderPropertyTest.java new file mode 100644 index 0000000000000000000000000000000000000000..90c8bf71bdf97a223e582e5bba50be261104e633 --- /dev/null +++ b/test/src/test/java/jenkins/model/BuildDiscarderPropertyTest.java @@ -0,0 +1,71 @@ +/* + * The MIT License + * + * Copyright 2015 CloudBees, Inc. + * + * 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 jenkins.model; + +import hudson.model.AbstractProject; +import hudson.tasks.LogRotator; +import java.io.StringReader; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; +import org.junit.Test; +import static org.junit.Assert.*; +import org.junit.Rule; +import org.jvnet.hudson.test.Issue; +import org.jvnet.hudson.test.JenkinsRule; +import org.jvnet.hudson.test.recipes.LocalData; + +public class BuildDiscarderPropertyTest { + + @Rule + public JenkinsRule r = new JenkinsRule(); + + @Issue("JENKINS-16979") + @LocalData + @Test + public void logRotatorField() throws Exception { + AbstractProject p = r.jenkins.getItemByFullName("foo", AbstractProject.class); + verifyLogRotatorSanity(p); + + // now persist in the new format + p.save(); + String xml = p.getConfigFile().asString(); + + // make sure this new format roundtrips by itself + p.setBuildDiscarder(null); + p.updateByXml((Source) new StreamSource(new StringReader(xml))); + verifyLogRotatorSanity(p); + + // another sanity check + assertTrue(xml, xml.contains("")); + } + + private static void verifyLogRotatorSanity(AbstractProject p) { + LogRotator d = (LogRotator) p.getBuildDiscarder(); + assertEquals(4, d.getDaysToKeep()); + assertEquals(3, d.getNumToKeep()); + assertEquals(2, d.getArtifactDaysToKeep()); + assertEquals(1, d.getArtifactNumToKeep()); + } +} diff --git a/test/src/test/resources/jenkins/model/BuildDiscarderTest/compatibility/config.xml b/test/src/test/resources/jenkins/model/BuildDiscarderPropertyTest/logRotatorField/config.xml similarity index 100% rename from test/src/test/resources/jenkins/model/BuildDiscarderTest/compatibility/config.xml rename to test/src/test/resources/jenkins/model/BuildDiscarderPropertyTest/logRotatorField/config.xml diff --git a/test/src/test/resources/jenkins/model/BuildDiscarderTest/compatibility/jobs/foo/config.xml b/test/src/test/resources/jenkins/model/BuildDiscarderPropertyTest/logRotatorField/jobs/foo/config.xml similarity index 100% rename from test/src/test/resources/jenkins/model/BuildDiscarderTest/compatibility/jobs/foo/config.xml rename to test/src/test/resources/jenkins/model/BuildDiscarderPropertyTest/logRotatorField/jobs/foo/config.xml