From 11e583e4e37bd274390643d494d2a8670e118c36 Mon Sep 17 00:00:00 2001 From: amshegokar Date: Tue, 13 Mar 2018 18:55:12 +0530 Subject: Coverage for org.onap.appc.adapter.ssh classes Coverage for org.onap.appc.adapter.ssh classes Sonar-Link: https://sonar.onap.org/code?id=org.onap.appc%3Aappc&selected=org.onap.appc%3Aappc-ssh-adapter-tests%3Asrc%2Fmain%2Fjava%2Forg%2Fonap%2Fappc%2Fadapter%2Fssh Change-Id: Icd1dde27c8588f217b6cca83f1cde3a8b24a41c3 Issue-ID: APPC-725 Signed-off-by: amshegokar --- .../appc-ssh-adapter-tests/pom.xml | 34 +++++---- .../onap/appc/adapter/ssh/TestSshAdapterMock.java | 65 +++++++++++++++++ .../appc/adapter/ssh/TestSshConnectionMock.java | 83 ++++++++++++++++++++++ 3 files changed, 168 insertions(+), 14 deletions(-) create mode 100644 appc-adapters/appc-ssh-adapter/appc-ssh-adapter-tests/src/test/java/org/onap/appc/adapter/ssh/TestSshAdapterMock.java create mode 100644 appc-adapters/appc-ssh-adapter/appc-ssh-adapter-tests/src/test/java/org/onap/appc/adapter/ssh/TestSshConnectionMock.java (limited to 'appc-adapters/appc-ssh-adapter') diff --git a/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-tests/pom.xml b/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-tests/pom.xml index bf91cd2cd..3bc3a5a5a 100644 --- a/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-tests/pom.xml +++ b/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-tests/pom.xml @@ -21,19 +21,25 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. --> - 4.0.0 - - org.onap.appc - appc-ssh-adapter - 1.3.0-SNAPSHOT - - appc-ssh-adapter-tests + 4.0.0 + + org.onap.appc + appc-ssh-adapter + 1.3.0-SNAPSHOT + + appc-ssh-adapter-tests - - - org.onap.appc - appc-ssh-adapter-api - ${project.version} - - + + + org.onap.appc + appc-ssh-adapter-api + ${project.version} + + + junit + junit + 4.12 + test + + \ No newline at end of file diff --git a/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-tests/src/test/java/org/onap/appc/adapter/ssh/TestSshAdapterMock.java b/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-tests/src/test/java/org/onap/appc/adapter/ssh/TestSshAdapterMock.java new file mode 100644 index 000000000..f3badd775 --- /dev/null +++ b/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-tests/src/test/java/org/onap/appc/adapter/ssh/TestSshAdapterMock.java @@ -0,0 +1,65 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : APPC +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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. +* ============LICENSE_END========================================================= +*/ +package org.onap.appc.adapter.ssh; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +public class TestSshAdapterMock { + private SshAdapterMock sshAdapterMock; + + @Before + public void setUp() { + sshAdapterMock = new SshAdapterMock(); + } + + @Test + public void testGetReturnStatus() { + sshAdapterMock.setReturnStatus(200); + assertNotNull(sshAdapterMock.getReturnStatus()); + assertEquals(sshAdapterMock.getReturnStatus(), 200); + } + + @Test + public void testGetReturnStdout() { + sshAdapterMock.setReturnStdout("success"); + assertNotNull(sshAdapterMock.getReturnStdout()); + assertEquals(sshAdapterMock.getReturnStdout(), "success"); + } + + @Test + public void testGetReturnStderr() { + sshAdapterMock.setReturnStderr("error"); + assertNotNull(sshAdapterMock.getReturnStderr()); + assertEquals(sshAdapterMock.getReturnStderr(), "error"); + } + + @Test + public void testGetConnectionMocks() { + sshAdapterMock.setReturnStatus(200); + sshAdapterMock.setReturnStdout("success"); + sshAdapterMock.setReturnStderr("error"); + sshAdapterMock.getConnection("localhost", 8080, "myUser", "myPassword"); + assertEquals(false, sshAdapterMock.getConnectionMocks().isEmpty()); + assertNotNull(sshAdapterMock.getConnectionMocks()); + } +} diff --git a/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-tests/src/test/java/org/onap/appc/adapter/ssh/TestSshConnectionMock.java b/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-tests/src/test/java/org/onap/appc/adapter/ssh/TestSshConnectionMock.java new file mode 100644 index 000000000..182e0d7c7 --- /dev/null +++ b/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-tests/src/test/java/org/onap/appc/adapter/ssh/TestSshConnectionMock.java @@ -0,0 +1,83 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : APPC +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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. +* ============LICENSE_END========================================================= +*/ +package org.onap.appc.adapter.ssh; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +public class TestSshConnectionMock { + + private SshConnectionMock sshConnectionMock; + @Before + public void setUp() { + sshConnectionMock=new SshConnectionMock("localhost", 8080, "myUser", "myPassword"); + } + + @Test + public void testGetHost() { + assertNotNull(sshConnectionMock.getHost()); + assertEquals(sshConnectionMock.getHost(), "localhost"); + } + + @Test + public void testGetPort() { + assertNotNull(sshConnectionMock.getPort()); + assertEquals(sshConnectionMock.getPort(), 8080); + } + + @Test + public void testGetUsername() { + assertNotNull(sshConnectionMock.getUsername()); + assertEquals(sshConnectionMock.getUsername(), "myUser"); + } + + @Test + public void testGetPassword() { + assertNotNull(sshConnectionMock.getPassword()); + assertEquals(sshConnectionMock.getPassword(), "myPassword"); + } + @Test + public void testGetReturnStderr() { + sshConnectionMock.setReturnStderr("returnStderr"); + assertNotNull(sshConnectionMock.getReturnStderr()); + assertEquals(sshConnectionMock.getReturnStderr(), "returnStderr"); + } + @Test + public void testGetReturnStdout() { + sshConnectionMock.setReturnStdout("returnStdout"); + assertNotNull(sshConnectionMock.getReturnStdout()); + assertEquals(sshConnectionMock.getReturnStdout(), "returnStdout"); + } + @Test + public void testGetReturnStatus() { + sshConnectionMock.setReturnStatus(200); + assertNotNull(sshConnectionMock.getReturnStatus()); + assertEquals(sshConnectionMock.getReturnStatus(), 200); + } + @Test + public void testGetExecutedCommands() { + sshConnectionMock.getExecutedCommands().add("cls"); + sshConnectionMock.getExecutedCommands().add("pwd"); + assertNotNull(sshConnectionMock.getExecutedCommands()); + assertEquals(false, sshConnectionMock.getExecutedCommands().isEmpty()); + } +} -- cgit 1.2.3-korg