Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. |
| 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 4657979 ("WEB:JSP:JDBC:Server failed to load zip file under |
| 23 | * ../WEB-INF/lib directory") |
| 24 | */ |
| 25 | public class WebTest { |
| 26 | |
| 27 | private static SimpleReporterAdapter stat |
| 28 | = new SimpleReporterAdapter("appserv-tests"); |
| 29 | private static final String TEST_NAME = "load-classes-from-zip-file"; |
| 30 | private static final String EXPECTED_RESPONSE = "true"; |
| 31 | |
| 32 | private String host; |
| 33 | private String port; |
| 34 | private String contextRoot; |
| 35 | |
| 36 | public WebTest(String[] args) { |
| 37 | host = args[0]; |
| 38 | port = args[1]; |
| 39 | contextRoot = args[2]; |
| 40 | } |
David Matějček | f4dc06a | 2021-05-17 12:10:57 +0200 | [diff] [blame^] | 41 | |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 42 | public static void main(String[] args) { |
| 43 | stat.addDescription("Unit test for 4657979"); |
| 44 | WebTest webTest = new WebTest(args); |
| 45 | webTest.doTest(); |
| 46 | stat.printSummary(TEST_NAME); |
| 47 | } |
| 48 | |
| 49 | public void doTest() { |
David Matějček | f4dc06a | 2021-05-17 12:10:57 +0200 | [diff] [blame^] | 50 | try { |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 51 | invoke(); |
| 52 | stat.addStatus(TEST_NAME, stat.PASS); |
| 53 | } catch (Exception ex) { |
| 54 | System.out.println(TEST_NAME + " test failed"); |
| 55 | stat.addStatus(TEST_NAME, stat.FAIL); |
| 56 | ex.printStackTrace(); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | private void invoke() throws Exception { |
David Matějček | f4dc06a | 2021-05-17 12:10:57 +0200 | [diff] [blame^] | 61 | |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 62 | String url = "http://" + host + ":" + port + contextRoot |
| 63 | + "/TestServlet"; |
| 64 | HttpURLConnection conn = (HttpURLConnection) |
| 65 | (new URL(url)).openConnection(); |
| 66 | |
| 67 | int code = conn.getResponseCode(); |
| 68 | if (code != 200) { |
| 69 | throw new Exception("Unexpected return code: " + code); |
| 70 | } |
| 71 | |
| 72 | InputStream is = null; |
| 73 | BufferedReader input = null; |
| 74 | try { |
| 75 | is = conn.getInputStream(); |
| 76 | input = new BufferedReader(new InputStreamReader(is)); |
| 77 | String line = input.readLine(); |
| 78 | if (!EXPECTED_RESPONSE.equals(line)) { |
David Matějček | f4dc06a | 2021-05-17 12:10:57 +0200 | [diff] [blame^] | 79 | throw new Exception("Wrong response. Expected: " + |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 80 | EXPECTED_RESPONSE + ", received: " + line); |
| 81 | } |
| 82 | } finally { |
| 83 | try { |
| 84 | if (is != null) { |
| 85 | is.close(); |
| 86 | } |
| 87 | } catch (IOException ioe) { |
| 88 | // ignore |
| 89 | } |
| 90 | try { |
| 91 | if (input != null) { |
| 92 | input.close(); |
| 93 | } |
| 94 | } catch (IOException ioe) { |
| 95 | // ignore |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | } |