summaryrefslogtreecommitdiffstats
path: root/adaptors/saltstack-adaptor/saltstack-adaptor-provider
diff options
context:
space:
mode:
authorGanesh <ganesh.c@samsung.com>2022-03-26 10:41:01 +0530
committerGanesh <ganesh.c@samsung.com>2022-03-26 10:41:17 +0530
commitab3fb66ccf5b490275b3ee23024d1d2422bce407 (patch)
treead5c758644123ace54ee0a3d569def00b1dd84b3 /adaptors/saltstack-adaptor/saltstack-adaptor-provider
parent7c0ec3e4540c1a10a03efcfbae06c4a7915977a6 (diff)
unit test enhancement
Signed-off-by: Ganesh <ganesh.c@samsung.com> Change-Id: Ie9f1596860b6f0d1dee7eef5e1998232730c0c54 Issue-ID: CCSDK-3476
Diffstat (limited to 'adaptors/saltstack-adaptor/saltstack-adaptor-provider')
-rw-r--r--adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestConnectionBuilder.java13
-rw-r--r--adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSaltstackAdaptorPropertiesProviderImpl.java17
-rw-r--r--adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSshConnection.java112
3 files changed, 30 insertions, 112 deletions
diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestConnectionBuilder.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestConnectionBuilder.java
index 0ed2f7d69..51e8b8457 100644
--- a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestConnectionBuilder.java
+++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestConnectionBuilder.java
@@ -181,4 +181,17 @@ public class TestConnectionBuilder {
int status = result.getStatusCode();
assertEquals(613, status);
}
+
+ @Test
+ public void reqExecCommand_exitStatusNoReadPermission() {
+
+ int exitStatus = 255;
+ String errFilePath = "src/test/resources/test.json";
+ String command = "test";
+
+ SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
+ int status = result.getStatusCode();
+ assertEquals(698, status);
+ }
+
}
diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSaltstackAdaptorPropertiesProviderImpl.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSaltstackAdaptorPropertiesProviderImpl.java
index 29639f2ac..d8a855ec7 100644
--- a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSaltstackAdaptorPropertiesProviderImpl.java
+++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSaltstackAdaptorPropertiesProviderImpl.java
@@ -307,4 +307,21 @@ public class TestSaltstackAdaptorPropertiesProviderImpl {
adaptor = new SaltstackAdaptorImpl();
assertNotNull(adaptor);
}
+
+ @Test
+ public void reqExecCommand_setPropertiesTwoPortNull() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+ params.put("org.onap.appc.adaptor.saltstack.clientType", "BOTH");
+ params.put("User", "test");
+ params.put("Password", "test");
+ SaltstackAdaptorPropertiesProvider propProvider = new SaltstackAdaptorPropertiesProvider() {
+ @Override
+ public Properties getProperties() {
+ return params;
+ }
+ };
+ adaptor = new SaltstackAdaptorImpl(propProvider);
+ assertNotNull(propProvider);
+ }
+
}
diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSshConnection.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSshConnection.java
deleted file mode 100644
index b7a06ae12..000000000
--- a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSshConnection.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK
- * ================================================================================
- * Copyright (C) 2021 Samsung Electronics. 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.
- *
- *
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.ccsdk.sli.adaptors.saltstack.impl;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackResult;
-import org.onap.ccsdk.sli.adaptors.saltstack.impl.SshConnection;
-
-
-import java.io.FileOutputStream;
-import java.io.OutputStream;
-import java.util.Properties;
-
-import static org.junit.Assert.assertEquals;
-
-public class TestSshConnection {
-
-private SshConnection sshConnection;
-private Properties params;
-
-
- @Before
- public void setup() throws IllegalArgumentException {
- String HostName = "localhost";
- int Port = 22;
- String User = "test";
- String Password = "test";
- sshConnection = new SshConnection(HostName, Port, User, Password);
- params = new Properties();
- }
-
- @Test(expected=NullPointerException.class)
- public void reqConnect_exitStatusFailed() {
- sshConnection.setExecTimeout(10);
- sshConnection.connect();
- }
-
- @Test
- public void reqexecCommandWithPty_exitStatusFailed() {
- sshConnection.setExecTimeout(10);
- int outcome = 999;
- try {
- params.put("org.onap.appc.adaptor.saltstack.clientType", "SSH_CERT");
- params.put("org.onap.appc.adaptor.saltstack.host", "test");
- params.put("org.onap.appc.adaptor.saltstack.port", "10");
- params.put("org.onap.appc.adaptor.saltstack.userName", "test");
- params.put("org.onap.appc.adaptor.saltstack.userPasswd", "test");
- params.put("org.onap.appc.adaptor.saltstack.sshKey", "test");
- OutputStream res = new FileOutputStream("test.out");
- outcome = sshConnection.execCommandWithPty("ls",res);
- assertEquals(1,outcome);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Test(expected=NullPointerException.class)
- public void reqDisconnect_exitStatusFailed() {
- params.put("org.onap.appc.adaptor.saltstack.clientType", "SSH_CERT");
- params.put("org.onap.appc.adaptor.saltstack.host", "test");
- params.put("org.onap.appc.adaptor.saltstack.port", "10");
- params.put("org.onap.appc.adaptor.saltstack.userName", "test");
- params.put("org.onap.appc.adaptor.saltstack.userPasswd", "test");
- params.put("org.onap.appc.adaptor.saltstack.sshKey", "test");
- sshConnection.setExecTimeout(10);
- sshConnection.disconnect();
- }
-
- @Test
- public void reqexecCommand_exitStatusFailed() {
- sshConnection.setExecTimeout(10);
- int outcome=999;
- try {
- params.put("org.onap.appc.adaptor.saltstack.clientType", "SSH_CERT");
- params.put("org.onap.appc.adaptor.saltstack.host", "test");
- params.put("org.onap.appc.adaptor.saltstack.port", "10");
- params.put("org.onap.appc.adaptor.saltstack.userName", "test");
- params.put("org.onap.appc.adaptor.saltstack.userPasswd", "test");
- params.put("org.onap.appc.adaptor.saltstack.sshKey", "test");
- OutputStream res = new FileOutputStream("test.out");
- OutputStream resErr = new FileOutputStream("test.out");
- outcome = sshConnection.execCommand("ls",res, resErr);
- assertEquals(1,outcome);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-}
-