aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java6
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapper2Test.java83
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapperTest.java27
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/RestObjectTest.java20
4 files changed, 92 insertions, 44 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java
index a5fb1a5f0..39d777be9 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java
@@ -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.
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapper2Test.java b/vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapper2Test.java
index 5ec645a90..dd959a8aa 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapper2Test.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoResponseWrapper2Test.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,41 +21,75 @@
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
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 6cba339d1..191b91ba2 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
@@ -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
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/RestObjectTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/RestObjectTest.java
index 803083321..9f8614b92 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/RestObjectTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/RestObjectTest.java
@@ -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