Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 1 | /* |
arjantijms | bf2bda3 | 2021-03-07 12:32:06 +0100 | [diff] [blame] | 2 | * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 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 | |
| 17 | import java.io.*; |
| 18 | import java.net.*; |
| 19 | import 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 | */ |
| 30 | public class WebTest { |
| 31 | |
arjantijms | bf2bda3 | 2021-03-07 12:32:06 +0100 | [diff] [blame] | 32 | private static SimpleReporterAdapter stat = new SimpleReporterAdapter("appserv-tests"); |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 33 | |
| 34 | private static final String TEST_NAME = "jsp-precompiled-bundled-in-jar"; |
arjantijms | bf2bda3 | 2021-03-07 12:32:06 +0100 | [diff] [blame] | 35 | private static final String EXPECTED_RESPONSE = "This is my UPDATED output"; |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 36 | |
| 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 | } |
arjantijms | bf2bda3 | 2021-03-07 12:32:06 +0100 | [diff] [blame] | 46 | |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 47 | 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 | |
arjantijms | bf2bda3 | 2021-03-07 12:32:06 +0100 | [diff] [blame] | 54 | public void doTest() { |
| 55 | try { |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 56 | invokeJsp(); |
| 57 | } catch (Exception ex) { |
| 58 | stat.addStatus(TEST_NAME, stat.FAIL); |
| 59 | ex.printStackTrace(); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | public void invokeJsp() throws Exception { |
arjantijms | bf2bda3 | 2021-03-07 12:32:06 +0100 | [diff] [blame] | 64 | String url = "http://" + host + ":" + port + contextRoot + "/jsp/test.jsp"; |
| 65 | HttpURLConnection conn = (HttpURLConnection) (new URL(url)).openConnection(); |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 66 | |
arjantijms | bf2bda3 | 2021-03-07 12:32:06 +0100 | [diff] [blame] | 67 | 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ček | f4dc06a | 2021-05-17 12:10:57 +0200 | [diff] [blame^] | 72 | try (InputStream is = conn.getInputStream(); BufferedReader input = new BufferedReader(new InputStreamReader(is))) { |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 73 | String line = input.readLine(); |
| 74 | if (!EXPECTED_RESPONSE.equals(line)) { |
arjantijms | bf2bda3 | 2021-03-07 12:32:06 +0100 | [diff] [blame] | 75 | System.err.println("Wrong response. " + "Expected: " + EXPECTED_RESPONSE + ", received: " + line); |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 76 | stat.addStatus(TEST_NAME, stat.FAIL); |
| 77 | } else { |
| 78 | stat.addStatus(TEST_NAME, stat.PASS); |
| 79 | } |
| 80 | } |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | } |