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 org.mockito.Mock;
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;
32 import org.testng.annotations.BeforeClass;
33 import org.testng.annotations.Test;
35 import javax.ws.rs.core.Response;
38 public class MsoResponseWrapperTest {
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]";
45 private Response response;
47 private MsoResponseWrapper responseWrapper;
55 public void shouldHaveValidGettersAndSetters(){
56 assertThat(MsoResponseWrapper.class, hasValidGettersAndSettersExcluding("response"));
60 public void shouldProperlyConstructMsoResponseWrapperWithParameters(){
62 responseWrapper = new MsoResponseWrapper(1,"testEntity");
65 assertThat(responseWrapper.getStatus()).isEqualTo(1);
66 assertThat(responseWrapper.getEntity()).isEqualTo("testEntity");
70 public void shouldProperlyConstructMsoResponseWrapperFromResponse(){
72 when(response.getStatus()).thenReturn(1);
73 when(response.readEntity(String.class)).thenReturn("testEntity");
76 responseWrapper = new MsoResponseWrapper(response);
79 assertThat(responseWrapper.getStatus()).isEqualTo(1);
80 assertThat(responseWrapper.getEntity()).isEqualTo("testEntity");
84 public void shouldProperlyGetResponseWithEmptyEntity(){
86 responseWrapper = new MsoResponseWrapper();
89 responseWrapper.setStatus(1);
92 assertThat(responseWrapper.getResponse()).isEqualToIgnoringWhitespace(PROPER_RESPONSE_WITH_NO_ENTITY);
96 public void shouldProperlyGetResponse(){
98 responseWrapper = new MsoResponseWrapper(1,"testEntity");
101 assertThat(responseWrapper.getResponse()).isEqualToIgnoringWhitespace(PROPER_RESPONSE);
105 public void shouldProperlyConvertToString(){
107 responseWrapper = new MsoResponseWrapper(1,"testEntity");
110 assertThat(responseWrapper.toString()).endsWith(PROPER_TO_STRING);