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.mockito.Mockito.when;
29 import static org.mockito.MockitoAnnotations.initMocks;
30 import org.testng.annotations.BeforeSuite;
31 import org.testng.annotations.Test;
33 import static org.assertj.core.api.Assertions.assertThat;
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 shouldProperlyConstructResponseWrapperWithParameters(){
61 responseWrapper = new MsoResponseWrapper(1,"testEntity");
63 assertThat(responseWrapper.getStatus()).isEqualTo(1);
64 assertThat(responseWrapper.getEntity()).isEqualTo("testEntity");
68 public void shouldProperlyConstructResponseWrapperFromResponse(){
69 when(response.getStatus()).thenReturn(1);
70 when(response.readEntity(String.class)).thenReturn("testEntity");
72 responseWrapper = new MsoResponseWrapper(response);
74 assertThat(responseWrapper.getStatus()).isEqualTo(1);
75 assertThat(responseWrapper.getEntity()).isEqualTo("testEntity");
79 public void shouldProperlyGetResponseWithEmptyEntity(){
80 responseWrapper = new MsoResponseWrapper();
81 responseWrapper.setStatus(1);
83 assertThat(responseWrapper.getResponse()).isEqualToIgnoringWhitespace(PROPER_RESPONSE_WITH_NO_ENTITY);
87 public void shouldProperlyGetResponse(){
88 responseWrapper = new MsoResponseWrapper(1,"testEntity");
90 assertThat(responseWrapper.getResponse()).isEqualToIgnoringWhitespace(PROPER_RESPONSE);
94 public void shouldProperlyConvertToString(){
95 responseWrapper = new MsoResponseWrapper(1,"testEntity");
97 assertThat(responseWrapper.toString()).endsWith(PROPER_TO_STRING);