diff options
author | liamfallon <liam.fallon@ericsson.com> | 2018-09-27 16:52:23 +0100 |
---|---|---|
committer | liamfallon <liam.fallon@ericsson.com> | 2018-09-27 16:52:34 +0100 |
commit | afd3a44e210de3c1aed9f6f7278913b2a2f2f6d2 (patch) | |
tree | 3b7c6038ec3d526549e4795032ea1c8baf2fcc0a /tools/simple-wsclient/src/test | |
parent | 3595f7c277778a64d1d828b66ed8127d92c010b5 (diff) |
Add JUnit for web service client tool
JUnit, SOnar fixes, and some minor bug fixes.
Issue-ID: POLICY-1034
Change-Id: I72f46e944051f7d65d6b106afe33c759975283af
Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'tools/simple-wsclient/src/test')
-rw-r--r-- | tools/simple-wsclient/src/test/java/org/onap/policy/apex/tools/simple/wsclient/WsClientTest.java | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/tools/simple-wsclient/src/test/java/org/onap/policy/apex/tools/simple/wsclient/WsClientTest.java b/tools/simple-wsclient/src/test/java/org/onap/policy/apex/tools/simple/wsclient/WsClientTest.java new file mode 100644 index 000000000..0b097a0d0 --- /dev/null +++ b/tools/simple-wsclient/src/test/java/org/onap/policy/apex/tools/simple/wsclient/WsClientTest.java @@ -0,0 +1,170 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.tools.simple.wsclient; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.PrintStream; + +import org.junit.Test; + +/** + * Test the WsClient utility. + */ +public class WsClientTest { + @Test + public void testWsClient() { + try { + final String[] EventArgs = + { "-h" }; + + WsClientMain.main(EventArgs); + } catch (Exception exc) { + fail("test should not throw an exception"); + } + } + + @Test + public void testWsClientNoOptions() { + final String[] EventArgs = new String[] + {}; + + final String outputString = runWsClient(EventArgs); + + assertTrue(outputString.contains("ws-client: starting simple event echo")); + } + + @Test + public void testWsClientBadOptions() { + final String[] EventArgs = + { "-zabbu" }; + + final String outputString = runWsClient(EventArgs); + + assertTrue(outputString.contains("usage: ws-client")); + } + + @Test + public void testWsClientHelp() { + final String[] EventArgs = + { "-h" }; + + final String outputString = runWsClient(EventArgs); + + assertTrue(outputString.contains("usage: ws-client")); + } + + @Test + public void testWsClientVersion() { + final String[] EventArgs = + { "-v" }; + + final String outputString = runWsClient(EventArgs); + + assertTrue(outputString.contains("ws-client")); + } + + @Test + public void testWsClientNoServerArg() { + final String[] EventArgs = + { "-s" }; + + final String outputString = runWsClient(EventArgs); + + assertTrue(outputString.contains("ws-client")); + } + + @Test + public void testWsClientNoPortArg() { + final String[] EventArgs = + { "-p" }; + + final String outputString = runWsClient(EventArgs); + + assertTrue(outputString.contains("ws-client")); + } + + @Test + public void testWsClientBadPortArg() { + final String[] EventArgs = + { "-p", "hello" }; + + final String outputString = runWsClient(EventArgs); + + assertTrue(outputString.contains("ws-client")); + } + + @Test + public void testWsClientBadServerArg() { + final String[] EventArgs = + { "-s", "asdsadadasd:asdasdsadasd@@" }; + + final String outputString = runWsClient(EventArgs); + + assertTrue(outputString.contains("ws-client")); + } + + @Test + public void testWsClientConsole() { + final String[] EventArgs = + { "-c", "-s", "AServerThatDoesntExist", "-p", "99999999" }; + + final String outputString = runWsClient(EventArgs); + + assertTrue(outputString.contains("terminate the application typing")); + } + + @Test + public void testWsClientEcho() { + final String[] EventArgs = + { "-s", "AServerThatDoesntExist", "-p", "99999999" }; + + final String outputString = runWsClient(EventArgs); + + assertTrue(outputString.contains( + "Once started, the application will simply print out all received events to standard out")); + } + + /** + * Run the application. + * + * @param eventArgs the command arguments + * @return a string containing the command output + */ + private String runWsClient(final String[] eventArgs) { + final ByteArrayOutputStream baosOut = new ByteArrayOutputStream(); + final ByteArrayOutputStream baosErr = new ByteArrayOutputStream(); + + new WsClientMain(eventArgs, new PrintStream(baosOut, true)); + + InputStream testInput = new ByteArrayInputStream("Test Data for Input to WS".getBytes()); + System.setIn(testInput); + + String outString = baosOut.toString(); + String errString = baosErr.toString(); + + return "*** StdOut ***\n" + outString + "\n*** StdErr ***\n" + errString; + } +} |