blob: 467e6b9024f3aae036e6128aef5682792f3354bd [file] [log] [blame]
Vinay Vishal57171472018-09-18 20:22:00 +05301/*
2 * Copyright (c) 2017, 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
17package client;
18
19import java.io.BufferedReader;
20import java.io.InputStream;
21import java.io.InputStreamReader;
22import java.io.IOException;
23import java.net.HttpURLConnection;
24import java.net.URL;
25
26import com.sun.ejte.ccl.reporter.SimpleReporterAdapter;
27
28public class TestClient {
29
30 private static SimpleReporterAdapter stat =
31 new SimpleReporterAdapter("appserv-tests");
32
33 public boolean found1 = false;
34 public boolean found2 = false;
35
36 public static void main (String[] args) {
37 stat.addDescription("msgctxt");
38 TestClient client = new TestClient();
39 client.doTest(args);
40 stat.printSummary("msgctxt");
41 }
42
43 public void doTest(String[] args) {
44
45 String url = args[0];
46 try {
47 int code = invokeServlet(url);
48 report(code);
David Matějčekf4dc06a2021-05-17 12:10:57 +020049 } catch (Exception e) {
Vinay Vishal57171472018-09-18 20:22:00 +053050 e.printStackTrace();
51 fail();
52 }
53 }
54
55 private int invokeServlet(String url) throws Exception {
56 log("Invoking url = " + url);
57 URL u = new URL(url);
58 HttpURLConnection c1 = (HttpURLConnection)u.openConnection();
59 int code = c1.getResponseCode();
60 InputStream is = c1.getInputStream();
61 BufferedReader input = new BufferedReader (new InputStreamReader(is));
62 String line = null;
David Matějčekf4dc06a2021-05-17 12:10:57 +020063
Vinay Vishal57171472018-09-18 20:22:00 +053064 while ((line = input.readLine()) != null) {
65 log(line);
66 if(line.indexOf("So the RESULT OF HELLO SERVICE IS") != -1)
67 found1 = true;
68 if(line.indexOf("WebSvcTest-Hello All") != -1)
69 found2 = true;
70 }
71 return code;
72 }
73
74 private void report(int code) {
75 if(code != 200) {
76 log("Incorrect return code: " + code);
77 fail();
78 }
79 if(!found1) {
80 fail();
81 }
82 if(!found2) {
83 fail();
84 }
85 pass();
86 }
87
88 private void log(String message) {
89 System.out.println("[client.TestClient]:: " + message);
90 }
91
92 private void pass() {
93 stat.addStatus("msgctxt", stat.PASS);
94 }
95
96 private void fail() {
97 stat.addStatus("msgctxt", stat.FAIL);
98 }
99}