various bugfixes for casablanca
[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         LinkedHashMap<String, Object> responseMap = new LinkedHashMap<>();
64         LinkedHashMap<String, Object> output = new LinkedHashMap<>();
65         output.put("response-code", "0");
66         output.put("response-message", "success");
67         responseMap.put("output", output);
68         assertEquals("success", sdnCommonTasks.validateSDNResponse(responseMap));
69     }
70
71     @Test
72     public void validateSDNResponseTestException() throws BadResponseException {
73         expectedException.expect(BadResponseException.class);
74         LinkedHashMap responseMap = new LinkedHashMap();
75         Assert.assertNotNull(sdnCommonTasks.validateSDNResponse(responseMap));
76     }
77
78     @Test
79     public void validateSDNResponseTestRespCodeNot200() throws BadResponseException {
80         expectedException.expect(BadResponseException.class);
81         LinkedHashMap<String, Object> responseMap = new LinkedHashMap<>();
82         LinkedHashMap<String, Object> output = new LinkedHashMap<>();
83         output.put("response-code", "300");
84         output.put("response-message", "Failed");
85         responseMap.put("output", output);
86         sdnCommonTasks.validateSDNResponse(responseMap);
87     }
88
89 }