Increasing test coverage for vid.mso 32/79632/2
authorBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>
Mon, 4 Mar 2019 15:01:39 +0000 (16:01 +0100)
committerBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>
Wed, 6 Mar 2019 13:58:14 +0000 (14:58 +0100)
Change-Id: I3b9c4aeb628a50e5bb9032dd78605cfa0a4c3f57
Issue-ID: VID-387
Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com>
vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java
vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapper2Test.java
vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapperTest.java
vid-app-common/src/test/java/org/onap/vid/mso/RestObjectTest.java

index a5fb1a5..39d777b 100644 (file)
@@ -3,14 +3,14 @@
  * VID
  * ================================================================================
  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2018 - 2019 Nokia. 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.
index 5ec645a..dd959a8 100644 (file)
@@ -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.
 
 package org.onap.vid.mso;
 
-import org.junit.Test;
+import static org.mockito.Mockito.when;
+
+import io.joshworks.restclient.http.HttpResponse;
+import org.mockito.Mock;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.MockitoAnnotations.initMocks;
 
 public class MsoResponseWrapper2Test {
 
-    private MsoResponseWrapper2 createTestSubject() {
-        return new MsoResponseWrapper2(new RestObject());
+    @Mock
+    private RestObject<String> msoResponse;
+
+    @Mock
+    private HttpResponse<String> httpResponse;
+
+    private MsoResponseWrapper2<String> responseWrapper;
+
+    private int status = 202;
+    private String entity = "testEntity";
+    private String rawString = "testRawString";
+
+    @BeforeClass
+    public void setUp() {
+        initMocks(this);
     }
 
     @Test
-    public void testGetStatus() throws Exception {
-        MsoResponseWrapper2 testSubject;
-        int result;
+    public void shouldProperlyCreateInstanceFromRestObject() {
+        //  given
+        when(msoResponse.getStatusCode()).thenReturn(status);
+        when(msoResponse.get()).thenReturn(entity);
+        when(msoResponse.getRaw()).thenReturn(rawString);
+
+        //  when
+        responseWrapper = new MsoResponseWrapper2<>(msoResponse);
 
-        // default test
-        testSubject = createTestSubject();
-        result = testSubject.getStatus();
+        //  then
+        assertThat(responseWrapper.getStatus()).isEqualTo(status);
+        assertThat(responseWrapper.getEntity()).isEqualTo(entity);
+        assertThat(responseWrapper.getResponse()).isEqualTo("{\"status\":"+status+",\"entity\":\""+entity+"\"}");
     }
 
     @Test
-    public void testGetResponse() throws Exception {
-        MsoResponseWrapper2 testSubject;
-        String result;
+    public void shouldProperlyCreateInstanceFromHttpResponse() {
+        //  given
+        when(httpResponse.getStatus()).thenReturn(status);
+        when(httpResponse.getBody()).thenReturn(entity);
 
-        // default test
-        testSubject = createTestSubject();
-        result = testSubject.getResponse();
+        //  when
+        responseWrapper = new MsoResponseWrapper2<>(httpResponse);
+
+        //  then
+        assertThat(responseWrapper.getStatus()).isEqualTo(status);
+        assertThat(responseWrapper.getEntity()).isEqualTo(entity);
+        assertThat(responseWrapper.getResponse()).isEqualTo("{\"status\":"+status+",\"entity\":\""+entity+"\"}");
     }
 
     @Test
-    public void testGetEntity() throws Exception {
-        MsoResponseWrapper2 testSubject;
-        Object result;
+    public void shouldProperlyCreateInstanceFromStatusAndEntity() {
+        //  when
+        responseWrapper = new MsoResponseWrapper2<>(status,entity);
 
-        // default test
-        testSubject = createTestSubject();
-        result = testSubject.getEntity();
+        //  then
+        assertThat(responseWrapper.getStatus()).isEqualTo(status);
+        assertThat(responseWrapper.getEntity()).isEqualTo(entity);
+        assertThat(responseWrapper.getResponse()).isEqualTo("{\"status\":"+status+",\"entity\":\""+entity+"\"}");
     }
-}
+
+}
\ No newline at end of file
index 6cba339..191b91b 100644 (file)
@@ -25,12 +25,12 @@ import org.mockito.Mock;
 
 import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.AssertionsForClassTypes.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 org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
 
 import javax.ws.rs.core.Response;
 
@@ -46,7 +46,7 @@ public class MsoResponseWrapperTest {
 
     private MsoResponseWrapper responseWrapper;
 
-    @BeforeSuite
+    @BeforeClass
     public void setUp() {
         initMocks(this);
     }
@@ -57,45 +57,58 @@ public class MsoResponseWrapperTest {
     }
 
     @Test
-    public void shouldProperlyConstructResponseWrapperWithParameters(){
+    public void shouldProperlyConstructMsoResponseWrapperWithParameters(){
+        //  when
         responseWrapper = new MsoResponseWrapper(1,"testEntity");
 
+        //  then
         assertThat(responseWrapper.getStatus()).isEqualTo(1);
         assertThat(responseWrapper.getEntity()).isEqualTo("testEntity");
     }
 
     @Test
-    public void shouldProperlyConstructResponseWrapperFromResponse(){
+    public void shouldProperlyConstructMsoResponseWrapperFromResponse(){
+        //  given
         when(response.getStatus()).thenReturn(1);
         when(response.readEntity(String.class)).thenReturn("testEntity");
 
+        //  when
         responseWrapper = new MsoResponseWrapper(response);
 
+        //  then
         assertThat(responseWrapper.getStatus()).isEqualTo(1);
         assertThat(responseWrapper.getEntity()).isEqualTo("testEntity");
     }
 
     @Test
     public void shouldProperlyGetResponseWithEmptyEntity(){
+        //  given
         responseWrapper = new MsoResponseWrapper();
+
+        //  when
         responseWrapper.setStatus(1);
 
+        //  then
         assertThat(responseWrapper.getResponse()).isEqualToIgnoringWhitespace(PROPER_RESPONSE_WITH_NO_ENTITY);
     }
 
     @Test
     public void shouldProperlyGetResponse(){
+        //  when
         responseWrapper = new MsoResponseWrapper(1,"testEntity");
 
+        //  then
         assertThat(responseWrapper.getResponse()).isEqualToIgnoringWhitespace(PROPER_RESPONSE);
     }
 
     @Test
     public void shouldProperlyConvertToString(){
+        //  when
         responseWrapper = new MsoResponseWrapper(1,"testEntity");
 
+        //  then
         assertThat(responseWrapper.toString()).endsWith(PROPER_TO_STRING);
     }
 
 
-}
+}
\ No newline at end of file
index 8030833..9f8614b 100644 (file)
@@ -7,9 +7,9 @@
  * 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.
@@ -21,7 +21,7 @@
 package org.onap.vid.mso;
 
 import org.hamcrest.MatcherAssert;
-import org.testng.annotations.BeforeSuite;
+import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
 import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding;
@@ -29,11 +29,11 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class RestObjectTest {
 
-    private RestObject restObject;
+    private RestObject<Object> restObject;
 
-    @BeforeSuite
+    @BeforeClass
     private void setUp() {
-        restObject = new RestObject();
+        restObject = new RestObject<>();
     }
 
     @Test
@@ -42,7 +42,7 @@ public class RestObjectTest {
     }
 
     @Test
-    public void shouldHaveValidGetterAndSetterForBody() {
+    public void shouldHaveValidGetterAndSetterForTObject() {
         //  given
         String testString = "set/get_testString";
 
@@ -54,13 +54,13 @@ public class RestObjectTest {
     }
 
     @Test
-    public void shouldProperlyCopyRestObject() {
+    public void shouldProperlyCopyFromOneRestObjectToAnotherWithProperParameters() {
         //  given
         MsoResponseWrapper testResponseWraper = new MsoResponseWrapper();
         String rawTestString = "rawTestString";
         int statusCode = 404;
 
-        RestObject restObjectToCopyFrom = new RestObject<>();
+        RestObject<Object> restObjectToCopyFrom = new RestObject<>();
         restObjectToCopyFrom.set(testResponseWraper);
         restObjectToCopyFrom.setRaw(rawTestString);
         restObjectToCopyFrom.setStatusCode(statusCode);
@@ -91,4 +91,4 @@ public class RestObjectTest {
         //  then
         assertThat(toStringResponse).isEqualTo(properString);
     }
-}
+}
\ No newline at end of file