From 58cbfa63f239b22e8feb1440919b5fc2cf0118ce Mon Sep 17 00:00:00 2001 From: Bartosz Gardziejewski Date: Mon, 18 Feb 2019 10:41:17 +0100 Subject: Increasing test coverage for vid.mso Change-Id: I71d44c6b36babcc5b8931cda65ab86940062deda Issue-ID: VID-387 Signed-off-by: Bartosz Gardziejewski --- .../org/onap/vid/mso/MsoResponseWrapperTest.java | 95 ++++++++++++---------- 1 file changed, 53 insertions(+), 42 deletions(-) (limited to 'vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapperTest.java') diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapperTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapperTest.java index d09f4a2c5..6cba339d1 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapperTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapperTest.java @@ -3,13 +3,14 @@ * VID * ================================================================================ * Copyright (C) 2017 - 2019 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. @@ -20,71 +21,81 @@ package org.onap.vid.mso; -import org.junit.Test; +import org.mockito.Mock; + +import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +import javax.ws.rs.core.Response; + public class MsoResponseWrapperTest { - private MsoResponseWrapper createTestSubject() { - return new MsoResponseWrapper(); + private static final String PROPER_RESPONSE = "{ \"status\": 1, \"entity\": testEntity}"; + private static final String PROPER_RESPONSE_WITH_NO_ENTITY = "{ \"status\": 1, \"entity\": \"\"}"; + private static final String PROPER_TO_STRING = "[status=1,entity=testEntity]"; + + @Mock + private Response response; + + private MsoResponseWrapper responseWrapper; + + @BeforeSuite + public void setUp() { + initMocks(this); } @Test - public void testGetEntity() throws Exception { - MsoResponseWrapper testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getEntity(); + public void shouldHaveValidGettersAndSetters(){ + assertThat(MsoResponseWrapper.class, hasValidGettersAndSettersExcluding("response")); } @Test - public void testGetStatus() throws Exception { - MsoResponseWrapper testSubject; - int result; + public void shouldProperlyConstructResponseWrapperWithParameters(){ + responseWrapper = new MsoResponseWrapper(1,"testEntity"); - // default test - testSubject = createTestSubject(); - result = testSubject.getStatus(); + assertThat(responseWrapper.getStatus()).isEqualTo(1); + assertThat(responseWrapper.getEntity()).isEqualTo("testEntity"); } @Test - public void testSetStatus() throws Exception { - MsoResponseWrapper testSubject; - int v = 0; + public void shouldProperlyConstructResponseWrapperFromResponse(){ + when(response.getStatus()).thenReturn(1); + when(response.readEntity(String.class)).thenReturn("testEntity"); + + responseWrapper = new MsoResponseWrapper(response); - // default test - testSubject = createTestSubject(); - testSubject.setStatus(v); + assertThat(responseWrapper.getStatus()).isEqualTo(1); + assertThat(responseWrapper.getEntity()).isEqualTo("testEntity"); } @Test - public void testSetEntity() throws Exception { - MsoResponseWrapper testSubject; - String v = ""; + public void shouldProperlyGetResponseWithEmptyEntity(){ + responseWrapper = new MsoResponseWrapper(); + responseWrapper.setStatus(1); - // default test - testSubject = createTestSubject(); - testSubject.setEntity(v); + assertThat(responseWrapper.getResponse()).isEqualToIgnoringWhitespace(PROPER_RESPONSE_WITH_NO_ENTITY); } @Test - public void testToString() throws Exception { - MsoResponseWrapper testSubject; - String result; + public void shouldProperlyGetResponse(){ + responseWrapper = new MsoResponseWrapper(1,"testEntity"); - // default test - testSubject = createTestSubject(); - result = testSubject.toString(); + assertThat(responseWrapper.getResponse()).isEqualToIgnoringWhitespace(PROPER_RESPONSE); } @Test - public void testGetResponse() throws Exception { - MsoResponseWrapper testSubject; - String result; + public void shouldProperlyConvertToString(){ + responseWrapper = new MsoResponseWrapper(1,"testEntity"); - // default test - testSubject = createTestSubject(); - result = testSubject.getResponse(); + assertThat(responseWrapper.toString()).endsWith(PROPER_TO_STRING); } + + } -- cgit 1.2.3-korg