summaryrefslogtreecommitdiffstats
path: root/saltstack-adapter/saltstack-adapter-provider/src/test/java/org
diff options
context:
space:
mode:
authorGanesh Chandrasekaran <ganesh.c@samsung.com>2018-07-10 18:27:17 +0900
committerGanesh Chandrasekaran <ganesh.c@samsung.com>2018-07-10 18:33:52 +0900
commit67c775f8adfce8b0e139ce9e6b70386047090c69 (patch)
tree1f0190c3c35d2b40a9f4368489ac54dff0f796f3 /saltstack-adapter/saltstack-adapter-provider/src/test/java/org
parentf7c04ba242c8cead90536dc27a4620593304189a (diff)
saltstack reqExecSls implemented as adaptor
Issue-ID: CCSDK-330 Change-Id: Icdb2c70d94d4901f1b18713b8b33666169a2b6d9 Signed-off-by: Ganesh Chandrasekaran <ganesh.c@samsung.com>
Diffstat (limited to 'saltstack-adapter/saltstack-adapter-provider/src/test/java/org')
-rw-r--r--saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/impl/TestConnectionBuilder.java174
-rw-r--r--saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/impl/TestSaltstackAdapterImpl.java410
-rw-r--r--saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/model/TestJsonParser.java74
3 files changed, 626 insertions, 32 deletions
diff --git a/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/impl/TestConnectionBuilder.java b/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/impl/TestConnectionBuilder.java
new file mode 100644
index 000000000..d9a384141
--- /dev/null
+++ b/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/impl/TestConnectionBuilder.java
@@ -0,0 +1,174 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.adapter.impl;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.ccsdk.sli.adaptors.saltstack.impl.ConnectionBuilder;
+import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackResult;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+
+public class TestConnectionBuilder {
+
+ private final String PENDING = "100";
+ private final String SUCCESS = "400";
+ private String message = "{\"Results\":{\"192.168.1.10\":{\"Id\":\"101\",\"StatusCode\":200,\"StatusMessage\":\"SUCCESS\"}},\"StatusCode\":200,\"StatusMessage\":\"FINISHED\"}";
+
+ private ConnectionBuilder connBuilder;
+ private String TestId;
+ private boolean testMode = true;
+ private Map<String, String> params;
+ private SvcLogicContext svcContext;
+
+
+ @Before
+ public void setup() throws IllegalArgumentException {
+ testMode = true;
+ svcContext = new SvcLogicContext();
+ String HostName = "test";
+ String Port = "10";
+ String User = "test";
+ String Password = "test";
+ connBuilder = new ConnectionBuilder(HostName, Port, User, Password);
+
+ params = new HashMap<>();
+ params.put("AgentUrl", "https://192.168.1.1");
+ params.put("User", "test");
+ params.put("Password", "test");
+ }
+
+ @After
+ public void tearDown() {
+ testMode = false;
+ connBuilder = null;
+ params = null;
+ svcContext = null;
+ }
+
+ @Test
+ public void reqExecCommand_exitStatus255() {
+
+ 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);
+ }
+
+ @Test
+ public void reqExecCommand_exitStatus1() {
+
+ int exitStatus = 1;
+ String errFilePath = "src/test/resources/test.json";
+ String command = "test";
+
+ SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
+ int status = result.getStatusCode();
+ assertEquals(698, status);
+ }
+
+ @Test
+ public void reqExecCommand_exitStatus5() {
+
+ int exitStatus = 5;
+ String errFilePath = "src/test/resources/test.json";
+ String command = "test";
+
+ SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
+ int status = result.getStatusCode();
+ assertEquals(613, status);
+ }
+
+ @Test
+ public void reqExecCommand_exitStatus65() {
+
+ int exitStatus = 65;
+ String errFilePath = "src/test/resources/test.json";
+ String command = "test";
+
+ SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
+ int status = result.getStatusCode();
+ assertEquals(613, status);
+ }
+
+ @Test
+ public void reqExecCommand_exitStatus67() {
+
+ int exitStatus = 5;
+ String errFilePath = "src/test/resources/test.json";
+ String command = "test";
+
+ SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
+ int status = result.getStatusCode();
+ assertEquals(613, status);
+ }
+
+ @Test
+ public void reqExecCommand_exitStatus73() {
+
+ int exitStatus = 65;
+ String errFilePath = "src/test/resources/test.json";
+ String command = "test";
+
+ SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
+ int status = result.getStatusCode();
+ assertEquals(613, status);
+ }
+
+ @Test
+ public void reqExecCommand_exitStatusUnknown() {
+
+ int exitStatus = 5121;
+ String errFilePath = "src/test/resources/test.json";
+ String command = "test";
+
+ SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
+ int status = result.getStatusCode();
+ assertEquals(699, status);
+ }
+
+ @Test
+ public void reqExecCommand_exitStatusNoFile() {
+
+ int exitStatus = 65;
+ String errFilePath = "src/test/resource/test.json";
+ String command = "test";
+
+ SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
+ int status = result.getStatusCode();
+ assertEquals(613, status);
+ }
+}
diff --git a/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/impl/TestSaltstackAdapterImpl.java b/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/impl/TestSaltstackAdapterImpl.java
index d7b330387..c8776fb8d 100644
--- a/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/impl/TestSaltstackAdapterImpl.java
+++ b/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/impl/TestSaltstackAdapterImpl.java
@@ -82,7 +82,7 @@ public class TestSaltstackAdapterImpl {
params.put("Test", "fail");
adapter.reqExecCommand(params, svcContext);
String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
- TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.Id");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
assertEquals("101", status);
}
@@ -96,7 +96,7 @@ public class TestSaltstackAdapterImpl {
params.put("Test", "fail");
adapter.reqExecCommand(params, svcContext);
String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
- TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.Id");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
assertEquals("101", status);
}
@@ -110,7 +110,7 @@ public class TestSaltstackAdapterImpl {
params.put("Test", "fail");
adapter.reqExecCommand(params, svcContext);
String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
- TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.Id");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
assertEquals("101", status);
}
@@ -124,7 +124,7 @@ public class TestSaltstackAdapterImpl {
params.put("Test", "fail");
adapter.reqExecCommand(params, svcContext);
String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
- TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.Id");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
assertEquals("101", status);
}
@@ -138,7 +138,7 @@ public class TestSaltstackAdapterImpl {
params.put("Test", "fail");
adapter.reqExecCommand(params, svcContext);
String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
- TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.Id");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
assertEquals("101", status);
}
@@ -149,24 +149,25 @@ public class TestSaltstackAdapterImpl {
params.put("Test", "fail");
adapter.reqExecCommand(params, svcContext);
String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
- TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.Id");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
assertEquals("101", status);
}
@Test(expected = SvcLogicException.class)
- public void reqExecCommand_shouldSetSuccess() throws SvcLogicException,
+ public void reqExecCommand_NoResponseFile() throws SvcLogicException,
IllegalStateException, IllegalArgumentException {
- params.put("PlaybookName", "test_playbook.yaml");
params.put("HostName", "test");
params.put("Port", "10");
params.put("User", "test");
params.put("Password", "test");
params.put("Test", "success");
+ params.put("cmd", "test");
+ params.put("slsExec", "false");
try {
adapter.reqExecCommand(params, svcContext);
String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
- TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.Id");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
assertEquals("400", status);
} catch (NullPointerException e) {
fail(e.getMessage() + " Unknown exception encountered ");
@@ -174,10 +175,9 @@ public class TestSaltstackAdapterImpl {
}
@Test(expected = SvcLogicException.class)
- public void reqExecCommand_shouldSetSuccessWithRetry() throws SvcLogicException,
+ public void reqExecCommand_NoResponseFileWithRetry() throws SvcLogicException,
IllegalStateException, IllegalArgumentException {
- params.put("PlaybookName", "test_playbook.yaml");
params.put("HostName", "test");
params.put("Port", "10");
params.put("User", "test");
@@ -185,10 +185,12 @@ public class TestSaltstackAdapterImpl {
params.put("Test", "success");
params.put("retryDelay", "10");
params.put("retryCount", "10");
+ params.put("cmd", "test");
+ params.put("slsExec", "false");
try {
adapter.reqExecCommand(params, svcContext);
String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
- TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.Id");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
assertEquals("400", status);
} catch (NullPointerException e) {
fail(e.getMessage() + " Unknown exception encountered ");
@@ -196,10 +198,9 @@ public class TestSaltstackAdapterImpl {
}
@Test(expected = SvcLogicException.class)
- public void reqExecCommand_shouldSetSuccessWithRetryZero() throws SvcLogicException,
+ public void reqExecCommand_NoResponseFileWithRetryZero() throws SvcLogicException,
IllegalStateException, IllegalArgumentException {
- params.put("PlaybookName", "test_playbook.yaml");
params.put("HostName", "test");
params.put("Port", "10");
params.put("User", "test");
@@ -207,10 +208,12 @@ public class TestSaltstackAdapterImpl {
params.put("Test", "success");
params.put("retryDelay", "0");
params.put("retryCount", "0");
+ params.put("cmd", "test");
+ params.put("slsExec", "false");
try {
adapter.reqExecCommand(params, svcContext);
String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
- TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.Id");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
assertEquals("400", status);
} catch (NullPointerException e) {
fail(e.getMessage() + " Unknown exception encountered ");
@@ -218,10 +221,9 @@ public class TestSaltstackAdapterImpl {
}
@Test(expected = SvcLogicException.class)
- public void reqExecCommand_shouldSetSuccessWithNoRetry() throws SvcLogicException,
+ public void reqExecCommand_NoResponseFileWithNoRetry() throws SvcLogicException,
IllegalStateException, IllegalArgumentException {
- params.put("PlaybookName", "test_playbook.yaml");
params.put("HostName", "test");
params.put("Port", "10");
params.put("User", "test");
@@ -229,38 +231,382 @@ public class TestSaltstackAdapterImpl {
params.put("Test", "success");
params.put("retryDelay", "-1");
params.put("retryCount", "-1");
+ params.put("cmd", "test");
+ params.put("slsExec", "false");
+
try {
adapter.reqExecCommand(params, svcContext);
String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
- TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.Id");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
assertEquals("400", status);
} catch (NullPointerException e) {
fail(e.getMessage() + " Unknown exception encountered ");
}
}
- @Test
- public void reqExecSLS_shouldSetSuccess() throws IllegalStateException, IllegalArgumentException {
- params.put("Id", "100");
-
- for (String ukey : params.keySet()) {
- System.out.println(String.format("Saltstack Parameter %s = %s", ukey, params.get(ukey)));
- }
+ @Test(expected = SvcLogicException.class)
+ public void reqExecCommand_shouldSetFailure() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+ params.put("HostName", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("cmd", "test");
+ params.put("slsExec", "test");
+ params.put("Test", "fail");
try {
- adapter.reqExecSLS(params, svcContext);
- String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
- //assertEquals(SUCCESS, status);
- assertEquals(null, status);
- } catch (SvcLogicException e) {
+ adapter.reqExecCommand(params, svcContext);
String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
- fail(e.getMessage() + " Code = " + status);
- } catch (Exception e) {
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
+ assertEquals("400", status);
+ } catch (NullPointerException e) {
fail(e.getMessage() + " Unknown exception encountered ");
}
}
@Test
+ public void reqExecCommand_shouldSetSuccessNoSLS() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("HostName", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "success");
+ params.put("fileName", "src/test/resources/test.json");
+ params.put("Id", "test1");
+ params.put("cmd", "test");
+ params.put("slsExec", "false");
+
+ adapter.reqExecCommand(params, svcContext);
+ String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
+ assertEquals("250", status);
+ assertEquals(TestId, "test1");
+ }
+
+ @Test
+ public void reqExecCommand_shouldSetSuccessExecSLS() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("HostName", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "success");
+ params.put("fileName", "src/test/resources/test-sls.json");
+ params.put("Id", "test1");
+ params.put("cmd", "test");
+ params.put("slsExec", "true");
+
+ adapter.reqExecCommand(params, svcContext);
+ String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
+ assertEquals("200", status);
+ assertEquals(TestId, "test1");
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void reqExecCommand_shouldSetFailExecSLS() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("HostName", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "success");
+ params.put("fileName", "src/test/resources/test.json");
+ params.put("Id", "test1");
+ params.put("cmd", "test");
+ params.put("slsExec", "true");
+
+ adapter.reqExecCommand(params, svcContext);
+ String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
+ assertEquals(TestId, "test1");
+ }
+
+ @Test
+ public void reqExecCommand_shouldSetSuccessFileTxt() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("HostName", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "success");
+ params.put("fileName", "src/test/resources/test.txt");
+ params.put("Id", "txt");
+ params.put("cmd", "test");
+ params.put("slsExec", "false");
+
+ adapter.reqExecCommand(params, svcContext);
+ String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
+ assertEquals("250", status);
+ assertEquals(TestId, "txt");
+ }
+
+ @Test
+ public void reqExecCommand_shouldSetSuccessFileNoExtension() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("HostName", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "success");
+ params.put("fileName", "src/test/resources/test");
+ params.put("Id", "txt");
+ params.put("cmd", "test");
+ params.put("slsExec", "false");
+
+ adapter.reqExecCommand(params, svcContext);
+ String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
+ assertEquals("250", status);
+ assertEquals(TestId, "txt");
+ }
+
+ @Test
+ public void reqExecCommand_shouldSetSuccessFileInvalidJson() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("HostName", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "success");
+ params.put("fileName", "src/test/resources/test-invalid.json");
+ params.put("Id", "test1");
+ params.put("cmd", "test");
+ params.put("slsExec", "false");
+
+ adapter.reqExecCommand(params, svcContext);
+ String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
+ assertEquals("250", status);
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void reqExecCommand_shouldSetFailFileInvalidFile() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("HostName", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "success");
+ params.put("fileName", "src/test/resources/test-none.json");
+ params.put("Id", "test1");
+
+ adapter.reqExecCommand(params, svcContext);
+ }
+
+ @Test
+ public void reqExecCommand_shouldSetSuccessFileJsonNoReqID() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("HostName", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "success");
+ params.put("fileName", "src/test/resources/test.json");
+ params.put("cmd", "test");
+ params.put("slsExec", "false");
+
+ adapter.reqExecCommand(params, svcContext);
+ String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
+ assertEquals("250", status);
+ }
+
+ @Test
+ public void reqExecSLSFile_shouldSetSuccessJson() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("HostName", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "success");
+ params.put("slsFile", "src/test/resources/test.json");
+ params.put("fileName", "src/test/resources/test-sls.json");
+ params.put("Id", "test1");
+ params.put("cmd", "test");
+
+ adapter.reqExecSLSFile(params, svcContext);
+ String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
+ assertEquals("200", status);
+ assertEquals(TestId, "test1");
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void reqExecSLSFile_NoSLSfile() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("HostName", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "success");
+ params.put("slsFile", "src/test/resources/test-none.json");
+ params.put("fileName", "src/test/resources/test-sls.json");
+ params.put("Id", "test1");
+
+ adapter.reqExecSLSFile(params, svcContext);
+ String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
+ assertEquals(TestId, "test1");
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void reqExecSLSFile_NoResponsefile() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("HostName", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "success");
+ params.put("slsFile", "src/test/resources/test.json");
+ params.put("fileName", "src/test/resources/test-none.json");
+ params.put("Id", "test1");
+
+ adapter.reqExecSLSFile(params, svcContext);
+ String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
+ assertEquals(TestId, "test1");
+ }
+
+ @Test
+ public void reqExecSLSFile_WithMinionSetSuccessJson() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("HostName", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "success");
+ params.put("slsFile", "src/test/resources/test.json");
+ params.put("fileName", "src/test/resources/test-sls.json");
+ params.put("Id", "test1");
+ params.put("cmd", "test");
+ params.put("applyTo", "minion1");
+
+ adapter.reqExecSLSFile(params, svcContext);
+ String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
+ assertEquals("200", status);
+ assertEquals(TestId, "test1");
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void reqExecSLSFile_WithMinionNoSLSfile() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("HostName", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "success");
+ params.put("slsFile", "src/test/resources/test-none.json");
+ params.put("fileName", "src/test/resources/test-sls.json");
+ params.put("Id", "test1");
+ params.put("applyTo", "minion1");
+
+ adapter.reqExecSLSFile(params, svcContext);
+ String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
+ assertEquals(TestId, "test1");
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void reqExecSLSFile_WithMinionNoResponsefile() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("HostName", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "success");
+ params.put("slsFile", "src/test/resources/test.json");
+ params.put("fileName", "src/test/resources/test-none.json");
+ params.put("Id", "test1");
+ params.put("applyTo", "minion1");
+
+ adapter.reqExecSLSFile(params, svcContext);
+ String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
+ assertEquals(TestId, "test1");
+ }
+
+ @Test
+ public void reqExecSLSFile_WithAllMinionSetSuccessJson() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("HostName", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "success");
+ params.put("slsFile", "src/test/resources/test.json");
+ params.put("fileName", "src/test/resources/test-sls.json");
+ params.put("Id", "test1");
+ params.put("cmd", "test");
+ params.put("applyTo", "*");
+
+ adapter.reqExecSLSFile(params, svcContext);
+ String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
+ assertEquals("200", status);
+ assertEquals(TestId, "test1");
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void reqExecSLSFile_WithAllMinionNoSLSfile() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("HostName", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "success");
+ params.put("slsFile", "src/test/resources/test-none.json");
+ params.put("fileName", "src/test/resources/test-sls.json");
+ params.put("Id", "test1");
+ params.put("applyTo", "*");
+
+ adapter.reqExecSLSFile(params, svcContext);
+ String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
+ assertEquals(TestId, "test1");
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void reqExecSLSFile_WithAllMinionNoResponsefile() throws SvcLogicException,
+ IllegalStateException, IllegalArgumentException {
+
+ params.put("HostName", "test");
+ params.put("Port", "10");
+ params.put("User", "test");
+ params.put("Password", "test");
+ params.put("Test", "success");
+ params.put("slsFile", "src/test/resources/test.json");
+ params.put("fileName", "src/test/resources/test-none.json");
+ params.put("Id", "test1");
+ params.put("applyTo", "*");
+
+ adapter.reqExecSLSFile(params, svcContext);
+ String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
+ TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
+ assertEquals(TestId, "test1");
+ }
+
+ @Test
public void reqExecLog_shouldSetMessage() throws IllegalStateException, IllegalArgumentException {
params.put("Id", "101");
diff --git a/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/model/TestJsonParser.java b/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/model/TestJsonParser.java
new file mode 100644
index 000000000..ae13da6c8
--- /dev/null
+++ b/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/model/TestJsonParser.java
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.appc.adapter.model;
+
+import org.codehaus.jettison.json.JSONException;
+import org.junit.Test;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.adaptors.saltstack.model.JsonParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+public class TestJsonParser {
+
+ private static final Logger log = LoggerFactory.getLogger(TestJsonParser.class);
+
+ @Test
+ public void test() throws SvcLogicException, IOException, JSONException {
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(ClassLoader.getSystemResourceAsStream("test.json"))
+ );
+ StringBuilder b = new StringBuilder();
+ String line;
+ while ((line = in.readLine()) != null)
+ b.append(line).append('\n');
+
+ Map<String, String> mm = JsonParser.convertToProperties(b.toString());
+
+ logProperties(mm);
+
+ in.close();
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testNullString() throws SvcLogicException, JSONException {
+ JsonParser.convertToProperties(null);
+ }
+
+ private void logProperties(Map<String, String> mm) {
+ List<String> ll = new ArrayList<>();
+ for (Object o : mm.keySet())
+ ll.add((String) o);
+ Collections.sort(ll);
+ log.info("Properties:");
+ for (String name : ll)
+ log.info("--- {}: {}", name, mm.get(name));
+ }
+}