2636aec4a790b3eeacf1b58f607a4c1233c3a00a
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / client / sdn / common / SdnCommonTasksTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.client.sdn.common;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.util.LinkedHashMap;
26
27 import org.junit.Assert;
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.junit.rules.ExpectedException;
31 import org.onap.so.client.exception.BadResponseException;
32 import org.onap.so.client.exception.MapperException;
33 import org.onap.so.client.sdnc.SdnCommonTasks;
34
35
36 public class SdnCommonTasksTest{
37
38     
39     SdnCommonTasks sdnCommonTasks = new SdnCommonTasks();
40
41     @Rule
42     public ExpectedException expectedException = ExpectedException.none();
43
44     @Test
45     public void buildJsonRequestTest() throws MapperException {
46         String jsonStr = sdnCommonTasks.buildJsonRequest("");
47         Assert.assertNotNull(jsonStr);
48     }
49
50     @Test
51     public void buildJsonRequestTestException() throws MapperException {
52         expectedException.expect(MapperException.class);
53         sdnCommonTasks.buildJsonRequest(new Object());
54     }
55
56     @Test
57     public void getHttpHeadersTest() {
58         Assert.assertNotNull(sdnCommonTasks.getHttpHeaders(""));
59     }
60
61     @Test
62     public void validateSDNResponseTest() throws BadResponseException {
63         String jsonResponse = "{\"output\":{\"response-code\":\"0\",\"response-message\":\"success\"}}";
64         LinkedHashMap<String, Object> responseMap = new LinkedHashMap<>();
65         LinkedHashMap<String, Object> output = new LinkedHashMap<>();
66         output.put("response-code", "0");
67         output.put("response-message", "success");
68         responseMap.put("output", output);
69         assertEquals(jsonResponse, sdnCommonTasks.validateSDNResponse(responseMap));
70     }
71
72     @Test
73     public void validateSDNResponseTestException() throws BadResponseException {
74         expectedException.expect(BadResponseException.class);
75         LinkedHashMap responseMap = new LinkedHashMap();
76         Assert.assertNotNull(sdnCommonTasks.validateSDNResponse(responseMap));
77     }
78
79     @Test
80     public void validateSDNResponseTestRespCodeNot200() throws BadResponseException {
81         expectedException.expect(BadResponseException.class);
82         LinkedHashMap<String, Object> responseMap = new LinkedHashMap<>();
83         LinkedHashMap<String, Object> output = new LinkedHashMap<>();
84         output.put("response-code", "300");
85         output.put("response-message", "Failed");
86         responseMap.put("output", output);
87         sdnCommonTasks.validateSDNResponse(responseMap);
88     }
89
90 }