Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package client; |
| 18 | |
| 19 | import java.io.BufferedReader; |
| 20 | import java.io.InputStream; |
| 21 | import java.io.InputStreamReader; |
| 22 | import java.io.IOException; |
| 23 | import java.net.HttpURLConnection; |
| 24 | import java.net.URL; |
| 25 | |
| 26 | import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; |
| 27 | |
| 28 | public 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ček | f4dc06a | 2021-05-17 12:10:57 +0200 | [diff] [blame^] | 49 | } catch (Exception e) { |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 50 | 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ček | f4dc06a | 2021-05-17 12:10:57 +0200 | [diff] [blame^] | 66 | found1 = true; |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 67 | if(line.indexOf("[1113]") != -1) |
David Matějček | f4dc06a | 2021-05-17 12:10:57 +0200 | [diff] [blame^] | 68 | found2 = true; |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 69 | } |
| 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 | } |