forked from jenkinsci/jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request jenkinsci#3185 from mikecirioli/OSS-2590
[JENKINS-48463] Update jenkins core to use XML v1.1
- Loading branch information
Showing
21 changed files
with
226 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<hudson> | ||
<disabledAdministrativeMonitors/> | ||
<version>1.480.1</version> | ||
<numExecutors>2</numExecutors> | ||
<mode>NORMAL</mode> | ||
<!-- Yeah, we deleted a lot of this ... fine for testing. --> | ||
</hudson> |
9 changes: 9 additions & 0 deletions
9
core/src/test/resources/hudson/config_1_0_with_special_chars.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<hudson> | ||
<disabledAdministrativeMonitors/> | ||
<version>1.480.1</version> | ||
<numExecutors>2</numExecutors> | ||
<mode>NORMAL</mode> | ||
<label>LESS_TERMCAP_mb=[01;31m</label> | ||
<!-- Yeah, we deleted a lot of this ... fine for testing. --> | ||
</hudson> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version='1.1' encoding='UTF-8'?> | ||
<hudson> | ||
<disabledAdministrativeMonitors/> | ||
<version>1.480.1</version> | ||
<numExecutors>2</numExecutors> | ||
<mode>NORMAL</mode> | ||
<!-- Yeah, we deleted a lot of this ... fine for testing. --> | ||
</hudson> |
9 changes: 9 additions & 0 deletions
9
core/src/test/resources/hudson/config_1_1_with_special_chars.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version='1.1' encoding='UTF-8'?> | ||
<hudson> | ||
<disabledAdministrativeMonitors/> | ||
<version>1.480.1</version> | ||
<numExecutors>2</numExecutors> | ||
<mode>NORMAL</mode> | ||
<label>LESS_TERMCAP_mb=[01;31m</label> | ||
<!-- Yeah, we deleted a lot of this ... fine for testing. --> | ||
</hudson> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
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; | ||
import org.jvnet.hudson.test.recipes.LocalData; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class XMLFileTest { | ||
|
||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
@Test | ||
@LocalData | ||
public void canStartWithXml_1_1_ConfigsTest() { | ||
|
||
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("I am a label")); | ||
//verify that the persisted top level config.xml is v1.1 | ||
File configFile = new File(j.jenkins.getRootDir(), "config.xml"); | ||
assertThat(configFile.exists(), is(true)); | ||
|
||
try (BufferedReader config = new BufferedReader(new FileReader(configFile))) { | ||
assertThat(config.readLine(), is("<?xml version='1.1' encoding='UTF-8'?>")); | ||
config.close(); | ||
} | ||
} | ||
} |
Oops, something went wrong.