From 3323c0829fa0492a5c7b3544a83cc24412c9934c Mon Sep 17 00:00:00 2001 From: Ganesh Chandrasekaran Date: Fri, 13 Jul 2018 09:41:32 +0900 Subject: saltstack adaptor fixes from Sonar Issue-ID: CCSDK-364 Change-Id: Ief9705370d84fcb99fcb718f03c31e6cbfd47363 Signed-off-by: Ganesh Chandrasekaran --- .../appc/adapter/impl/TestConnectionBuilder.java | 174 ----- .../adapter/impl/TestSaltstackAdapterImpl.java | 816 --------------------- ...TestSaltstackAdapterPropertiesProviderImpl.java | 323 -------- .../onap/appc/adapter/model/TestJsonParser.java | 74 -- .../appc/adapter/model/TestSaltstackAdapter.java | 80 -- .../ccsdk/adapter/impl/TestConnectionBuilder.java | 163 ++++ .../adapter/impl/TestSaltstackAdapterImpl.java | 802 ++++++++++++++++++++ ...TestSaltstackAdapterPropertiesProviderImpl.java | 318 ++++++++ .../onap/ccsdk/adapter/model/TestJsonParser.java | 74 ++ .../ccsdk/adapter/model/TestSaltstackAdapter.java | 76 ++ 10 files changed, 1433 insertions(+), 1467 deletions(-) delete mode 100644 saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/impl/TestConnectionBuilder.java delete mode 100644 saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/impl/TestSaltstackAdapterImpl.java delete mode 100644 saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/impl/TestSaltstackAdapterPropertiesProviderImpl.java delete mode 100644 saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/model/TestJsonParser.java delete mode 100644 saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/model/TestSaltstackAdapter.java create mode 100644 saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestConnectionBuilder.java create mode 100644 saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestSaltstackAdapterImpl.java create mode 100644 saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestSaltstackAdapterPropertiesProviderImpl.java create mode 100644 saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/model/TestJsonParser.java create mode 100644 saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/model/TestSaltstackAdapter.java (limited to 'saltstack-adapter/saltstack-adapter-provider/src/test/java') 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 deleted file mode 100644 index d9a38414..00000000 --- a/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/impl/TestConnectionBuilder.java +++ /dev/null @@ -1,174 +0,0 @@ -/*- - * ============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 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 deleted file mode 100644 index d60059e4..00000000 --- a/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/impl/TestSaltstackAdapterImpl.java +++ /dev/null @@ -1,816 +0,0 @@ -/*- - * ============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.SaltstackAdapterImpl; -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 TestSaltstackAdapterImpl { - - 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 SaltstackAdapterImpl adapter; - private String TestId; - private boolean testMode = true; - private Map params; - private SvcLogicContext svcContext; - - - @Before - public void setup() throws IllegalArgumentException { - testMode = true; - svcContext = new SvcLogicContext(); - adapter = new SaltstackAdapterImpl(testMode); - - 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; - adapter = null; - params = null; - svcContext = null; - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_shouldSetFailed() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - 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.Id"); - assertEquals("101", status); - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_shouldSetUserFailed() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("Password", "test"); - 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.Id"); - assertEquals("101", status); - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_shouldSetHostFailed() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("Port", "10"); - params.put("User", "test"); - params.put("Password", "test"); - 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.Id"); - assertEquals("101", status); - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_shouldSetPortFailed() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("User", "test"); - params.put("Password", "test"); - 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.Id"); - assertEquals("101", status); - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_shouldSetPasswordFailed() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - params.put("HostName", "test"); - params.put("Port", "10"); - params.put("User", "test"); - 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.Id"); - assertEquals("101", status); - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_shouldSetMandatoryFailed() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - - 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.Id"); - assertEquals("101", status); - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_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("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.Id"); - assertEquals("400", status); - } catch (NullPointerException e) { - fail(e.getMessage() + " Unknown exception encountered "); - } - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_NoResponseFileWithRetry() 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("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.Id"); - assertEquals("400", status); - } catch (NullPointerException e) { - fail(e.getMessage() + " Unknown exception encountered "); - } - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_NoResponseFileWithRetryZero() 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("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.Id"); - assertEquals("400", status); - } catch (NullPointerException e) { - fail(e.getMessage() + " Unknown exception encountered "); - } - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_NoResponseFileWithNoRetry() 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("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.Id"); - assertEquals("400", status); - } catch (NullPointerException e) { - fail(e.getMessage() + " Unknown exception encountered "); - } - } - - @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.reqExecCommand(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); - 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); - 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.sls"); - 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.sls"); - 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_NoExtn() 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"); - 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(expected = SvcLogicException.class) - public void reqExecSLSFile_WithMinionSetNotSLSType() 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 - public void reqExecSLSFile_WithMinionSetSuccessSls() 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.sls"); - 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.sls"); - 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 reqExecSLS_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("slsName", "src/test.sls"); - params.put("fileName", "src/test/resources/test-sls.json"); - params.put("Id", "test1"); - params.put("cmd", "test"); - - adapter.reqExecSLS(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 - public void reqExecSLS_shouldSetNoExtn() 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("slsName", "src/test"); - params.put("fileName", "src/test/resources/test-sls.json"); - params.put("Id", "test1"); - params.put("cmd", "test"); - - adapter.reqExecSLS(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 reqExecSLS_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("slsName", "src/test/resources/test.json"); - params.put("fileName", "src/test/resources/test-none.json"); - params.put("Id", "test1"); - - adapter.reqExecSLS(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 reqExecSLS_WithMinionSetSuccessSls() 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("slsName", "src/test/resources/test.sls"); - params.put("fileName", "src/test/resources/test-sls.json"); - params.put("Id", "test1"); - params.put("cmd", "test"); - params.put("applyTo", "minion1"); - - adapter.reqExecSLS(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 reqExecSLS_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("slsName", "src/test/resources/test.json"); - params.put("fileName", "src/test/resources/test-none.json"); - params.put("Id", "test1"); - params.put("applyTo", "minion1"); - - adapter.reqExecSLS(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 reqExecSLS_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("slsName", "src/test/resources/test.sls"); - params.put("fileName", "src/test/resources/test-sls.json"); - params.put("Id", "test1"); - params.put("cmd", "test"); - params.put("applyTo", "*"); - - adapter.reqExecSLS(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 reqExecSLS_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("slsName", "src/test/resources/test.json"); - params.put("fileName", "src/test/resources/test-none.json"); - params.put("Id", "test1"); - params.put("applyTo", "*"); - - adapter.reqExecSLS(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"); - - try { - adapter.reqExecLog(params, svcContext); - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.log"); - //assertEquals(message, status); - assertEquals(null, status); - } catch (SvcLogicException e) { - String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.log"); - fail(e.getMessage() + " Code = " + status); - } catch (Exception e) { - fail(e.getMessage() + " Unknown exception encountered "); - } - } -} diff --git a/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/impl/TestSaltstackAdapterPropertiesProviderImpl.java b/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/impl/TestSaltstackAdapterPropertiesProviderImpl.java deleted file mode 100644 index 92759183..00000000 --- a/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/impl/TestSaltstackAdapterPropertiesProviderImpl.java +++ /dev/null @@ -1,323 +0,0 @@ -/*- - * ============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.SaltstackAdapterPropertiesProvider; -import org.onap.ccsdk.sli.adaptors.saltstack.impl.SaltstackAdapterImpl; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; - -import java.util.Properties; - -import static org.junit.Assert.assertEquals; - -public class TestSaltstackAdapterPropertiesProviderImpl { - 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 SaltstackAdapterImpl adapter; - private Properties params; - private SvcLogicContext svcContext; - - - @Before - public void setup() throws IllegalArgumentException { - params = new Properties(); - } - - @After - public void tearDown() { - adapter = null; - params = null; - svcContext = null; - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_setPropertiesBasicPortNull() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "BASIC"); - params.put("User", "test"); - params.put("Password", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_setPropertiesBasicPortString() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "BASIC"); - params.put("org.onap.appc.adapter.saltstack.host", "test"); - params.put("org.onap.appc.adapter.saltstack.port", "test"); - params.put("org.onap.appc.adapter.saltstack.userName", "test"); - params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); - params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - } - - @Test - public void reqExecCommand_setPropertiesBasicSuccess() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "BASIC"); - params.put("org.onap.appc.adapter.saltstack.host", "test"); - params.put("org.onap.appc.adapter.saltstack.port", "10"); - params.put("org.onap.appc.adapter.saltstack.userName", "test"); - params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); - params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_setPropertiesSSH_CERTPortNull() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "SSH_CERT"); - params.put("User", "test"); - params.put("Password", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_setPropertiesSSH_CERTPortString() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "SSH_CERT"); - params.put("org.onap.appc.adapter.saltstack.host", "test"); - params.put("org.onap.appc.adapter.saltstack.port", "test"); - params.put("org.onap.appc.adapter.saltstack.userName", "test"); - params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); - params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - } - - @Test - public void reqExecCommand_setPropertiesSSH_CERTSuccess() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "SSH_CERT"); - params.put("org.onap.appc.adapter.saltstack.host", "test"); - params.put("org.onap.appc.adapter.saltstack.port", "10"); - params.put("org.onap.appc.adapter.saltstack.userName", "test"); - params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); - params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_setPropertiesBOTHPortNull() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "BOTH"); - params.put("User", "test"); - params.put("Password", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - } - - @Test(expected = SvcLogicException.class) - public void reqExecCommand_setPropertiesBOTHPortString() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "BOTH"); - params.put("org.onap.appc.adapter.saltstack.host", "test"); - params.put("org.onap.appc.adapter.saltstack.port", "test"); - params.put("org.onap.appc.adapter.saltstack.userName", "test"); - params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); - params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - } - - @Test - public void reqExecCommand_setPropertiesBOTHSuccess() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "BOTH"); - params.put("org.onap.appc.adapter.saltstack.host", "test"); - params.put("org.onap.appc.adapter.saltstack.port", "10"); - params.put("org.onap.appc.adapter.saltstack.userName", "test"); - params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); - params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - } - - @Test - public void reqExecCommand_setPropertiesNonePortNull() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "NONE"); - params.put("User", "test"); - params.put("Password", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - } - - @Test - public void reqExecCommand_setPropertiesNonePortString() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "NONE"); - params.put("org.onap.appc.adapter.saltstack.host", "test"); - params.put("org.onap.appc.adapter.saltstack.port", "test"); - params.put("org.onap.appc.adapter.saltstack.userName", "test"); - params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); - params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - } - - @Test - public void reqExecCommand_setPropertiesNoneSuccess() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.clientType", "NONE"); - params.put("org.onap.appc.adapter.saltstack.host", "test"); - params.put("org.onap.appc.adapter.saltstack.port", "10"); - params.put("org.onap.appc.adapter.saltstack.userName", "test"); - params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); - params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - } - - - - @Test - public void reqExecCommand_setPropertiesElsePortNull() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("User", "test"); - params.put("Password", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - } - - @Test - public void reqExecCommand_setPropertiesElsePortString() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.host", "test"); - params.put("org.onap.appc.adapter.saltstack.port", "test"); - params.put("org.onap.appc.adapter.saltstack.userName", "test"); - params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); - params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - } - - @Test - public void reqExecCommand_setPropertiesElseSuccess() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - params.put("org.onap.appc.adapter.saltstack.host", "test"); - params.put("org.onap.appc.adapter.saltstack.port", "10"); - params.put("org.onap.appc.adapter.saltstack.userName", "test"); - params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); - params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); - SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { - @Override - public Properties getProperties() { - return params; - } - }; - adapter = new SaltstackAdapterImpl(propProvider); - String adaptorName = adapter.getAdapterName(); - assertEquals("Saltstack Adapter", adaptorName); - adapter.setExecTimeout(10); - } - - @Test - public void reqExecCommand_setPropertiesDefault() throws SvcLogicException, - IllegalStateException, IllegalArgumentException { - adapter = new SaltstackAdapterImpl(); - } -} 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 deleted file mode 100644 index ae13da6c..00000000 --- a/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/model/TestJsonParser.java +++ /dev/null @@ -1,74 +0,0 @@ -/*- - * ============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 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 mm) { - List 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)); - } -} diff --git a/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/model/TestSaltstackAdapter.java b/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/model/TestSaltstackAdapter.java deleted file mode 100644 index 37b6502c..00000000 --- a/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/appc/adapter/model/TestSaltstackAdapter.java +++ /dev/null @@ -1,80 +0,0 @@ -/*- - * ============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.model; - -import org.junit.Test; -import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackMessageParser; -import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackResult; -import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackServerEmulator; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import static org.junit.Assert.assertNotNull; - -public class TestSaltstackAdapter { - - private Class[] parameterTypes; - private SaltstackMessageParser saltstackMessageParser; - private Method m; - private String name; - - @Test - public void callPrivateConstructorsMethodsForCodeCoverage() throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { - - /* test constructors */ - Class[] classesOne = {SaltstackMessageParser.class}; - for(Class clazz : classesOne) { - Constructor constructor = clazz.getDeclaredConstructor(); - name = constructor.getName(); - constructor.setAccessible(true); - assertNotNull(constructor.newInstance()); - } - Class[] classesTwo = {SaltstackServerEmulator.class}; - for(Class clazz : classesTwo) { - Constructor constructor = clazz.getDeclaredConstructor(); - name = constructor.getName(); - constructor.setAccessible(true); - assertNotNull(constructor.newInstance()); - } - Class[] classesThree = {SaltstackResult.class}; - for(Class clazz : classesThree) { - Constructor constructor = clazz.getDeclaredConstructor(); - name = constructor.getName(); - constructor.setAccessible(true); - assertNotNull(constructor.newInstance()); - } - - /* test methods */ - saltstackMessageParser = new SaltstackMessageParser(); - parameterTypes = new Class[1]; - parameterTypes[0] = String.class; - - m = saltstackMessageParser.getClass().getDeclaredMethod("getFilePayload", parameterTypes); - m.setAccessible(true); - assertNotNull(m.invoke(saltstackMessageParser,"{\"test\": test}")); - - } -} diff --git a/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestConnectionBuilder.java b/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestConnectionBuilder.java new file mode 100644 index 00000000..933f3fcf --- /dev/null +++ b/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestConnectionBuilder.java @@ -0,0 +1,163 @@ +/*- + * ============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.ccsdk.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 ConnectionBuilder connBuilder; + private Map params; + + + @Before + public void setup() throws IllegalArgumentException { + 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() { + connBuilder = null; + params = 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/ccsdk/adapter/impl/TestSaltstackAdapterImpl.java b/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestSaltstackAdapterImpl.java new file mode 100644 index 00000000..0622a471 --- /dev/null +++ b/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestSaltstackAdapterImpl.java @@ -0,0 +1,802 @@ +/*- + * ============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.ccsdk.adapter.impl; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.sli.adaptors.saltstack.impl.SaltstackAdapterImpl; +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 TestSaltstackAdapterImpl { + + private SaltstackAdapterImpl adapter; + private String TestId; + private boolean testMode = true; + private Map params; + private SvcLogicContext svcContext; + + + @Before + public void setup() throws IllegalArgumentException { + testMode = true; + svcContext = new SvcLogicContext(); + adapter = new SaltstackAdapterImpl(testMode); + + 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; + adapter = null; + params = null; + svcContext = null; + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_shouldSetFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + 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.Id"); + assertEquals("101", status); + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_shouldSetUserFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("Password", "test"); + 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.Id"); + assertEquals("101", status); + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_shouldSetHostFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + 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.Id"); + assertEquals("101", status); + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_shouldSetPortFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("User", "test"); + params.put("Password", "test"); + 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.Id"); + assertEquals("101", status); + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_shouldSetPasswordFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + 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.Id"); + assertEquals("101", status); + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_shouldSetMandatoryFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + 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.Id"); + assertEquals("101", status); + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_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("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.Id"); + assertEquals("400", status); + } catch (NullPointerException e) { + fail(e.getMessage() + " Unknown exception encountered "); + } + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_NoResponseFileWithRetry() 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("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.Id"); + assertEquals("400", status); + } catch (NullPointerException e) { + fail(e.getMessage() + " Unknown exception encountered "); + } + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_NoResponseFileWithRetryZero() 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("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.Id"); + assertEquals("400", status); + } catch (NullPointerException e) { + fail(e.getMessage() + " Unknown exception encountered "); + } + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_NoResponseFileWithNoRetry() 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("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.Id"); + assertEquals("400", status); + } catch (NullPointerException e) { + fail(e.getMessage() + " Unknown exception encountered "); + } + } + + @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.reqExecCommand(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code"); + 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); + 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.sls"); + 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.sls"); + params.put("fileName", "src/test/resources/test-sls.json"); + params.put("Id", "test1"); + + adapter.reqExecSLSFile(params, svcContext); + TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); + assertEquals(TestId, "test1"); + } + + @Test(expected = SvcLogicException.class) + public void reqExecSLSFile_NoExtn() 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"); + params.put("fileName", "src/test/resources/test-sls.json"); + params.put("Id", "test1"); + + adapter.reqExecSLSFile(params, svcContext); + 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); + TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); + assertEquals(TestId, "test1"); + } + + @Test(expected = SvcLogicException.class) + public void reqExecSLSFile_WithMinionSetNotSLSType() 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 + public void reqExecSLSFile_WithMinionSetSuccessSls() 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.sls"); + 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); + 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); + 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.sls"); + 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); + 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); + TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); + assertEquals(TestId, "test1"); + } + + + @Test + public void reqExecSLS_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("slsName", "src/test.sls"); + params.put("fileName", "src/test/resources/test-sls.json"); + params.put("Id", "test1"); + params.put("cmd", "test"); + + adapter.reqExecSLS(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 + public void reqExecSLS_shouldSetNoExtn() 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("slsName", "src/test"); + params.put("fileName", "src/test/resources/test-sls.json"); + params.put("Id", "test1"); + params.put("cmd", "test"); + + adapter.reqExecSLS(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 reqExecSLS_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("slsName", "src/test/resources/test.json"); + params.put("fileName", "src/test/resources/test-none.json"); + params.put("Id", "test1"); + + adapter.reqExecSLS(params, svcContext); + TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); + assertEquals(TestId, "test1"); + } + + + @Test + public void reqExecSLS_WithMinionSetSuccessSls() 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("slsName", "src/test/resources/test.sls"); + params.put("fileName", "src/test/resources/test-sls.json"); + params.put("Id", "test1"); + params.put("cmd", "test"); + params.put("applyTo", "minion1"); + + adapter.reqExecSLS(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 reqExecSLS_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("slsName", "src/test/resources/test.json"); + params.put("fileName", "src/test/resources/test-none.json"); + params.put("Id", "test1"); + params.put("applyTo", "minion1"); + + adapter.reqExecSLS(params, svcContext); + TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); + assertEquals(TestId, "test1"); + } + + @Test + public void reqExecSLS_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("slsName", "src/test/resources/test.sls"); + params.put("fileName", "src/test/resources/test-sls.json"); + params.put("Id", "test1"); + params.put("cmd", "test"); + params.put("applyTo", "*"); + + adapter.reqExecSLS(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 reqExecSLS_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("slsName", "src/test/resources/test.json"); + params.put("fileName", "src/test/resources/test-none.json"); + params.put("Id", "test1"); + params.put("applyTo", "*"); + + adapter.reqExecSLS(params, svcContext); + TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id"); + assertEquals(TestId, "test1"); + } + + + @Test + public void reqExecLog_shouldSetMessage() throws IllegalStateException, IllegalArgumentException { + + params.put("Id", "101"); + + try { + adapter.reqExecLog(params, svcContext); + String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.log"); + //assertEquals(message, status); + assertEquals(null, status); + } catch (SvcLogicException e) { + String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.log"); + fail(e.getMessage() + " Code = " + status); + } catch (Exception e) { + fail(e.getMessage() + " Unknown exception encountered "); + } + } +} diff --git a/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestSaltstackAdapterPropertiesProviderImpl.java b/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestSaltstackAdapterPropertiesProviderImpl.java new file mode 100644 index 00000000..094e78c7 --- /dev/null +++ b/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/impl/TestSaltstackAdapterPropertiesProviderImpl.java @@ -0,0 +1,318 @@ +/*- + * ============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.ccsdk.adapter.impl; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.sli.adaptors.saltstack.SaltstackAdapterPropertiesProvider; +import org.onap.ccsdk.sli.adaptors.saltstack.impl.SaltstackAdapterImpl; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; + +import java.util.Properties; + +import static org.junit.Assert.assertEquals; + +public class TestSaltstackAdapterPropertiesProviderImpl { + + private SaltstackAdapterImpl adapter; + private Properties params; + + + @Before + public void setup() throws IllegalArgumentException { + params = new Properties(); + } + + @After + public void tearDown() { + adapter = null; + params = null; + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_setPropertiesBasicPortNull() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adapter.saltstack.clientType", "BASIC"); + params.put("User", "test"); + params.put("Password", "test"); + SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adapter = new SaltstackAdapterImpl(propProvider); + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_setPropertiesBasicPortString() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adapter.saltstack.clientType", "BASIC"); + params.put("org.onap.appc.adapter.saltstack.host", "test"); + params.put("org.onap.appc.adapter.saltstack.port", "test"); + params.put("org.onap.appc.adapter.saltstack.userName", "test"); + params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); + params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); + SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adapter = new SaltstackAdapterImpl(propProvider); + } + + @Test + public void reqExecCommand_setPropertiesBasicSuccess() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adapter.saltstack.clientType", "BASIC"); + params.put("org.onap.appc.adapter.saltstack.host", "test"); + params.put("org.onap.appc.adapter.saltstack.port", "10"); + params.put("org.onap.appc.adapter.saltstack.userName", "test"); + params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); + params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); + SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adapter = new SaltstackAdapterImpl(propProvider); + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_setPropertiesSSH_CERTPortNull() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adapter.saltstack.clientType", "SSH_CERT"); + params.put("User", "test"); + params.put("Password", "test"); + SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adapter = new SaltstackAdapterImpl(propProvider); + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_setPropertiesSSH_CERTPortString() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adapter.saltstack.clientType", "SSH_CERT"); + params.put("org.onap.appc.adapter.saltstack.host", "test"); + params.put("org.onap.appc.adapter.saltstack.port", "test"); + params.put("org.onap.appc.adapter.saltstack.userName", "test"); + params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); + params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); + SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adapter = new SaltstackAdapterImpl(propProvider); + } + + @Test + public void reqExecCommand_setPropertiesSSH_CERTSuccess() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adapter.saltstack.clientType", "SSH_CERT"); + params.put("org.onap.appc.adapter.saltstack.host", "test"); + params.put("org.onap.appc.adapter.saltstack.port", "10"); + params.put("org.onap.appc.adapter.saltstack.userName", "test"); + params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); + params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); + SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adapter = new SaltstackAdapterImpl(propProvider); + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_setPropertiesBOTHPortNull() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adapter.saltstack.clientType", "BOTH"); + params.put("User", "test"); + params.put("Password", "test"); + SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adapter = new SaltstackAdapterImpl(propProvider); + } + + @Test(expected = SvcLogicException.class) + public void reqExecCommand_setPropertiesBOTHPortString() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adapter.saltstack.clientType", "BOTH"); + params.put("org.onap.appc.adapter.saltstack.host", "test"); + params.put("org.onap.appc.adapter.saltstack.port", "test"); + params.put("org.onap.appc.adapter.saltstack.userName", "test"); + params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); + params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); + SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adapter = new SaltstackAdapterImpl(propProvider); + } + + @Test + public void reqExecCommand_setPropertiesBOTHSuccess() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adapter.saltstack.clientType", "BOTH"); + params.put("org.onap.appc.adapter.saltstack.host", "test"); + params.put("org.onap.appc.adapter.saltstack.port", "10"); + params.put("org.onap.appc.adapter.saltstack.userName", "test"); + params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); + params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); + SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adapter = new SaltstackAdapterImpl(propProvider); + } + + @Test + public void reqExecCommand_setPropertiesNonePortNull() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adapter.saltstack.clientType", "NONE"); + params.put("User", "test"); + params.put("Password", "test"); + SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adapter = new SaltstackAdapterImpl(propProvider); + } + + @Test + public void reqExecCommand_setPropertiesNonePortString() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adapter.saltstack.clientType", "NONE"); + params.put("org.onap.appc.adapter.saltstack.host", "test"); + params.put("org.onap.appc.adapter.saltstack.port", "test"); + params.put("org.onap.appc.adapter.saltstack.userName", "test"); + params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); + params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); + SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adapter = new SaltstackAdapterImpl(propProvider); + } + + @Test + public void reqExecCommand_setPropertiesNoneSuccess() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adapter.saltstack.clientType", "NONE"); + params.put("org.onap.appc.adapter.saltstack.host", "test"); + params.put("org.onap.appc.adapter.saltstack.port", "10"); + params.put("org.onap.appc.adapter.saltstack.userName", "test"); + params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); + params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); + SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adapter = new SaltstackAdapterImpl(propProvider); + } + + + + @Test + public void reqExecCommand_setPropertiesElsePortNull() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("User", "test"); + params.put("Password", "test"); + SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adapter = new SaltstackAdapterImpl(propProvider); + } + + @Test + public void reqExecCommand_setPropertiesElsePortString() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adapter.saltstack.host", "test"); + params.put("org.onap.appc.adapter.saltstack.port", "test"); + params.put("org.onap.appc.adapter.saltstack.userName", "test"); + params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); + params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); + SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adapter = new SaltstackAdapterImpl(propProvider); + } + + @Test + public void reqExecCommand_setPropertiesElseSuccess() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params.put("org.onap.appc.adapter.saltstack.host", "test"); + params.put("org.onap.appc.adapter.saltstack.port", "10"); + params.put("org.onap.appc.adapter.saltstack.userName", "test"); + params.put("org.onap.appc.adapter.saltstack.userPasswd", "test"); + params.put("org.onap.appc.adapter.saltstack.sshKey", "test"); + SaltstackAdapterPropertiesProvider propProvider = new SaltstackAdapterPropertiesProvider() { + @Override + public Properties getProperties() { + return params; + } + }; + adapter = new SaltstackAdapterImpl(propProvider); + String adaptorName = adapter.getAdapterName(); + assertEquals("Saltstack Adapter", adaptorName); + adapter.setExecTimeout(10); + } + + @Test + public void reqExecCommand_setPropertiesDefault() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + adapter = new SaltstackAdapterImpl(); + } +} diff --git a/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/model/TestJsonParser.java b/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/model/TestJsonParser.java new file mode 100644 index 00000000..74e7ed0c --- /dev/null +++ b/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/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.ccsdk.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 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 mm) { + List 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)); + } +} diff --git a/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/model/TestSaltstackAdapter.java b/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/model/TestSaltstackAdapter.java new file mode 100644 index 00000000..0caaf332 --- /dev/null +++ b/saltstack-adapter/saltstack-adapter-provider/src/test/java/org/onap/ccsdk/adapter/model/TestSaltstackAdapter.java @@ -0,0 +1,76 @@ +/*- + * ============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.ccsdk.adapter.model; + +import org.junit.Test; +import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackMessageParser; +import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackResult; +import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackServerEmulator; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import static org.junit.Assert.assertNotNull; + +public class TestSaltstackAdapter { + + private Class[] parameterTypes; + private SaltstackMessageParser saltstackMessageParser; + private Method m; + + @Test + public void callPrivateConstructorsMethodsForCodeCoverage() throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { + + /* test constructors */ + Class[] classesOne = {SaltstackMessageParser.class}; + for(Class clazz : classesOne) { + Constructor constructor = clazz.getDeclaredConstructor(); + constructor.setAccessible(true); + assertNotNull(constructor.newInstance()); + } + Class[] classesTwo = {SaltstackServerEmulator.class}; + for(Class clazz : classesTwo) { + Constructor constructor = clazz.getDeclaredConstructor(); + constructor.setAccessible(true); + assertNotNull(constructor.newInstance()); + } + Class[] classesThree = {SaltstackResult.class}; + for(Class clazz : classesThree) { + Constructor constructor = clazz.getDeclaredConstructor(); + constructor.setAccessible(true); + assertNotNull(constructor.newInstance()); + } + + /* test methods */ + saltstackMessageParser = new SaltstackMessageParser(); + parameterTypes = new Class[1]; + parameterTypes[0] = String.class; + + m = saltstackMessageParser.getClass().getDeclaredMethod("getFilePayload", parameterTypes); + m.setAccessible(true); + assertNotNull(m.invoke(saltstackMessageParser,"{\"test\": test}")); + + } +} -- cgit 1.2.3-korg