Merge "Fix sonar issue in AAIClientRESTExecutor"
[ccsdk/sli/adaptors.git] / saltstack-adapter / saltstack-adapter-provider / src / test / java / org / onap / appc / 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.appc.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 final String PENDING = "100";
45     private final String SUCCESS = "400";
46     private String message = "{\"Results\":{\"192.168.1.10\":{\"Id\":\"101\",\"StatusCode\":200,\"StatusMessage\":\"SUCCESS\"}},\"StatusCode\":200,\"StatusMessage\":\"FINISHED\"}";
47
48     private ConnectionBuilder connBuilder;
49     private String TestId;
50     private boolean testMode = true;
51     private Map<String, String> params;
52     private SvcLogicContext svcContext;
53
54
55     @Before
56     public void setup() throws IllegalArgumentException {
57         testMode = true;
58         svcContext = new SvcLogicContext();
59         String HostName = "test";
60         String Port = "10";
61         String User = "test";
62         String Password = "test";
63         connBuilder = new ConnectionBuilder(HostName, Port, User, Password);
64
65         params = new HashMap<>();
66         params.put("AgentUrl", "https://192.168.1.1");
67         params.put("User", "test");
68         params.put("Password", "test");
69     }
70
71     @After
72     public void tearDown() {
73         testMode = false;
74         connBuilder = null;
75         params = null;
76         svcContext = null;
77     }
78
79     @Test
80     public void reqExecCommand_exitStatus255() {
81
82         int exitStatus = 255;
83         String errFilePath = "src/test/resources/test.json";
84         String command = "test";
85
86         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
87         int status = result.getStatusCode();
88         assertEquals(698, status);
89     }
90
91     @Test
92     public void reqExecCommand_exitStatus1() {
93
94         int exitStatus = 1;
95         String errFilePath = "src/test/resources/test.json";
96         String command = "test";
97
98         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
99         int status = result.getStatusCode();
100         assertEquals(698, status);
101     }
102
103     @Test
104     public void reqExecCommand_exitStatus5() {
105
106         int exitStatus = 5;
107         String errFilePath = "src/test/resources/test.json";
108         String command = "test";
109
110         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
111         int status = result.getStatusCode();
112         assertEquals(613, status);
113     }
114
115     @Test
116     public void reqExecCommand_exitStatus65() {
117
118         int exitStatus = 65;
119         String errFilePath = "src/test/resources/test.json";
120         String command = "test";
121
122         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
123         int status = result.getStatusCode();
124         assertEquals(613, status);
125     }
126
127     @Test
128     public void reqExecCommand_exitStatus67() {
129
130         int exitStatus = 5;
131         String errFilePath = "src/test/resources/test.json";
132         String command = "test";
133
134         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
135         int status = result.getStatusCode();
136         assertEquals(613, status);
137     }
138
139     @Test
140     public void reqExecCommand_exitStatus73() {
141
142         int exitStatus = 65;
143         String errFilePath = "src/test/resources/test.json";
144         String command = "test";
145
146         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
147         int status = result.getStatusCode();
148         assertEquals(613, status);
149     }
150
151     @Test
152     public void reqExecCommand_exitStatusUnknown() {
153
154         int exitStatus = 5121;
155         String errFilePath = "src/test/resources/test.json";
156         String command = "test";
157
158         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
159         int status = result.getStatusCode();
160         assertEquals(699, status);
161     }
162
163     @Test
164     public void reqExecCommand_exitStatusNoFile() {
165
166         int exitStatus = 65;
167         String errFilePath = "src/test/resource/test.json";
168         String command = "test";
169
170         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
171         int status = result.getStatusCode();
172         assertEquals(613, status);
173     }
174 }