diff --git a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentC.java b/test/org/apache/catalina/startup/HostConfigAutomaticDeploymentBaseTest.java similarity index 52% rename from test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentC.java rename to test/org/apache/catalina/startup/HostConfigAutomaticDeploymentBaseTest.java index 0b2189f62fcc..d720f4202ca8 100644 --- a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentC.java +++ b/test/org/apache/catalina/startup/HostConfigAutomaticDeploymentBaseTest.java @@ -22,11 +22,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.IsInstanceOf.instanceOf; - import org.junit.Assert; -import org.junit.Test; import org.apache.catalina.Context; import org.apache.catalina.Host; @@ -38,52 +34,37 @@ import org.apache.catalina.core.StandardHost; import org.apache.catalina.util.ContextName; -/** - * The purpose of this class is to test the automatic deployment features of the - * {@link HostConfig} implementation. - */ -public class TestHostConfigAutomaticDeploymentC extends TomcatBaseTest { - - private static final ContextName APP_NAME = new ContextName("myapp", false); - private static final File XML_SOURCE = - 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 = - new File("test/deployment/contextUnpackWARTrue.war"); - private static final File WAR_SOURCE = - new File("test/deployment/noContext.war"); - private static final File WAR_BROKEN_SOURCE = - new File("test/deployment/broken.war"); - private static final File DIR_XML_SOURCE = - new File("test/deployment/dirContext"); - private static final File DIR_XML_SOURCE_META_INF = - new File("test/deployment/dirContext/META-INF"); - private static final File DIR_SOURCE = - new File("test/deployment/dirNoContext"); - - private static final int XML = 1; - private static final int EXT = 2; - private static final int WAR = 3; - private static final int DIR = 4; - private static final int DIR_XML = 5; - - private static final int NONE = 1; - private static final int RELOAD = 2; - private static final int REDEPLOY = 3; - - private static final String XML_COOKIE_NAME = "XML_CONTEXT"; - private static final String WAR_COOKIE_NAME = "WAR_CONTEXT"; - private static final String DIR_COOKIE_NAME = "DIR_CONTEXT"; - // private static final String DEFAULT_COOKIE_NAME = "JSESSIONID"; - - private File external; +public class HostConfigAutomaticDeploymentBaseTest extends TomcatBaseTest { + + protected static final ContextName APP_NAME = new ContextName("myapp", false); + protected static final File XML_SOURCE = new File("test/deployment/context.xml"); + protected static final File WAR_XML_SOURCE = new File("test/deployment/context.war"); + protected static final File WAR_XML_COPYXML_FALSE_SOURCE = new File("test/deployment/contextCopyXMLFalse.war"); + protected static final File WAR_XML_COPYXML_TRUE_SOURCE = new File("test/deployment/contextCopyXMLTrue.war"); + protected static final File WAR_XML_UNPACKWAR_FALSE_SOURCE = new File("test/deployment/contextUnpackWARFalse.war"); + protected static final File WAR_XML_UNPACKWAR_TRUE_SOURCE = new File("test/deployment/contextUnpackWARTrue.war"); + protected static final File WAR_SOURCE = new File("test/deployment/noContext.war"); + protected static final File WAR_BROKEN_SOURCE = new File("test/deployment/broken.war"); + protected static final File DIR_XML_SOURCE = new File("test/deployment/dirContext"); + protected static final File DIR_XML_SOURCE_META_INF = new File("test/deployment/dirContext/META-INF"); + protected static final File DIR_SOURCE = new File("test/deployment/dirNoContext"); + + protected static final int XML = 1; + protected static final int EXT = 2; + protected static final int WAR = 3; + protected static final int DIR = 4; + protected static final int DIR_XML = 5; + + protected static final int NONE = 1; + protected static final int RELOAD = 2; + protected static final int REDEPLOY = 3; + + protected static final String XML_COOKIE_NAME = "XML_CONTEXT"; + protected static final String WAR_COOKIE_NAME = "WAR_CONTEXT"; + protected static final String DIR_COOKIE_NAME = "DIR_CONTEXT"; + + protected File external; + @Override public void setUp() throws Exception { @@ -111,146 +92,181 @@ public void setUp() throws Exception { } - /* - * Expected behaviour for modification of files. - * - * Artifacts present Artifact Artifacts remaining - * XML WAR EXT DIR Modified XML WAR EXT DIR Action - * N N N Y DIR - - - M None - * N Y N N WAR - M - - Redeploy - * N Y N Y DIR - Y - M None - * N Y N Y WAR - M - R Redeploy - * Y N N N XML M - - - Redeploy - * Y N N Y DIR Y - - M None - * Y N N Y XML M - - Y Redeploy - * Y N Y N EXT Y - M - Reload if WAR - * Y N Y N XML M - Y - Redeploy - * Y N Y Y DIR Y - Y M None - * Y N Y Y EXT Y - M R Reload - * Y N Y Y XML M - Y Y Redeploy - * Y Y N N WAR Y M - - Reload - * Y Y N N XML M Y - - Redeploy - * Y Y N Y DIR Y Y - M None - * Y Y N Y WAR Y M - - Reload - * Y Y N Y XML M Y - Y Redeploy - */ - @Test - public void testModifyDirUpdateDir() throws Exception { - doTestModify(false, false, false, false, true, DIR, - false, false, true, DIR_COOKIE_NAME, NONE); - } + protected void doTestDelete(boolean startXml, boolean startExternalWar, + boolean startExternalDir, boolean startWar, boolean startDir, + int toDelete, boolean resultXml, boolean resultWar, + boolean resultDir, String resultCookieName) throws Exception { - @Test - public void testModifyWarUpdateWar() throws Exception { - doTestModify(false, false, false, true, false, WAR, - false, true, false, WAR_COOKIE_NAME, REDEPLOY); - } + Tomcat tomcat = getTomcatInstance(); + StandardHost host = (StandardHost) tomcat.getHost(); - @Test - public void testModifyWarDirUpdateDir() throws Exception { - // DIR_COOKIE_NAME since Tomcat is going to assume DIR is expanded WAR - doTestModify(false, false, false, true, true, DIR, - false, true, true, DIR_COOKIE_NAME, NONE); - } + // Init + File xml = null; + File ext = null; + File war = null; + File dir = null; - @Test - public void testModifyWarDirUpdateWar() throws Exception { - doTestModify(false, false, false, true, true, WAR, - false, true, true, WAR_COOKIE_NAME, REDEPLOY); - } + if (startXml && !startExternalWar && !startExternalDir) { + xml = createXmlInConfigBaseForAppbase(); + } + if (startExternalWar) { + ext = createWar(WAR_XML_SOURCE, false); + xml = createXmlInConfigBaseForExternal(ext); + } + if (startExternalDir) { + ext = createDirInExternal(true); + xml = createXmlInConfigBaseForExternal(ext); + } + if (startWar) { + war = createWar(WAR_XML_SOURCE, true); + } + if (startDir) { + dir = createDirInAppbase(true); + } - @Test - public void testModifyXmlUpdateXml() throws Exception { - doTestModify(true, false, false, false, false, XML, - true, false, false, XML_COOKIE_NAME, REDEPLOY, - LifecycleState.FAILED); - } + if ((startWar || startExternalWar) && !startDir) { + host.setUnpackWARs(false); + } - @Test - public void testModifyXmlDirUpdateDir() throws Exception { - doTestModify(true, false, false, false, true, DIR, - true, false, true, XML_COOKIE_NAME, NONE); - } + // Deploy the files we copied + tomcat.start(); + host.backgroundProcess(); - @Test - public void testModifyXmlDirUpdateXml() throws Exception { - doTestModify(true, false, false, false, true, XML, - true, false, true, XML_COOKIE_NAME, REDEPLOY); - } + // Remove the specified file + switch (toDelete) { + case XML: + ExpandWar.delete(xml); + break; + case EXT: + ExpandWar.delete(ext); + break; + case WAR: + ExpandWar.delete(war); + break; + case DIR: + ExpandWar.delete(dir); + break; + default: + Assert.fail(); + } - @Test - public void testModifyXmlExtwarUpdateExtwar() throws Exception { - doTestModify(true, true, false, false, false, EXT, - true, false, false, XML_COOKIE_NAME, RELOAD); - } + // Trigger an auto-deployment cycle + host.backgroundProcess(); - @Test - public void testModifyXmlExtdirUpdateExtdir() throws Exception { - doTestModify(true, false, true, false, false, EXT, - true, false, false, XML_COOKIE_NAME, NONE); - } + Context ctxt = (Context) host.findChild(APP_NAME.getName()); - @Test - public void testModifyXmlExtwarUpdateXml() throws Exception { - doTestModify(true, true, false, false, false, XML, - true, false, false, XML_COOKIE_NAME, REDEPLOY); - } + // Check the results + // External WAR and DIR should only be deleted if the test is testing + // behaviour when the external resource is deleted + if (toDelete == EXT) { + if (ext == null) { + Assert.fail(); + } else { + Assert.assertFalse(ext.exists()); + } + } else { + if (startExternalWar) { + if (ext == null) { + Assert.fail(); + } else { + Assert.assertTrue(ext.isFile()); + } + } + if (startExternalDir) { + if (ext == null) { + Assert.fail(); + } else { + Assert.assertTrue(ext.isDirectory()); + } + } + } - @Test - public void testModifyXmlExtdirUpdateXml() throws Exception { - doTestModify(true, false, true, false, false, XML, - true, false, false, XML_COOKIE_NAME, REDEPLOY); - } + if (resultXml) { + if (xml == null) { + Assert.fail(); + } else { + Assert.assertTrue(xml.isFile()); + } + } + if (resultWar) { + if (war == null) { + Assert.fail(); + } else { + Assert.assertTrue(war.isFile()); + } + } + if (resultDir) { + if (dir == null) { + Assert.fail(); + } else { + Assert.assertTrue(dir.isDirectory()); + } + } - @Test - public void testModifyXmlExtwarDirUpdateDir() throws Exception { - doTestModify(true, true, false, false, true, DIR, - true, false, false, XML_COOKIE_NAME, NONE); - } + if (!resultXml && (startExternalWar || startExternalDir)) { + Assert.assertNull(ctxt); + } + if (!resultWar && !resultDir) { + if (resultXml) { + Assert.assertNotNull(ctxt); + Assert.assertEquals(LifecycleState.FAILED, ctxt.getState()); + } else { + Assert.assertNull(ctxt); + } + } - @Test - public void testModifyXmlExtwarDirUpdateExt() throws Exception { - doTestModify(true, true, false, false, true, EXT, - true, false, true, XML_COOKIE_NAME, RELOAD); + if (ctxt != null) { + Assert.assertEquals(resultCookieName, ctxt.getSessionCookieName()); + } } - @Test - public void testModifyXmlExtwarDirUpdateXml() throws Exception { - doTestModify(true, true, false, false, true, XML, - true, false, false, XML_COOKIE_NAME, REDEPLOY); - } - @Test - public void testModifyXmlWarUpdateWar() throws Exception { - doTestModify(true, false, false, true, false, WAR, - true, true, false, XML_COOKIE_NAME, RELOAD); - } + protected void doTestDeployment(boolean deployXML, boolean copyXML, + boolean unpackWARs, LifecycleState resultState, String cookieName, + boolean resultXml, boolean resultWar, boolean resultDir) + throws Exception { - @Test - public void testModifyXmlWarUpdateXml() throws Exception { - doTestModify(true, false, false, true, false, XML, - true, true, false, XML_COOKIE_NAME, REDEPLOY); - } + Tomcat tomcat = getTomcatInstance(); - @Test - public void testModifyXmlWarDirUpdateDir() throws Exception { - doTestModify(true, false, false, true, true, DIR, - true, true, true, XML_COOKIE_NAME, NONE); - } + // Start the instance + tomcat.start(); - @Test - public void testModifyXmlWarDirUpdateWar() throws Exception { - doTestModify(true, false, false, true, true, WAR, - true, true, true, XML_COOKIE_NAME, RELOAD); - } + // Set the attributes + StandardHost host = (StandardHost) tomcat.getHost(); + host.setDeployXML(deployXML); + host.setCopyXML(copyXML); + host.setUnpackWARs(unpackWARs); + + // Trigger automatic deployment + host.backgroundProcess(); + + // Test the results + Context ctxt = (Context) tomcat.getHost().findChild(APP_NAME.getPath()); + if (resultState == null) { + Assert.assertNull(ctxt); + } else { + Assert.assertNotNull(ctxt); + Assert.assertEquals(resultState, ctxt.getState()); + Assert.assertEquals(cookieName, ctxt.getSessionCookieName()); + } + + File xml = new File( + host.getConfigBaseFile(), APP_NAME.getBaseName() + ".xml"); + Assert.assertEquals( + Boolean.valueOf(resultXml), Boolean.valueOf(xml.isFile())); - @Test - public void testModifyXmlWarDirUpdateXml() throws Exception { - doTestModify(true, false, false, true, true, XML, - true, true, true, XML_COOKIE_NAME, REDEPLOY); + File war = new File( + host.getAppBaseFile(), APP_NAME.getBaseName() + ".war"); + Assert.assertEquals( + Boolean.valueOf(resultWar), Boolean.valueOf(war.isFile())); + + File dir = new File(host.getAppBase(), APP_NAME.getBaseName()); + Assert.assertEquals( + Boolean.valueOf(resultDir), Boolean.valueOf(dir.isDirectory())); } - private void doTestModify(boolean startXml, boolean startExternalWar, + + protected void doTestModify(boolean startXml, boolean startExternalWar, boolean startExternalDir, boolean startWar, boolean startDir, int toModify, boolean resultXml, boolean resultWar, boolean resultDir, String resultCookieName, int resultAction) @@ -260,7 +276,8 @@ private void doTestModify(boolean startXml, boolean startExternalWar, resultCookieName, resultAction, LifecycleState.STARTED); } - private void doTestModify(boolean startXml, boolean startExternalWar, + + protected void doTestModify(boolean startXml, boolean startExternalWar, boolean startExternalDir, boolean startWar, boolean startDir, int toModify, boolean resultXml, boolean resultWar, boolean resultDir, String resultCookieName, int resultAction, @@ -416,161 +433,7 @@ private void doTestModify(boolean startXml, boolean startExternalWar, } - /* - * Expected behaviour for the addition of files. - * - * Artifacts present copyXML deployXML Artifact Artifacts remaining - * XML WAR EXT DIR Added XML WAR EXT DIR Action - * N Y N N N Y DIR - Y - A None - * N N N Y N Y WAR - A - R Redeploy - * Y N N N N Y DIR Y - - A None - * N N N Y N Y XML A - - Y Redeploy - * Y N N N N Y WAR Y A - - Reload - * N Y N N N Y XML A Y - - Redeploy - * Y Y N N N Y DIR Y Y - A None - * Y N N Y N Y WAR Y A - N Reload - * N Y N Y N Y XML A Y - Y Redeploy - * Y N Y N N Y DIR Y - Y A None - * Y N Y N N Y WAR Y A Y - None - * N N N Y N Y EXT A - A R Redeploy - * N Y N N N Y EXT A Y A - Redeploy - * - * N N N Y Y/N N DIR+XML - - - Y Redeploy (failed) - * N N N Y Y Y DIR+XML A - - Y Redeploy - * N N N Y N Y DIR+XML - - - Y Redeploy - * - * Addition of a file is treated as if the added file has been modified - * with the following additional actions: - * - If a WAR is added, any DIR is removed and may be recreated depending on - * unpackWARs. - * - If an XML file is added that refers to an external docBase any WAR or - * DIR in the appBase will be removed. The DIR may be recreated if the - * external resource is a WAR and unpackWARs is true. - * - If a DIR is added when a WAR already exists and unpackWARs is false, - * the DIR will be ignored but a warning will be logged when the DIR is - * first detected. If the WAR is removed, the DIR will be left and may be - * deployed via automatic deployment. - * - If a WAR is added when an external WAR already exists for the same - * context, the WAR will be treated the same way as a DIR is treated in - * the previous bullet point. - */ - @Test - public void testAdditionWarAddDir() throws Exception { - doTestAddition(false, false, false, true, false, DIR, - false, true, true, WAR_COOKIE_NAME, NONE); - } - - @Test - public void testAdditionDirAddWar() throws Exception { - doTestAddition(false, false, false, false, true, WAR, - false, true, true, WAR_COOKIE_NAME, REDEPLOY); - } - - @Test - public void testAdditionXmlAddDir() throws Exception { - doTestAddition(true, false, false, false, false, DIR, - true, false, true, XML_COOKIE_NAME, NONE); - } - - @Test - public void testAdditionDirAddXml() throws Exception { - doTestAddition(false, false, false, false, true, XML, - true, false, true, XML_COOKIE_NAME, REDEPLOY); - } - - @Test - public void testAdditionXmlAddWar() throws Exception { - doTestAddition(true, false, false, false, false, WAR, - true, true, false, XML_COOKIE_NAME, RELOAD); - } - - @Test - public void testAdditionWarAddXml() throws Exception { - doTestAddition(false, false, false, true, false, XML, - true, true, false, XML_COOKIE_NAME, REDEPLOY); - } - - @Test - public void testAdditionXmlWarAddDir() throws Exception { - doTestAddition(true, false, false, true, false, DIR, - true, true, true, XML_COOKIE_NAME, NONE); - } - - @Test - public void testAdditionXmlDirAddWar() throws Exception { - doTestAddition(true, false, false, false, true, WAR, - true, true, false, XML_COOKIE_NAME, RELOAD); - } - - @Test - public void testAdditionWarDirAddXml() throws Exception { - doTestAddition(false, false, false, true, true, XML, - true, true, true, XML_COOKIE_NAME, REDEPLOY); - } - - @Test - public void testAdditionXmlExtwarAddDir() throws Exception { - doTestAddition(true, true, false, false, false, DIR, - true, false, true, XML_COOKIE_NAME, NONE); - } - - @Test - public void testAdditionXmlExtdirAddDir() throws Exception { - doTestAddition(true, false, true, false, false, DIR, - true, false, true, XML_COOKIE_NAME, NONE); - } - - @Test - public void testAdditionXmlExtwarAddWar() throws Exception { - doTestAddition(true, true, false, false, false, WAR, - true, true, false, XML_COOKIE_NAME, NONE); - } - - @Test - public void testAdditionXmlExtdirAddWar() throws Exception { - doTestAddition(true, false, true, false, false, WAR, - true, true, false, XML_COOKIE_NAME, NONE); - } - - @Test - public void testAdditionDirAddXmlExtwar() throws Exception { - doTestAddition(false, false, false, false, true, EXT, - true, false, true, XML_COOKIE_NAME, REDEPLOY); - } - - @Test - public void testAdditionWarAddXmlExtwar() throws Exception { - doTestAddition(false, false, false, true, false, EXT, - true, true, false, XML_COOKIE_NAME, REDEPLOY); - } - - @Test - public void testAdditionDirAddDirXmlTF() throws Exception { - doTestAddition(false, false, false, false, true, true, false, DIR_XML, - false, false, true, null, REDEPLOY, LifecycleState.FAILED); - } - - @Test - public void testAdditionDirAddDirXmlFF() throws Exception { - doTestAddition(false, false, false, false, true, false, false, DIR_XML, - false, false, true, null, REDEPLOY, LifecycleState.FAILED); - } - - @Test - public void testAdditionDirAddDirXmlTT() throws Exception { - doTestAddition(false, false, false, false, true, true, true, DIR_XML, - true, false, true, DIR_COOKIE_NAME, REDEPLOY, - LifecycleState.STARTED); - } - - @Test - public void testAdditionDirAddDirXmlFT() throws Exception { - doTestAddition(false, false, false, false, true, false, true, DIR_XML, - false, false, true, DIR_COOKIE_NAME, REDEPLOY, - LifecycleState.STARTED); - } - - private void doTestAddition(boolean startXml, boolean startExternalWar, + protected void doTestAddition(boolean startXml, boolean startExternalWar, boolean startExternalDir, boolean startWar, boolean startDir, int toAdd, boolean resultXml, boolean resultWar, boolean resultDir, String resultCookieName, int resultAction) @@ -581,7 +444,8 @@ private void doTestAddition(boolean startXml, boolean startExternalWar, resultCookieName, resultAction, LifecycleState.STARTED); } - private void doTestAddition(boolean startXml, boolean startExternalWar, + + protected void doTestAddition(boolean startXml, boolean startExternalWar, boolean startExternalDir, boolean startWar, boolean startDir, boolean copyXML, boolean deployXML, int toAdd, boolean resultXml, boolean resultWar, boolean resultDir, String resultCookieName, @@ -741,52 +605,32 @@ private void doTestAddition(boolean startXml, boolean startExternalWar, } - /* - * Test context unpackWAR setting. - * If context.getUnpackWAR != Host.getUnpackWARs the Host wins. - */ - @Test - public void testUnpackWARFFF() throws Exception { - doTestUnpackWAR(false, false, false, false); - } + protected void doTestBrokenAppWithAntiLocking(boolean unpackWARs) + throws Exception { - @Test - public void testUnpackWARFFT() throws Exception { - doTestUnpackWAR(false, false, true, false); - } + Tomcat tomcat = getTomcatInstance(); + StandardHost host = (StandardHost) tomcat.getHost(); - @Test - public void testUnpackWARFTF() throws Exception { - doTestUnpackWAR(false, true, false, false); - } + host.setUnpackWARs(unpackWARs); - @Test - public void testUnpackWARFTT() throws Exception { - doTestUnpackWAR(false, true, true, false); - } + File war = createWar(WAR_BROKEN_SOURCE, false); + createXmlInConfigBaseForExternal(war, true); - @Test - public void testUnpackWARTFF() throws Exception { - doTestUnpackWAR(true, false, false, false); - } + File dir = new File(host.getAppBaseFile(), APP_NAME.getBaseName()); - @Test - public void testUnpackWARTFT() throws Exception { - // External WAR - therefore XML in WAR will be ignored - doTestUnpackWAR(true, false, true, true); - } + tomcat.start(); - @Test - public void testUnpackWARTTF() throws Exception { - doTestUnpackWAR(true, true, false, true); - } + // Simulate deploy on start-up + tomcat.getHost().backgroundProcess(); - @Test - public void testUnpackWARTTT() throws Exception { - doTestUnpackWAR(true, true, true, true); + Assert.assertTrue(war.isFile()); + if (unpackWARs) { + Assert.assertTrue(dir.isDirectory()); + } } - private void doTestUnpackWAR(boolean unpackWARs, boolean unpackWAR, + + protected void doTestUnpackWAR(boolean unpackWARs, boolean unpackWAR, boolean external, boolean resultDir) throws Exception { Tomcat tomcat = getTomcatInstance(); @@ -814,41 +658,80 @@ private void doTestUnpackWAR(boolean unpackWARs, boolean unpackWAR, } - @Test - public void testBrokenAppWithAntiLockingF() throws Exception { - testBrokenAppWithAntiLocking(false); - } + protected 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); + } - @Test - public void testBrokenAppWithAntiLockingT() throws Exception { - testBrokenAppWithAntiLocking(true); + 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()); + } } - private void testBrokenAppWithAntiLocking(boolean unpackWARs) - throws Exception { + protected void doTestUpdateWarOffline(File srcWar, boolean deployOnStartUp, boolean autoDeploy) + throws Exception { Tomcat tomcat = getTomcatInstance(); StandardHost host = (StandardHost) tomcat.getHost(); + host.setDeployOnStartup(deployOnStartUp); - host.setUnpackWARs(unpackWARs); - - File war = createWar(WAR_BROKEN_SOURCE, false); - createXmlInConfigBaseForExternal(war, true); - - File dir = new File(host.getAppBaseFile(), APP_NAME.getBaseName()); + File war = createWar(srcWar, true); + // Make the WAR appear to have been created earlier + Assert.assertTrue("Failed to set last modified for [" + war + "]", war.setLastModified( + war.lastModified() - 2 * HostConfig.FILE_MODIFICATION_RESOLUTION_MS)); + tomcat.addWebapp(APP_NAME.getPath(), war.getAbsolutePath()); tomcat.start(); - // Simulate deploy on start-up - tomcat.getHost().backgroundProcess(); + // Get the last modified timestamp for the expanded dir + File dir = new File(host.getAppBase(), APP_NAME.getBaseName()); + // Make the DIR appear to have been created earlier + long lastModified = war.lastModified() - 2 * HostConfig.FILE_MODIFICATION_RESOLUTION_MS; + Assert.assertTrue("Failed to set last modified for [" + dir + "]", + dir.setLastModified(lastModified)); - Assert.assertTrue(war.isFile()); - if (unpackWARs) { - Assert.assertTrue(dir.isDirectory()); + host.stop(); + Assert.assertTrue("Failed to set last modified for [" + war + "]", + war.setLastModified(System.currentTimeMillis())); + host.start(); + if (autoDeploy) { + host.backgroundProcess(); } + + long newLastModified = dir.lastModified(); + + Assert.assertNotEquals("Timestamp hasn't changed", lastModified, newLastModified); } - private File createDirInAppbase(boolean withXml) throws IOException { + + protected File createDirInAppbase(boolean withXml) throws IOException { File dir = new File(getTomcatInstance().getHost().getAppBaseFile(), APP_NAME.getBaseName()); if (withXml) { @@ -859,14 +742,16 @@ private File createDirInAppbase(boolean withXml) throws IOException { return dir; } - private File createDirXmlInAppbase() throws IOException { + + protected File createDirXmlInAppbase() throws IOException { File dir = new File(getTomcatInstance().getHost().getAppBaseFile(), APP_NAME.getBaseName() + "/META-INF"); recursiveCopy(DIR_XML_SOURCE_META_INF.toPath(), dir.toPath()); return dir; } - private File createDirInExternal(boolean withXml) throws IOException { + + protected File createDirInExternal(boolean withXml) throws IOException { File ext = new File(external, "external" + ".war"); if (withXml) { recursiveCopy(DIR_XML_SOURCE.toPath(), ext.toPath()); @@ -876,7 +761,8 @@ private File createDirInExternal(boolean withXml) throws IOException { return ext; } - private File createWar(File src, boolean useAppbase) throws IOException { + + protected File createWar(File src, boolean useAppbase) throws IOException { File dest; if (useAppbase) { dest = new File(getTomcatInstance().getHost().getAppBaseFile(), @@ -891,7 +777,8 @@ private File createWar(File src, boolean useAppbase) throws IOException { return dest; } - private File createXmlInConfigBaseForAppbase() throws IOException { + + protected File createXmlInConfigBaseForAppbase() throws IOException { File xml = getXmlInConfigBaseForAppbase(); File parent = xml.getParentFile(); if (!parent.isDirectory()) { @@ -904,16 +791,19 @@ private File createXmlInConfigBaseForAppbase() throws IOException { return xml; } - private File getXmlInConfigBaseForAppbase() { + + protected File getXmlInConfigBaseForAppbase() { Host host = getTomcatInstance().getHost(); return new File(host.getConfigBaseFile(), APP_NAME + ".xml"); } - private File createXmlInConfigBaseForExternal(File ext) throws IOException { + + protected File createXmlInConfigBaseForExternal(File ext) throws IOException { return createXmlInConfigBaseForExternal(ext, false); } - private File createXmlInConfigBaseForExternal(File ext, boolean antiLocking) + + protected File createXmlInConfigBaseForExternal(File ext, boolean antiLocking) throws IOException { File xml = new File(getTomcatInstance().getHost().getConfigBaseFile(), APP_NAME + ".xml"); @@ -940,6 +830,7 @@ private File createXmlInConfigBaseForExternal(File ext, boolean antiLocking) return xml; } + private static class StateTracker implements LifecycleListener { private StringBuilder stateHistory = new StringBuilder(); @@ -963,200 +854,7 @@ public String getHistory() { } - /* - * 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()); - } - } - - - @Test - public void testSetContextClassName() throws Exception { - - Tomcat tomcat = getTomcatInstance(); - - Host host = tomcat.getHost(); - if (host instanceof StandardHost) { - StandardHost standardHost = (StandardHost) host; - standardHost.setContextClass(TesterContext.class.getName()); - } - - // Copy the WAR file - File war = new File(host.getAppBaseFile(), - APP_NAME.getBaseName() + ".war"); - Files.copy(WAR_XML_SOURCE.toPath(), war.toPath()); - - // Deploy the copied war - tomcat.start(); - host.backgroundProcess(); - - // Check the Context class - Context ctxt = (Context) host.findChild(APP_NAME.getName()); - - assertThat(ctxt, instanceOf(TesterContext.class)); - } - - public static class TesterContext extends StandardContext { // No functional change } - - - @Test - public void testUpdateWarOfflineNoContextFF() throws Exception { - doTestUpdateWarOffline(WAR_SOURCE, false, false); - } - - - @Test - public void testUpdateWarOfflineNoContextTF() throws Exception { - doTestUpdateWarOffline(WAR_SOURCE, true, false); - } - - - @Test - public void testUpdateWarOfflineNoContextFT() throws Exception { - doTestUpdateWarOffline(WAR_SOURCE, false, true); - } - - - @Test - public void testUpdateWarOfflineNoContextTT() throws Exception { - doTestUpdateWarOffline(WAR_SOURCE, true, true); - } - - - @Test - public void testUpdateWarOfflineContextFF() throws Exception { - doTestUpdateWarOffline(WAR_XML_SOURCE, false, false); - } - - - @Test - public void testUpdateWarOfflineContextTF() throws Exception { - doTestUpdateWarOffline(WAR_XML_SOURCE, true, false); - } - - - @Test - public void testUpdateWarOfflineContextFT() throws Exception { - doTestUpdateWarOffline(WAR_XML_SOURCE, false, true); - } - - - @Test - public void testUpdateWarOfflineContextTT() throws Exception { - doTestUpdateWarOffline(WAR_XML_SOURCE, true, true); - } - - - private void doTestUpdateWarOffline(File srcWar, boolean deployOnStartUp, boolean autoDeploy) - throws Exception { - Tomcat tomcat = getTomcatInstance(); - StandardHost host = (StandardHost) tomcat.getHost(); - host.setDeployOnStartup(deployOnStartUp); - - File war = createWar(srcWar, true); - // Make the WAR appear to have been created earlier - Assert.assertTrue("Failed to set last modified for [" + war + "]", war.setLastModified( - war.lastModified() - 2 * HostConfig.FILE_MODIFICATION_RESOLUTION_MS)); - - tomcat.addWebapp(APP_NAME.getPath(), war.getAbsolutePath()); - tomcat.start(); - - // Get the last modified timestamp for the expanded dir - File dir = new File(host.getAppBase(), APP_NAME.getBaseName()); - // Make the DIR appear to have been created earlier - long lastModified = war.lastModified() - 2 * HostConfig.FILE_MODIFICATION_RESOLUTION_MS; - Assert.assertTrue("Failed to set last modified for [" + dir + "]", - dir.setLastModified(lastModified)); - - host.stop(); - Assert.assertTrue("Failed to set last modified for [" + war + "]", - war.setLastModified(System.currentTimeMillis())); - host.start(); - if (autoDeploy) { - host.backgroundProcess(); - } - - long newLastModified = dir.lastModified(); - - Assert.assertNotEquals("Timestamp hasn't changed", lastModified, newLastModified); - } } diff --git a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentA.java b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentA.java deleted file mode 100644 index 60f9dd78f562..000000000000 --- a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentA.java +++ /dev/null @@ -1,482 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.catalina.startup; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; - -import org.junit.Assert; -import org.junit.Test; - -import org.apache.catalina.Context; -import org.apache.catalina.Host; -import org.apache.catalina.LifecycleState; -import org.apache.catalina.core.StandardContext; -import org.apache.catalina.core.StandardHost; -import org.apache.catalina.util.ContextName; - -/** - * The purpose of this class is to test the automatic deployment features of the - * {@link HostConfig} implementation. - */ -public class TestHostConfigAutomaticDeploymentA extends TomcatBaseTest { - - private static final ContextName APP_NAME = new ContextName("myapp", false); - private static final File XML_SOURCE = - new File("test/deployment/context.xml"); - private static final File WAR_XML_SOURCE = - new File("test/deployment/context.war"); - private static final File DIR_XML_SOURCE = - new File("test/deployment/dirContext"); - private static final File DIR_SOURCE = - new File("test/deployment/dirNoContext"); - - private static final int XML = 1; - private static final int EXT = 2; - private static final int WAR = 3; - private static final int DIR = 4; - - private static final String XML_COOKIE_NAME = "XML_CONTEXT"; - private static final String WAR_COOKIE_NAME = "WAR_CONTEXT"; - private static final String DIR_COOKIE_NAME = "DIR_CONTEXT"; - // private static final String DEFAULT_COOKIE_NAME = "JSESSIONID"; - - private File external; - - @Override - public void setUp() throws Exception { - super.setUp(); - - Tomcat tomcat = getTomcatInstance(); - - external = new File(getTemporaryDirectory(), "external"); - if (!external.exists() && !external.mkdir()) { - Assert.fail("Unable to create external for test"); - } - - // Disable background thread - tomcat.getEngine().setBackgroundProcessorDelay(-1); - - // Enable deployer - tomcat.getHost().addLifecycleListener(new HostConfig()); - - // Disable deployment on start up - tomcat.getHost().setDeployOnStartup(false); - - // Clean-up after test - addDeleteOnTearDown(new File(tomcat.basedir, "/conf")); - addDeleteOnTearDown(external); - } - - - /* - * Expected behaviour for the deletion of files. - * - * Artifacts present Artifact Artifacts remaining - * XML WAR EXT DIR Removed XML WAR EXT DIR Notes - * N N N Y DIR - - - N - * N Y N N WAR - N - - - * N Y N Y DIR - Y - R 1 - * N Y N Y WAR - N - N - * Y N N N XML N - - - - * Y N N Y DIR N - - N - * Y N N Y XML R - - Y 2 - * Y N Y N EXT Y - N - - * Y N Y N XML N - Y - - * Y N Y Y DIR R - Y R 1,2 - * Y N Y Y EXT Y - N N - * Y N Y Y XML N - Y N - * Y Y N N WAR N N - - - * Y Y N N XML N N - - - * Y Y N Y DIR R Y - R 1,2 - * Y Y N Y WAR N N - - - * Y Y N Y XML R Y - Y - * - * Notes: 1. The DIR will be re-created since unpackWARs is true. - * 2. The XML will be extracted from the WAR/DIR if deployXML and - * copyXML are true. - */ - @Test - public void testDeleteDirRemoveDir() throws Exception { - doTestDelete(false, false, false, false, true, DIR, false, false, false, - null); - } - - @Test - public void testDeleteWarRemoveWar() throws Exception { - doTestDelete(false, false, false, true, false, WAR, false, false, false, - null); - } - - @Test - public void testDeleteWarDirRemoveDir() throws Exception { - doTestDelete(false, false, false, true, true, DIR, false, true, true, - WAR_COOKIE_NAME); - } - - @Test - public void testDeleteWarDirRemoveWar() throws Exception { - doTestDelete(false, false, false, true, true, WAR, false, false, false, - null); - } - - @Test - public void testDeleteXmlRemoveXml() throws Exception { - doTestDelete(true, false, false, false, false, XML, false, false, false, - null); - } - - @Test - public void testDeleteXmlDirRemoveDir() throws Exception { - doTestDelete(true, false, false, false, true, DIR, false, false, false, - null); - } - - @Test - public void testDeleteXmlDirRemoveXml() throws Exception { - doTestDelete(true, false, false, false, true, XML, false, false, true, - DIR_COOKIE_NAME); - } - - @Test - public void testDeleteXmlDirRemoveXmlCopyXml() throws Exception { - ((StandardHost) getTomcatInstance().getHost()).setCopyXML(true); - doTestDelete(true, false, false, false, true, XML, true, false, true, - DIR_COOKIE_NAME); - } - - @Test - public void testDeleteXmlExtwarRemoveExt() throws Exception { - doTestDelete(true, true, false, false, false, EXT, true, false, false, - XML_COOKIE_NAME); - } - - @Test - public void testDeleteXmlExtdirRemoveExt() throws Exception { - doTestDelete(true, false, true, false, false, EXT, true, false, false, - XML_COOKIE_NAME); - } - - @Test - public void testDeleteXmlExtwarRemoveXml() throws Exception { - doTestDelete(true, true, false, false, false, XML, false, false, false, - null); - } - - @Test - public void testDeleteXmlExtdirRemoveXml() throws Exception { - doTestDelete(true, false, true, false, false, XML, false, false, false, - null); - } - - @Test - public void testDeleteXmlExtwarDirRemoveDir() throws Exception { - doTestDelete(true, true, false, false, true, DIR, true, false, true, - XML_COOKIE_NAME); - } - - @Test - public void testDeleteXmlExtwarDirRemoveExt() throws Exception { - doTestDelete(true, true, false, false, true, EXT, true, false, false, - XML_COOKIE_NAME); - } - - @Test - public void testDeleteXmlExtwarDirRemoveXml() throws Exception { - doTestDelete(true, true, false, false, true, XML, false, false, false, - null); - } - - @Test - public void testDeleteXmlWarRemoveWar() throws Exception { - doTestDelete(true, false, false, true, false, WAR, false, false, false, - null); - } - - @Test - public void testDeleteXmlWarRemoveXml() throws Exception { - doTestDelete(true, false, false, true, false, XML, false, true, false, - WAR_COOKIE_NAME); - } - - @Test - public void testDeleteXmlWarRemoveXmlCopyXml() throws Exception { - ((StandardHost) getTomcatInstance().getHost()).setCopyXML(true); - doTestDelete(true, false, false, true, false, XML, true, true, false, - WAR_COOKIE_NAME); - } - - @Test - public void testDeleteXmlWarDirRemoveDir() throws Exception { - doTestDelete(true, false, false, true, true, DIR, false, true, true, - WAR_COOKIE_NAME); - } - - @Test - public void testDeleteXmlWarDirRemoveDirCopyXml() throws Exception { - ((StandardHost) getTomcatInstance().getHost()).setCopyXML(true); - doTestDelete(true, false, false, true, true, DIR, true, true, true, - WAR_COOKIE_NAME); - } - - @Test - public void testDeleteXmlWarDirRemoveWar() throws Exception { - doTestDelete(true, false, false, true, true, WAR, false, false, false, - null); - } - - @Test - public void testDeleteXmlWarDirRemoveWarCopyXml() throws Exception { - ((StandardHost) getTomcatInstance().getHost()).setCopyXML(true); - doTestDelete(true, false, false, true, true, WAR, false, false, false, - null); - } - - @Test - public void testDeleteXmlWarDirRemoveXml() throws Exception { - doTestDelete(true, false, false, true, true, XML, false, true, true, - DIR_COOKIE_NAME); - } - - @Test - public void testDeleteXmlWarDirRemoveXmlCopyXml() throws Exception { - ((StandardHost) getTomcatInstance().getHost()).setCopyXML(true); - doTestDelete(true, false, false, true, true, XML, true, true, true, - WAR_COOKIE_NAME); - } - - private void doTestDelete(boolean startXml, boolean startExternalWar, - boolean startExternalDir, boolean startWar, boolean startDir, - int toDelete, boolean resultXml, boolean resultWar, - boolean resultDir, String resultCookieName) throws Exception { - - Tomcat tomcat = getTomcatInstance(); - StandardHost host = (StandardHost) tomcat.getHost(); - - // Init - File xml = null; - File ext = null; - File war = null; - File dir = null; - - if (startXml && !startExternalWar && !startExternalDir) { - xml = createXmlInConfigBaseForAppbase(); - } - if (startExternalWar) { - ext = createWar(WAR_XML_SOURCE, false); - xml = createXmlInConfigBaseForExternal(ext); - } - if (startExternalDir) { - ext = createDirInExternal(true); - xml = createXmlInConfigBaseForExternal(ext); - } - if (startWar) { - war = createWar(WAR_XML_SOURCE, true); - } - if (startDir) { - dir = createDirInAppbase(true); - } - - if ((startWar || startExternalWar) && !startDir) { - host.setUnpackWARs(false); - } - - // Deploy the files we copied - tomcat.start(); - host.backgroundProcess(); - - // Remove the specified file - switch (toDelete) { - case XML: - ExpandWar.delete(xml); - break; - case EXT: - ExpandWar.delete(ext); - break; - case WAR: - ExpandWar.delete(war); - break; - case DIR: - ExpandWar.delete(dir); - break; - default: - Assert.fail(); - } - - // Trigger an auto-deployment cycle - host.backgroundProcess(); - - Context ctxt = (Context) host.findChild(APP_NAME.getName()); - - // Check the results - // External WAR and DIR should only be deleted if the test is testing - // behaviour when the external resource is deleted - if (toDelete == EXT) { - if (ext == null) { - Assert.fail(); - } else { - Assert.assertFalse(ext.exists()); - } - } else { - if (startExternalWar) { - if (ext == null) { - Assert.fail(); - } else { - Assert.assertTrue(ext.isFile()); - } - } - if (startExternalDir) { - if (ext == null) { - Assert.fail(); - } else { - Assert.assertTrue(ext.isDirectory()); - } - } - } - - if (resultXml) { - if (xml == null) { - Assert.fail(); - } else { - Assert.assertTrue(xml.isFile()); - } - } - if (resultWar) { - if (war == null) { - Assert.fail(); - } else { - Assert.assertTrue(war.isFile()); - } - } - if (resultDir) { - if (dir == null) { - Assert.fail(); - } else { - Assert.assertTrue(dir.isDirectory()); - } - } - - if (!resultXml && (startExternalWar || startExternalDir)) { - Assert.assertNull(ctxt); - } - if (!resultWar && !resultDir) { - if (resultXml) { - Assert.assertNotNull(ctxt); - Assert.assertEquals(LifecycleState.FAILED, ctxt.getState()); - } else { - Assert.assertNull(ctxt); - } - } - - if (ctxt != null) { - Assert.assertEquals(resultCookieName, ctxt.getSessionCookieName()); - } - } - - - private File createDirInAppbase(boolean withXml) throws IOException { - File dir = new File(getTomcatInstance().getHost().getAppBaseFile(), - APP_NAME.getBaseName()); - if (withXml) { - recursiveCopy(DIR_XML_SOURCE.toPath(), dir.toPath()); - } else { - recursiveCopy(DIR_SOURCE.toPath(), dir.toPath()); - } - return dir; - } - - private File createDirInExternal(boolean withXml) throws IOException { - File ext = new File(external, "external" + ".war"); - if (withXml) { - recursiveCopy(DIR_XML_SOURCE.toPath(), ext.toPath()); - } else { - recursiveCopy(DIR_SOURCE.toPath(), ext.toPath()); - } - return ext; - } - - private File createWar(File src, boolean useAppbase) throws IOException { - File dest; - if (useAppbase) { - dest = new File(getTomcatInstance().getHost().getAppBaseFile(), - APP_NAME.getBaseName() + ".war"); - } else { - dest = new File(external, "external" + ".war"); - } - Files.copy(src.toPath(), dest.toPath()); - // Make sure that HostConfig thinks the WAR has been modified. - Assert.assertTrue("Failed to set last modified for [" + dest + "]", dest.setLastModified( - System.currentTimeMillis() - 2 * HostConfig.FILE_MODIFICATION_RESOLUTION_MS)); - return dest; - } - - private File createXmlInConfigBaseForAppbase() throws IOException { - File xml = getXmlInConfigBaseForAppbase(); - File parent = xml.getParentFile(); - if (!parent.isDirectory()) { - Assert.assertTrue(parent.mkdirs()); - } - Files.copy(XML_SOURCE.toPath(), xml.toPath()); - // Make sure that HostConfig thinks the xml has been modified. - Assert.assertTrue("Failed to set last modified for [" + xml + "]", xml.setLastModified( - System.currentTimeMillis() - 2 * HostConfig.FILE_MODIFICATION_RESOLUTION_MS)); - return xml; - } - - private File getXmlInConfigBaseForAppbase() { - Host host = getTomcatInstance().getHost(); - return new File(host.getConfigBaseFile(), APP_NAME + ".xml"); - } - - private File createXmlInConfigBaseForExternal(File ext) throws IOException { - return createXmlInConfigBaseForExternal(ext, false); - } - - private File createXmlInConfigBaseForExternal(File ext, boolean antiLocking) - throws IOException { - File xml = new File(getTomcatInstance().getHost().getConfigBaseFile(), - APP_NAME + ".xml"); - File parent = xml.getParentFile(); - if (!parent.isDirectory()) { - Assert.assertTrue(parent.mkdirs()); - } - - try (FileOutputStream fos = new FileOutputStream(xml)) { - StringBuilder context = new StringBuilder(); - context.append(""); - fos.write(context.toString().getBytes(StandardCharsets.ISO_8859_1)); - } - // Make sure that HostConfig thinks the xml has been modified. - Assert.assertTrue("Failed to set last modified for [" + xml + "]", xml.setLastModified( - System.currentTimeMillis() - 2 * HostConfig.FILE_MODIFICATION_RESOLUTION_MS)); - return xml; - } - - public static class TesterContext extends StandardContext { - // No functional change - } -} diff --git a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentAddition.java b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentAddition.java new file mode 100644 index 000000000000..7b38f42e277b --- /dev/null +++ b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentAddition.java @@ -0,0 +1,182 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.startup; + +import org.junit.Test; + +import org.apache.catalina.LifecycleState; + +/** + * The purpose of this class is to test the automatic deployment features of the + * {@link HostConfig} implementation. + */ +public class TestHostConfigAutomaticDeploymentAddition extends HostConfigAutomaticDeploymentBaseTest { + + /* + * Expected behaviour for the addition of files. + * + * Artifacts present copyXML deployXML Artifact Artifacts remaining + * XML WAR EXT DIR Added XML WAR EXT DIR Action + * N Y N N N Y DIR - Y - A None + * N N N Y N Y WAR - A - R Redeploy + * Y N N N N Y DIR Y - - A None + * N N N Y N Y XML A - - Y Redeploy + * Y N N N N Y WAR Y A - - Reload + * N Y N N N Y XML A Y - - Redeploy + * Y Y N N N Y DIR Y Y - A None + * Y N N Y N Y WAR Y A - N Reload + * N Y N Y N Y XML A Y - Y Redeploy + * Y N Y N N Y DIR Y - Y A None + * Y N Y N N Y WAR Y A Y - None + * N N N Y N Y EXT A - A R Redeploy + * N Y N N N Y EXT A Y A - Redeploy + * + * N N N Y Y/N N DIR+XML - - - Y Redeploy (failed) + * N N N Y Y Y DIR+XML A - - Y Redeploy + * N N N Y N Y DIR+XML - - - Y Redeploy + * + * Addition of a file is treated as if the added file has been modified + * with the following additional actions: + * - If a WAR is added, any DIR is removed and may be recreated depending on + * unpackWARs. + * - If an XML file is added that refers to an external docBase any WAR or + * DIR in the appBase will be removed. The DIR may be recreated if the + * external resource is a WAR and unpackWARs is true. + * - If a DIR is added when a WAR already exists and unpackWARs is false, + * the DIR will be ignored but a warning will be logged when the DIR is + * first detected. If the WAR is removed, the DIR will be left and may be + * deployed via automatic deployment. + * - If a WAR is added when an external WAR already exists for the same + * context, the WAR will be treated the same way as a DIR is treated in + * the previous bullet point. + */ + @Test + public void testAdditionWarAddDir() throws Exception { + doTestAddition(false, false, false, true, false, DIR, + false, true, true, WAR_COOKIE_NAME, NONE); + } + + @Test + public void testAdditionDirAddWar() throws Exception { + doTestAddition(false, false, false, false, true, WAR, + false, true, true, WAR_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testAdditionXmlAddDir() throws Exception { + doTestAddition(true, false, false, false, false, DIR, + true, false, true, XML_COOKIE_NAME, NONE); + } + + @Test + public void testAdditionDirAddXml() throws Exception { + doTestAddition(false, false, false, false, true, XML, + true, false, true, XML_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testAdditionXmlAddWar() throws Exception { + doTestAddition(true, false, false, false, false, WAR, + true, true, false, XML_COOKIE_NAME, RELOAD); + } + + @Test + public void testAdditionWarAddXml() throws Exception { + doTestAddition(false, false, false, true, false, XML, + true, true, false, XML_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testAdditionXmlWarAddDir() throws Exception { + doTestAddition(true, false, false, true, false, DIR, + true, true, true, XML_COOKIE_NAME, NONE); + } + + @Test + public void testAdditionXmlDirAddWar() throws Exception { + doTestAddition(true, false, false, false, true, WAR, + true, true, false, XML_COOKIE_NAME, RELOAD); + } + + @Test + public void testAdditionWarDirAddXml() throws Exception { + doTestAddition(false, false, false, true, true, XML, + true, true, true, XML_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testAdditionXmlExtwarAddDir() throws Exception { + doTestAddition(true, true, false, false, false, DIR, + true, false, true, XML_COOKIE_NAME, NONE); + } + + @Test + public void testAdditionXmlExtdirAddDir() throws Exception { + doTestAddition(true, false, true, false, false, DIR, + true, false, true, XML_COOKIE_NAME, NONE); + } + + @Test + public void testAdditionXmlExtwarAddWar() throws Exception { + doTestAddition(true, true, false, false, false, WAR, + true, true, false, XML_COOKIE_NAME, NONE); + } + + @Test + public void testAdditionXmlExtdirAddWar() throws Exception { + doTestAddition(true, false, true, false, false, WAR, + true, true, false, XML_COOKIE_NAME, NONE); + } + + @Test + public void testAdditionDirAddXmlExtwar() throws Exception { + doTestAddition(false, false, false, false, true, EXT, + true, false, true, XML_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testAdditionWarAddXmlExtwar() throws Exception { + doTestAddition(false, false, false, true, false, EXT, + true, true, false, XML_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testAdditionDirAddDirXmlTF() throws Exception { + doTestAddition(false, false, false, false, true, true, false, DIR_XML, + false, false, true, null, REDEPLOY, LifecycleState.FAILED); + } + + @Test + public void testAdditionDirAddDirXmlFF() throws Exception { + doTestAddition(false, false, false, false, true, false, false, DIR_XML, + false, false, true, null, REDEPLOY, LifecycleState.FAILED); + } + + @Test + public void testAdditionDirAddDirXmlTT() throws Exception { + doTestAddition(false, false, false, false, true, true, true, DIR_XML, + true, false, true, DIR_COOKIE_NAME, REDEPLOY, + LifecycleState.STARTED); + } + + @Test + public void testAdditionDirAddDirXmlFT() throws Exception { + doTestAddition(false, false, false, false, true, false, true, DIR_XML, + false, false, true, DIR_COOKIE_NAME, REDEPLOY, + LifecycleState.STARTED); + } +} diff --git a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentB.java b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentB.java deleted file mode 100644 index b892b194c54f..000000000000 --- a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentB.java +++ /dev/null @@ -1,687 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.catalina.startup; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; - -import org.junit.Assert; -import org.junit.Test; - -import org.apache.catalina.Context; -import org.apache.catalina.Host; -import org.apache.catalina.LifecycleState; -import org.apache.catalina.core.StandardContext; -import org.apache.catalina.core.StandardHost; -import org.apache.catalina.util.ContextName; - -/** - * The purpose of this class is to test the automatic deployment features of the - * {@link HostConfig} implementation. - */ -public class TestHostConfigAutomaticDeploymentB extends TomcatBaseTest { - - private static final ContextName APP_NAME = new ContextName("myapp", false); - private static final File XML_SOURCE = - new File("test/deployment/context.xml"); - private static final File WAR_XML_SOURCE = - new File("test/deployment/context.war"); - private static final File WAR_SOURCE = - new File("test/deployment/noContext.war"); - private static final File DIR_XML_SOURCE = - new File("test/deployment/dirContext"); - private static final File DIR_SOURCE = - new File("test/deployment/dirNoContext"); - - private static final String XML_COOKIE_NAME = "XML_CONTEXT"; - private static final String WAR_COOKIE_NAME = "WAR_CONTEXT"; - private static final String DIR_COOKIE_NAME = "DIR_CONTEXT"; - // private static final String DEFAULT_COOKIE_NAME = "JSESSIONID"; - - private File external; - - @Override - public void setUp() throws Exception { - super.setUp(); - - Tomcat tomcat = getTomcatInstance(); - - external = new File(getTemporaryDirectory(), "external"); - if (!external.exists() && !external.mkdir()) { - Assert.fail("Unable to create external for test"); - } - - // Disable background thread - tomcat.getEngine().setBackgroundProcessorDelay(-1); - - // Enable deployer - tomcat.getHost().addLifecycleListener(new HostConfig()); - - // Disable deployment on start up - tomcat.getHost().setDeployOnStartup(false); - - // Clean-up after test - addDeleteOnTearDown(new File(tomcat.basedir, "/conf")); - addDeleteOnTearDown(external); - } - - - /* - * Expected behaviour for deployment of an XML file. - * deployXML copyXML unpackWARs XML WAR DIR - * Y/N Y/N Y/N Y N N - * - * Note: Context will fail to start because no valid docBase is present. - */ - @Test - public void testDeploymentXmlFFF() throws Exception { - createXmlInConfigBaseForAppbase(); - doTestDeployment(false, false, false, - LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false); - } - - @Test - public void testDeploymentXmlFFT() throws Exception { - createXmlInConfigBaseForAppbase(); - doTestDeployment(false, false, true, - LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false); - } - - @Test - public void testDeploymentXmlFTF() throws Exception { - createXmlInConfigBaseForAppbase(); - doTestDeployment(false, true, false, - LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false); - } - - @Test - public void testDeploymentXmlFTT() throws Exception { - createXmlInConfigBaseForAppbase(); - doTestDeployment(false, true, true, - LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false); - } - - @Test - public void testDeploymentXmlTFF() throws Exception { - createXmlInConfigBaseForAppbase(); - doTestDeployment(true, false, false, - LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false); - } - - @Test - public void testDeploymentXmlTFT() throws Exception { - createXmlInConfigBaseForAppbase(); - doTestDeployment(true, false, true, - LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false); - } - - @Test - public void testDeploymentXmlTTF() throws Exception { - createXmlInConfigBaseForAppbase(); - doTestDeployment(true, true, false, - LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false); - } - - @Test - public void testDeploymentXmlTTT() throws Exception { - createXmlInConfigBaseForAppbase(); - doTestDeployment(true, true, true, - LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false); - } - - - /* - * Expected behaviour for deployment of an XML file that points to an - * external WAR. - * deployXML copyXML unpackWARs XML WAR DIR - * Y/N Y/N Y Y N Y - * Y/N Y/N N Y N N - * - * Notes: No WAR file is present in the appBase because it is an external - * WAR. - * Any context.xml file embedded in the external WAR file is ignored. - */ - @Test - public void testDeploymentXmlExternalWarXmlFFF() throws Exception { - File war = createWar(WAR_XML_SOURCE, false); - createXmlInConfigBaseForExternal(war); - doTestDeployment(false, false, false, - LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); - } - - @Test - public void testDeploymentXmlExternalWarXmlFFT() throws Exception { - File war = createWar(WAR_XML_SOURCE, false); - createXmlInConfigBaseForExternal(war); - doTestDeployment(false, false, true, - LifecycleState.STARTED, XML_COOKIE_NAME, true, false, true); - } - - @Test - public void testDeploymentXmlExternalWarXmlFTF() throws Exception { - File war = createWar(WAR_XML_SOURCE, false); - createXmlInConfigBaseForExternal(war); - doTestDeployment(false, true, false, - LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); - } - - @Test - public void testDeploymentXmlExternalWarXmlFTT() throws Exception { - File war = createWar(WAR_XML_SOURCE, false); - createXmlInConfigBaseForExternal(war); - doTestDeployment(false, true, true, - LifecycleState.STARTED, XML_COOKIE_NAME, true, false, true); - } - - @Test - public void testDeploymentXmlExternalWarXmlTFF() throws Exception { - File war = createWar(WAR_XML_SOURCE, false); - createXmlInConfigBaseForExternal(war); - doTestDeployment(true, false, false, - LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); - } - - @Test - public void testDeploymentXmlExternalWarXmlTFT() throws Exception { - File war = createWar(WAR_XML_SOURCE, false); - createXmlInConfigBaseForExternal(war); - doTestDeployment(true, false, true, - LifecycleState.STARTED, XML_COOKIE_NAME, true, false, true); - } - - @Test - public void testDeploymentXmlExternalWarXmlTTF() throws Exception { - File war = createWar(WAR_XML_SOURCE, false); - createXmlInConfigBaseForExternal(war); - doTestDeployment(true, true, false, - LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); - } - - @Test - public void testDeploymentXmlExternalWarXmlTTT() throws Exception { - File war = createWar(WAR_XML_SOURCE, false); - createXmlInConfigBaseForExternal(war); - doTestDeployment(true, true, true, - LifecycleState.STARTED, XML_COOKIE_NAME, true, false, true); - } - - - /* - * Expected behaviour for deployment of an XML file that points to an - * external DIR. - * deployXML copyXML unpackWARs XML WAR DIR - * Y/N Y/N Y/N Y N N - * - * Notes: Any context.xml file embedded in the external DIR file is ignored. - */ - @Test - public void testDeploymentXmlExternalDirXmlFFF() throws Exception { - File dir = createDirInExternal(true); - createXmlInConfigBaseForExternal(dir); - doTestDeployment(false, false, false, - LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); - } - - @Test - public void testDeploymentXmlExternalDirXmlFFT() throws Exception { - File dir = createDirInExternal(true); - createXmlInConfigBaseForExternal(dir); - doTestDeployment(false, false, true, - LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); - } - - @Test - public void testDeploymentXmlExternalDirXmlFTF() throws Exception { - File dir = createDirInExternal(true); - createXmlInConfigBaseForExternal(dir); - doTestDeployment(false, true, false, - LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); - } - - @Test - public void testDeploymentXmlExternalDirXmlFTT() throws Exception { - File dir = createDirInExternal(true); - createXmlInConfigBaseForExternal(dir); - doTestDeployment(false, true, true, - LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); - } - - @Test - public void testDeploymentXmlExternalDirXmlTFF() throws Exception { - File dir = createDirInExternal(true); - createXmlInConfigBaseForExternal(dir); - doTestDeployment(true, false, false, - LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); - } - - @Test - public void testDeploymentXmlExternalDirXmlTFT() throws Exception { - File dir = createDirInExternal(true); - createXmlInConfigBaseForExternal(dir); - doTestDeployment(true, false, true, - LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); - } - - @Test - public void testDeploymentXmlExternalDirXmlTTF() throws Exception { - File dir = createDirInExternal(true); - createXmlInConfigBaseForExternal(dir); - doTestDeployment(true, true, false, - LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); - } - - @Test - public void testDeploymentXmlExternalDirXmlTTT() throws Exception { - File dir = createDirInExternal(true); - createXmlInConfigBaseForExternal(dir); - doTestDeployment(true, true, true, - LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); - } - - - /* - * Expected behaviour for deployment of a WAR with an embedded XML file. - * deployXML copyXML unpackWARs XML WAR DIR - * N Y/N N N Y N - * N Y/N Y N Y Y - * Y N N N Y N - * Y N Y N Y Y - * Y Y N Y Y N - * Y Y Y Y Y Y - */ - @Test - public void testDeploymentWarXmlFFF() throws Exception { - createWar(WAR_XML_SOURCE, true); - doTestDeployment(false, false, false, - LifecycleState.FAILED, null, false, true, false); - } - - @Test - public void testDeploymentWarXmlFFT() throws Exception { - createWar(WAR_XML_SOURCE, true); - doTestDeployment(false, false, true, - LifecycleState.FAILED, null, false, true, true); - } - - @Test - public void testDeploymentWarXmlFTF() throws Exception { - createWar(WAR_XML_SOURCE, true); - doTestDeployment(false, true, false, - LifecycleState.FAILED, null, false, true, false); - } - - @Test - public void testDeploymentWarXmlFTT() throws Exception { - createWar(WAR_XML_SOURCE, true); - doTestDeployment(false, true, true, - LifecycleState.FAILED, null, false, true, true); - } - - @Test - public void testDeploymentWarXmlTFF() throws Exception { - createWar(WAR_XML_SOURCE, true); - doTestDeployment(true, false, false, - LifecycleState.STARTED, WAR_COOKIE_NAME, false, true, false); - } - - @Test - public void testDeploymentWarXmlTFT() throws Exception { - createWar(WAR_XML_SOURCE, true); - doTestDeployment(true, false, true, - LifecycleState.STARTED, WAR_COOKIE_NAME, false, true, true); - } - - @Test - public void testDeploymentWarXmlTTF() throws Exception { - createWar(WAR_XML_SOURCE, true); - doTestDeployment(true, true, false, - LifecycleState.STARTED, WAR_COOKIE_NAME, true, true, false); - } - - @Test - public void testDeploymentWarXmlTTT() throws Exception { - createWar(WAR_XML_SOURCE, true); - doTestDeployment(true, true, true, - LifecycleState.STARTED, WAR_COOKIE_NAME, true, true, true); - } - - - /* - * Expected behaviour for deployment of a WAR without an embedded XML file. - * deployXML copyXML unpackWARs XML WAR DIR - * Y/N Y/N N N Y N - * Y/N Y/N Y N Y Y - */ - @Test - public void testDeploymentWarFFF() throws Exception { - createWar(WAR_SOURCE, true); - doTestDeployment(false, false, false, - LifecycleState.STARTED, null, false, true, false); - } - - @Test - public void testDeploymentWarFFT() throws Exception { - createWar(WAR_SOURCE, true); - doTestDeployment(false, false, true, - LifecycleState.STARTED, null, false, true, true); - } - - @Test - public void testDeploymentWarFTF() throws Exception { - createWar(WAR_SOURCE, true); - doTestDeployment(false, true, false, - LifecycleState.STARTED, null, false, true, false); - } - - @Test - public void testDeploymentWarFTT() throws Exception { - createWar(WAR_SOURCE, true); - doTestDeployment(false, true, true, - LifecycleState.STARTED, null, false, true, true); - } - - @Test - public void testDeploymentWarTFF() throws Exception { - createWar(WAR_SOURCE, true); - doTestDeployment(true, false, false, - LifecycleState.STARTED, null, false, true, false); - } - - @Test - public void testDeploymentWarTFT() throws Exception { - createWar(WAR_SOURCE, true); - doTestDeployment(true, false, true, - LifecycleState.STARTED, null, false, true, true); - } - - @Test - public void testDeploymentWarTTF() throws Exception { - createWar(WAR_SOURCE, true); - doTestDeployment(true, true, false, - LifecycleState.STARTED, null, false, true, false); - } - - @Test - public void testDeploymentWarTTT() throws Exception { - createWar(WAR_SOURCE, true); - doTestDeployment(true, true, true, - LifecycleState.STARTED, null, false, true, true); - } - - - /* - * Expected behaviour for deployment of a DIR with an embedded XML file. - * deployXML copyXML unpackWARs XML WAR DIR - * N Y/N Y/N N N Y - * Y N Y/N N N Y - * Y Y Y/N Y N Y - */ - @Test - public void testDeploymentDirXmlFFF() throws Exception { - createDirInAppbase(true); - doTestDeployment(false, false, false, - LifecycleState.FAILED, null, false, false, true); - } - - @Test - public void testDeploymentDirXmlFFT() throws Exception { - createDirInAppbase(true); - doTestDeployment(false, false, true, - LifecycleState.FAILED, null, false, false, true); - } - - @Test - public void testDeploymentDirXmlFTF() throws Exception { - createDirInAppbase(true); - doTestDeployment(false, true, false, - LifecycleState.FAILED, null, false, false, true); - } - - @Test - public void testDeploymentDirXmlFTT() throws Exception { - createDirInAppbase(true); - doTestDeployment(false, true, true, - LifecycleState.FAILED, null, false, false, true); - } - - @Test - public void testDeploymentDirXmlTFF() throws Exception { - createDirInAppbase(true); - doTestDeployment(true, false, false, - LifecycleState.STARTED, DIR_COOKIE_NAME, false, false, true); - } - - @Test - public void testDeploymentDirXmlTFT() throws Exception { - createDirInAppbase(true); - doTestDeployment(true, false, true, - LifecycleState.STARTED, DIR_COOKIE_NAME, false, false, true); - } - - @Test - public void testDeploymentDirXmlTTF() throws Exception { - createDirInAppbase(true); - doTestDeployment(true, true, false, - LifecycleState.STARTED, DIR_COOKIE_NAME, true, false, true); - } - - @Test - public void testDeploymentDirXmlTTT() throws Exception { - createDirInAppbase(true); - doTestDeployment(true, true, true, - LifecycleState.STARTED, DIR_COOKIE_NAME, true, false, true); - } - - - /* - * Expected behaviour for deployment of a DIR without an embedded XML file. - * deployXML copyXML unpackWARs XML WAR DIR - * Y/N Y/N Y/N N N Y - */ - @Test - public void testDeploymentDirFFF() throws Exception { - createDirInAppbase(false); - doTestDeployment(false, false, false, - LifecycleState.STARTED, null, false, false, true); - } - - @Test - public void testDeploymentDirFFT() throws Exception { - createDirInAppbase(false); - doTestDeployment(false, false, true, - LifecycleState.STARTED, null, false, false, true); - } - - @Test - public void testDeploymentDirFTF() throws Exception { - createDirInAppbase(false); - doTestDeployment(false, true, false, - LifecycleState.STARTED, null, false, false, true); - } - - @Test - public void testDeploymentDirFTT() throws Exception { - createDirInAppbase(false); - doTestDeployment(false, true, true, - LifecycleState.STARTED, null, false, false, true); - } - - @Test - public void testDeploymentDirTFF() throws Exception { - createDirInAppbase(false); - doTestDeployment(true, false, false, - LifecycleState.STARTED, null, false, false, true); - } - - @Test - public void testDeploymentDirTFT() throws Exception { - createDirInAppbase(false); - doTestDeployment(true, false, true, - LifecycleState.STARTED, null, false, false, true); - } - - @Test - public void testDeploymentDirTTF() throws Exception { - createDirInAppbase(false); - doTestDeployment(true, true, false, - LifecycleState.STARTED, null, false, false, true); - } - - @Test - public void testDeploymentDirTTT() throws Exception { - createDirInAppbase(false); - doTestDeployment(true, true, true, - LifecycleState.STARTED, null, false, false, true); - } - - private void doTestDeployment(boolean deployXML, boolean copyXML, - boolean unpackWARs, LifecycleState resultState, String cookieName, - boolean resultXml, boolean resultWar, boolean resultDir) - throws Exception { - - Tomcat tomcat = getTomcatInstance(); - - // Start the instance - tomcat.start(); - - // Set the attributes - StandardHost host = (StandardHost) tomcat.getHost(); - host.setDeployXML(deployXML); - host.setCopyXML(copyXML); - host.setUnpackWARs(unpackWARs); - - // Trigger automatic deployment - host.backgroundProcess(); - - // Test the results - Context ctxt = (Context) tomcat.getHost().findChild(APP_NAME.getPath()); - if (resultState == null) { - Assert.assertNull(ctxt); - } else { - Assert.assertNotNull(ctxt); - Assert.assertEquals(resultState, ctxt.getState()); - Assert.assertEquals(cookieName, ctxt.getSessionCookieName()); - } - - File xml = new File( - host.getConfigBaseFile(), APP_NAME.getBaseName() + ".xml"); - Assert.assertEquals( - Boolean.valueOf(resultXml), Boolean.valueOf(xml.isFile())); - - File war = new File( - host.getAppBaseFile(), APP_NAME.getBaseName() + ".war"); - Assert.assertEquals( - Boolean.valueOf(resultWar), Boolean.valueOf(war.isFile())); - - File dir = new File(host.getAppBase(), APP_NAME.getBaseName()); - Assert.assertEquals( - Boolean.valueOf(resultDir), Boolean.valueOf(dir.isDirectory())); - } - - - private File createDirInAppbase(boolean withXml) throws IOException { - File dir = new File(getTomcatInstance().getHost().getAppBaseFile(), - APP_NAME.getBaseName()); - if (withXml) { - recursiveCopy(DIR_XML_SOURCE.toPath(), dir.toPath()); - } else { - recursiveCopy(DIR_SOURCE.toPath(), dir.toPath()); - } - return dir; - } - - private File createDirInExternal(boolean withXml) throws IOException { - File ext = new File(external, "external" + ".war"); - if (withXml) { - recursiveCopy(DIR_XML_SOURCE.toPath(), ext.toPath()); - } else { - recursiveCopy(DIR_SOURCE.toPath(), ext.toPath()); - } - return ext; - } - - private File createWar(File src, boolean useAppbase) throws IOException { - File dest; - if (useAppbase) { - dest = new File(getTomcatInstance().getHost().getAppBaseFile(), - APP_NAME.getBaseName() + ".war"); - } else { - dest = new File(external, "external" + ".war"); - } - Files.copy(src.toPath(), dest.toPath()); - // Make sure that HostConfig thinks the WAR has been modified. - Assert.assertTrue("Failed to set last modified for [" + dest + "]", dest.setLastModified( - System.currentTimeMillis() - 2 * HostConfig.FILE_MODIFICATION_RESOLUTION_MS)); - return dest; - } - - private File createXmlInConfigBaseForAppbase() throws IOException { - File xml = getXmlInConfigBaseForAppbase(); - File parent = xml.getParentFile(); - if (!parent.isDirectory()) { - Assert.assertTrue(parent.mkdirs()); - } - Files.copy(XML_SOURCE.toPath(), xml.toPath()); - // Make sure that HostConfig thinks the xml has been modified. - Assert.assertTrue("Failed to set last modified for [" + xml + "]", xml.setLastModified( - System.currentTimeMillis() - 2 * HostConfig.FILE_MODIFICATION_RESOLUTION_MS)); - return xml; - } - - private File getXmlInConfigBaseForAppbase() { - Host host = getTomcatInstance().getHost(); - return new File(host.getConfigBaseFile(), APP_NAME + ".xml"); - } - - private File createXmlInConfigBaseForExternal(File ext) throws IOException { - return createXmlInConfigBaseForExternal(ext, false); - } - - private File createXmlInConfigBaseForExternal(File ext, boolean antiLocking) - throws IOException { - File xml = new File(getTomcatInstance().getHost().getConfigBaseFile(), - APP_NAME + ".xml"); - File parent = xml.getParentFile(); - if (!parent.isDirectory()) { - Assert.assertTrue(parent.mkdirs()); - } - - try (FileOutputStream fos = new FileOutputStream(xml)) { - StringBuilder context = new StringBuilder(); - context.append(""); - fos.write(context.toString().getBytes(StandardCharsets.ISO_8859_1)); - } - // Make sure that HostConfig thinks the xml has been modified. - Assert.assertTrue("Failed to set last modified for [" + xml + "]", xml.setLastModified( - System.currentTimeMillis() - 2 * HostConfig.FILE_MODIFICATION_RESOLUTION_MS)); - return xml; - } - - public static class TesterContext extends StandardContext { - // No functional change - } -} diff --git a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentBrokenApp.java b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentBrokenApp.java new file mode 100644 index 000000000000..42bbb05d5465 --- /dev/null +++ b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentBrokenApp.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.startup; + +import org.junit.Test; + +/** + * The purpose of this class is to test the automatic deployment features of the + * {@link HostConfig} implementation. + */ +public class TestHostConfigAutomaticDeploymentBrokenApp extends HostConfigAutomaticDeploymentBaseTest { + + @Test + public void testBrokenAppWithAntiLockingF() throws Exception { + doTestBrokenAppWithAntiLocking(false); + } + + @Test + public void testBrokenAppWithAntiLockingT() throws Exception { + doTestBrokenAppWithAntiLocking(true); + } +} diff --git a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentC8.java b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentC8.java new file mode 100644 index 000000000000..af3bd31074c0 --- /dev/null +++ b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentC8.java @@ -0,0 +1,504 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.startup; + +import java.io.File; +import java.nio.file.Files; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsInstanceOf.instanceOf; + +import org.junit.Test; + +import org.apache.catalina.Context; +import org.apache.catalina.Host; +import org.apache.catalina.LifecycleState; +import org.apache.catalina.core.StandardHost; + +/** + * The purpose of this class is to test the automatic deployment features of the + * {@link HostConfig} implementation. + */ +public class TestHostConfigAutomaticDeploymentC8 extends HostConfigAutomaticDeploymentBaseTest { + + /* + * Expected behaviour for modification of files. + * + * Artifacts present Artifact Artifacts remaining + * XML WAR EXT DIR Modified XML WAR EXT DIR Action + * N N N Y DIR - - - M None + * N Y N N WAR - M - - Redeploy + * N Y N Y DIR - Y - M None + * N Y N Y WAR - M - R Redeploy + * Y N N N XML M - - - Redeploy + * Y N N Y DIR Y - - M None + * Y N N Y XML M - - Y Redeploy + * Y N Y N EXT Y - M - Reload if WAR + * Y N Y N XML M - Y - Redeploy + * Y N Y Y DIR Y - Y M None + * Y N Y Y EXT Y - M R Reload + * Y N Y Y XML M - Y Y Redeploy + * Y Y N N WAR Y M - - Reload + * Y Y N N XML M Y - - Redeploy + * Y Y N Y DIR Y Y - M None + * Y Y N Y WAR Y M - - Reload + * Y Y N Y XML M Y - Y Redeploy + */ + @Test + public void testModifyDirUpdateDir() throws Exception { + doTestModify(false, false, false, false, true, DIR, + false, false, true, DIR_COOKIE_NAME, NONE); + } + + @Test + public void testModifyWarUpdateWar() throws Exception { + doTestModify(false, false, false, true, false, WAR, + false, true, false, WAR_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testModifyWarDirUpdateDir() throws Exception { + // DIR_COOKIE_NAME since Tomcat is going to assume DIR is expanded WAR + doTestModify(false, false, false, true, true, DIR, + false, true, true, DIR_COOKIE_NAME, NONE); + } + + @Test + public void testModifyWarDirUpdateWar() throws Exception { + doTestModify(false, false, false, true, true, WAR, + false, true, true, WAR_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testModifyXmlUpdateXml() throws Exception { + doTestModify(true, false, false, false, false, XML, + true, false, false, XML_COOKIE_NAME, REDEPLOY, + LifecycleState.FAILED); + } + + @Test + public void testModifyXmlDirUpdateDir() throws Exception { + doTestModify(true, false, false, false, true, DIR, + true, false, true, XML_COOKIE_NAME, NONE); + } + + @Test + public void testModifyXmlDirUpdateXml() throws Exception { + doTestModify(true, false, false, false, true, XML, + true, false, true, XML_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testModifyXmlExtwarUpdateExtwar() throws Exception { + doTestModify(true, true, false, false, false, EXT, + true, false, false, XML_COOKIE_NAME, RELOAD); + } + + @Test + public void testModifyXmlExtdirUpdateExtdir() throws Exception { + doTestModify(true, false, true, false, false, EXT, + true, false, false, XML_COOKIE_NAME, NONE); + } + + @Test + public void testModifyXmlExtwarUpdateXml() throws Exception { + doTestModify(true, true, false, false, false, XML, + true, false, false, XML_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testModifyXmlExtdirUpdateXml() throws Exception { + doTestModify(true, false, true, false, false, XML, + true, false, false, XML_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testModifyXmlExtwarDirUpdateDir() throws Exception { + doTestModify(true, true, false, false, true, DIR, + true, false, false, XML_COOKIE_NAME, NONE); + } + + @Test + public void testModifyXmlExtwarDirUpdateExt() throws Exception { + doTestModify(true, true, false, false, true, EXT, + true, false, true, XML_COOKIE_NAME, RELOAD); + } + + @Test + public void testModifyXmlExtwarDirUpdateXml() throws Exception { + doTestModify(true, true, false, false, true, XML, + true, false, false, XML_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testModifyXmlWarUpdateWar() throws Exception { + doTestModify(true, false, false, true, false, WAR, + true, true, false, XML_COOKIE_NAME, RELOAD); + } + + @Test + public void testModifyXmlWarUpdateXml() throws Exception { + doTestModify(true, false, false, true, false, XML, + true, true, false, XML_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testModifyXmlWarDirUpdateDir() throws Exception { + doTestModify(true, false, false, true, true, DIR, + true, true, true, XML_COOKIE_NAME, NONE); + } + + @Test + public void testModifyXmlWarDirUpdateWar() throws Exception { + doTestModify(true, false, false, true, true, WAR, + true, true, true, XML_COOKIE_NAME, RELOAD); + } + + @Test + public void testModifyXmlWarDirUpdateXml() throws Exception { + doTestModify(true, false, false, true, true, XML, + true, true, true, XML_COOKIE_NAME, REDEPLOY); + } + + /* + * Expected behaviour for the addition of files. + * + * Artifacts present copyXML deployXML Artifact Artifacts remaining + * XML WAR EXT DIR Added XML WAR EXT DIR Action + * N Y N N N Y DIR - Y - A None + * N N N Y N Y WAR - A - R Redeploy + * Y N N N N Y DIR Y - - A None + * N N N Y N Y XML A - - Y Redeploy + * Y N N N N Y WAR Y A - - Reload + * N Y N N N Y XML A Y - - Redeploy + * Y Y N N N Y DIR Y Y - A None + * Y N N Y N Y WAR Y A - N Reload + * N Y N Y N Y XML A Y - Y Redeploy + * Y N Y N N Y DIR Y - Y A None + * Y N Y N N Y WAR Y A Y - None + * N N N Y N Y EXT A - A R Redeploy + * N Y N N N Y EXT A Y A - Redeploy + * + * N N N Y Y/N N DIR+XML - - - Y Redeploy (failed) + * N N N Y Y Y DIR+XML A - - Y Redeploy + * N N N Y N Y DIR+XML - - - Y Redeploy + * + * Addition of a file is treated as if the added file has been modified + * with the following additional actions: + * - If a WAR is added, any DIR is removed and may be recreated depending on + * unpackWARs. + * - If an XML file is added that refers to an external docBase any WAR or + * DIR in the appBase will be removed. The DIR may be recreated if the + * external resource is a WAR and unpackWARs is true. + * - If a DIR is added when a WAR already exists and unpackWARs is false, + * the DIR will be ignored but a warning will be logged when the DIR is + * first detected. If the WAR is removed, the DIR will be left and may be + * deployed via automatic deployment. + * - If a WAR is added when an external WAR already exists for the same + * context, the WAR will be treated the same way as a DIR is treated in + * the previous bullet point. + */ + @Test + public void testAdditionWarAddDir() throws Exception { + doTestAddition(false, false, false, true, false, DIR, + false, true, true, WAR_COOKIE_NAME, NONE); + } + + @Test + public void testAdditionDirAddWar() throws Exception { + doTestAddition(false, false, false, false, true, WAR, + false, true, true, WAR_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testAdditionXmlAddDir() throws Exception { + doTestAddition(true, false, false, false, false, DIR, + true, false, true, XML_COOKIE_NAME, NONE); + } + + @Test + public void testAdditionDirAddXml() throws Exception { + doTestAddition(false, false, false, false, true, XML, + true, false, true, XML_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testAdditionXmlAddWar() throws Exception { + doTestAddition(true, false, false, false, false, WAR, + true, true, false, XML_COOKIE_NAME, RELOAD); + } + + @Test + public void testAdditionWarAddXml() throws Exception { + doTestAddition(false, false, false, true, false, XML, + true, true, false, XML_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testAdditionXmlWarAddDir() throws Exception { + doTestAddition(true, false, false, true, false, DIR, + true, true, true, XML_COOKIE_NAME, NONE); + } + + @Test + public void testAdditionXmlDirAddWar() throws Exception { + doTestAddition(true, false, false, false, true, WAR, + true, true, false, XML_COOKIE_NAME, RELOAD); + } + + @Test + public void testAdditionWarDirAddXml() throws Exception { + doTestAddition(false, false, false, true, true, XML, + true, true, true, XML_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testAdditionXmlExtwarAddDir() throws Exception { + doTestAddition(true, true, false, false, false, DIR, + true, false, true, XML_COOKIE_NAME, NONE); + } + + @Test + public void testAdditionXmlExtdirAddDir() throws Exception { + doTestAddition(true, false, true, false, false, DIR, + true, false, true, XML_COOKIE_NAME, NONE); + } + + @Test + public void testAdditionXmlExtwarAddWar() throws Exception { + doTestAddition(true, true, false, false, false, WAR, + true, true, false, XML_COOKIE_NAME, NONE); + } + + @Test + public void testAdditionXmlExtdirAddWar() throws Exception { + doTestAddition(true, false, true, false, false, WAR, + true, true, false, XML_COOKIE_NAME, NONE); + } + + @Test + public void testAdditionDirAddXmlExtwar() throws Exception { + doTestAddition(false, false, false, false, true, EXT, + true, false, true, XML_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testAdditionWarAddXmlExtwar() throws Exception { + doTestAddition(false, false, false, true, false, EXT, + true, true, false, XML_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testAdditionDirAddDirXmlTF() throws Exception { + doTestAddition(false, false, false, false, true, true, false, DIR_XML, + false, false, true, null, REDEPLOY, LifecycleState.FAILED); + } + + @Test + public void testAdditionDirAddDirXmlFF() throws Exception { + doTestAddition(false, false, false, false, true, false, false, DIR_XML, + false, false, true, null, REDEPLOY, LifecycleState.FAILED); + } + + @Test + public void testAdditionDirAddDirXmlTT() throws Exception { + doTestAddition(false, false, false, false, true, true, true, DIR_XML, + true, false, true, DIR_COOKIE_NAME, REDEPLOY, + LifecycleState.STARTED); + } + + @Test + public void testAdditionDirAddDirXmlFT() throws Exception { + doTestAddition(false, false, false, false, true, false, true, DIR_XML, + false, false, true, DIR_COOKIE_NAME, REDEPLOY, + LifecycleState.STARTED); + } + + /* + * Test context unpackWAR setting. + * If context.getUnpackWAR != Host.getUnpackWARs the Host wins. + */ + @Test + public void testUnpackWARFFF() throws Exception { + doTestUnpackWAR(false, false, false, false); + } + + @Test + public void testUnpackWARFFT() throws Exception { + doTestUnpackWAR(false, false, true, false); + } + + @Test + public void testUnpackWARFTF() throws Exception { + doTestUnpackWAR(false, true, false, false); + } + + @Test + public void testUnpackWARFTT() throws Exception { + doTestUnpackWAR(false, true, true, false); + } + + @Test + public void testUnpackWARTFF() throws Exception { + doTestUnpackWAR(true, false, false, false); + } + + @Test + public void testUnpackWARTFT() throws Exception { + // External WAR - therefore XML in WAR will be ignored + doTestUnpackWAR(true, false, true, true); + } + + @Test + public void testUnpackWARTTF() throws Exception { + doTestUnpackWAR(true, true, false, true); + } + + @Test + public void testUnpackWARTTT() throws Exception { + doTestUnpackWAR(true, true, true, true); + } + + @Test + public void testBrokenAppWithAntiLockingF() throws Exception { + doTestBrokenAppWithAntiLocking(false); + } + + @Test + public void testBrokenAppWithAntiLockingT() throws Exception { + doTestBrokenAppWithAntiLocking(true); + } + + /* + * 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); + } + + @Test + public void testSetContextClassName() throws Exception { + + Tomcat tomcat = getTomcatInstance(); + + Host host = tomcat.getHost(); + if (host instanceof StandardHost) { + StandardHost standardHost = (StandardHost) host; + standardHost.setContextClass(TesterContext.class.getName()); + } + + // Copy the WAR file + File war = new File(host.getAppBaseFile(), + APP_NAME.getBaseName() + ".war"); + Files.copy(WAR_XML_SOURCE.toPath(), war.toPath()); + + // Deploy the copied war + tomcat.start(); + host.backgroundProcess(); + + // Check the Context class + Context ctxt = (Context) host.findChild(APP_NAME.getName()); + + assertThat(ctxt, instanceOf(TesterContext.class)); + } + + + @Test + public void testUpdateWarOfflineNoContextFF() throws Exception { + doTestUpdateWarOffline(WAR_SOURCE, false, false); + } + + + @Test + public void testUpdateWarOfflineNoContextTF() throws Exception { + doTestUpdateWarOffline(WAR_SOURCE, true, false); + } + + + @Test + public void testUpdateWarOfflineNoContextFT() throws Exception { + doTestUpdateWarOffline(WAR_SOURCE, false, true); + } + + + @Test + public void testUpdateWarOfflineNoContextTT() throws Exception { + doTestUpdateWarOffline(WAR_SOURCE, true, true); + } + + + @Test + public void testUpdateWarOfflineContextFF() throws Exception { + doTestUpdateWarOffline(WAR_XML_SOURCE, false, false); + } + + + @Test + public void testUpdateWarOfflineContextTF() throws Exception { + doTestUpdateWarOffline(WAR_XML_SOURCE, true, false); + } + + + @Test + public void testUpdateWarOfflineContextFT() throws Exception { + doTestUpdateWarOffline(WAR_XML_SOURCE, false, true); + } + + + @Test + public void testUpdateWarOfflineContextTT() throws Exception { + doTestUpdateWarOffline(WAR_XML_SOURCE, true, true); + } +} diff --git a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentContextClassName.java b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentContextClassName.java new file mode 100644 index 000000000000..1be9748de472 --- /dev/null +++ b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentContextClassName.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.startup; + +import java.io.File; +import java.nio.file.Files; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsInstanceOf.instanceOf; + +import org.junit.Test; + +import org.apache.catalina.Context; +import org.apache.catalina.Host; +import org.apache.catalina.core.StandardHost; + +/** + * The purpose of this class is to test the automatic deployment features of the + * {@link HostConfig} implementation. + */ +public class TestHostConfigAutomaticDeploymentContextClassName extends HostConfigAutomaticDeploymentBaseTest { + + @Test + public void testSetContextClassName() throws Exception { + + Tomcat tomcat = getTomcatInstance(); + + Host host = tomcat.getHost(); + if (host instanceof StandardHost) { + StandardHost standardHost = (StandardHost) host; + standardHost.setContextClass(TesterContext.class.getName()); + } + + // Copy the WAR file + File war = new File(host.getAppBaseFile(), + APP_NAME.getBaseName() + ".war"); + Files.copy(WAR_XML_SOURCE.toPath(), war.toPath()); + + // Deploy the copied war + tomcat.start(); + host.backgroundProcess(); + + // Check the Context class + Context ctxt = (Context) host.findChild(APP_NAME.getName()); + + assertThat(ctxt, instanceOf(TesterContext.class)); + } +} diff --git a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentCopyXML.java b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentCopyXML.java new file mode 100644 index 000000000000..74d2a92368a9 --- /dev/null +++ b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentCopyXML.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.startup; + +import org.junit.Test; + +/** + * The purpose of this class is to test the automatic deployment features of the + * {@link HostConfig} implementation. + */ +public class TestHostConfigAutomaticDeploymentCopyXML extends HostConfigAutomaticDeploymentBaseTest { + + /* + * 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); + } +} diff --git a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentDeleteA.java b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentDeleteA.java new file mode 100644 index 000000000000..e6ff4db84037 --- /dev/null +++ b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentDeleteA.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.startup; + +import org.junit.Test; + +/** + * The purpose of this class is to test the automatic deployment features of the + * {@link HostConfig} implementation. + */ +public class TestHostConfigAutomaticDeploymentDeleteA extends HostConfigAutomaticDeploymentBaseTest { + + /* + * Expected behaviour for the deletion of files. + * + * Artifacts present Artifact Artifacts remaining + * XML WAR EXT DIR Removed XML WAR EXT DIR Notes + * N N N Y DIR - - - N + * N Y N N WAR - N - - + * N Y N Y DIR - Y - R 1 + * N Y N Y WAR - N - N + * + * Notes: 1. The DIR will be re-created since unpackWARs is true. + */ + @Test + public void testDeleteDirRemoveDir() throws Exception { + doTestDelete(false, false, false, false, true, DIR, false, false, false, + null); + } + + @Test + public void testDeleteWarRemoveWar() throws Exception { + doTestDelete(false, false, false, true, false, WAR, false, false, false, + null); + } + + @Test + public void testDeleteWarDirRemoveDir() throws Exception { + doTestDelete(false, false, false, true, true, DIR, false, true, true, + WAR_COOKIE_NAME); + } + + @Test + public void testDeleteWarDirRemoveWar() throws Exception { + doTestDelete(false, false, false, true, true, WAR, false, false, false, + null); + } +} diff --git a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentDeleteB.java b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentDeleteB.java new file mode 100644 index 000000000000..cac8d073b28d --- /dev/null +++ b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentDeleteB.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.startup; + +import org.junit.Test; + +import org.apache.catalina.core.StandardHost; + +/** + * The purpose of this class is to test the automatic deployment features of the + * {@link HostConfig} implementation. + */ +public class TestHostConfigAutomaticDeploymentDeleteB extends HostConfigAutomaticDeploymentBaseTest { + + /* + * Expected behaviour for the deletion of files. + * + * Artifacts present Artifact Artifacts remaining + * XML WAR EXT DIR Removed XML WAR EXT DIR Notes + * Y N N N XML N - - - + * Y N N Y DIR N - - N + * Y N N Y XML R - - Y 2 + * Y N Y N EXT Y - N - + * Y N Y N XML N - Y - + * Y N Y Y DIR R - Y R 1,2 + * Y N Y Y EXT Y - N N + * Y N Y Y XML N - Y N + * + * Notes: 1. The DIR will be re-created since unpackWARs is true. + * 2. The XML will be extracted from the WAR/DIR if deployXML and + * copyXML are true. + */ + @Test + public void testDeleteXmlRemoveXml() throws Exception { + doTestDelete(true, false, false, false, false, XML, false, false, false, + null); + } + + @Test + public void testDeleteXmlDirRemoveDir() throws Exception { + doTestDelete(true, false, false, false, true, DIR, false, false, false, + null); + } + + @Test + public void testDeleteXmlDirRemoveXml() throws Exception { + doTestDelete(true, false, false, false, true, XML, false, false, true, + DIR_COOKIE_NAME); + } + + @Test + public void testDeleteXmlDirRemoveXmlCopyXml() throws Exception { + ((StandardHost) getTomcatInstance().getHost()).setCopyXML(true); + doTestDelete(true, false, false, false, true, XML, true, false, true, + DIR_COOKIE_NAME); + } + + @Test + public void testDeleteXmlExtwarRemoveExt() throws Exception { + doTestDelete(true, true, false, false, false, EXT, true, false, false, + XML_COOKIE_NAME); + } + + @Test + public void testDeleteXmlExtdirRemoveExt() throws Exception { + doTestDelete(true, false, true, false, false, EXT, true, false, false, + XML_COOKIE_NAME); + } + + @Test + public void testDeleteXmlExtwarRemoveXml() throws Exception { + doTestDelete(true, true, false, false, false, XML, false, false, false, + null); + } + + @Test + public void testDeleteXmlExtdirRemoveXml() throws Exception { + doTestDelete(true, false, true, false, false, XML, false, false, false, + null); + } + + @Test + public void testDeleteXmlExtwarDirRemoveDir() throws Exception { + doTestDelete(true, true, false, false, true, DIR, true, false, true, + XML_COOKIE_NAME); + } + + @Test + public void testDeleteXmlExtwarDirRemoveExt() throws Exception { + doTestDelete(true, true, false, false, true, EXT, true, false, false, + XML_COOKIE_NAME); + } + + @Test + public void testDeleteXmlExtwarDirRemoveXml() throws Exception { + doTestDelete(true, true, false, false, true, XML, false, false, false, + null); + } +} diff --git a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentDeleteC.java b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentDeleteC.java new file mode 100644 index 000000000000..61ec60db093d --- /dev/null +++ b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentDeleteC.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.startup; + +import org.junit.Test; + +import org.apache.catalina.core.StandardHost; + +/** + * The purpose of this class is to test the automatic deployment features of the + * {@link HostConfig} implementation. + */ +public class TestHostConfigAutomaticDeploymentDeleteC extends HostConfigAutomaticDeploymentBaseTest { + + /* + * Expected behaviour for the deletion of files. + * + * Artifacts present Artifact Artifacts remaining + * XML WAR EXT DIR Removed XML WAR EXT DIR Notes + * Y Y N N WAR N N - - + * Y Y N N XML N N - - + * Y Y N Y DIR R Y - R 1,2 + * Y Y N Y WAR N N - - + * Y Y N Y XML R Y - Y + * + * Notes: 1. The DIR will be re-created since unpackWARs is true. + * 2. The XML will be extracted from the WAR/DIR if deployXML and + * copyXML are true. + */ + @Test + public void testDeleteXmlWarRemoveWar() throws Exception { + doTestDelete(true, false, false, true, false, WAR, false, false, false, + null); + } + + @Test + public void testDeleteXmlWarRemoveXml() throws Exception { + doTestDelete(true, false, false, true, false, XML, false, true, false, + WAR_COOKIE_NAME); + } + + @Test + public void testDeleteXmlWarRemoveXmlCopyXml() throws Exception { + ((StandardHost) getTomcatInstance().getHost()).setCopyXML(true); + doTestDelete(true, false, false, true, false, XML, true, true, false, + WAR_COOKIE_NAME); + } + + @Test + public void testDeleteXmlWarDirRemoveDir() throws Exception { + doTestDelete(true, false, false, true, true, DIR, false, true, true, + WAR_COOKIE_NAME); + } + + @Test + public void testDeleteXmlWarDirRemoveDirCopyXml() throws Exception { + ((StandardHost) getTomcatInstance().getHost()).setCopyXML(true); + doTestDelete(true, false, false, true, true, DIR, true, true, true, + WAR_COOKIE_NAME); + } + + @Test + public void testDeleteXmlWarDirRemoveWar() throws Exception { + doTestDelete(true, false, false, true, true, WAR, false, false, false, + null); + } + + @Test + public void testDeleteXmlWarDirRemoveWarCopyXml() throws Exception { + ((StandardHost) getTomcatInstance().getHost()).setCopyXML(true); + doTestDelete(true, false, false, true, true, WAR, false, false, false, + null); + } + + @Test + public void testDeleteXmlWarDirRemoveXml() throws Exception { + doTestDelete(true, false, false, true, true, XML, false, true, true, + DIR_COOKIE_NAME); + } + + @Test + public void testDeleteXmlWarDirRemoveXmlCopyXml() throws Exception { + ((StandardHost) getTomcatInstance().getHost()).setCopyXML(true); + doTestDelete(true, false, false, true, true, XML, true, true, true, + WAR_COOKIE_NAME); + } +} diff --git a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentDir.java b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentDir.java new file mode 100644 index 000000000000..4f2fedca4c2e --- /dev/null +++ b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentDir.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.startup; + +import org.junit.Test; + +import org.apache.catalina.LifecycleState; + +/** + * The purpose of this class is to test the automatic deployment features of the + * {@link HostConfig} implementation. + */ +public class TestHostConfigAutomaticDeploymentDir extends HostConfigAutomaticDeploymentBaseTest { + + /* + * Expected behaviour for deployment of a DIR without an embedded XML file. + * deployXML copyXML unpackWARs XML WAR DIR + * Y/N Y/N Y/N N N Y + */ + @Test + public void testDeploymentDirFFF() throws Exception { + createDirInAppbase(false); + doTestDeployment(false, false, false, + LifecycleState.STARTED, null, false, false, true); + } + + @Test + public void testDeploymentDirFFT() throws Exception { + createDirInAppbase(false); + doTestDeployment(false, false, true, + LifecycleState.STARTED, null, false, false, true); + } + + @Test + public void testDeploymentDirFTF() throws Exception { + createDirInAppbase(false); + doTestDeployment(false, true, false, + LifecycleState.STARTED, null, false, false, true); + } + + @Test + public void testDeploymentDirFTT() throws Exception { + createDirInAppbase(false); + doTestDeployment(false, true, true, + LifecycleState.STARTED, null, false, false, true); + } + + @Test + public void testDeploymentDirTFF() throws Exception { + createDirInAppbase(false); + doTestDeployment(true, false, false, + LifecycleState.STARTED, null, false, false, true); + } + + @Test + public void testDeploymentDirTFT() throws Exception { + createDirInAppbase(false); + doTestDeployment(true, false, true, + LifecycleState.STARTED, null, false, false, true); + } + + @Test + public void testDeploymentDirTTF() throws Exception { + createDirInAppbase(false); + doTestDeployment(true, true, false, + LifecycleState.STARTED, null, false, false, true); + } + + @Test + public void testDeploymentDirTTT() throws Exception { + createDirInAppbase(false); + doTestDeployment(true, true, true, + LifecycleState.STARTED, null, false, false, true); + } +} diff --git a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentDirXml.java b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentDirXml.java new file mode 100644 index 000000000000..8cd1a7b95a42 --- /dev/null +++ b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentDirXml.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.startup; + +import org.junit.Test; + +import org.apache.catalina.LifecycleState; + +/** + * The purpose of this class is to test the automatic deployment features of the + * {@link HostConfig} implementation. + */ +public class TestHostConfigAutomaticDeploymentDirXml extends HostConfigAutomaticDeploymentBaseTest { + + /* + * Expected behaviour for deployment of a DIR with an embedded XML file. + * deployXML copyXML unpackWARs XML WAR DIR + * N Y/N Y/N N N Y + * Y N Y/N N N Y + * Y Y Y/N Y N Y + */ + @Test + public void testDeploymentDirXmlFFF() throws Exception { + createDirInAppbase(true); + doTestDeployment(false, false, false, + LifecycleState.FAILED, null, false, false, true); + } + + @Test + public void testDeploymentDirXmlFFT() throws Exception { + createDirInAppbase(true); + doTestDeployment(false, false, true, + LifecycleState.FAILED, null, false, false, true); + } + + @Test + public void testDeploymentDirXmlFTF() throws Exception { + createDirInAppbase(true); + doTestDeployment(false, true, false, + LifecycleState.FAILED, null, false, false, true); + } + + @Test + public void testDeploymentDirXmlFTT() throws Exception { + createDirInAppbase(true); + doTestDeployment(false, true, true, + LifecycleState.FAILED, null, false, false, true); + } + + @Test + public void testDeploymentDirXmlTFF() throws Exception { + createDirInAppbase(true); + doTestDeployment(true, false, false, + LifecycleState.STARTED, DIR_COOKIE_NAME, false, false, true); + } + + @Test + public void testDeploymentDirXmlTFT() throws Exception { + createDirInAppbase(true); + doTestDeployment(true, false, true, + LifecycleState.STARTED, DIR_COOKIE_NAME, false, false, true); + } + + @Test + public void testDeploymentDirXmlTTF() throws Exception { + createDirInAppbase(true); + doTestDeployment(true, true, false, + LifecycleState.STARTED, DIR_COOKIE_NAME, true, false, true); + } + + @Test + public void testDeploymentDirXmlTTT() throws Exception { + createDirInAppbase(true); + doTestDeployment(true, true, true, + LifecycleState.STARTED, DIR_COOKIE_NAME, true, false, true); + } +} diff --git a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentModification.java b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentModification.java new file mode 100644 index 000000000000..65e5755d7872 --- /dev/null +++ b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentModification.java @@ -0,0 +1,167 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.startup; + +import org.junit.Test; + +import org.apache.catalina.LifecycleState; + +/** + * The purpose of this class is to test the automatic deployment features of the + * {@link HostConfig} implementation. + */ +public class TestHostConfigAutomaticDeploymentModification extends HostConfigAutomaticDeploymentBaseTest { + + /* + * Expected behaviour for modification of files. + * + * Artifacts present Artifact Artifacts remaining + * XML WAR EXT DIR Modified XML WAR EXT DIR Action + * N N N Y DIR - - - M None + * N Y N N WAR - M - - Redeploy + * N Y N Y DIR - Y - M None + * N Y N Y WAR - M - R Redeploy + * Y N N N XML M - - - Redeploy + * Y N N Y DIR Y - - M None + * Y N N Y XML M - - Y Redeploy + * Y N Y N EXT Y - M - Reload if WAR + * Y N Y N XML M - Y - Redeploy + * Y N Y Y DIR Y - Y M None + * Y N Y Y EXT Y - M R Reload + * Y N Y Y XML M - Y Y Redeploy + * Y Y N N WAR Y M - - Reload + * Y Y N N XML M Y - - Redeploy + * Y Y N Y DIR Y Y - M None + * Y Y N Y WAR Y M - - Reload + * Y Y N Y XML M Y - Y Redeploy + */ + @Test + public void testModifyDirUpdateDir() throws Exception { + doTestModify(false, false, false, false, true, DIR, + false, false, true, DIR_COOKIE_NAME, NONE); + } + + @Test + public void testModifyWarUpdateWar() throws Exception { + doTestModify(false, false, false, true, false, WAR, + false, true, false, WAR_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testModifyWarDirUpdateDir() throws Exception { + // DIR_COOKIE_NAME since Tomcat is going to assume DIR is expanded WAR + doTestModify(false, false, false, true, true, DIR, + false, true, true, DIR_COOKIE_NAME, NONE); + } + + @Test + public void testModifyWarDirUpdateWar() throws Exception { + doTestModify(false, false, false, true, true, WAR, + false, true, true, WAR_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testModifyXmlUpdateXml() throws Exception { + doTestModify(true, false, false, false, false, XML, + true, false, false, XML_COOKIE_NAME, REDEPLOY, + LifecycleState.FAILED); + } + + @Test + public void testModifyXmlDirUpdateDir() throws Exception { + doTestModify(true, false, false, false, true, DIR, + true, false, true, XML_COOKIE_NAME, NONE); + } + + @Test + public void testModifyXmlDirUpdateXml() throws Exception { + doTestModify(true, false, false, false, true, XML, + true, false, true, XML_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testModifyXmlExtwarUpdateExtwar() throws Exception { + doTestModify(true, true, false, false, false, EXT, + true, false, false, XML_COOKIE_NAME, RELOAD); + } + + @Test + public void testModifyXmlExtdirUpdateExtdir() throws Exception { + doTestModify(true, false, true, false, false, EXT, + true, false, false, XML_COOKIE_NAME, NONE); + } + + @Test + public void testModifyXmlExtwarUpdateXml() throws Exception { + doTestModify(true, true, false, false, false, XML, + true, false, false, XML_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testModifyXmlExtdirUpdateXml() throws Exception { + doTestModify(true, false, true, false, false, XML, + true, false, false, XML_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testModifyXmlExtwarDirUpdateDir() throws Exception { + doTestModify(true, true, false, false, true, DIR, + true, false, false, XML_COOKIE_NAME, NONE); + } + + @Test + public void testModifyXmlExtwarDirUpdateExt() throws Exception { + doTestModify(true, true, false, false, true, EXT, + true, false, true, XML_COOKIE_NAME, RELOAD); + } + + @Test + public void testModifyXmlExtwarDirUpdateXml() throws Exception { + doTestModify(true, true, false, false, true, XML, + true, false, false, XML_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testModifyXmlWarUpdateWar() throws Exception { + doTestModify(true, false, false, true, false, WAR, + true, true, false, XML_COOKIE_NAME, RELOAD); + } + + @Test + public void testModifyXmlWarUpdateXml() throws Exception { + doTestModify(true, false, false, true, false, XML, + true, true, false, XML_COOKIE_NAME, REDEPLOY); + } + + @Test + public void testModifyXmlWarDirUpdateDir() throws Exception { + doTestModify(true, false, false, true, true, DIR, + true, true, true, XML_COOKIE_NAME, NONE); + } + + @Test + public void testModifyXmlWarDirUpdateWar() throws Exception { + doTestModify(true, false, false, true, true, WAR, + true, true, true, XML_COOKIE_NAME, RELOAD); + } + + @Test + public void testModifyXmlWarDirUpdateXml() throws Exception { + doTestModify(true, false, false, true, true, XML, + true, true, true, XML_COOKIE_NAME, REDEPLOY); + } +} diff --git a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentUnpackWAR.java b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentUnpackWAR.java new file mode 100644 index 000000000000..cdef493490e5 --- /dev/null +++ b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentUnpackWAR.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.startup; + +import org.junit.Test; + +/** + * The purpose of this class is to test the automatic deployment features of the + * {@link HostConfig} implementation. + */ +public class TestHostConfigAutomaticDeploymentUnpackWAR extends HostConfigAutomaticDeploymentBaseTest { + + /* + * Test context unpackWAR setting. + * If context.getUnpackWAR != Host.getUnpackWARs the Host wins. + */ + @Test + public void testUnpackWARFFF() throws Exception { + doTestUnpackWAR(false, false, false, false); + } + + @Test + public void testUnpackWARFFT() throws Exception { + doTestUnpackWAR(false, false, true, false); + } + + @Test + public void testUnpackWARFTF() throws Exception { + doTestUnpackWAR(false, true, false, false); + } + + @Test + public void testUnpackWARFTT() throws Exception { + doTestUnpackWAR(false, true, true, false); + } + + @Test + public void testUnpackWARTFF() throws Exception { + doTestUnpackWAR(true, false, false, false); + } + + @Test + public void testUnpackWARTFT() throws Exception { + // External WAR - therefore XML in WAR will be ignored + doTestUnpackWAR(true, false, true, true); + } + + @Test + public void testUnpackWARTTF() throws Exception { + doTestUnpackWAR(true, true, false, true); + } + + @Test + public void testUnpackWARTTT() throws Exception { + doTestUnpackWAR(true, true, true, true); + } +} diff --git a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentUpdateWarOffline.java b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentUpdateWarOffline.java new file mode 100644 index 000000000000..403c153b35dc --- /dev/null +++ b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentUpdateWarOffline.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.startup; + +import org.junit.Test; + +/** + * The purpose of this class is to test the automatic deployment features of the + * {@link HostConfig} implementation. + */ +public class TestHostConfigAutomaticDeploymentUpdateWarOffline extends HostConfigAutomaticDeploymentBaseTest { + + @Test + public void testUpdateWarOfflineNoContextFF() throws Exception { + doTestUpdateWarOffline(WAR_SOURCE, false, false); + } + + + @Test + public void testUpdateWarOfflineNoContextTF() throws Exception { + doTestUpdateWarOffline(WAR_SOURCE, true, false); + } + + + @Test + public void testUpdateWarOfflineNoContextFT() throws Exception { + doTestUpdateWarOffline(WAR_SOURCE, false, true); + } + + + @Test + public void testUpdateWarOfflineNoContextTT() throws Exception { + doTestUpdateWarOffline(WAR_SOURCE, true, true); + } + + + @Test + public void testUpdateWarOfflineContextFF() throws Exception { + doTestUpdateWarOffline(WAR_XML_SOURCE, false, false); + } + + + @Test + public void testUpdateWarOfflineContextTF() throws Exception { + doTestUpdateWarOffline(WAR_XML_SOURCE, true, false); + } + + + @Test + public void testUpdateWarOfflineContextFT() throws Exception { + doTestUpdateWarOffline(WAR_XML_SOURCE, false, true); + } + + + @Test + public void testUpdateWarOfflineContextTT() throws Exception { + doTestUpdateWarOffline(WAR_XML_SOURCE, true, true); + } +} diff --git a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentWar.java b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentWar.java new file mode 100644 index 000000000000..2e95c1fe7df3 --- /dev/null +++ b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentWar.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.startup; + +import org.junit.Test; + +import org.apache.catalina.LifecycleState; + +/** + * The purpose of this class is to test the automatic deployment features of the + * {@link HostConfig} implementation. + */ +public class TestHostConfigAutomaticDeploymentWar extends HostConfigAutomaticDeploymentBaseTest { + + /* + * Expected behaviour for deployment of a WAR without an embedded XML file. + * deployXML copyXML unpackWARs XML WAR DIR + * Y/N Y/N N N Y N + * Y/N Y/N Y N Y Y + */ + @Test + public void testDeploymentWarFFF() throws Exception { + createWar(WAR_SOURCE, true); + doTestDeployment(false, false, false, + LifecycleState.STARTED, null, false, true, false); + } + + @Test + public void testDeploymentWarFFT() throws Exception { + createWar(WAR_SOURCE, true); + doTestDeployment(false, false, true, + LifecycleState.STARTED, null, false, true, true); + } + + @Test + public void testDeploymentWarFTF() throws Exception { + createWar(WAR_SOURCE, true); + doTestDeployment(false, true, false, + LifecycleState.STARTED, null, false, true, false); + } + + @Test + public void testDeploymentWarFTT() throws Exception { + createWar(WAR_SOURCE, true); + doTestDeployment(false, true, true, + LifecycleState.STARTED, null, false, true, true); + } + + @Test + public void testDeploymentWarTFF() throws Exception { + createWar(WAR_SOURCE, true); + doTestDeployment(true, false, false, + LifecycleState.STARTED, null, false, true, false); + } + + @Test + public void testDeploymentWarTFT() throws Exception { + createWar(WAR_SOURCE, true); + doTestDeployment(true, false, true, + LifecycleState.STARTED, null, false, true, true); + } + + @Test + public void testDeploymentWarTTF() throws Exception { + createWar(WAR_SOURCE, true); + doTestDeployment(true, true, false, + LifecycleState.STARTED, null, false, true, false); + } + + @Test + public void testDeploymentWarTTT() throws Exception { + createWar(WAR_SOURCE, true); + doTestDeployment(true, true, true, + LifecycleState.STARTED, null, false, true, true); + } +} diff --git a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentWarXml.java b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentWarXml.java new file mode 100644 index 000000000000..30cbd28962ed --- /dev/null +++ b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentWarXml.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.startup; + +import org.junit.Test; + +import org.apache.catalina.LifecycleState; + +/** + * The purpose of this class is to test the automatic deployment features of the + * {@link HostConfig} implementation. + */ +public class TestHostConfigAutomaticDeploymentWarXml extends HostConfigAutomaticDeploymentBaseTest { + + /* + * Expected behaviour for deployment of a WAR with an embedded XML file. + * deployXML copyXML unpackWARs XML WAR DIR + * N Y/N N N Y N + * N Y/N Y N Y Y + * Y N N N Y N + * Y N Y N Y Y + * Y Y N Y Y N + * Y Y Y Y Y Y + */ + @Test + public void testDeploymentWarXmlFFF() throws Exception { + createWar(WAR_XML_SOURCE, true); + doTestDeployment(false, false, false, + LifecycleState.FAILED, null, false, true, false); + } + + @Test + public void testDeploymentWarXmlFFT() throws Exception { + createWar(WAR_XML_SOURCE, true); + doTestDeployment(false, false, true, + LifecycleState.FAILED, null, false, true, true); + } + + @Test + public void testDeploymentWarXmlFTF() throws Exception { + createWar(WAR_XML_SOURCE, true); + doTestDeployment(false, true, false, + LifecycleState.FAILED, null, false, true, false); + } + + @Test + public void testDeploymentWarXmlFTT() throws Exception { + createWar(WAR_XML_SOURCE, true); + doTestDeployment(false, true, true, + LifecycleState.FAILED, null, false, true, true); + } + + @Test + public void testDeploymentWarXmlTFF() throws Exception { + createWar(WAR_XML_SOURCE, true); + doTestDeployment(true, false, false, + LifecycleState.STARTED, WAR_COOKIE_NAME, false, true, false); + } + + @Test + public void testDeploymentWarXmlTFT() throws Exception { + createWar(WAR_XML_SOURCE, true); + doTestDeployment(true, false, true, + LifecycleState.STARTED, WAR_COOKIE_NAME, false, true, true); + } + + @Test + public void testDeploymentWarXmlTTF() throws Exception { + createWar(WAR_XML_SOURCE, true); + doTestDeployment(true, true, false, + LifecycleState.STARTED, WAR_COOKIE_NAME, true, true, false); + } + + @Test + public void testDeploymentWarXmlTTT() throws Exception { + createWar(WAR_XML_SOURCE, true); + doTestDeployment(true, true, true, + LifecycleState.STARTED, WAR_COOKIE_NAME, true, true, true); + } +} diff --git a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentXml.java b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentXml.java new file mode 100644 index 000000000000..30b946f901a3 --- /dev/null +++ b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentXml.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.startup; + +import org.junit.Test; + +import org.apache.catalina.LifecycleState; + +/** + * The purpose of this class is to test the automatic deployment features of the + * {@link HostConfig} implementation. + */ +public class TestHostConfigAutomaticDeploymentXml extends HostConfigAutomaticDeploymentBaseTest { + + /* + * Expected behaviour for deployment of an XML file. + * deployXML copyXML unpackWARs XML WAR DIR + * Y/N Y/N Y/N Y N N + * + * Note: Context will fail to start because no valid docBase is present. + */ + @Test + public void testDeploymentXmlFFF() throws Exception { + createXmlInConfigBaseForAppbase(); + doTestDeployment(false, false, false, + LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false); + } + + @Test + public void testDeploymentXmlFFT() throws Exception { + createXmlInConfigBaseForAppbase(); + doTestDeployment(false, false, true, + LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false); + } + + @Test + public void testDeploymentXmlFTF() throws Exception { + createXmlInConfigBaseForAppbase(); + doTestDeployment(false, true, false, + LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false); + } + + @Test + public void testDeploymentXmlFTT() throws Exception { + createXmlInConfigBaseForAppbase(); + doTestDeployment(false, true, true, + LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false); + } + + @Test + public void testDeploymentXmlTFF() throws Exception { + createXmlInConfigBaseForAppbase(); + doTestDeployment(true, false, false, + LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false); + } + + @Test + public void testDeploymentXmlTFT() throws Exception { + createXmlInConfigBaseForAppbase(); + doTestDeployment(true, false, true, + LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false); + } + + @Test + public void testDeploymentXmlTTF() throws Exception { + createXmlInConfigBaseForAppbase(); + doTestDeployment(true, true, false, + LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false); + } + + @Test + public void testDeploymentXmlTTT() throws Exception { + createXmlInConfigBaseForAppbase(); + doTestDeployment(true, true, true, + LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false); + } +} diff --git a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentXmlExternalDirXml.java b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentXmlExternalDirXml.java new file mode 100644 index 000000000000..fb89c942c02a --- /dev/null +++ b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentXmlExternalDirXml.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.startup; + +import java.io.File; + +import org.junit.Test; + +import org.apache.catalina.LifecycleState; + +/** + * The purpose of this class is to test the automatic deployment features of the + * {@link HostConfig} implementation. + */ +public class TestHostConfigAutomaticDeploymentXmlExternalDirXml extends HostConfigAutomaticDeploymentBaseTest { + + /* + * Expected behaviour for deployment of an XML file that points to an + * external DIR. + * deployXML copyXML unpackWARs XML WAR DIR + * Y/N Y/N Y/N Y N N + * + * Notes: Any context.xml file embedded in the external DIR file is ignored. + */ + @Test + public void testDeploymentXmlExternalDirXmlFFF() throws Exception { + File dir = createDirInExternal(true); + createXmlInConfigBaseForExternal(dir); + doTestDeployment(false, false, false, + LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); + } + + @Test + public void testDeploymentXmlExternalDirXmlFFT() throws Exception { + File dir = createDirInExternal(true); + createXmlInConfigBaseForExternal(dir); + doTestDeployment(false, false, true, + LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); + } + + @Test + public void testDeploymentXmlExternalDirXmlFTF() throws Exception { + File dir = createDirInExternal(true); + createXmlInConfigBaseForExternal(dir); + doTestDeployment(false, true, false, + LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); + } + + @Test + public void testDeploymentXmlExternalDirXmlFTT() throws Exception { + File dir = createDirInExternal(true); + createXmlInConfigBaseForExternal(dir); + doTestDeployment(false, true, true, + LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); + } + + @Test + public void testDeploymentXmlExternalDirXmlTFF() throws Exception { + File dir = createDirInExternal(true); + createXmlInConfigBaseForExternal(dir); + doTestDeployment(true, false, false, + LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); + } + + @Test + public void testDeploymentXmlExternalDirXmlTFT() throws Exception { + File dir = createDirInExternal(true); + createXmlInConfigBaseForExternal(dir); + doTestDeployment(true, false, true, + LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); + } + + @Test + public void testDeploymentXmlExternalDirXmlTTF() throws Exception { + File dir = createDirInExternal(true); + createXmlInConfigBaseForExternal(dir); + doTestDeployment(true, true, false, + LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); + } + + @Test + public void testDeploymentXmlExternalDirXmlTTT() throws Exception { + File dir = createDirInExternal(true); + createXmlInConfigBaseForExternal(dir); + doTestDeployment(true, true, true, + LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); + } +} diff --git a/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentXmlExternalWarXml.java b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentXmlExternalWarXml.java new file mode 100644 index 000000000000..a4df88b3fab7 --- /dev/null +++ b/test/org/apache/catalina/startup/TestHostConfigAutomaticDeploymentXmlExternalWarXml.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.startup; + +import java.io.File; + +import org.junit.Test; + +import org.apache.catalina.LifecycleState; + +/** + * The purpose of this class is to test the automatic deployment features of the + * {@link HostConfig} implementation. + */ +public class TestHostConfigAutomaticDeploymentXmlExternalWarXml extends HostConfigAutomaticDeploymentBaseTest { + + /* + * Expected behaviour for deployment of an XML file that points to an + * external WAR. + * deployXML copyXML unpackWARs XML WAR DIR + * Y/N Y/N Y Y N Y + * Y/N Y/N N Y N N + * + * Notes: No WAR file is present in the appBase because it is an external + * WAR. + * Any context.xml file embedded in the external WAR file is ignored. + */ + @Test + public void testDeploymentXmlExternalWarXmlFFF() throws Exception { + File war = createWar(WAR_XML_SOURCE, false); + createXmlInConfigBaseForExternal(war); + doTestDeployment(false, false, false, + LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); + } + + @Test + public void testDeploymentXmlExternalWarXmlFFT() throws Exception { + File war = createWar(WAR_XML_SOURCE, false); + createXmlInConfigBaseForExternal(war); + doTestDeployment(false, false, true, + LifecycleState.STARTED, XML_COOKIE_NAME, true, false, true); + } + + @Test + public void testDeploymentXmlExternalWarXmlFTF() throws Exception { + File war = createWar(WAR_XML_SOURCE, false); + createXmlInConfigBaseForExternal(war); + doTestDeployment(false, true, false, + LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); + } + + @Test + public void testDeploymentXmlExternalWarXmlFTT() throws Exception { + File war = createWar(WAR_XML_SOURCE, false); + createXmlInConfigBaseForExternal(war); + doTestDeployment(false, true, true, + LifecycleState.STARTED, XML_COOKIE_NAME, true, false, true); + } + + @Test + public void testDeploymentXmlExternalWarXmlTFF() throws Exception { + File war = createWar(WAR_XML_SOURCE, false); + createXmlInConfigBaseForExternal(war); + doTestDeployment(true, false, false, + LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); + } + + @Test + public void testDeploymentXmlExternalWarXmlTFT() throws Exception { + File war = createWar(WAR_XML_SOURCE, false); + createXmlInConfigBaseForExternal(war); + doTestDeployment(true, false, true, + LifecycleState.STARTED, XML_COOKIE_NAME, true, false, true); + } + + @Test + public void testDeploymentXmlExternalWarXmlTTF() throws Exception { + File war = createWar(WAR_XML_SOURCE, false); + createXmlInConfigBaseForExternal(war); + doTestDeployment(true, true, false, + LifecycleState.STARTED, XML_COOKIE_NAME, true, false, false); + } + + @Test + public void testDeploymentXmlExternalWarXmlTTT() throws Exception { + File war = createWar(WAR_XML_SOURCE, false); + createXmlInConfigBaseForExternal(war); + doTestDeployment(true, true, true, + LifecycleState.STARTED, XML_COOKIE_NAME, true, false, true); + } +}