Skip to content

Commit

Permalink
Add test cases for context level copyXML and fix bug they identified.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1489812 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Jun 5, 2013
1 parent 7cbd2bb commit 6509668
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 2 deletions.
4 changes: 2 additions & 2 deletions java/org/apache/catalina/startup/HostConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -894,8 +894,8 @@ protected void deployWAR(ContextName cn, File war) {
}

// If Host is using default value Context can override it.
if (!copyXML && context instanceof StandardContext) {
copyXML = ((StandardContext) context).getCopyXML();
if (!copyThisXml && context instanceof StandardContext) {
copyThisXml = ((StandardContext) context).getCopyXML();
}

if (xmlInWar && copyThisXml) {
Expand Down
Binary file added test/deployment/contextCopyXMLFalse.war
Binary file not shown.
Binary file added test/deployment/contextCopyXMLTrue.war
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public class TestHostConfigAutomaticDeployment extends TomcatBaseTest {
new File("test/deployment/context.xml");
private static final File WAR_XML_SOURCE =
new File("test/deployment/context.war");
private static final File WAR_XML_COPYXML_FALSE_SOURCE =
new File("test/deployment/contextCopyXMLFalse.war");
private static final File WAR_XML_COPYXML_TRUE_SOURCE =
new File("test/deployment/contextCopyXMLTrue.war");
private static final File WAR_XML_UNPACKWAR_FALSE_SOURCE =
new File("test/deployment/contextUnpackWARFalse.war");
private static final File WAR_XML_UNPACKWAR_TRUE_SOURCE =
Expand Down Expand Up @@ -1726,4 +1730,87 @@ public String getHistory() {
return stateHistory.toString();
}
}


/*
* Test context copyXML setting.
* If context.copyXML != Host.copyXML the Host wins.
* For external WARs, a context.xml must always already exist
*/
@Test
public void testCopyXMLFFF() throws Exception {
doTestCopyXML(false, false, false, false);
}

@Test
public void testCopyXMLFFT() throws Exception {
doTestCopyXML(false, false, true, true);
}

@Test
public void testCopyXMLFTF() throws Exception {
doTestCopyXML(false, true, false, true);
}

@Test
public void testCopyXMLFTT() throws Exception {
doTestCopyXML(false, true, true, true);
}

@Test
public void testCopyXMLTFF() throws Exception {
doTestCopyXML(true, false, false, true);
}

@Test
public void testCopyXMLTFT() throws Exception {
doTestCopyXML(true, false, true, true);
}

@Test
public void testCopyXMLTTF() throws Exception {
doTestCopyXML(true, true, false, true);
}

@Test
public void testCopyXMLTTT() throws Exception {
doTestCopyXML(true, true, true, true);
}

private void doTestCopyXML(boolean copyXmlHost, boolean copyXmlWar,
boolean external, boolean resultXml) throws Exception {

Tomcat tomcat = getTomcatInstance();
StandardHost host = (StandardHost) tomcat.getHost();

host.setCopyXML(copyXmlHost);

tomcat.start();

File war;
if (copyXmlWar) {
war = createWar(WAR_XML_COPYXML_TRUE_SOURCE, !external);
} else {
war = createWar(WAR_XML_COPYXML_FALSE_SOURCE, !external);
}
if (external) {
createXmlInConfigBaseForExternal(war);
}

host.backgroundProcess();

File xml = new File(host.getConfigBaseFile(),
APP_NAME.getBaseName() + ".xml");
Assert.assertEquals(
Boolean.valueOf(resultXml), Boolean.valueOf(xml.isFile()));

Context context = (Context) host.findChild(APP_NAME.getName());
if (external) {
Assert.assertEquals(XML_COOKIE_NAME,
context.getSessionCookieName());
} else {
Assert.assertEquals(WAR_COOKIE_NAME,
context.getSessionCookieName());
}
}
}

0 comments on commit 6509668

Please sign in to comment.