Increasing test coverage for vid.mso
[vid.git] / vid-app-common / src / test / java / org / onap / vid / mso / MsoResponseWrapperTest.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 org.mockito.Mock;
25
26 import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding;
27 import static org.hamcrest.MatcherAssert.assertThat;
28 import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
29 import static org.mockito.Mockito.when;
30 import static org.mockito.MockitoAnnotations.initMocks;
31
32 import org.testng.annotations.BeforeClass;
33 import org.testng.annotations.Test;
34
35 import javax.ws.rs.core.Response;
36
37
38 public class MsoResponseWrapperTest {
39
40     private static final String PROPER_RESPONSE = "{ \"status\": 1, \"entity\": testEntity}";
41     private static final String PROPER_RESPONSE_WITH_NO_ENTITY = "{ \"status\": 1, \"entity\": \"\"}";
42     private static final String PROPER_TO_STRING = "[status=1,entity=testEntity]";
43
44     @Mock
45     private Response response;
46
47     private MsoResponseWrapper responseWrapper;
48
49     @BeforeClass
50     public void setUp() {
51         initMocks(this);
52     }
53
54     @Test
55     public void shouldHaveValidGettersAndSetters(){
56         assertThat(MsoResponseWrapper.class, hasValidGettersAndSettersExcluding("response"));
57     }
58
59     @Test
60     public void shouldProperlyConstructMsoResponseWrapperWithParameters(){
61         //  when
62         responseWrapper = new MsoResponseWrapper(1,"testEntity");
63
64         //  then
65         assertThat(responseWrapper.getStatus()).isEqualTo(1);
66         assertThat(responseWrapper.getEntity()).isEqualTo("testEntity");
67     }
68
69     @Test
70     public void shouldProperlyConstructMsoResponseWrapperFromResponse(){
71         //  given
72         when(response.getStatus()).thenReturn(1);
73         when(response.readEntity(String.class)).thenReturn("testEntity");
74
75         //  when
76         responseWrapper = new MsoResponseWrapper(response);
77
78         //  then
79         assertThat(responseWrapper.getStatus()).isEqualTo(1);
80         assertThat(responseWrapper.getEntity()).isEqualTo("testEntity");
81     }
82
83     @Test
84     public void shouldProperlyGetResponseWithEmptyEntity(){
85         //  given
86         responseWrapper = new MsoResponseWrapper();
87
88         //  when
89         responseWrapper.setStatus(1);
90
91         //  then
92         assertThat(responseWrapper.getResponse()).isEqualToIgnoringWhitespace(PROPER_RESPONSE_WITH_NO_ENTITY);
93     }
94
95     @Test
96     public void shouldProperlyGetResponse(){
97         //  when
98         responseWrapper = new MsoResponseWrapper(1,"testEntity");
99
100         //  then
101         assertThat(responseWrapper.getResponse()).isEqualToIgnoringWhitespace(PROPER_RESPONSE);
102     }
103
104     @Test
105     public void shouldProperlyConvertToString(){
106         //  when
107         responseWrapper = new MsoResponseWrapper(1,"testEntity");
108
109         //  then
110         assertThat(responseWrapper.toString()).endsWith(PROPER_TO_STRING);
111     }
112
113
114 }