Skip to content

Commit 67a96f4

Browse files
committed
Expand TCK tests to cover new welcome file behaviour
1 parent b774a48 commit 67a96f4

File tree

8 files changed

+359
-0
lines changed

8 files changed

+359
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
package servlet.tck.spec.welcomefiles;
17+
18+
import java.io.IOException;
19+
import java.io.PrintWriter;
20+
21+
import jakarta.servlet.GenericServlet;
22+
import jakarta.servlet.ServletException;
23+
import jakarta.servlet.ServletRequest;
24+
import jakarta.servlet.ServletResponse;
25+
26+
/**
27+
* Simple servlet used for the welcome servlet tests.
28+
*/
29+
public class IndexServletDo extends GenericServlet {
30+
31+
private static final long serialVersionUID = 1L;
32+
33+
@Override
34+
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
35+
PrintWriter pw = response.getWriter();
36+
// Test looks for this string to confirm the welcome servlet was used.
37+
pw.println("INDEX from *.do");
38+
}
39+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
package servlet.tck.spec.welcomefiles;
17+
18+
import servlet.tck.common.client.AbstractTckTest;
19+
import org.jboss.arquillian.container.test.api.Deployment;
20+
import org.jboss.shrinkwrap.api.ShrinkWrap;
21+
import org.jboss.shrinkwrap.api.spec.WebArchive;
22+
import org.junit.jupiter.api.Test;
23+
24+
import java.util.Arrays;
25+
26+
public class WelcomeFilesFileTests extends AbstractTckTest {
27+
28+
/**
29+
* Deployment for the test.
30+
*
31+
* @return The web archive to test.
32+
*
33+
* @throws Exception If an error occurs creating the archive.
34+
*/
35+
@Deployment(testable = false)
36+
public static WebArchive getTestArchive() throws Exception {
37+
WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "servlet_spec_welcomefiles_file_web.war")
38+
.addClasses(IndexServletDo.class)
39+
.setWebXML(WelcomeFilesFileTests.class.getResource("servlet_spec_welcomefiles_file_web.xml"));
40+
Arrays.asList("legacy/index.html")
41+
.forEach(s -> webArchive.addAsWebResource("spec/welcomefiles/" +s, s));
42+
return webArchive;
43+
}
44+
45+
46+
/*
47+
* Test should trigger a 404 since index.do is configured as a welcome file and no such file exists.
48+
*/
49+
@Test
50+
public void partialfoundLegacy() throws Exception {
51+
TEST_PROPS.get().setProperty(FOLLOW_REDIRECT, "follow_redirect");
52+
TEST_PROPS.get().setProperty(STATUS_CODE, NOT_FOUND);
53+
TEST_PROPS.get().setProperty(SEARCH_STRING, "<html");
54+
TEST_PROPS.get().setProperty(APITEST, "legacy");
55+
invoke();
56+
}
57+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
package servlet.tck.spec.welcomefiles;
17+
18+
import servlet.tck.common.client.AbstractTckTest;
19+
import org.jboss.arquillian.container.test.api.Deployment;
20+
import org.jboss.shrinkwrap.api.ShrinkWrap;
21+
import org.jboss.shrinkwrap.api.spec.WebArchive;
22+
import org.junit.jupiter.api.Test;
23+
24+
import java.util.Arrays;
25+
26+
public class WelcomeFilesLegacyTests extends AbstractTckTest {
27+
28+
/**
29+
* Deployment for the test.
30+
*
31+
* @return The web archive to test.
32+
*
33+
* @throws Exception If an error occurs creating the archive.
34+
*/
35+
@Deployment(testable = false)
36+
public static WebArchive getTestArchive() throws Exception {
37+
WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "servlet_spec_welcomefiles_legacy_web.war")
38+
.addClasses(IndexServletDo.class)
39+
.setWebXML(WelcomeFilesLegacyTests.class.getResource("servlet_spec_welcomefiles_legacy_web.xml"));
40+
Arrays.asList("legacy/index.html")
41+
.forEach(s -> webArchive.addAsWebResource("spec/welcomefiles/" +s, s));
42+
return webArchive;
43+
}
44+
45+
46+
/*
47+
* Test should trigger a 404 since default.jsp is a valid welcome file but does not exist.
48+
*/
49+
@Test
50+
public void partialfoundLegacy() throws Exception {
51+
TEST_PROPS.get().setProperty(FOLLOW_REDIRECT, "follow_redirect");
52+
TEST_PROPS.get().setProperty(STATUS_CODE, NOT_FOUND);
53+
TEST_PROPS.get().setProperty(SEARCH_STRING, "<html");
54+
TEST_PROPS.get().setProperty(APITEST, "legacy");
55+
invoke();
56+
}
57+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
package servlet.tck.spec.welcomefiles;
17+
18+
import servlet.tck.common.client.AbstractTckTest;
19+
import org.jboss.arquillian.container.test.api.Deployment;
20+
import org.jboss.shrinkwrap.api.ShrinkWrap;
21+
import org.jboss.shrinkwrap.api.spec.WebArchive;
22+
import org.junit.jupiter.api.Test;
23+
24+
import java.util.Arrays;
25+
26+
public class WelcomeFilesServletTests extends AbstractTckTest {
27+
28+
/**
29+
* Deployment for the test.
30+
*
31+
* @return The web archive to test.
32+
*
33+
* @throws Exception If an error occurs creating the archive.
34+
*/
35+
@Deployment(testable = false)
36+
public static WebArchive getTestArchive() throws Exception {
37+
WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "servlet_spec_welcomefiles_servlet_web.war")
38+
.addClasses(IndexServletDo.class)
39+
.setWebXML(WelcomeFilesServletTests.class.getResource("servlet_spec_welcomefiles_servlet_web.xml"));
40+
Arrays.asList("legacy/index.html")
41+
.forEach(s -> webArchive.addAsWebResource("spec/welcomefiles/" +s, s));
42+
return webArchive;
43+
}
44+
45+
46+
/*
47+
* Test should use the index.do mapping since it is configured as a welcome-servlet.
48+
*/
49+
@Test
50+
public void partialfoundServlet() throws Exception {
51+
TEST_PROPS.get().setProperty(FOLLOW_REDIRECT, "follow_redirect");
52+
TEST_PROPS.get().setProperty(SEARCH_STRING, "INDEX from *.do");
53+
TEST_PROPS.get().setProperty(APITEST, "legacy");
54+
invoke();
55+
}
56+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (c) 2025 Contributors to the Eclipse Foundation
5+
6+
This program and the accompanying materials are made available under the
7+
terms of the Eclipse Public License v. 2.0, which is available at
8+
http://www.eclipse.org/legal/epl-2.0.
9+
10+
This Source Code may also be made available under the following Secondary
11+
Licenses when the conditions for such availability set forth in the
12+
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
13+
version 2 with the GNU Classpath Exception, which is available at
14+
https://www.gnu.org/software/classpath/license.html.
15+
16+
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
17+
18+
-->
19+
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
version="6.2"
22+
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_2.xsd">
23+
<display-name>Welcome Files - File</display-name>
24+
<servlet>
25+
<servlet-name>DefaultLegacyJSP</servlet-name>
26+
<jsp-file>/legacy/default.jsp</jsp-file>
27+
</servlet>
28+
<servlet>
29+
<servlet-name>IndexDo</servlet-name>
30+
<servlet-class>servlet.tck.spec.welcomefiles.IndexServletDo</servlet-class>
31+
</servlet>
32+
<servlet-mapping>
33+
<servlet-name>IndexDo</servlet-name>
34+
<url-pattern>*.do</url-pattern>
35+
</servlet-mapping>
36+
<welcome-file-list>
37+
<welcome-file>default.jsp</welcome-file>
38+
<welcome-file>index.do</welcome-file>
39+
</welcome-file-list>
40+
</web-app>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (c) 2025 Contributors to the Eclipse Foundation
5+
6+
This program and the accompanying materials are made available under the
7+
terms of the Eclipse Public License v. 2.0, which is available at
8+
http://www.eclipse.org/legal/epl-2.0.
9+
10+
This Source Code may also be made available under the following Secondary
11+
Licenses when the conditions for such availability set forth in the
12+
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
13+
version 2 with the GNU Classpath Exception, which is available at
14+
https://www.gnu.org/software/classpath/license.html.
15+
16+
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
17+
18+
-->
19+
<!--
20+
DO NOT increment the deployment descriptor beyond 6.1. This version is required to test legacy welcome files behaviour.
21+
-->
22+
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
23+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24+
version="6.1"
25+
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_1.xsd">
26+
<display-name>Welcome Files - Legacy</display-name>
27+
<servlet>
28+
<servlet-name>DefaultLegacyJSP</servlet-name>
29+
<jsp-file>/legacy/default.jsp</jsp-file>
30+
</servlet>
31+
<servlet>
32+
<servlet-name>IndexDo</servlet-name>
33+
<servlet-class>servlet.tck.spec.welcomefiles.IndexServletDo</servlet-class>
34+
</servlet>
35+
<servlet-mapping>
36+
<servlet-name>IndexDo</servlet-name>
37+
<url-pattern>*.do</url-pattern>
38+
</servlet-mapping>
39+
<welcome-file-list>
40+
<welcome-file>default.jsp</welcome-file>
41+
<welcome-file>index.do</welcome-file>
42+
</welcome-file-list>
43+
</web-app>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (c) 2025 Contributors to the Eclipse Foundation
5+
6+
This program and the accompanying materials are made available under the
7+
terms of the Eclipse Public License v. 2.0, which is available at
8+
http://www.eclipse.org/legal/epl-2.0.
9+
10+
This Source Code may also be made available under the following Secondary
11+
Licenses when the conditions for such availability set forth in the
12+
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
13+
version 2 with the GNU Classpath Exception, which is available at
14+
https://www.gnu.org/software/classpath/license.html.
15+
16+
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
17+
18+
-->
19+
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
version="6.2"
22+
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_2.xsd">
23+
<display-name>Welcome Files - Servlet</display-name>
24+
<servlet>
25+
<servlet-name>DefaultLegacyJSP</servlet-name>
26+
<jsp-file>/legacy/default.jsp</jsp-file>
27+
</servlet>
28+
<servlet>
29+
<servlet-name>IndexDo</servlet-name>
30+
<servlet-class>servlet.tck.spec.welcomefiles.IndexServletDo</servlet-class>
31+
</servlet>
32+
<servlet-mapping>
33+
<servlet-name>IndexDo</servlet-name>
34+
<url-pattern>*.do</url-pattern>
35+
</servlet-mapping>
36+
<welcome-file-list>
37+
<welcome-file>default.jsp</welcome-file>
38+
<welcome-servlet>index.do</welcome-servlet>
39+
</welcome-file-list>
40+
</web-app>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<html>
2+
<head>
3+
<!--
4+
5+
Copyright (c) 2018-2025 Oracle and/or its affiliates and others.
6+
All rights reserved.
7+
8+
This program and the accompanying materials are made available under the
9+
terms of the Eclipse Public License v. 2.0, which is available at
10+
http://www.eclipse.org/legal/epl-2.0.
11+
12+
This Source Code may also be made available under the following Secondary
13+
Licenses when the conditions for such availability set forth in the
14+
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
15+
version 2 with the GNU Classpath Exception, which is available at
16+
https://www.gnu.org/software/classpath/license.html.
17+
18+
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
19+
20+
-->
21+
22+
<title>index.html</title>
23+
</head>
24+
<body>
25+
INDEX from legacy/index.html
26+
</body>
27+
</html>

0 commit comments

Comments
 (0)