6cba339d14b26d7c7161a08a98222ce35cd4c92a
[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.mockito.Mockito.when;
29 import static org.mockito.MockitoAnnotations.initMocks;
30 import org.testng.annotations.BeforeSuite;
31 import org.testng.annotations.Test;
32
33 import static org.assertj.core.api.Assertions.assertThat;
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     @BeforeSuite
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 shouldProperlyConstructResponseWrapperWithParameters(){
61         responseWrapper = new MsoResponseWrapper(1,"testEntity");
62
63         assertThat(responseWrapper.getStatus()).isEqualTo(1);
64         assertThat(responseWrapper.getEntity()).isEqualTo("testEntity");
65     }
66
67     @Test
68     public void shouldProperlyConstructResponseWrapperFromResponse(){
69         when(response.getStatus()).thenReturn(1);
70         when(response.readEntity(String.class)).thenReturn("testEntity");
71
72         responseWrapper = new MsoResponseWrapper(response);
73
74         assertThat(responseWrapper.getStatus()).isEqualTo(1);
75         assertThat(responseWrapper.getEntity()).isEqualTo("testEntity");
76     }
77
78     @Test
79     public void shouldProperlyGetResponseWithEmptyEntity(){
80         responseWrapper = new MsoResponseWrapper();
81         responseWrapper.setStatus(1);
82
83         assertThat(responseWrapper.getResponse()).isEqualToIgnoringWhitespace(PROPER_RESPONSE_WITH_NO_ENTITY);
84     }
85
86     @Test
87     public void shouldProperlyGetResponse(){
88         responseWrapper = new MsoResponseWrapper(1,"testEntity");
89
90         assertThat(responseWrapper.getResponse()).isEqualToIgnoringWhitespace(PROPER_RESPONSE);
91     }
92
93     @Test
94     public void shouldProperlyConvertToString(){
95         responseWrapper = new MsoResponseWrapper(1,"testEntity");
96
97         assertThat(responseWrapper.toString()).endsWith(PROPER_TO_STRING);
98     }
99
100
101 }