Skip to content

Commit

Permalink
[JENKINS-48463] Added additional unit tests for verifying xml v1.1 co…
Browse files Browse the repository at this point in the history
…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
mikecirioli committed Jan 24, 2018
1 parent 570b52d commit 24a1852
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 1 deletion.
84 changes: 84 additions & 0 deletions core/src/test/java/hudson/XmlFileTest.java
@@ -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"));
}
}
}
@@ -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=&#x1b;[01;31m</label>
<!-- Yeah, we deleted a lot of this ... fine for testing. -->
</hudson>
8 changes: 8 additions & 0 deletions core/src/test/resources/hudson/config_1_0.xml
@@ -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>
8 changes: 8 additions & 0 deletions core/src/test/resources/hudson/config_1_1.xml
@@ -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>
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -129,7 +129,7 @@ THE SOFTWARE.
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.8.4</version>
<version>1.9.2</version>
</dependency>

<dependency>
Expand Down
23 changes: 23 additions & 0 deletions test/src/test/java/hudson/XMLFileTest.java
@@ -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"));

}
}
@@ -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=&#x1b;[01;31m</label>
<!-- Yeah, we deleted a lot of this ... fine for testing. -->
</hudson>

0 comments on commit 24a1852

Please sign in to comment.