Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-48463] Added additional unit tests for verifying xml v1.1 co…
…mpatibility - verify can still read xml 1.0 - verify can read xml 1.1 - verify can read xml 1.1 with 'special' characters - verify that jenkins can start with a config.xml having <?xml version='1.1'> and special characters
- Loading branch information
1 parent
570b52d
commit 24a1852
Showing
7 changed files
with
142 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
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 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"); | ||
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")); | ||
} | ||
} | ||
|
||
@Test | ||
public void canReadXml1_1Test() throws IOException { | ||
URL configUrl = getClass().getResource("/hudson/config_1_1.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")); | ||
} | ||
} | ||
|
||
@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"); | ||
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")); | ||
assertThat(n.getLabelString(), is("LESS_TERMCAP_mb=\u001B[01;31m")); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
core/src/test/resources/hudson/confg_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
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> |
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> |
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,23 @@ | ||
package hudson; | ||
|
||
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")); | ||
|
||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
test/src/test/resources/hudson/XMLFileTest/canStartWithXml_1_1_ConfigsTest/config.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> |