aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapperTest.java
diff options
context:
space:
mode:
authorBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2019-02-18 10:41:17 +0100
committerBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2019-02-27 16:17:57 +0100
commit58cbfa63f239b22e8feb1440919b5fc2cf0118ce (patch)
tree268a88f08b6975f096b29b14591fe61cf9aa3f3f /vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapperTest.java
parent389d728d8d25dc1e44f8d95bb16ce588ea9bba0e (diff)
Increasing test coverage for vid.mso
Change-Id: I71d44c6b36babcc5b8931cda65ab86940062deda Issue-ID: VID-387 Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com>
Diffstat (limited to 'vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapperTest.java')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapperTest.java95
1 files changed, 53 insertions, 42 deletions
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);
}
+
+
}