Increasing test coverage for vid.mso
[vid.git] / vid-app-common / src / test / java / org / onap / vid / mso / MsoResponseWrapper2Test.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.vid.mso;
23
24 import static org.mockito.Mockito.when;
25
26 import io.joshworks.restclient.http.HttpResponse;
27 import org.mockito.Mock;
28 import org.testng.annotations.BeforeClass;
29 import org.testng.annotations.Test;
30
31 import static org.assertj.core.api.Assertions.assertThat;
32 import static org.mockito.MockitoAnnotations.initMocks;
33
34 public class MsoResponseWrapper2Test {
35
36     @Mock
37     private RestObject<String> msoResponse;
38
39     @Mock
40     private HttpResponse<String> httpResponse;
41
42     private MsoResponseWrapper2<String> responseWrapper;
43
44     private int status = 202;
45     private String entity = "testEntity";
46     private String rawString = "testRawString";
47
48     @BeforeClass
49     public void setUp() {
50         initMocks(this);
51     }
52
53     @Test
54     public void shouldProperlyCreateInstanceFromRestObject() {
55         //  given
56         when(msoResponse.getStatusCode()).thenReturn(status);
57         when(msoResponse.get()).thenReturn(entity);
58         when(msoResponse.getRaw()).thenReturn(rawString);
59
60         //  when
61         responseWrapper = new MsoResponseWrapper2<>(msoResponse);
62
63         //  then
64         assertThat(responseWrapper.getStatus()).isEqualTo(status);
65         assertThat(responseWrapper.getEntity()).isEqualTo(entity);
66         assertThat(responseWrapper.getResponse()).isEqualTo("{\"status\":"+status+",\"entity\":\""+entity+"\"}");
67     }
68
69     @Test
70     public void shouldProperlyCreateInstanceFromHttpResponse() {
71         //  given
72         when(httpResponse.getStatus()).thenReturn(status);
73         when(httpResponse.getBody()).thenReturn(entity);
74
75         //  when
76         responseWrapper = new MsoResponseWrapper2<>(httpResponse);
77
78         //  then
79         assertThat(responseWrapper.getStatus()).isEqualTo(status);
80         assertThat(responseWrapper.getEntity()).isEqualTo(entity);
81         assertThat(responseWrapper.getResponse()).isEqualTo("{\"status\":"+status+",\"entity\":\""+entity+"\"}");
82     }
83
84     @Test
85     public void shouldProperlyCreateInstanceFromStatusAndEntity() {
86         //  when
87         responseWrapper = new MsoResponseWrapper2<>(status,entity);
88
89         //  then
90         assertThat(responseWrapper.getStatus()).isEqualTo(status);
91         assertThat(responseWrapper.getEntity()).isEqualTo(entity);
92         assertThat(responseWrapper.getResponse()).isEqualTo("{\"status\":"+status+",\"entity\":\""+entity+"\"}");
93     }
94
95 }