blob: 1494959a61189a21bff2e08b53bec320e0a105b4 [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("webservices-svchandler-annotation");
38 TestClient client = new TestClient();
39 client.doTest(args);
40 stat.printSummary("webservices-annotation");
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;
63 while ((line = input.readLine()) != null) {
64 log(line);
65 if(line.indexOf("So the RESULT OF SUBTRACT SERVICE IS") != -1)
David Matějčekf4dc06a2021-05-17 12:10:57 +020066 found1 = true;
Vinay Vishal57171472018-09-18 20:22:00 +053067 if(line.indexOf("[1113]") != -1)
David Matějčekf4dc06a2021-05-17 12:10:57 +020068 found2 = true;
Vinay Vishal57171472018-09-18 20:22:00 +053069 }
70 return code;
71 }
72
73 private void report(int code) {
74 if(code != 200) {
75 log("Incorrect return code: " + code);
76 fail();
77 }
78 if(!found1) {
79 fail();
80 }
81 if(!found2) {
82 fail();
83 }
84 pass();
85 }
86
87 private void log(String message) {
88 System.out.println("[client.TestClient]:: " + message);
89 }
90
91 private void pass() {
92 stat.addStatus("svchandler-1", stat.PASS);
93 }
94
95 private void fail() {
96 stat.addStatus("svchandler-1", stat.FAIL);
97 }
98}