Use ByteStream instead of FileStream
[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 : CCSDK
4  * ================================================================================
5  * Copyright (C) 2018 Samsung Electronics. All rights reserved.
6  * ================================================================================
7  *
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  *
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
33 import java.util.HashMap;
34 import java.util.Map;
35
36 import static org.junit.Assert.assertEquals;
37
38
39 public class TestConnectionBuilder {
40
41     private ConnectionBuilder connBuilder;
42     private Map<String, String> params;
43
44
45     @Before
46     public void setup() throws IllegalArgumentException {
47         String HostName = "test";
48         String Port = "10";
49         String User = "test";
50         String Password = "test";
51         connBuilder = new ConnectionBuilder(HostName, Port, User, Password);
52
53         params = new HashMap<>();
54         params.put("AgentUrl", "https://192.168.1.1");
55         params.put("User", "test");
56         params.put("Password", "test");
57     }
58
59     @After
60     public void tearDown() {
61         connBuilder = null;
62         params = null;
63     }
64
65     @Test
66     public void reqExecCommand_exitStatus255() {
67
68         int exitStatus = 255;
69         String errFilePath = "src/test/resources/test.json";
70         String command = "test";
71
72         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
73         int status = result.getStatusCode();
74         assertEquals(698, status);
75     }
76
77     @Test
78     public void reqExecCommand_exitStatus1() {
79
80         int exitStatus = 1;
81         String errFilePath = "src/test/resources/test.json";
82         String command = "test";
83
84         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
85         int status = result.getStatusCode();
86         assertEquals(698, status);
87     }
88
89     @Test
90     public void reqExecCommand_exitStatus5() {
91
92         int exitStatus = 5;
93         String errFilePath = "src/test/resources/test.json";
94         String command = "test";
95
96         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
97         int status = result.getStatusCode();
98         assertEquals(613, status);
99     }
100
101     @Test
102     public void reqExecCommand_exitStatus65() {
103
104         int exitStatus = 65;
105         String errFilePath = "src/test/resources/test.json";
106         String command = "test";
107
108         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
109         int status = result.getStatusCode();
110         assertEquals(613, status);
111     }
112
113     @Test
114     public void reqExecCommand_exitStatus67() {
115
116         int exitStatus = 5;
117         String errFilePath = "src/test/resources/test.json";
118         String command = "test";
119
120         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
121         int status = result.getStatusCode();
122         assertEquals(613, status);
123     }
124
125     @Test
126     public void reqExecCommand_exitStatus73() {
127
128         int exitStatus = 65;
129         String errFilePath = "src/test/resources/test.json";
130         String command = "test";
131
132         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
133         int status = result.getStatusCode();
134         assertEquals(613, status);
135     }
136
137     @Test
138     public void reqExecCommand_exitStatusUnknown() {
139
140         int exitStatus = 5121;
141         String errFilePath = "src/test/resources/test.json";
142         String command = "test";
143
144         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
145         int status = result.getStatusCode();
146         assertEquals(699, status);
147     }
148
149     @Test
150     public void reqExecCommand_exitStatusNoFile() {
151
152         int exitStatus = 65;
153         String errFilePath = "src/test/resource/test.json";
154         String command = "test";
155
156         SaltstackResult result = connBuilder.sortExitStatus(exitStatus, errFilePath, command);
157         int status = result.getStatusCode();
158         assertEquals(613, status);
159     }
160 }