diff options
author | biniek <lukasz.biniek@nokia.com> | 2019-01-04 16:21:41 +0100 |
---|---|---|
committer | biniek <lukasz.biniek@nokia.com> | 2019-01-24 16:15:55 +0100 |
commit | 100d6f872c53fdd7e8373062733811005806f40c (patch) | |
tree | 8939a96c23741631ff9e57cb19bec9cdaecac949 /vid-app-common/src/test/java/org/onap | |
parent | 659874df80409170e57b6dd6197eb3a81eb3468e (diff) |
MsoUtil refactor
Change-Id: I778d60064508aa47e1225d0dbae38ca1100d248f
Issue-ID: VID-368
Signed-off-by: biniek <lukasz.biniek@nokia.com>
Diffstat (limited to 'vid-app-common/src/test/java/org/onap')
-rw-r--r-- | vid-app-common/src/test/java/org/onap/vid/mso/MsoUtilTest.java | 113 |
1 files changed, 73 insertions, 40 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/MsoUtilTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/MsoUtilTest.java index 9d625c4f7..82242b6d1 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/MsoUtilTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoUtilTest.java @@ -1,50 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nokia. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + package org.onap.vid.mso; -import org.glassfish.jersey.client.ClientResponse; -import org.junit.Assert; +import io.joshworks.restclient.http.HttpResponse; +import io.joshworks.restclient.http.mapper.ObjectMapper; +import org.apache.http.HttpResponseFactory; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.DefaultHttpResponseFactory; +import org.apache.http.message.BasicStatusLine; import org.junit.Test; -public class MsoUtilTest { - - private MsoUtil createTestSubject() { - return new MsoUtil(); - } - - @Test - public void testWrapResponse() throws Exception { - String body = ""; - int statusCode = 0; - MsoResponseWrapper result; +import static org.apache.http.HttpStatus.SC_OK; +import static org.apache.http.HttpVersion.HTTP_1_1; +import static org.assertj.core.api.Assertions.assertThat; - // default test - result = MsoUtil.wrapResponse(body, statusCode); - } - - - @Test - public void testWrapResponse_2() throws Exception { - RestObject<String> rs = null; - MsoResponseWrapper result; - - // test 1 - result = MsoUtil.wrapResponse(rs); - Assert.assertNotNull(result); - } +public class MsoUtilTest { - @Test - public void testConvertPojoToString() throws Exception { - String result; + @Test + public void shouldWrapRestObject() { + // given + String entity = "entity"; + RestObject<String> restObject = new RestObject<>(); + restObject.set(entity); + restObject.setStatusCode(SC_OK); + // when + MsoResponseWrapper result = MsoUtil.wrapResponse(restObject); + // then + assertThat(result.getEntity()).isEqualTo(entity); + assertThat(result.getStatus()).isEqualTo(SC_OK); + } - // test 1 - result = MsoUtil.convertPojoToString(null); - Assert.assertEquals("", result); - } + @Test + public void shouldWrapHttpResponse() throws Exception { + // given + HttpResponse<String> httpResponse = createTestHttpResponse(SC_OK, null); + // when + MsoResponseWrapper result = MsoUtil.wrapResponse(httpResponse); + // then + assertThat(result.getEntity()).isEqualTo(null); + assertThat(result.getStatus()).isEqualTo(SC_OK); + } - @Test - public void testMain() throws Exception { - String[] args = new String[] { "" }; + @Test + public void shouldWrapHttpResponseWithEntity() throws Exception { + // given + String entity = "entity"; + HttpResponse<String> httpResponse = createTestHttpResponse(SC_OK, entity); + // when + MsoResponseWrapper result = MsoUtil.wrapResponse(httpResponse); + // then + assertThat(result.getEntity()).isEqualTo(entity); + assertThat(result.getStatus()).isEqualTo(SC_OK); + } - // default test - MsoUtil.main(args); - } + private HttpResponse<String> createTestHttpResponse(int statusCode, String entity) throws Exception { + HttpResponseFactory factory = new DefaultHttpResponseFactory(); + org.apache.http.HttpResponse response = factory.newHttpResponse(new BasicStatusLine(HTTP_1_1, statusCode, null), null); + if (entity != null) { + response.setEntity(new StringEntity(entity)); + } + return new HttpResponse<>(response, String.class, null); + } }
\ No newline at end of file |