Skip to content

Commit

Permalink
[JENKINS-48463] Added a unit test that validates jenkins xml v1.0 con…
Browse files Browse the repository at this point in the history
…figs

are silently migrated to xml v1.1 as they are persisted
  • Loading branch information
mikecirioli committed Jan 24, 2018
1 parent 24a1852 commit b9c2148
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
24 changes: 1 addition & 23 deletions core/src/test/java/hudson/XmlFileTest.java
Expand Up @@ -7,7 +7,6 @@
import java.net.URL;

import jenkins.model.Jenkins;
import org.junit.Ignore;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
Expand Down Expand Up @@ -44,28 +43,7 @@ public void canReadXml1_1Test() throws IOException {
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");
Expand Down
22 changes: 22 additions & 0 deletions test/src/test/java/hudson/XMLFileTest.java
@@ -1,5 +1,8 @@
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;
Expand All @@ -20,4 +23,23 @@ 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("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();
}
}
@@ -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=&#x1b;[01;31m</label>
<!-- Yeah, we deleted a lot of this ... fine for testing. -->
</hudson>

0 comments on commit b9c2148

Please sign in to comment.