blob: 4c936e1ec63b54b10aca9374c1a2f400752f6dcf [file] [log] [blame]
Vinay Vishal57171472018-09-18 20:22:00 +05301/*
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
17import java.io.*;
18import java.net.*;
19import 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 */
25public 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čekf4dc06a2021-05-17 12:10:57 +020041
Vinay Vishal57171472018-09-18 20:22:00 +053042 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čekf4dc06a2021-05-17 12:10:57 +020050 try {
Vinay Vishal57171472018-09-18 20:22:00 +053051 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čekf4dc06a2021-05-17 12:10:57 +020061
Vinay Vishal57171472018-09-18 20:22:00 +053062 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čekf4dc06a2021-05-17 12:10:57 +020079 throw new Exception("Wrong response. Expected: " +
Vinay Vishal57171472018-09-18 20:22:00 +053080 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}