2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.client.sdn.common;
23 import static org.junit.Assert.assertEquals;
25 import java.util.LinkedHashMap;
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;
36 public class SdnCommonTasksTest{
39 SdnCommonTasks sdnCommonTasks = new SdnCommonTasks();
42 public ExpectedException expectedException = ExpectedException.none();
45 public void buildJsonRequestTest() throws MapperException {
46 String jsonStr = sdnCommonTasks.buildJsonRequest("");
47 Assert.assertNotNull(jsonStr);
51 public void buildJsonRequestTestException() throws MapperException {
52 expectedException.expect(MapperException.class);
53 sdnCommonTasks.buildJsonRequest(new Object());
57 public void getHttpHeadersTest() {
58 Assert.assertNotNull(sdnCommonTasks.getHttpHeaders(""));
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));
73 public void validateSDNResponseTestException() throws BadResponseException {
74 expectedException.expect(BadResponseException.class);
75 LinkedHashMap responseMap = new LinkedHashMap();
76 Assert.assertNotNull(sdnCommonTasks.validateSDNResponse(responseMap));
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);