提交 b9c2148d 编写于 作者: M mike cirioli

[JENKINS-48463] Added a unit test that validates jenkins xml v1.0 configs

are silently migrated to xml v1.1 as they are persisted
上级 24a1852f
......@@ -7,7 +7,6 @@ import java.io.IOException;
import java.net.URL;
import jenkins.model.Jenkins;
import org.junit.Ignore;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
......@@ -44,28 +43,7 @@ public class XmlFileTest {
assertThat(n.getMode().toString(), is("NORMAL"));
}
}
@Test
@Ignore
//TODO: find a way to complete this test
public void xml1_0ConfigMigrateTo1_1Test() throws IOException {
URL configUrl = getClass().getResource("/hudson/config_1_0.xml");
File configFile = new File(configUrl.getFile());
XStream2 xs = new XStream2();
xs.alias("hudson", Jenkins.class);
XmlFile xmlFile = new XmlFile(xs, configFile);
if (xmlFile.exists()) {
Node n = (Node) xmlFile.read();
assertThat(n.getNumExecutors(), is(2));
assertThat(n.getMode().toString(), is("NORMAL"));
// this fails, because configFile.getParent() returns null....how do i fix?
n.save();
// Now verify that the node is showing <?xml version='1.1'> tag
}
}
@Test
public void canReadXmlWithControlCharsTest() throws IOException {
URL configUrl = getClass().getResource("/hudson/confg_1_1_with_special_chars.xml");
......
package hudson;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
......@@ -20,4 +23,23 @@ public class XMLFileTest {
assertThat(j.jenkins.getLabelString(),is("LESS_TERMCAP_mb=\u001B[01;31m"));
}
/**
*
* This test validates that xml v1.0 configs silently get migrated to xml v1.1 when they are persisted
*
*/
@Test
@LocalData
public void silentlyMigrateConfigsTest() throws Exception {
j.jenkins.save();
// verify that we did indeed load our test config.xml
assertThat(j.jenkins.getLabelString(), is("LESS_TERMCAP_mb=\u001B[01;31m"));
//verify that the persisted top level config.xml is v1.1
File configFile = new File(j.jenkins.getRootPath().getRemote() + File.separator + "config.xml");
assertThat(configFile.exists(), is(true));
BufferedReader config = new BufferedReader(new FileReader(configFile));
assertThat(config.readLine(), is("<?xml version='1.1' encoding='UTF-8'?>"));
config.close();
}
}
<?xml version='1.0' encoding='UTF-8'?>
<hudson>
<disabledAdministrativeMonitors/>
<version>1.480.1</version>
<numExecutors>2</numExecutors>
<mode>NORMAL</mode>
<label>LESS_TERMCAP_mb=&#x1b;[01;31m</label>
<!-- Yeah, we deleted a lot of this ... fine for testing. -->
</hudson>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册