933f3fcf73923d7d0f363af62a705c49f81d8c35
[ccsdk/sli/adaptors.git] / saltstack-adapter / saltstack-adapter-provider / src / test / java / org / onap / ccsdk / adapter / impl / TestConnectionBuilder.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.ccsdk.adapter.impl;
26
27 import org.junit.After;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.ccsdk.sli.adaptors.saltstack.impl.ConnectionBuilder;
31 import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackResult;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
34
35 import java.util.HashMap;
36 import java.util.Map;
37
38 import static org.junit.Assert.assertEquals;
39 import static org.junit.Assert.fail;
40
41
42 public class TestConnectionBuilder {
43
44     private ConnectionBuilder connBuilder;
45     private Map<String, String> params;
46
47
48     @Before
49     public void setup() throws IllegalArgumentException {
50         String HostName = "test";
51         String Port = "10";
52         String User = "test";
53         String Password = "test";
54         connBuilder = new ConnectionBuilder(HostName, Port, User, Password);
55
56         params = new HashMap<>();
57         params.put("AgentUrl", "https://192.168.1.1");
58         params.put("User", "test");
59         params.put("Password", "test");
60     }
61
62     @After
63     public void tearDown() {
64         connBuilder = null;
65         params = null;
66     }
67
68     @Test
69     public void reqExecCommand_exitStatus255() {
70
71         int exitStatus = 255;
72         String errFilePath = "src/test/resources/test.json";
73         String command = "test";
74
75         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
76         int status = result.getStatusCode();
77         assertEquals(698, status);
78     }
79
80     @Test
81     public void reqExecCommand_exitStatus1() {
82
83         int exitStatus = 1;
84         String errFilePath = "src/test/resources/test.json";
85         String command = "test";
86
87         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
88         int status = result.getStatusCode();
89         assertEquals(698, status);
90     }
91
92     @Test
93     public void reqExecCommand_exitStatus5() {
94
95         int exitStatus = 5;
96         String errFilePath = "src/test/resources/test.json";
97         String command = "test";
98
99         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
100         int status = result.getStatusCode();
101         assertEquals(613, status);
102     }
103
104     @Test
105     public void reqExecCommand_exitStatus65() {
106
107         int exitStatus = 65;
108         String errFilePath = "src/test/resources/test.json";
109         String command = "test";
110
111         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
112         int status = result.getStatusCode();
113         assertEquals(613, status);
114     }
115
116     @Test
117     public void reqExecCommand_exitStatus67() {
118
119         int exitStatus = 5;
120         String errFilePath = "src/test/resources/test.json";
121         String command = "test";
122
123         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
124         int status = result.getStatusCode();
125         assertEquals(613, status);
126     }
127
128     @Test
129     public void reqExecCommand_exitStatus73() {
130
131         int exitStatus = 65;
132         String errFilePath = "src/test/resources/test.json";
133         String command = "test";
134
135         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
136         int status = result.getStatusCode();
137         assertEquals(613, status);
138     }
139
140     @Test
141     public void reqExecCommand_exitStatusUnknown() {
142
143         int exitStatus = 5121;
144         String errFilePath = "src/test/resources/test.json";
145         String command = "test";
146
147         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
148         int status = result.getStatusCode();
149         assertEquals(699, status);
150     }
151
152     @Test
153     public void reqExecCommand_exitStatusNoFile() {
154
155         int exitStatus = 65;
156         String errFilePath = "src/test/resource/test.json";
157         String command = "test";
158
159         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
160         int status = result.getStatusCode();
161         assertEquals(613, status);
162     }
163 }