提交 2200711b 编写于 作者: J Jesse Glick

[JENKINS-16979] Migrated test from Groovy to Java for ease of maintenance.

上级 1151be43
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("<logRotator class=\"${LogRotator.class.name}\">")
}
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
}
}
/*
* 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("<logRotator class=\"" + LogRotator.class.getName() + "\">"));
}
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());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册