Issue #4431 Add tests for default-context-path (#4467)

Signed-off-by: Jan Bartel <janb@webtide.com>
This commit is contained in:
Jan Bartel 2020-01-17 00:39:16 +11:00 committed by GitHub
parent d4f72256e7
commit f1474a4a3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 99 additions and 0 deletions

View File

@ -79,6 +79,65 @@ public class WebAppContextTest
Configurations.cleanKnown();
}
@Test
public void testDefaultContextPath() throws Exception
{
Server server = new Server();
File webXml = MavenTestingUtils.getTestResourceFile("web-with-default-context-path.xml");
File webXmlEmptyPath = MavenTestingUtils.getTestResourceFile("web-with-empty-default-context-path.xml");
File webDefaultXml = MavenTestingUtils.getTestResourceFile("web-default-with-default-context-path.xml");
File overrideWebXml = MavenTestingUtils.getTestResourceFile("override-web-with-default-context-path.xml");
assertNotNull(webXml);
assertNotNull(webDefaultXml);
assertNotNull(overrideWebXml);
assertNotNull(webXmlEmptyPath);
try
{
WebAppContext wac = new WebAppContext();
wac.setResourceBase(MavenTestingUtils.getTargetTestingDir().getAbsolutePath());
server.setHandler(wac);
//test that an empty default-context-path defaults to root
wac.setDescriptor(webXmlEmptyPath.getAbsolutePath());
server.start();
assertEquals("/", wac.getContextPath());
server.stop();
//test web-default.xml value is used
wac.setDescriptor(null);
wac.setDefaultsDescriptor(webDefaultXml.getAbsolutePath());
server.start();
assertEquals("/one", wac.getContextPath());
server.stop();
//test web.xml value is used
wac.setDescriptor(webXml.getAbsolutePath());
server.start();
assertEquals("/two", wac.getContextPath());
server.stop();
//test override-web.xml value is used
wac.setOverrideDescriptor(overrideWebXml.getAbsolutePath());
server.start();
assertEquals("/three", wac.getContextPath());
server.stop();
//test that explicitly set context path is used instead
wac.setContextPath("/foo");
server.start();
assertEquals("/foo", wac.getContextPath());
}
finally
{
server.stop();
}
}
@Test
public void testSessionListeners()
{

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee web-app_4_0.xsd"
version="4.0">
<display-name>Test 4 WebApp</display-name>
<default-context-path>/three</default-context-path>
</web-app>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee web-app_4_0.xsd"
version="4.0">
<display-name>Test 4 WebApp</display-name>
<default-context-path>/one</default-context-path>
</web-app>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee web-app_4_0.xsd"
version="4.0">
<display-name>Test 4 WebApp</display-name>
<default-context-path>/two</default-context-path>
</web-app>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee web-app_4_0.xsd"
version="4.0">
<display-name>Test 4 WebApp</display-name>
<default-context-path></default-context-path>
</web-app>