summaryrefslogtreecommitdiffstats
path: root/nokiav2/generatedapis/src/test
diff options
context:
space:
mode:
authorDenes Nemeth <denes.nemeth@nokia.com>2018-03-14 09:51:50 +0100
committerDenes Nemeth <denes.nemeth@nokia.com>2018-03-14 14:53:54 +0100
commit876a4acf6f2e8264bb82e960e9aa886799c4bdb1 (patch)
treee929d22a832b73a2345b8c8f7f8c4a06721e4731 /nokiav2/generatedapis/src/test
parent626ebae46807adeab6d0b9d5568515f457c7ece3 (diff)
Fix some security vulnerabilities
Change-Id: Ib1c08c4f73df8cfe42b2857ee674f102ec09c253 Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com> Issue-ID: VFC-728
Diffstat (limited to 'nokiav2/generatedapis/src/test')
-rw-r--r--nokiav2/generatedapis/src/test/java/TestInhertence.java97
1 files changed, 30 insertions, 67 deletions
diff --git a/nokiav2/generatedapis/src/test/java/TestInhertence.java b/nokiav2/generatedapis/src/test/java/TestInhertence.java
index 8e7d551e..f7e1108a 100644
--- a/nokiav2/generatedapis/src/test/java/TestInhertence.java
+++ b/nokiav2/generatedapis/src/test/java/TestInhertence.java
@@ -16,10 +16,19 @@
import com.nokia.cbam.lcm.v32.ApiClient;
import com.nokia.cbam.lcm.v32.model.*;
+import okhttp3.Headers;
+import okhttp3.RequestBody;
+import okhttp3.ResponseBody;
+import okhttp3.internal.http.RealResponseBody;
+import okio.Buffer;
+import okio.BufferedSource;
import org.junit.Test;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+
import static junit.framework.TestCase.assertEquals;
-import static junit.framework.TestCase.assertNull;
import static junit.framework.TestCase.assertTrue;
public class TestInhertence {
@@ -28,7 +37,7 @@ public class TestInhertence {
* test OpenStack v2 inheritence handling in serialization and deserialization
*/
@Test
- public void testOpenStackV2(){
+ public void testOpenStackV2() throws IOException{
InstantiateVnfRequest req = new InstantiateVnfRequest();
OPENSTACKV2INFO vim = new OPENSTACKV2INFO();
req.getVims().add(vim);
@@ -36,78 +45,32 @@ public class TestInhertence {
OpenStackAccessInfoV2 accessInfo = new OpenStackAccessInfoV2();
accessInfo.setPassword("myPassword");
vim.setAccessInfo(accessInfo);
- String serialize = new ApiClient().getJSON().serialize(req);
- assertTrue(serialize.contains("myPassword"));
- InstantiateVnfRequest deserialize = new ApiClient().getJSON().deserialize(serialize, InstantiateVnfRequest.class);
+ Annotation[] x = new Annotation[0];
+ RequestBody requestBody = new ApiClient().getAdapterBuilder().build().requestBodyConverter(InstantiateVnfRequest.class, x, new Annotation[0]).convert(req);
+ assertTrue(getContent(requestBody).contains("myPassword"));
+ ResponseBody responseBody = toResponse(requestBody);
+ InstantiateVnfRequest deserialize = (InstantiateVnfRequest) new ApiClient().getAdapterBuilder().build().responseBodyConverter(InstantiateVnfRequest.class, new Annotation[0]).convert(responseBody);
assertEquals(1, deserialize.getVims().size());
OPENSTACKV2INFO deserializedVim = (OPENSTACKV2INFO) deserialize.getVims().get(0);
assertEquals("myPassword", deserializedVim.getAccessInfo().getPassword());
}
- /**
- * test OpenStack v3 inheritence handling in serialization and deserialization
- */
- @Test
- public void testOpenStackV3(){
- InstantiateVnfRequest req = new InstantiateVnfRequest();
- OPENSTACKV3INFO vim = new OPENSTACKV3INFO();
- req.getVims().add(vim);
- vim.setVimInfoType(VimInfo.VimInfoTypeEnum.OPENSTACK_V3_INFO);
- OpenStackAccessInfoV3 accessInfo = new OpenStackAccessInfoV3();
- accessInfo.setPassword("myPassword");
- vim.setAccessInfo(accessInfo);
- String serialize = new ApiClient().getJSON().serialize(req);
- assertTrue(serialize.contains("myPassword"));
- InstantiateVnfRequest deserialize = new ApiClient().getJSON().deserialize(serialize, InstantiateVnfRequest.class);
- assertEquals(1, deserialize.getVims().size());
- OPENSTACKV3INFO deserializedVim = (OPENSTACKV3INFO) deserialize.getVims().get(0);
- assertEquals("myPassword", deserializedVim.getAccessInfo().getPassword());
- }
-
- /**
- * test vCloud inheritence handling in serialization and deserialization
- */
- @Test
- public void testVCloud(){
- InstantiateVnfRequest req = new InstantiateVnfRequest();
- VMWAREVCLOUDINFO vim = new VMWAREVCLOUDINFO();
- req.getVims().add(vim);
- vim.setVimInfoType(VimInfo.VimInfoTypeEnum.VMWARE_VCLOUD_INFO);
- VCloudAccessInfo accessInfo = new VCloudAccessInfo();
- accessInfo.setPassword("myPassword");
- vim.setAccessInfo(accessInfo);
- String serialize = new ApiClient().getJSON().serialize(req);
- assertTrue(serialize.contains("myPassword"));
- InstantiateVnfRequest deserialize = new ApiClient().getJSON().deserialize(serialize, InstantiateVnfRequest.class);
- assertEquals(1, deserialize.getVims().size());
- VMWAREVCLOUDINFO deserializedVim = (VMWAREVCLOUDINFO) deserialize.getVims().get(0);
- assertEquals("myPassword", deserializedVim.getAccessInfo().getPassword());
+ private ResponseBody toResponse(RequestBody convert) throws IOException {
+ Headers headers = new Headers.Builder().build();
+ Buffer buffer = new Buffer();
+ convert.writeTo(buffer);
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ buffer.copyTo(byteArrayOutputStream);
+ BufferedSource response = buffer;
+ return new RealResponseBody(headers, response);
}
- /**
- * test LCN serialization and deserialization
- */
- @Test
- public void testLcn() throws Exception{
- VnfLifecycleChangeNotification vnfLifecycleChangeNotification = new VnfLifecycleChangeNotification();
- vnfLifecycleChangeNotification.setNotificationType(VnfNotificationType.VNFLIFECYCLECHANGENOTIFICATION);
- vnfLifecycleChangeNotification.setVnfInstanceId("myId");
- String serialize = new ApiClient().getJSON().serialize(vnfLifecycleChangeNotification);
- VnfLifecycleChangeNotification deserialize = new ApiClient().getJSON().deserialize(serialize, VnfLifecycleChangeNotification.class);
- assertEquals("myId", deserialize.getVnfInstanceId());
+ private String getContent(RequestBody requestBody) throws IOException {
+ Buffer buffer = new Buffer();
+ requestBody.writeTo(buffer);
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ buffer.copyTo(byteArrayOutputStream);
+ return new String(byteArrayOutputStream.toByteArray());
}
- /**
- * test arrays are not initialized to empty arrays
- */
- @Test
- public void testArrayBehaviour() throws Exception{
- VnfLifecycleChangeNotification vnfLifecycleChangeNotification = new VnfLifecycleChangeNotification();
- vnfLifecycleChangeNotification.setNotificationType(VnfNotificationType.VNFLIFECYCLECHANGENOTIFICATION);
- vnfLifecycleChangeNotification.setVnfInstanceId("myId");
- String serialize = new ApiClient().getJSON().serialize(vnfLifecycleChangeNotification);
- VnfLifecycleChangeNotification deserialize = new ApiClient().getJSON().deserialize(serialize, VnfLifecycleChangeNotification.class);
- assertNull(deserialize.getAffectedVirtualLinks());
- }
-
}