mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-15 13:02:19 +00:00
Merge pull request #3185 from mikecirioli/OSS-2590
[JENKINS-48463] Update jenkins core to use XML v1.1
This commit is contained in:
21 files changed
+226
-27
No files matched your search
@@ -0,0 +1,79 @@
|
||||
package hudson;
|
||||
|
||||
import hudson.model.Node;
|
||||
import hudson.util.XStream2;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import jenkins.model.Jenkins;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class XmlFileTest {
|
||||
|
||||
@Test
|
||||
public void canReadXml1_0Test() throws IOException {
|
||||
URL configUrl = getClass().getResource("/hudson/config_1_0.xml");
|
||||
XStream2 xs = new XStream2();
|
||||
xs.alias("hudson", Jenkins.class);
|
||||
|
||||
XmlFile xmlFile = new XmlFile(xs, new File(configUrl.getFile()));
|
||||
if (xmlFile.exists()) {
|
||||
Node n = (Node) xmlFile.read();
|
||||
assertThat(n.getNumExecutors(), is(2));
|
||||
assertThat(n.getMode().toString(), is("NORMAL"));
|
||||
}
|
||||
}
|
||||
|
||||
// KXml2Driver is able to parse XML 1.0 even if it has control characters which
|
||||
// should be illegal. Ignoring this test until we switch to a more compliant driver
|
||||
@Ignore
|
||||
@Test(expected = SAXParseException.class)
|
||||
public void xml1_0_withSpecialCharsShouldFail() throws IOException {
|
||||
URL configUrl = getClass().getResource("/hudson/config_1_0_with_special_chars.xml");
|
||||
XStream2 xs = new XStream2();
|
||||
xs.alias("hudson", Jenkins.class);
|
||||
|
||||
XmlFile xmlFile = new XmlFile(xs, new File(configUrl.getFile()));
|
||||
if (xmlFile.exists()) {
|
||||
Node n = (Node) xmlFile.read();
|
||||
assertThat(n.getNumExecutors(), is(2));
|
||||
assertThat(n.getMode().toString(), is("NORMAL"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canReadXml1_1Test() throws IOException {
|
||||
URL configUrl = getClass().getResource("/hudson/config_1_1.xml");
|
||||
XStream2 xs = new XStream2();
|
||||
xs.alias("hudson", Jenkins.class);
|
||||
|
||||
XmlFile xmlFile = new XmlFile(xs, new File(configUrl.getFile()));
|
||||
if (xmlFile.exists()) {
|
||||
Node n = (Node) xmlFile.read();
|
||||
assertThat(n.getNumExecutors(), is(2));
|
||||
assertThat(n.getMode().toString(), is("NORMAL"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canReadXmlWithControlCharsTest() throws IOException {
|
||||
URL configUrl = getClass().getResource("/hudson/config_1_1_with_special_chars.xml");
|
||||
XStream2 xs = new XStream2();
|
||||
xs.alias("hudson", Jenkins.class);
|
||||
|
||||
XmlFile xmlFile = new XmlFile(xs, new File(configUrl.getFile()));
|
||||
if (xmlFile.exists()) {
|
||||
Node n = (Node) xmlFile.read();
|
||||
assertThat(n.getNumExecutors(), is(2));
|
||||
assertThat(n.getMode().toString(), is("NORMAL"));
|
||||
assertThat(n.getLabelString(), is("LESS_TERMCAP_mb=\u001B[01;31m"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ import static org.junit.Assert.*;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.thoughtworks.xstream.XStreamException;
|
||||
import com.thoughtworks.xstream.io.xml.Xpp3Driver;
|
||||
import com.thoughtworks.xstream.io.xml.KXml2Driver;
|
||||
import com.thoughtworks.xstream.security.ForbiddenClassException;
|
||||
import hudson.model.Result;
|
||||
import hudson.model.Run;
|
||||
@@ -426,7 +426,7 @@ public class XStream2Test {
|
||||
|
||||
private Object fromXMLNullingOut(String xml, Object root) {
|
||||
// Currently not offering a public convenience API for this:
|
||||
return Jenkins.XSTREAM2.unmarshal(new Xpp3Driver().createReader(new StringReader(xml)), root, null, true);
|
||||
return Jenkins.XSTREAM2.unmarshal(XStream2.getDefaultDriver().createReader(new StringReader(xml)), root, null, true);
|
||||
}
|
||||
|
||||
public static class WithDefaults {
|
||||
|
||||
Reference in new issue
Block a user