blob: 2791426b87cc13a38a5790fe696249bc1f361c2a [file] [log] [blame]
Vinay Vishal57171472018-09-18 20:22:00 +05301/*
arjantijmsbf2bda32021-03-07 12:32:06 +01002 * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
Vinay Vishal57171472018-09-18 20:22:00 +05303 *
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
17import java.io.*;
18import java.net.*;
19import com.sun.ejte.ccl.reporter.*;
20
21/*
22 * Unit test for 6181923 ("Add support for 'use-precompiled' JspServlet param
23 * introduced by WS 6.0"):
24 *
25 * Ensure that a JSP that was precompiled and whose servlet class file has
26 * been bundled in a JAR in WEB-INF/lib, may still be accessed even if the JSP
27 * file itself is not present in the webapp, provided that usePrecompiled
28 * has been set to TRUE.
29 */
30public class WebTest {
31
arjantijmsbf2bda32021-03-07 12:32:06 +010032 private static SimpleReporterAdapter stat = new SimpleReporterAdapter("appserv-tests");
Vinay Vishal57171472018-09-18 20:22:00 +053033
34 private static final String TEST_NAME = "jsp-precompiled-bundled-in-jar";
arjantijmsbf2bda32021-03-07 12:32:06 +010035 private static final String EXPECTED_RESPONSE = "This is my UPDATED output";
Vinay Vishal57171472018-09-18 20:22:00 +053036
37 private String host;
38 private String port;
39 private String contextRoot;
40
41 public WebTest(String[] args) {
42 host = args[0];
43 port = args[1];
44 contextRoot = args[2];
45 }
arjantijmsbf2bda32021-03-07 12:32:06 +010046
Vinay Vishal57171472018-09-18 20:22:00 +053047 public static void main(String[] args) {
48 stat.addDescription("Unit test for 6273340");
49 WebTest webTest = new WebTest(args);
50 webTest.doTest();
51 stat.printSummary(TEST_NAME);
52 }
53
arjantijmsbf2bda32021-03-07 12:32:06 +010054 public void doTest() {
55 try {
Vinay Vishal57171472018-09-18 20:22:00 +053056 invokeJsp();
57 } catch (Exception ex) {
58 stat.addStatus(TEST_NAME, stat.FAIL);
59 ex.printStackTrace();
60 }
61 }
62
63 public void invokeJsp() throws Exception {
arjantijmsbf2bda32021-03-07 12:32:06 +010064 String url = "http://" + host + ":" + port + contextRoot + "/jsp/test.jsp";
65 HttpURLConnection conn = (HttpURLConnection) (new URL(url)).openConnection();
Vinay Vishal57171472018-09-18 20:22:00 +053066
arjantijmsbf2bda32021-03-07 12:32:06 +010067 int code = conn.getResponseCode();
68 if (code != 200) {
69 System.err.println("Unexpected return code: " + code);
70 stat.addStatus(TEST_NAME, stat.FAIL);
71 } else {
David Matějčekf4dc06a2021-05-17 12:10:57 +020072 try (InputStream is = conn.getInputStream(); BufferedReader input = new BufferedReader(new InputStreamReader(is))) {
Vinay Vishal57171472018-09-18 20:22:00 +053073 String line = input.readLine();
74 if (!EXPECTED_RESPONSE.equals(line)) {
arjantijmsbf2bda32021-03-07 12:32:06 +010075 System.err.println("Wrong response. " + "Expected: " + EXPECTED_RESPONSE + ", received: " + line);
Vinay Vishal57171472018-09-18 20:22:00 +053076 stat.addStatus(TEST_NAME, stat.FAIL);
77 } else {
78 stat.addStatus(TEST_NAME, stat.PASS);
79 }
80 }
Vinay Vishal57171472018-09-18 20:22:00 +053081 }
82 }
83}