2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Nokia. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.vid.mso;
24 import static org.apache.http.HttpStatus.SC_OK;
25 import static org.assertj.core.api.Assertions.assertThat;
27 import io.joshworks.restclient.http.HttpResponse;
28 import org.onap.vid.testUtils.TestUtils;
29 import org.testng.annotations.DataProvider;
30 import org.testng.annotations.Test;
32 public class MsoUtilTest {
35 public void shouldWrapRestObject() {
37 String entity = "entity";
38 RestObject<String> restObject = new RestObject<>();
39 restObject.set(entity);
40 restObject.setStatusCode(SC_OK);
42 MsoResponseWrapper result = MsoUtil.wrapResponse(restObject);
44 assertThat(result.getEntity()).isEqualTo(entity);
45 assertThat(result.getStatus()).isEqualTo(SC_OK);
49 public void shouldWrapHttpResponse() throws Exception {
51 HttpResponse<String> httpResponse = TestUtils.createTestHttpResponse(SC_OK, null);
53 MsoResponseWrapper result = MsoUtil.wrapResponse(httpResponse);
55 assertThat(result.getEntity()).isEqualTo(null);
56 assertThat(result.getStatus()).isEqualTo(SC_OK);
60 public void shouldWrapHttpResponseWithEntity() throws Exception {
62 String entity = "entity";
63 HttpResponse<String> httpResponse = TestUtils.createTestHttpResponse(SC_OK, entity);
65 MsoResponseWrapper result = MsoUtil.wrapResponse(httpResponse);
67 assertThat(result.getEntity()).isEqualTo(entity);
68 assertThat(result.getStatus()).isEqualTo(SC_OK);
72 public static Object[][] formatExceptionAdditionalInfo() {
73 return new Object[][]{
74 {"message", "Http Code:400, message"},
76 {null, "Http Code:400"},
78 {"{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC0002\",\"text\":\"message\"}}}",
79 "Http Code:400, \"messageId\":\"SVC0002\",\"text\":\"message\""},
81 {"{\"validJson\": \"Error: message\"}", "Http Code:400, {\"validJson\": \"Error: message\"}"},
83 {"{\"serviceException\":{\"messageId\":\"SVC0002\",\"text\":\"Error: message\"}}",
84 "Http Code:400, \"messageId\":\"SVC0002\",\"text\":\"Error: message\""},
88 @Test(dataProvider = "formatExceptionAdditionalInfo")
89 public void formatExceptionAdditionalInfo_payloadWithError400_doNotReturnNull(String payload, String expected) {
90 assertThat(MsoUtil.formatExceptionAdditionalInfo(400, payload))