summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--INFO.yaml127
-rw-r--r--huawei/.gitignore5
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/DownloadCsarManager.java25
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/RestHttpContentExchange.java32
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/RestfulConfigure.java13
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/ScaleManager.java21
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/ReaderHelperTest.java117
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestHttpRest.java958
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestRestHttpContentExchange.java584
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestRestfulFactory.java106
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestRestfulOptions.java288
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestRestfulParametes.java229
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestRestfulResponse.java273
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfmTest.java75
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java56
-rw-r--r--zte/vmanager/docker/Dockerfile2
16 files changed, 2807 insertions, 104 deletions
diff --git a/INFO.yaml b/INFO.yaml
new file mode 100644
index 00000000..20442214
--- /dev/null
+++ b/INFO.yaml
@@ -0,0 +1,127 @@
+---
+project: 'vfc-nfvo-driver-vnfm-svnfm'
+project_creation_date: '2017-06-28'
+lifecycle_state: 'Incubation'
+project_lead: &onap_releng_ptl
+ name: 'Yan Yang'
+ email: 'yangyanyj@chinamobile.com'
+ id: 'yangyan'
+ company: 'China Mobile'
+ timezone: 'Asia/Shanghai'
+primary_contact: *onap_releng_ptl
+issue_tracking:
+ type: 'jira'
+ url: 'https://jira.onap.org/projects/VFC'
+ key: 'VFC'
+meetings:
+ - type: 'zoom'
+ agenda: 'https://wiki.onap.org/pages/viewpage.action?pageId=6590138'
+ url: 'https://wiki.onap.org/display/DW/Virtual+Function+Controller+Project'
+ server: 'n/a'
+ channel: 'n/a'
+ repeats: 'weekly'
+ time: '09:00 UTC'
+committers:
+ - <<: *onap_releng_ptl
+ - name: 'Anatoly Andrianov'
+ email: 'anatoly.andrianov@nokia.com'
+ company: 'Nokia'
+ id: 'caa028'
+ timezone: 'America/Chicago'
+ - name: 'Fu Jinhua'
+ email: 'fu.jinhua@zte.com.cn'
+ company: 'ZTE'
+ id: 'fujinhua'
+ timezone: 'Asia/Shanghai'
+ - name: 'Victor Gao'
+ email: 'victor.gao@huawei.com'
+ company: 'Huawei'
+ id: 'g310497'
+ timezone: 'Asia/Shanghai'
+ - name: 'han yanan'
+ email: 'hanyanan@raisecom.com'
+ company: 'Raisecom'
+ id: 'hanyanan'
+ timezone: 'Asia/Shanghai'
+ - name: 'lu xin'
+ email: 'luxin7@huawei.com'
+ company: 'Huawei'
+ id: 'l345485'
+ timezone: 'Asia/Shanghai'
+ - name: 'maopeng zhang'
+ email: 'zhang.maopeng1@zte.com.cn'
+ company: 'ZTE'
+ id: 'maopengzhang'
+ timezone: 'Asia/Shanghai'
+ - name: 'Kanagaraj Manickam'
+ email: 'kanagaraj.manickam@huawei.com'
+ company: 'Huawei'
+ id: 'mkr1481'
+ timezone: 'Asia/Kolkata'
+ - name: 'yunlong ying'
+ email: 'ying.yunlong@zte.com.cn'
+ company: 'ZTE'
+ id: 'ying.yunlong'
+ timezone: 'Asia/Shanghai'
+ - name: 'Yog Vashishth'
+ email: 'yog.vashishth@ril.com'
+ company: 'Ril'
+ id: 'yogvashishth'
+ timezone: 'Asia/Kolkata'
+ - name: 'Lingli Deng'
+ email: 'denglingli@chinamobile.com'
+ company: 'China Mobile'
+ id: 'denglingli'
+ timezone: 'Asia/Shanghai'
+ - name: 'Nagesha Subramanya'
+ email: 'nagesha.subramanya@nokia.com'
+ company: 'Nokia'
+ id: 'hsnagesh'
+ timezone: 'Asia/Kolkata'
+ - name: 'Xinhui Li'
+ email: 'lxinhui@vmware.com'
+ company: 'VMWare'
+ id: 'xinhuili'
+ timezone: 'Asia/Shanghai'
+ - name: 'Guirong Wang'
+ email: 'wangguirong@boco.com.cn'
+ company: 'Boco'
+ id: 'Wang_Guirong'
+ timezone: 'Asia/Shanghai'
+ - name: 'Xiaodong Ning'
+ email: 'ningxiaodong2017@boco.com.cn'
+ company: 'Boco'
+ id: 'ningxiaodong2017'
+ timezone: 'Asia/Shanghai'
+ - name: 'Adityakar Jha'
+ email: 'Adityakar.Jha@ril.com'
+ company: 'Ril'
+ id: 'adityakar.jha'
+ timezone: 'Asia/Kolkata'
+ - name: 'Hu Dong'
+ email: 'donghu@raisecom.com'
+ company: 'Raisecom'
+ id: 'donghu1102'
+ timezone: 'Asia/Shanghai'
+ - name: 'Yufei Zhou'
+ email: 'yufei.zhou@nokia-sbell.com'
+ company: 'Nokia'
+ id: 'yufei_zhou'
+ timezone: 'Asia/Shanghai'
+ - name: 'Denes Nemeth'
+ email: 'denes.nemeth@nokia.com'
+ company: 'Nokia'
+ id: 'thelittlemouse'
+ timezone: 'Europe/Budapest'
+ - name: 'Haibin Huang'
+ email: 'haibin.huang@intel.com'
+ company: 'Intel'
+ id: 'haibin'
+ timezone: 'Asia/Shanghai'
+tsc:
+ approval: 'https://lists.onap.org/pipermail/onap-tsc'
+ changes:
+ - type: 'Addition'
+ name: 'Denes Nemeth'
+ name: 'Haibin Huang'
+ link: 'https://lists.onap.org/g/ONAP-TSC/message/3269'
diff --git a/huawei/.gitignore b/huawei/.gitignore
new file mode 100644
index 00000000..70a2900c
--- /dev/null
+++ b/huawei/.gitignore
@@ -0,0 +1,5 @@
+.settings
+.project
+.checkstyle
+.classpath
+coverage-report/
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/DownloadCsarManager.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/DownloadCsarManager.java
index b09c50d7..4474c39b 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/DownloadCsarManager.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/DownloadCsarManager.java
@@ -172,10 +172,9 @@ public class DownloadCsarManager {
*/
public static int unzipCSAR(String fileName, String filePath) {
final int BUFFER = 2048;
- int status = 0;
- ZipFile zipFile = null;
- try {
- zipFile = new ZipFile(fileName);
+ int status = Constant.UNZIP_SUCCESS;
+
+ try(ZipFile zipFile = new ZipFile(fileName);) {
Enumeration emu = zipFile.entries();
while(emu.hasMoreElements()) {
ZipEntry entry = (ZipEntry)emu.nextElement();
@@ -192,33 +191,19 @@ public class DownloadCsarManager {
if(parent != null && (!parent.exists())) {
parent.mkdirs();
}
- try(FileOutputStream fos = new FileOutputStream(file)){
- try(BufferedOutputStream bos = new BufferedOutputStream(fos, BUFFER)){
-
+ try(FileOutputStream fos = new FileOutputStream(file);
+ BufferedOutputStream bos = new BufferedOutputStream(fos, BUFFER);){
int count;
byte data[] = new byte[BUFFER];
while((count = bis.read(data, 0, BUFFER)) != -1) {
bos.write(data, 0, count);
}
bos.flush();
- }
}
}
-
- status = Constant.UNZIP_SUCCESS;
-
} catch(Exception e) {
status = Constant.UNZIP_FAIL;
LOG.error("Exception: " + e);
- } finally {
- if(zipFile != null) {
- try {
- zipFile.close();
- } catch(IOException e) {
- LOG.error("IOException: " + e);
- ;
- }
- }
}
return status;
}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/RestHttpContentExchange.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/RestHttpContentExchange.java
index 26d2ad57..64017c79 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/RestHttpContentExchange.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/RestHttpContentExchange.java
@@ -81,40 +81,14 @@ public class RestHttpContentExchange extends ContentExchange {
if(data == null) {
return "";
}
- ByteArrayInputStream input = null;
- GZIPInputStream gzis = null;
- InputStreamReader reader = null;
final StringBuilder out = new StringBuilder();
- try {
- input = new ByteArrayInputStream(data);
- gzis = new GZIPInputStream(input);
- reader = new InputStreamReader(gzis, Charset.forName(RestfulClientConst.ENCODING));
+ try (ByteArrayInputStream input = new ByteArrayInputStream(data);
+ GZIPInputStream gzis = new GZIPInputStream(input);
+ InputStreamReader reader = new InputStreamReader(gzis, Charset.forName(RestfulClientConst.ENCODING));) {
final char[] buff = new char[1024];
for(int n; (n = reader.read(buff)) != -1;) {
out.append(new String(buff, 0, n));
}
- } finally {
- if(reader != null) {
- try {
- reader.close();
- } catch(final IOException e) {
- LOGGER.error("decompress Gzip reader exception:", e);
- }
- }
- if(gzis != null) {
- try {
- gzis.close();
- } catch(final IOException e) {
- LOGGER.error("decompress Gzip exception:", e);
- }
- }
- if(input != null) {
- try {
- input.close();
- } catch(final IOException e) {
- LOGGER.error("decompress Gzip input exception:", e);
- }
- }
}
return out.toString();
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/RestfulConfigure.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/RestfulConfigure.java
index 8b71941e..83bf9b53 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/RestfulConfigure.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/RestfulConfigure.java
@@ -134,11 +134,10 @@ public class RestfulConfigure {
LOG.error(filePath + "isn't exist.");
return null;
}
- BufferedReader reader = null;
+
final StringBuilder jsonstr = new StringBuilder();
JSONObject jo = null;
- try {
- reader = new BufferedReader(new FileReader(file));
+ try (BufferedReader reader = new BufferedReader(new FileReader(file));) {
final ReaderHelper rHelpper = new ReaderHelper(reader);
String tempString = null;
while((tempString = rHelpper.getLine()) != null) {
@@ -147,14 +146,6 @@ public class RestfulConfigure {
jo = JSONObject.fromObject(jsonstr.toString());
} catch(final IOException e) {
LOG.error("load file exception:" + e);
- } finally {
- if(reader != null) {
- try {
- reader.close();
- } catch(final IOException e) {
- LOG.error("close error.", e);
- }
- }
}
return jo;
}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/ScaleManager.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/ScaleManager.java
index 7b0a4db6..e92da07a 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/ScaleManager.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/ScaleManager.java
@@ -99,7 +99,6 @@ public abstract class ScaleManager {
private static void writeVmIdsToFile(String vnfId, JSONArray vms) {
String filePath = getVmIdsFilePath(vnfId);
- FileOutputStream outStream = null;
try {
File destFile = FileUtils.getFile(filePath);
@@ -112,28 +111,23 @@ public abstract class ScaleManager {
if(!destFile.exists()) {
destFile.createNewFile();
}
- outStream = new FileOutputStream(destFile);
- outStream.write(vms.toString().getBytes());
+ try(FileOutputStream outStream = new FileOutputStream(destFile)) {
+ outStream.write(vms.toString().getBytes());
+ }
} catch(IOException e) {
LOG.error("function=writeVmIdsToFile, msg=write vms to file ioexception, e : {}", e);
- } finally {
- IOUtils.closeQuietly(outStream);
}
}
private static JSONArray readVmIdsFile(String vnfId) {
String filePath = getVmIdsFilePath(vnfId);
- InputStream ins = null;
- BufferedInputStream bins = null;
- String fileContent = "";
- try {
- ins = FileUtils.openInputStream(FileUtils.getFile(filePath));
- bins = new BufferedInputStream(ins);
+ String fileContent = "";
+ try(InputStream ins = FileUtils.openInputStream(FileUtils.getFile(filePath));
+ BufferedInputStream bins = new BufferedInputStream(ins);) {
byte[] contentByte = new byte[ins.available()];
int num = bins.read(contentByte);
-
if(num > 0) {
fileContent = new String(contentByte);
}
@@ -145,9 +139,6 @@ public abstract class ScaleManager {
LOG.error("function=readVmIdsFile, msg=read vms from file IOException, filePath : {}", filePath);
} catch(JSONException e) {
LOG.error("function=readVmIdsFile, msg=read vms from file JSONException, fileContent : {}", fileContent);
- } finally {
- IOUtils.closeQuietly(bins);
- IOUtils.closeQuietly(ins);
}
return new JSONArray();
}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/ReaderHelperTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/ReaderHelperTest.java
new file mode 100644
index 00000000..9f45fa95
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/ReaderHelperTest.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.Reader;
+import java.io.StringReader;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * <br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version
+ */
+public class ReaderHelperTest {
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ * Test method for {@link org.openo.baseservice.util.inf.ReaderHelper#getLine()}.
+ */
+ @Test
+ public void testGetLine() {
+ final String message = "hello.. how are you?";
+ final Reader reader = new StringReader(message);
+ final ReaderHelper helper = new ReaderHelper(reader);
+ final String actual = helper.getLine();
+ assertEquals(message, actual);
+ }
+
+ /**
+ * Test method for {@link org.openo.baseservice.util.inf.ReaderHelper#getLine()}.
+ */
+ @Test
+ public void testGetLineMultiLine() {
+ final String line1 = "hello.. how are you?";
+ final String line2 = "I am fine.";
+ final Reader reader = new StringReader(line1 + System.lineSeparator() + line2);
+ final ReaderHelper helper = new ReaderHelper(reader);
+ String actual = helper.getLine();
+ assertEquals(line1, actual);
+ actual = helper.getLine();
+ assertEquals(line2, actual);
+ actual = helper.getLine();
+ assertEquals(null, actual);
+ }
+
+ @Test
+ public void testGetLineNull() {
+ final ReaderHelper helper = new ReaderHelper(null);
+ final String actual = helper.getLine();
+ assertEquals(null, actual);
+
+ }
+
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestHttpRest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestHttpRest.java
new file mode 100644
index 00000000..76025f3a
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestHttpRest.java
@@ -0,0 +1,958 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+
+import org.eclipse.jetty.client.HttpClient;
+import org.eclipse.jetty.client.HttpExchange;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+
+import mockit.Mock;
+import mockit.MockUp;
+import mockit.integration.junit4.JMockit;
+
+/**
+ * <br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version
+ */
+@RunWith(JMockit.class)
+public class TestHttpRest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws Exception
+ * @since
+ */
+ @Test
+ public void testInitHttpRest() throws Exception {
+ final RestfulOptions options = new RestfulOptions();
+ new MockUp<HttpClient>() {
+
+ @Mock
+ public void doStart() {
+ }
+ };
+ final HttpRest httpRest = new HttpRest();
+ httpRest.initHttpRest(options);
+ final Field httpClient = HttpBaseRest.class.getDeclaredField("client");
+ httpClient.setAccessible(true);
+ Assert.assertNotNull(httpClient.get(httpRest));
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws NoSuchFieldException
+ * @throws Exception
+ * @since
+ */
+ @Test
+ public void testCreateRestHttpContentExchange() throws NoSuchFieldException, Exception {
+ final HttpBaseRest httpRest = new HttpRest();
+ final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
+
+ @Override
+ public void callback(final RestfulResponse response) {
+
+ }
+
+ @Override
+ public void handleExcepion(final Throwable e) {
+
+ }
+
+ };
+ final RestHttpContentExchange exchange = httpRest.createRestHttpContentExchange(callback);
+ assertNotNull(exchange);
+ final Field callbackField = RestHttpContentExchange.class.getDeclaredField("callback");
+ assertNotNull(callbackField);
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws Exception
+ * @since
+ */
+ @Test
+ public void testGetStringRestfulParametes() throws Exception {
+ final RestfulOptions options = new RestfulOptions();
+
+ final HttpRest httpRest = getHttpRest(options);
+ new MockUp<RestHttpContentExchange>() {
+
+ @Mock
+ public int waitForDone() {
+ return HttpExchange.STATUS_COMPLETED;
+ }
+
+ @Mock
+ public RestfulResponse getResponse() throws IOException {
+ final RestfulResponse response = new RestfulResponse();
+ response.setStatus(HttpExchange.STATUS_COMPLETED);
+ return response;
+ }
+
+ };
+ final RestfulParametes parametes = new RestfulParametes();
+ parametes.put("id", "1234");
+ parametes.put("name", "some-name");
+ parametes.put("address", null);
+ parametes.putHttpContextHeader("Content-Type", "application/json");
+ parametes.putHttpContextHeader("Accept-Encoding", "*/*");
+ final RestfulResponse response = httpRest.get("path/to/service", parametes);
+ assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
+
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws Exception
+ * @since
+ */
+ @Test
+ public void testGetStringRestfulParametesRestfulOptions() throws Exception {
+ final RestfulOptions options = new RestfulOptions();
+
+ final HttpRest httpRest = getHttpRest(options);
+ new MockUp<RestHttpContentExchange>() {
+
+ @Mock
+ public int waitForDone() {
+ return HttpExchange.STATUS_COMPLETED;
+ }
+
+ @Mock
+ public RestfulResponse getResponse() throws IOException {
+ final RestfulResponse response = new RestfulResponse();
+ response.setStatus(HttpExchange.STATUS_COMPLETED);
+ return response;
+ }
+
+ };
+ final RestfulResponse response = httpRest.get("path/to/service", new RestfulParametes(), options);
+ assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws Exception
+ * @since
+ */
+ @Test
+ public void testHeadStringRestfulParametes() throws Exception {
+ final RestfulOptions options = new RestfulOptions();
+
+ final HttpRest httpRest = getHttpRest(options);
+ new MockUp<RestHttpContentExchange>() {
+
+ @Mock
+ public int waitForDone() {
+ return HttpExchange.STATUS_COMPLETED;
+ }
+
+ @Mock
+ public RestfulResponse getResponse() throws IOException {
+ final RestfulResponse response = new RestfulResponse();
+ response.setStatus(HttpExchange.STATUS_COMPLETED);
+ return response;
+ }
+
+ };
+ final RestfulParametes parametes = new RestfulParametes();
+ parametes.put("id", "1234");
+ parametes.put("name", "some-name");
+ parametes.put("address", null);
+ parametes.putHttpContextHeader("Content-Type", "");
+ parametes.putHttpContextHeader("Accept-Encoding", "");
+ final RestfulResponse response = httpRest.head("path/to/service", parametes);
+ assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws Exception
+ * @since
+ */
+ @Test
+ public void testHeadStringRestfulParametesRestfulOptions() throws Exception {
+ final RestfulOptions options = new RestfulOptions();
+
+ final HttpRest httpRest = getHttpRest(options);
+ new MockUp<RestHttpContentExchange>() {
+
+ @Mock
+ public int waitForDone() {
+ return HttpExchange.STATUS_COMPLETED;
+ }
+
+ @Mock
+ public RestfulResponse getResponse() throws IOException {
+ final RestfulResponse response = new RestfulResponse();
+ response.setStatus(HttpExchange.STATUS_COMPLETED);
+ return response;
+ }
+
+ };
+ final RestfulParametes parametes = new RestfulParametes();
+ parametes.put("id", "1234");
+ parametes.put("name", "some-name");
+ parametes.put("address", null);
+ parametes.putHttpContextHeader("Content-Type", "");
+ parametes.putHttpContextHeader("Accept-Encoding", "");
+ final RestfulResponse response = httpRest.head("path/to/service", parametes, options);
+ assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
+ }
+
+ /**
+ * <br/>
+ *
+ * @param options
+ * @return
+ * @throws ServiceException
+ * @since
+ */
+ private HttpRest getHttpRest(final RestfulOptions options) throws ServiceException {
+ final HttpRest httpRest = new HttpRest();
+ {
+ new MockUp<HttpClient>() {
+
+ @Mock
+ public void doStart() {
+ }
+
+ @Mock
+ public void send(final HttpExchange exchange) throws IOException {
+ }
+ };
+ httpRest.initHttpRest(options);
+
+ }
+ return httpRest;
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws Exception
+ * @since
+ */
+ @Test
+ public void testAsyncGetStringRestfulParametesRestfulAsyncCallback() throws Exception {
+ final RestfulOptions options = new RestfulOptions();
+
+ final HttpRest httpRest = getHttpRest(options);
+ new MockUp<RestHttpContentExchange>() {
+
+ @Mock
+ public int waitForDone() {
+ return HttpExchange.STATUS_COMPLETED;
+ }
+
+ @Mock
+ public RestfulResponse getResponse() throws IOException {
+ final RestfulResponse response = new RestfulResponse();
+ response.setStatus(HttpExchange.STATUS_COMPLETED);
+ return response;
+ }
+
+ };
+
+ final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
+
+ @Override
+ public void callback(final RestfulResponse response) {
+
+ }
+
+ @Override
+ public void handleExcepion(final Throwable e) {
+
+ }
+
+ };
+ httpRest.asyncGet("path/to/service", new RestfulParametes(), callback);
+ httpRest.asyncGet("path/to/service", new RestfulParametes(), null);
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws ServiceException
+ * @since
+ */
+ @Test
+ public void testAsyncGetStringRestfulParametesRestfulOptionsRestfulAsyncCallback() throws ServiceException {
+ final RestfulOptions options = new RestfulOptions();
+
+ final HttpRest httpRest = getHttpRest(options);
+ new MockUp<RestHttpContentExchange>() {
+
+ @Mock
+ public int waitForDone() {
+ return HttpExchange.STATUS_COMPLETED;
+ }
+
+ @Mock
+ public RestfulResponse getResponse() throws IOException {
+ final RestfulResponse response = new RestfulResponse();
+ response.setStatus(HttpExchange.STATUS_COMPLETED);
+ return response;
+ }
+
+ };
+
+ final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
+
+ @Override
+ public void callback(final RestfulResponse response) {
+
+ }
+
+ @Override
+ public void handleExcepion(final Throwable e) {
+
+ }
+
+ };
+ httpRest.asyncGet("path/to/service", new RestfulParametes(), new RestfulOptions(), callback);
+ httpRest.asyncGet("path/to/service", new RestfulParametes(), new RestfulOptions(), null);
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws ServiceException
+ * @since
+ */
+ @Test
+ public void testPutStringRestfulParametes() throws ServiceException {
+ final RestfulOptions options = new RestfulOptions();
+
+ final HttpRest httpRest = getHttpRest(options);
+ new MockUp<RestHttpContentExchange>() {
+
+ @Mock
+ public int waitForDone() {
+ return HttpExchange.STATUS_COMPLETED;
+ }
+
+ @Mock
+ public RestfulResponse getResponse() throws IOException {
+ final RestfulResponse response = new RestfulResponse();
+ response.setStatus(HttpExchange.STATUS_COMPLETED);
+ return response;
+ }
+
+ };
+ final RestfulParametes parametes = new RestfulParametes();
+ parametes.put("id", "1234");
+ parametes.put("name", "some-name");
+ parametes.put("address", null);
+ parametes.putHttpContextHeader("Content-Type", "");
+ parametes.putHttpContextHeader("Accept-Encoding", "");
+ final RestfulResponse response = httpRest.put("path/to/service", parametes);
+ assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws ServiceException
+ * @since
+ */
+ @Test
+ public void testPutStringRestfulParametesRestfulOptions() throws ServiceException {
+
+ final RestfulOptions options = new RestfulOptions();
+
+ final HttpRest httpRest = getHttpRest(options);
+ new MockUp<RestHttpContentExchange>() {
+
+ @Mock
+ public int waitForDone() {
+ return HttpExchange.STATUS_COMPLETED;
+ }
+
+ @Mock
+ public RestfulResponse getResponse() throws IOException {
+ final RestfulResponse response = new RestfulResponse();
+ response.setStatus(HttpExchange.STATUS_COMPLETED);
+ return response;
+ }
+
+ };
+ final RestfulParametes parametes = new RestfulParametes();
+ parametes.put("id", "1234");
+ parametes.put("name", "some-name");
+ parametes.put("address", null);
+ parametes.putHttpContextHeader("Content-Type", "");
+ parametes.putHttpContextHeader("Accept-Encoding", "");
+ final RestfulResponse response = httpRest.put("path/to/service", parametes, null);
+ assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws ServiceException
+ * @since
+ */
+ @Test
+ public void testAsyncPutStringRestfulParametesRestfulAsyncCallback() throws ServiceException {
+ final RestfulOptions options = new RestfulOptions();
+
+ final HttpRest httpRest = getHttpRest(options);
+ new MockUp<RestHttpContentExchange>() {
+
+ @Mock
+ public int waitForDone() {
+ return HttpExchange.STATUS_COMPLETED;
+ }
+
+ @Mock
+ public RestfulResponse getResponse() throws IOException {
+ final RestfulResponse response = new RestfulResponse();
+ response.setStatus(HttpExchange.STATUS_COMPLETED);
+ return response;
+ }
+
+ };
+
+ final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
+
+ @Override
+ public void callback(final RestfulResponse response) {
+
+ }
+
+ @Override
+ public void handleExcepion(final Throwable e) {
+
+ }
+
+ };
+ httpRest.asyncPut("path/to/service", new RestfulParametes(), callback);
+ httpRest.asyncPut("path/to/service", new RestfulParametes(), null);
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws Exception
+ * @since
+ */
+ @Test
+ public void testAsyncPutStringRestfulParametesRestfulOptionsRestfulAsyncCallback() throws Exception {
+ final RestfulOptions options = new RestfulOptions();
+
+ final HttpRest httpRest = getHttpRest(options);
+ new MockUp<RestHttpContentExchange>() {
+
+ @Mock
+ public int waitForDone() {
+ return HttpExchange.STATUS_COMPLETED;
+ }
+
+ @Mock
+ public RestfulResponse getResponse() throws IOException {
+ final RestfulResponse response = new RestfulResponse();
+ response.setStatus(HttpExchange.STATUS_COMPLETED);
+ return response;
+ }
+
+ };
+
+ final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
+
+ @Override
+ public void callback(final RestfulResponse response) {
+
+ }
+
+ @Override
+ public void handleExcepion(final Throwable e) {
+
+ }
+
+ };
+ httpRest.asyncPut("path/to/service", new RestfulParametes(), new RestfulOptions(), callback);
+ httpRest.asyncPut("path/to/service", new RestfulParametes(), new RestfulOptions(), null);
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws Exception
+ * @since
+ */
+ @Test
+ public void testAsyncPostStringRestfulParametesRestfulAsyncCallback() throws Exception {
+ final RestfulOptions options = new RestfulOptions();
+ options.setRestTimeout(10);
+
+ final HttpBaseRest httpRest = getHttpRest(options);
+ new MockUp<RestHttpContentExchange>() {
+
+ @Mock
+ public int waitForDone() {
+ return 99;
+ }
+
+ @Mock
+ public RestfulResponse getResponse() throws IOException {
+ final RestfulResponse response = new RestfulResponse();
+ response.setStatus(HttpExchange.STATUS_EXCEPTED);
+ return response;
+ }
+
+ };
+
+ final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
+
+ @Override
+ public void callback(final RestfulResponse response) {
+
+ }
+
+ @Override
+ public void handleExcepion(final Throwable e) {
+
+ }
+
+ };
+ httpRest.asyncPost("path/to/service", new RestfulParametes(), options, callback);
+ httpRest.asyncPost("path/to/service", new RestfulParametes(), options, null);
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws ServiceException
+ * @since
+ */
+ @Test
+ public void testAsyncPostStringRestfulParametesRestfulOptionsRestfulAsyncCallback() throws ServiceException {
+ final RestfulOptions options = new RestfulOptions();
+ options.setRestTimeout(10);
+
+ final HttpBaseRest httpRest = getHttpRest(options);
+ new MockUp<RestHttpContentExchange>() {
+
+ @Mock
+ public int waitForDone() {
+ return HttpExchange.STATUS_COMPLETED;
+ }
+
+ @Mock
+ public RestfulResponse getResponse() throws IOException {
+ final RestfulResponse response = new RestfulResponse();
+ response.setStatus(HttpExchange.STATUS_COMPLETED);
+ return response;
+ }
+
+ };
+
+ final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
+
+ @Override
+ public void callback(final RestfulResponse response) {
+
+ }
+
+ @Override
+ public void handleExcepion(final Throwable e) {
+
+ }
+
+ };
+ httpRest.asyncPost("path/to/service", new RestfulParametes(), options, callback);
+ httpRest.asyncPost("path/to/service", new RestfulParametes(), options, null);
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws ServiceException
+ * @since
+ */
+ @Test
+ public void testDeleteStringRestfulParametes() throws ServiceException {
+ final RestfulOptions options = new RestfulOptions();
+
+ final HttpBaseRest httpRest = getHttpRest(options);
+
+ final RestfulResponse response = httpRest.delete("path/to/service", null);
+ assertEquals(-1, response.getStatus());
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws ServiceException
+ * @since
+ */
+ @Test
+ public void testDeleteStringRestfulParametesRestfulOptions() throws ServiceException {
+ final RestfulOptions options = new RestfulOptions();
+
+ final HttpBaseRest httpRest = getHttpRest(options);
+ new MockUp<RestHttpContentExchange>() {
+
+ @Mock
+ public int waitForDone() {
+ return HttpExchange.STATUS_COMPLETED;
+ }
+
+ @Mock
+ public RestfulResponse getResponse() throws IOException {
+ final RestfulResponse response = new RestfulResponse();
+ response.setStatus(HttpExchange.STATUS_COMPLETED);
+ return response;
+ }
+
+ };
+ final RestfulParametes parameters = new RestfulParametes();
+ parameters.put("id", "1234");
+ parameters.put("name", "some-name");
+ parameters.put("address", null);
+ parameters.setRawData("{ \"data\"=\"sample JSON data\"");
+ parameters.putHttpContextHeader("Content-Type", "");
+ parameters.putHttpContextHeader("Accept-Encoding", "");
+ final RestfulResponse response = httpRest.delete("path/to/service", parameters, options);
+ assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws ServiceException
+ * @since
+ */
+ @Test
+ public void testAsyncDeleteStringRestfulParametesRestfulAsyncCallback() throws ServiceException {
+ final RestfulOptions options = new RestfulOptions();
+ options.setRestTimeout(10);
+
+ final HttpBaseRest httpRest = getHttpRest(options);
+ new MockUp<RestHttpContentExchange>() {
+
+ @Mock
+ public int waitForDone() {
+ return HttpExchange.STATUS_COMPLETED;
+ }
+
+ @Mock
+ public RestfulResponse getResponse() throws IOException {
+ final RestfulResponse response = new RestfulResponse();
+ response.setStatus(HttpExchange.STATUS_COMPLETED);
+ return response;
+ }
+
+ };
+
+ final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
+
+ @Override
+ public void callback(final RestfulResponse response) {
+
+ }
+
+ @Override
+ public void handleExcepion(final Throwable e) {
+
+ }
+
+ };
+ httpRest.asyncDelete("path/to/service", new RestfulParametes(), callback);
+ httpRest.asyncDelete("path/to/service", new RestfulParametes(), null);
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws ServiceException
+ * @since
+ */
+ @Test
+ public void testAsyncDeleteStringRestfulParametesRestfulOptionsRestfulAsyncCallback() throws ServiceException {
+ final RestfulOptions options = new RestfulOptions();
+ options.setRestTimeout(10);
+
+ final HttpBaseRest httpRest = getHttpRest(options);
+ new MockUp<RestHttpContentExchange>() {
+
+ @Mock
+ public int waitForDone() {
+ return HttpExchange.STATUS_COMPLETED;
+ }
+
+ @Mock
+ public RestfulResponse getResponse() throws IOException {
+ final RestfulResponse response = new RestfulResponse();
+ response.setStatus(HttpExchange.STATUS_COMPLETED);
+ return response;
+ }
+
+ };
+
+ final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
+
+ @Override
+ public void callback(final RestfulResponse response) {
+
+ }
+
+ @Override
+ public void handleExcepion(final Throwable e) {
+
+ }
+
+ };
+ httpRest.asyncDelete("path/to/service", new RestfulParametes(), options, callback);
+ httpRest.asyncDelete("path/to/service", new RestfulParametes(), options, null);
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws ServiceException
+ * @since
+ */
+ @Test
+ public void testPatchStringRestfulParametes() throws ServiceException {
+ final RestfulOptions options = new RestfulOptions();
+
+ final HttpBaseRest httpRest = getHttpRest(options);
+ new MockUp<RestHttpContentExchange>() {
+
+ @Mock
+ public int waitForDone() {
+ return HttpExchange.STATUS_COMPLETED;
+ }
+
+ @Mock
+ public RestfulResponse getResponse() throws IOException {
+ final RestfulResponse response = new RestfulResponse();
+ response.setStatus(HttpExchange.STATUS_COMPLETED);
+ return response;
+ }
+
+ };
+ final RestfulParametes parameters = new RestfulParametes();
+ parameters.put("id", "1234");
+ parameters.put("name", "some-name");
+ parameters.put("address", null);
+ parameters.setRawData("{ \"data\"=\"sample JSON data\"");
+ parameters.putHttpContextHeader("Content-Type", "");
+ parameters.putHttpContextHeader("Accept-Encoding", "");
+ final RestfulResponse response = httpRest.patch("path/to/service", parameters);
+ assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws ServiceException
+ * @since
+ */
+ @Test
+ public void testPatchStringRestfulParametesRestfulOptions() throws ServiceException {
+ final RestfulOptions options = new RestfulOptions();
+
+ final HttpBaseRest httpRest = getHttpRest(options);
+ new MockUp<RestHttpContentExchange>() {
+
+ @Mock
+ public int waitForDone() {
+ return HttpExchange.STATUS_COMPLETED;
+ }
+
+ @Mock
+ public RestfulResponse getResponse() throws IOException {
+ final RestfulResponse response = new RestfulResponse();
+ response.setStatus(HttpExchange.STATUS_COMPLETED);
+ return response;
+ }
+
+ };
+ final RestfulParametes parameters = new RestfulParametes();
+ parameters.put("id", "1234");
+ parameters.put("name", "some-name");
+ parameters.put("address", null);
+ parameters.setRawData("{ \"data\"=\"sample JSON data\"");
+ parameters.putHttpContextHeader("Content-Type", "");
+ parameters.putHttpContextHeader("Accept-Encoding", "");
+ final RestfulResponse response = httpRest.patch("path/to/service", parameters, options);
+ assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws ServiceException
+ * @since
+ */
+ @Test
+ public void testAsyncPatchStringRestfulParametesRestfulAsyncCallback() throws ServiceException {
+ final RestfulOptions options = new RestfulOptions();
+ options.setRestTimeout(10);
+
+ final HttpBaseRest httpRest = getHttpRest(options);
+ new MockUp<RestHttpContentExchange>() {
+
+ @Mock
+ public int waitForDone() {
+ return HttpExchange.STATUS_COMPLETED;
+ }
+
+ @Mock
+ public RestfulResponse getResponse() throws IOException {
+ final RestfulResponse response = new RestfulResponse();
+ response.setStatus(HttpExchange.STATUS_COMPLETED);
+ return response;
+ }
+
+ };
+
+ final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
+
+ @Override
+ public void callback(final RestfulResponse response) {
+
+ }
+
+ @Override
+ public void handleExcepion(final Throwable e) {
+
+ }
+
+ };
+ httpRest.asyncPatch("path/to/service", new RestfulParametes(), callback);
+ httpRest.asyncPatch("path/to/service", new RestfulParametes(), null);
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws ServiceException
+ * @since
+ */
+ @Test
+ public void testAsyncPatchStringRestfulParametesRestfulOptionsRestfulAsyncCallback() throws ServiceException {
+ final RestfulOptions options = new RestfulOptions();
+ options.setRestTimeout(10);
+
+ final HttpBaseRest httpRest = getHttpRest(options);
+ new MockUp<RestHttpContentExchange>() {
+
+ @Mock
+ public int waitForDone() {
+ return HttpExchange.STATUS_COMPLETED;
+ }
+
+ @Mock
+ public RestfulResponse getResponse() throws IOException {
+ final RestfulResponse response = new RestfulResponse();
+ response.setStatus(HttpExchange.STATUS_COMPLETED);
+ return response;
+ }
+
+ };
+
+ final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
+
+ @Override
+ public void callback(final RestfulResponse response) {
+
+ }
+
+ @Override
+ public void handleExcepion(final Throwable e) {
+
+ }
+
+ };
+ httpRest.asyncPatch("path/to/service", new RestfulParametes(), options, callback);
+ httpRest.asyncPatch("path/to/service", new RestfulParametes(), options, null);
+ }
+
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestRestHttpContentExchange.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestRestHttpContentExchange.java
new file mode 100644
index 00000000..ec03ea75
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestRestHttpContentExchange.java
@@ -0,0 +1,584 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.zip.GZIPInputStream;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.LogManager;
+import org.eclipse.jetty.client.Address;
+import org.eclipse.jetty.client.CachedExchange;
+import org.eclipse.jetty.client.HttpDestination;
+import org.eclipse.jetty.client.HttpExchange;
+import org.eclipse.jetty.http.HttpFields;
+import org.eclipse.jetty.http.HttpHeaders;
+import org.eclipse.jetty.io.Buffer;
+import org.eclipse.jetty.io.ByteArrayBuffer;
+import org.eclipse.jetty.util.StringUtil;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+
+import mockit.Mock;
+import mockit.MockUp;
+import mockit.Mocked;
+import mockit.integration.junit4.JMockit;
+
+/**
+ * <br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version
+ */
+@RunWith(JMockit.class)
+public class TestRestHttpContentExchange {
+
+ @Mocked
+ HttpDestination mockedDest;
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @After
+ public void tearDown() throws Exception {
+ LogManager.getLogger(RestHttpContentExchange.class).setLevel(Level.ERROR);
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws IOException
+ * @since
+ */
+ @Test
+ public void testOnRequestCommitted() throws IOException {
+ final RestHttpContentExchange exchange = new RestHttpContentExchange(false, null);
+ final Address address = new Address("localhost", 9999);
+ exchange.setAddress(address);
+ exchange.setRequestURI("/the/request/uri");
+ exchange.onRequestCommitted();
+
+ LogManager.getLogger(RestHttpContentExchange.class).setLevel(Level.DEBUG);
+ exchange.onRequestCommitted();
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws IOException
+ * @since
+ */
+ @Test
+ public void testOnRequestComplete() throws IOException {
+ final RestHttpContentExchange exchange = new RestHttpContentExchange(false, null);
+ final Address address = new Address("localhost", 9999);
+ exchange.setAddress(address);
+ exchange.setRequestURI("/the/request/uri");
+ exchange.onRequestComplete();
+
+ LogManager.getLogger(RestHttpContentExchange.class).setLevel(Level.DEBUG);
+ exchange.onRequestComplete();
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws Exception
+ * @since
+ */
+ @Test
+ public void testOnResponseComplete() throws Exception {
+ RestHttpContentExchange exchange = new RestHttpContentExchange(false, null);
+ final Address address = new Address("localhost", 9999);
+ exchange.setAddress(address);
+ exchange.setRequestURI("/the/request/uri");
+ exchange.onResponseComplete();
+
+ LogManager.getLogger(RestHttpContentExchange.class).setLevel(Level.DEBUG);
+ exchange.onResponseComplete();
+
+ final AtomicInteger isCallback = new AtomicInteger(0);
+ final AtomicInteger isException = new AtomicInteger(0);
+ final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
+
+ @Override
+ public void callback(final RestfulResponse response) {
+ isCallback.set(1);
+ }
+
+ @Override
+ public void handleExcepion(final Throwable e) {
+ isException.set(1);
+ }
+
+ };
+
+ final Field statusField = HttpExchange.class.getDeclaredField("_status");
+ statusField.setAccessible(true);
+ exchange = new RestHttpContentExchange(false, callback);
+ statusField.set(exchange, new AtomicInteger(200));
+ exchange.setAddress(new Address("localhost", 9999));
+ exchange.setRequestURI("/the/request/uri");
+ exchange.onResponseComplete();
+ assertEquals(1, isCallback.get());
+ assertEquals(0, isException.get());
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws Exception
+ * @since
+ */
+ @Test
+ @Ignore
+ public void testDecompressGzipToStr() throws Exception {
+ final RestHttpContentExchange exchange = new RestHttpContentExchange(false, null);
+ final Address address = new Address("localhost", 9999);
+ exchange.setAddress(address);
+ exchange.setRequestURI("/the/request/uri");
+
+ final InputStream stream = ClassLoader.getSystemResourceAsStream("sample.txt.gz");
+ final byte[] binaryData = new byte[1024];
+ stream.read(binaryData);
+ final String expected = "sample data.";
+
+ final String actual = exchange.decompressGzipToStr(binaryData);
+
+ assertEquals(actual, expected);
+
+ new MockUp<ByteArrayInputStream>() {
+
+ @Mock
+ public int read() throws Exception {
+ throw new IOException();
+ }
+
+ @Mock
+ public int read(final byte abyte0[], final int i, final int j) {
+
+ return -1;
+ }
+
+ };
+
+ thrown.expect(IOException.class);
+ exchange.decompressGzipToStr(binaryData);
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws Exception
+ * @since
+ */
+ @Test
+ @Ignore
+ public void testDecompressGzipToStrException() throws Exception {
+ final RestHttpContentExchange exchange = new RestHttpContentExchange(false, null);
+ final Address address = new Address("localhost", 9999);
+ exchange.setAddress(address);
+ exchange.setRequestURI("/the/request/uri");
+
+ final InputStream stream = ClassLoader.getSystemResourceAsStream("sample.txt.gz");
+ final byte[] binaryData = new byte[1024];
+ stream.read(binaryData);
+ final String expected = "sample data.";
+
+ new MockUp<GZIPInputStream>() {
+
+ @Mock
+ public void close() throws IOException {
+ throw new IOException();
+ }
+
+ };
+
+ new MockUp<InputStreamReader>() {
+
+ @Mock
+ public void close() throws IOException {
+ throw new IOException();
+ }
+
+ };
+
+ new MockUp<ByteArrayInputStream>() {
+
+ @Mock
+ public void close() throws IOException {
+ throw new IOException();
+ }
+
+ };
+
+ final String actual = exchange.decompressGzipToStr(binaryData);
+ assertEquals(actual, expected);
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws Exception
+ * @since
+ */
+ @Test
+ public void testDecompressGzipToStrNull() throws Exception {
+ final RestHttpContentExchange exchange = new RestHttpContentExchange(false, null);
+ final Address address = new Address("localhost", 9999);
+ exchange.setAddress(address);
+ exchange.setRequestURI("/the/request/uri");
+ final String expected = "";
+ final String actual = exchange.decompressGzipToStr(null);
+
+ assertEquals(actual, expected);
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws Exception
+ * @since
+ */
+ @Test
+ public void testOnResponseHeaderBufferBuffer() throws Exception {
+ final RestHttpContentExchange exchange = new RestHttpContentExchange(false, null);
+ final Address address = new Address("localhost", 9999);
+ exchange.setAddress(address);
+ exchange.setRequestURI("/the/request/uri");
+
+ final Buffer name = new ByteArrayBuffer("key");
+ final Buffer value = new ByteArrayBuffer("value");
+ exchange.onResponseHeader(name, value);
+
+ new MockUp<HttpHeaders>() {
+
+ @Mock
+ public int getOrdinal(final Buffer buffer) {
+ return HttpHeaders.CONTENT_ENCODING_ORDINAL;
+ }
+
+ };
+ exchange.onResponseHeader(name, value);
+
+ new MockUp<StringUtil>() {
+
+ @Mock
+ public String asciiToLowerCase(final String s) {
+ return "gzip";
+ }
+
+ };
+ exchange.onResponseHeader(name, value);
+
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testOnExceptionThrowable() {
+ final RestHttpContentExchange exchange = new RestHttpContentExchange(false, null);
+ final Address address = new Address("localhost", 9999);
+ exchange.setAddress(address);
+ exchange.setRequestURI("/the/request/uri");
+ exchange.onException(new Exception());
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testOnExceptionThrowableWithCallback() {
+ final AtomicInteger isCallback = new AtomicInteger(0);
+ final AtomicInteger isException = new AtomicInteger(0);
+ final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
+
+ @Override
+ public void callback(final RestfulResponse response) {
+ isCallback.set(1);
+ }
+
+ @Override
+ public void handleExcepion(final Throwable e) {
+ isException.set(1);
+ }
+
+ };
+ final RestHttpContentExchange exchange = new RestHttpContentExchange(true, callback);
+ final Address address = new Address("localhost", 9999);
+ exchange.setAddress(address);
+ exchange.setRequestURI("/the/request/uri");
+ exchange.onException(new Exception());
+ assertEquals(0, isCallback.get());
+ assertEquals(1, isException.get());
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testOnConnectionFailedThrowable() {
+ final RestHttpContentExchange exchange = new RestHttpContentExchange(false, null);
+ final Address address = new Address("localhost", 9999);
+ exchange.setAddress(address);
+ exchange.setRequestURI("/the/request/uri");
+ exchange.onConnectionFailed(new Exception());
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testOnConnectionFailedThrowableException() {
+ final AtomicInteger isCallback = new AtomicInteger(0);
+ final AtomicInteger isException = new AtomicInteger(0);
+ final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
+
+ @Override
+ public void callback(final RestfulResponse response) {
+ isCallback.set(1);
+ }
+
+ @Override
+ public void handleExcepion(final Throwable e) {
+ isException.set(1);
+ }
+
+ };
+ final RestHttpContentExchange exchange = new RestHttpContentExchange(true, callback);
+ final Address address = new Address("localhost", 9999);
+ exchange.setAddress(address);
+ exchange.setRequestURI("/the/request/uri");
+ exchange.onConnectionFailed(new Exception());
+ assertEquals(0, isCallback.get());
+ assertEquals(1, isException.get());
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testExpireHttpDestination() {
+ final RestHttpContentExchange exchange = new RestHttpContentExchange(true, null);
+ final Address address = new Address("localhost", 9999);
+ exchange.setAddress(address);
+ exchange.setRequestURI("/the/request/uri");
+ exchange.expire(mockedDest);
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws Exception
+ * @since
+ */
+ @Test
+ public void testExpireHttpDestinationException() throws Exception {
+ final AtomicInteger isCallback = new AtomicInteger(0);
+ final AtomicInteger isException = new AtomicInteger(0);
+ final List<Throwable> thrSet = new ArrayList<Throwable>();
+ final RestfulAsyncCallback callback = new RestfulAsyncCallback() {
+
+ @Override
+ public void callback(final RestfulResponse response) {
+ isCallback.set(1);
+ }
+
+ @Override
+ public void handleExcepion(final Throwable e) {
+ isException.set(1);
+ thrSet.add(e);
+ }
+
+ };
+ final RestHttpContentExchange exchange = new RestHttpContentExchange(true, callback);
+ final Address address = new Address("localhost", 9999);
+ exchange.setAddress(address);
+ exchange.setRequestURI("/the/request/uri");
+ exchange.expire(mockedDest);
+ assertEquals(0, isCallback.get());
+ assertEquals(1, isException.get());
+ assertEquals(1, thrSet.size());
+ final Throwable t = thrSet.get(0);
+ assertEquals(ServiceException.class, t.getClass());
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws Exception
+ * @since
+ */
+ @Test
+ public void testIsGzip() throws Exception {
+ final RestHttpContentExchange exchange = new RestHttpContentExchange(false, null);
+ final Address address = new Address("localhost", 9999);
+ exchange.setAddress(address);
+ exchange.setRequestURI("/the/request/uri");
+
+ final Buffer name = new ByteArrayBuffer("key");
+ final Buffer value = new ByteArrayBuffer("value");
+
+ new MockUp<HttpHeaders>() {
+
+ @Mock
+ public int getOrdinal(final Buffer buffer) {
+ return HttpHeaders.CONTENT_ENCODING_ORDINAL;
+ }
+
+ };
+ exchange.onResponseHeader(name, value);
+ assertFalse(exchange.isGzip());
+
+ new MockUp<StringUtil>() {
+
+ @Mock
+ public String asciiToLowerCase(final String s) {
+ return "gzip";
+ }
+
+ };
+ exchange.onResponseHeader(name, value);
+ assertTrue(exchange.isGzip());
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws Exception
+ * @since
+ */
+ @Test
+ public void testGetResponse() throws Exception {
+ final RestHttpContentExchange exchange = new RestHttpContentExchange(false, null);
+ final Address address = new Address("localhost", 9999);
+ exchange.setAddress(address);
+ exchange.setRequestURI("/the/request/uri");
+
+ final Field statusField = HttpExchange.class.getDeclaredField("_status");
+ statusField.setAccessible(true);
+ statusField.set(exchange, new AtomicInteger(200));
+
+ RestfulResponse response = exchange.getResponse();
+ assertEquals(0, response.getStatus());
+
+ final HttpFields fields = new HttpFields();
+ final Field headerFields = CachedExchange.class.getDeclaredField("_responseFields");
+ headerFields.setAccessible(true);
+ headerFields.set(exchange, fields);
+ response = exchange.getResponse();
+ assertEquals(0, response.getStatus());
+ fields.add("Content-Type", "application/json");
+ fields.add("Content-Encode", "UTF-8");
+ response = exchange.getResponse();
+ assertEquals(0, response.getStatus());
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws Exception
+ * @since
+ */
+ @Test
+ public void testGetResponseGzip() throws Exception {
+ final RestHttpContentExchange exchange = new RestHttpContentExchange(false, null);
+ final Address address = new Address("localhost", 9999);
+ exchange.setAddress(address);
+ exchange.setRequestURI("/the/request/uri");
+ new MockUp<RestHttpContentExchange>() {
+
+ @Mock
+ public boolean isGzip() {
+ return true;
+ }
+ };
+ final Field statusField = HttpExchange.class.getDeclaredField("_status");
+ statusField.setAccessible(true);
+ statusField.set(exchange, new AtomicInteger(200));
+
+ final RestfulResponse response = exchange.getResponse();
+ assertEquals(0, response.getStatus());
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestRestfulFactory.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestRestfulFactory.java
new file mode 100644
index 00000000..eccbb8d7
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestRestfulFactory.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import mockit.Mock;
+import mockit.MockUp;
+import mockit.integration.junit4.JMockit;
+
+/**
+ * <br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version
+ */
+@RunWith(JMockit.class)
+public class TestRestfulFactory {
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testGetRestInstance() {
+ Restful instance = RestfulFactory.getRestInstance("https");
+
+ new MockUp<HttpRest>() {
+
+ @Mock
+ public void initHttpRest(final RestfulOptions option) throws ServiceException {
+ throw new ServiceException();
+ }
+
+ };
+ instance = RestfulFactory.getRestInstance("http");
+ assertNotNull(instance);
+
+ instance = RestfulFactory.getRestInstance("http");
+ assertNotNull(instance);
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestRestfulOptions.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestRestfulOptions.java
new file mode 100644
index 00000000..48665be7
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestRestfulOptions.java
@@ -0,0 +1,288 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+
+import mockit.integration.junit4.JMockit;
+
+/**
+ * <br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version
+ */
+@RunWith(JMockit.class)
+public class TestRestfulOptions {
+
+ @Rule
+ final public ExpectedException thrown = ExpectedException.none();
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testGetPort() {
+ final RestfulOptions options = new RestfulOptions();
+ final int port = 9091;
+ assertEquals(0, options.getPort());
+ options.setPort(port);
+ assertEquals(port, options.getPort());
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testSetPort() {
+ final RestfulOptions options = new RestfulOptions();
+ final int port = 9091;
+ assertTrue(options.setPort(port));
+ assertEquals(port, options.getPort());
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testGetHost() {
+ final RestfulOptions options = new RestfulOptions();
+ final String host = "localhost";
+ assertEquals("", options.getHost());
+ options.setHost(host);
+ assertEquals(host, options.getHost());
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testSetHost() {
+ final RestfulOptions options = new RestfulOptions();
+ final String host = "localhost";
+ assertTrue(options.setHost(host));
+ assertEquals(host, options.getHost());
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testSetRestTimeout() {
+ final RestfulOptions options = new RestfulOptions();
+ int timeout = 0;
+ assertFalse(options.setRestTimeout(timeout));
+ assertEquals(0, options.getRestTimeout());
+
+ timeout = 1;
+ assertTrue(options.setRestTimeout(timeout));
+ assertEquals(timeout, options.getRestTimeout());
+
+ timeout = 10;
+ assertTrue(options.setRestTimeout(timeout));
+ assertEquals(timeout, options.getRestTimeout());
+
+ timeout = RestfulOptions.REST_OPTIONS_TIMEOUT_MAXTIMEOUT - 1;
+ assertTrue(options.setRestTimeout(timeout));
+ assertEquals(timeout, options.getRestTimeout());
+
+ timeout = RestfulOptions.REST_OPTIONS_TIMEOUT_MAXTIMEOUT;
+ assertTrue(options.setRestTimeout(timeout));
+ assertEquals(timeout, options.getRestTimeout());
+
+ timeout = RestfulOptions.REST_OPTIONS_TIMEOUT_MAXTIMEOUT + 1;
+ assertFalse(options.setRestTimeout(timeout));
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testGetRestTimeout() {
+ final RestfulOptions options = new RestfulOptions();
+ int timeout = 0;
+ assertEquals(0, options.getRestTimeout());
+
+ timeout = 1;
+ assertTrue(options.setRestTimeout(timeout));
+ assertEquals(timeout, options.getRestTimeout());
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testGetOption() {
+ final RestfulOptions options = new RestfulOptions();
+ assertNull(options.getOption("invalid"));
+
+ options.setHost("localhost");
+ Object obj = options.getOption(RestfulClientConst.HOST_KEY_NAME);
+ assertNotNull(obj);
+ assertTrue(obj instanceof String);
+ assertEquals("localhost", obj);
+
+ final List<String> list = new ArrayList<String>();
+ list.add("data");
+ options.setOption("list", list);
+ obj = options.getOption("list");
+ assertNotNull(obj);
+ assertTrue(obj instanceof List);
+ assertSame(list, obj);
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testGetIntOption() {
+ final RestfulOptions options = new RestfulOptions();
+
+ assertEquals(0, options.getIntOption("count"));
+
+ options.setOption("count", 1);
+ assertEquals(1, options.getIntOption("count"));
+
+ thrown.expect(RuntimeException.class);
+
+ options.setOption("string-count", "two");
+ final int value = options.getIntOption("string-count");
+ assertEquals(2, value);
+
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testGetStringOption() {
+ final RestfulOptions options = new RestfulOptions();
+
+ assertEquals("", options.getStringOption("count"));
+
+ options.setOption("string-count", "one");
+ assertEquals("one", options.getStringOption("string-count"));
+
+ thrown.expect(RuntimeException.class);
+
+ options.setOption("count", 2);
+ final String value = options.getStringOption("count");
+ assertEquals(2, value);
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testSetOption() {
+ final RestfulOptions options = new RestfulOptions();
+ assertNull(options.getOption("invalid"));
+
+ options.setHost("localhost");
+ Object obj = options.getOption(RestfulClientConst.HOST_KEY_NAME);
+ assertNotNull(obj);
+ assertTrue(obj instanceof String);
+ assertEquals("localhost", obj);
+
+ final List<String> list = new ArrayList<String>();
+ list.add("data");
+ options.setOption("list", list);
+ obj = options.getOption("list");
+ assertNotNull(obj);
+ assertTrue(obj instanceof List);
+ assertSame(list, obj);
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestRestfulParametes.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestRestfulParametes.java
new file mode 100644
index 00000000..6b07dcb3
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestRestfulParametes.java
@@ -0,0 +1,229 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * <br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version
+ */
+public class TestRestfulParametes {
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testGet() {
+ final RestfulParametes params = new RestfulParametes();
+ assertNull(params.get("param"));
+ final Map<String, String> paramMap = new HashMap<String, String>();
+ params.setParamMap(paramMap);
+ paramMap.put("param", "value");
+ assertEquals("value", params.get("param"));
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testSetRawData() {
+ final RestfulParametes params = new RestfulParametes();
+ final String data = "Sample data.";
+ params.setRawData(data);
+ assertEquals(data, params.getRawData());
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testGetRawData() {
+ final RestfulParametes params = new RestfulParametes();
+ assertNull(params.getRawData());
+ final String data = "Sample data.";
+ params.setRawData(data);
+ assertEquals(data, params.getRawData());
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testPut() {
+ final RestfulParametes params = new RestfulParametes();
+ params.put("somekey", "somevalue");
+ params.put("otherkey", "othervalue");
+ assertEquals("somevalue", params.get("somekey"));
+ assertEquals("othervalue", params.get("otherkey"));
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testPutHttpContextHeaderStringString() {
+ final RestfulParametes params = new RestfulParametes();
+ params.putHttpContextHeader("Context-Encoding", "UTF-8");
+ assertEquals("UTF-8", params.getHttpContextHeader("Context-Encoding"));
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testPutHttpContextHeaderStringInt() {
+ final RestfulParametes params = new RestfulParametes();
+ params.putHttpContextHeader("Expire-At", 1000);
+ assertEquals("1000", params.getHttpContextHeader("Expire-At"));
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testGetHttpContextHeader() {
+ final RestfulParametes params = new RestfulParametes();
+ params.putHttpContextHeader("Expire-At", 1000);
+ params.putHttpContextHeader("Context-Encoding", "UTF-8");
+ assertEquals("1000", params.getHttpContextHeader("Expire-At"));
+ assertEquals("UTF-8", params.getHttpContextHeader("Context-Encoding"));
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testGetParamMap() {
+ final RestfulParametes params = new RestfulParametes();
+ params.put("key", "value");
+ final Map<String, String> map = params.getParamMap();
+ assertEquals("value", map.get("key"));
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testSetParamMap() {
+ final RestfulParametes params = new RestfulParametes();
+ final Map<String, String> map = new HashMap<String, String>();
+ map.put("key", "value");
+ params.setParamMap(map);
+ assertEquals("value", params.get("key"));
+
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testGetHeaderMap() {
+ final RestfulParametes params = new RestfulParametes();
+ params.putHttpContextHeader("key", "value");
+ final Map<String, String> map = params.getHeaderMap();
+ assertEquals("value", map.get("key"));
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testSetHeaderMap() {
+ final RestfulParametes params = new RestfulParametes();
+ final Map<String, String> map = new HashMap<String, String>();
+ map.put("key", "value");
+ params.setHeaderMap(map);
+ assertEquals("value", params.getHttpContextHeader("key"));
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestRestfulResponse.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestRestfulResponse.java
new file mode 100644
index 00000000..f5f798a8
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/TestRestfulResponse.java
@@ -0,0 +1,273 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+/**
+ * <br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version
+ */
+public class TestRestfulResponse {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @throws java.lang.Exception
+ * @since
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testGetStatus() {
+ final RestfulResponse response = new RestfulResponse();
+ int actual = response.getStatus();
+ int expected = -1;
+
+ assertEquals(expected, actual);
+ expected = 202;
+ response.setStatus(expected);
+ actual = response.getStatus();
+ assertEquals(expected, actual);
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testSetStatus() {
+ final RestfulResponse response = new RestfulResponse();
+ final int expected = 10;
+ response.setStatus(expected);
+ final int actual = response.getStatus();
+ assertEquals(expected, actual);
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testGetRespHeaderMap() {
+ final RestfulResponse response = new RestfulResponse();
+ Map<String, String> expected = response.getRespHeaderMap();
+ assertNull(expected);
+ expected = new HashMap<String, String>();
+ expected.put("key", "value");
+ response.setRespHeaderMap(expected);
+ final Map<String, String> actual = response.getRespHeaderMap();
+ assertNotNull(actual);
+ assertSame(actual, expected);
+
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testSetRespHeaderMap() {
+ final RestfulResponse response = new RestfulResponse();
+ response.setRespHeaderMap(null);
+ Map<String, String> expected = response.getRespHeaderMap();
+ assertNull(expected);
+ expected = new HashMap<String, String>();
+ expected.put("key", "value");
+ response.setRespHeaderMap(expected);
+ final Map<String, String> actual = response.getRespHeaderMap();
+ assertNotNull(actual);
+ assertSame(actual, expected);
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testGetRespHeaderInt() {
+ final RestfulResponse response = new RestfulResponse();
+ response.setRespHeaderMap(null);
+ int actual = response.getRespHeaderInt("somekey");
+ assertEquals(-1, actual);
+ final Map<String, String> headers = new HashMap<String, String>();
+ headers.put("key", "value");
+ headers.put("count", "1");
+ response.setRespHeaderMap(headers);
+ actual = response.getRespHeaderInt("somekey");
+ assertEquals(-1, actual);
+
+ actual = response.getRespHeaderInt("count");
+ assertEquals(1, actual);
+
+ thrown.expect(RuntimeException.class);
+ actual = response.getRespHeaderInt("key");
+ assertEquals(1, actual);
+
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testGetRespHeaderLong() {
+ final RestfulResponse response = new RestfulResponse();
+ response.setRespHeaderMap(null);
+ long actual = response.getRespHeaderLong("somekey");
+ assertEquals(-1, actual);
+ final Map<String, String> headers = new HashMap<String, String>();
+ headers.put("key", "value");
+ headers.put("count", "1");
+ headers.put("max", "" + Long.MAX_VALUE);
+ headers.put("max++", Long.MAX_VALUE + 1 + "");
+ response.setRespHeaderMap(headers);
+ actual = response.getRespHeaderLong("somekey");
+ assertEquals(-1, actual);
+
+ actual = response.getRespHeaderLong("count");
+ assertEquals(1, actual);
+
+ actual = response.getRespHeaderLong("max");
+ assertEquals(Long.MAX_VALUE, actual);
+
+ actual = response.getRespHeaderLong("max++");
+ assertTrue(actual < 0);
+
+ thrown.expect(RuntimeException.class);
+ actual = response.getRespHeaderLong("key");
+ assertEquals(1, actual);
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testGetRespHeaderStr() {
+ final RestfulResponse response = new RestfulResponse();
+ response.setRespHeaderMap(null);
+ String actual = response.getRespHeaderStr("somekey");
+ assertEquals(null, actual);
+ final Map<String, String> headers = new HashMap<String, String>();
+ headers.put("key", "value");
+ headers.put("count", "1");
+ headers.put("max", "" + Long.MAX_VALUE);
+ response.setRespHeaderMap(headers);
+ actual = response.getRespHeaderStr("somekey");
+ assertEquals(null, actual);
+
+ actual = response.getRespHeaderStr("key");
+ assertEquals("value", actual);
+
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testGetResponseContent() {
+ final RestfulResponse response = new RestfulResponse();
+ assertEquals(null, response.getResponseContent());
+
+ final String content = "{ \"content\" = \"The response content\" }";
+ response.setResponseJson(content);
+ assertEquals(content, response.getResponseContent());
+ }
+
+ /**
+ * <br/>
+ *
+ * @since
+ */
+ @Test
+ public void testSetResponseJson() {
+ final RestfulResponse response = new RestfulResponse();
+ assertEquals(null, response.getResponseContent());
+
+ final String content = "{ \"content\" = \"The response content\" }";
+ response.setResponseJson(content);
+ assertEquals(content, response.getResponseContent());
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfmTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfmTest.java
index 38d7b93b..1e4937b8 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfmTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/vnf/VnfMgrVnfmTest.java
@@ -16,12 +16,12 @@
package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.vnf;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.ResultRequestUtil;
+import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.adapter.impl.AdapterResourceManager;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
-import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.vnf.VnfMgrVnfm;
import mockit.Mock;
import mockit.MockUp;
@@ -43,7 +43,7 @@ public class VnfMgrVnfmTest {
new MockUp<ResultRequestUtil>() {
@Mock
- public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson) {
+ public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
JSONObject resultJson = new JSONObject();
resultJson.put("retCode", Constant.HTTP_CREATED);
JSONObject appInfo = new JSONObject();
@@ -55,6 +55,8 @@ public class VnfMgrVnfmTest {
return resultJson;
}
};
+
+
String data = "{\"vnfmInfo\":{\"url\":\"url\"}}";
JSONObject subJsonObject = JSONObject.fromObject(data);
JSONObject vnfmObjcet = new JSONObject();
@@ -69,7 +71,7 @@ public class VnfMgrVnfmTest {
new MockUp<ResultRequestUtil>() {
@Mock
- public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson) {
+ public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
JSONObject resultJson = new JSONObject();
resultJson.put("retCode", Constant.HTTP_BAD_REQUEST);
return resultJson;
@@ -91,7 +93,7 @@ public class VnfMgrVnfmTest {
new MockUp<ResultRequestUtil>() {
@Mock
- public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson) {
+ public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
JSONObject resultJson = new JSONObject();
resultJson.put("retCode", Constant.HTTP_NOTFOUND);
return resultJson;
@@ -113,7 +115,7 @@ public class VnfMgrVnfmTest {
new MockUp<ResultRequestUtil>() {
@Mock
- public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson) {
+ public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
JSONObject resultJson = new JSONObject();
return resultJson;
}
@@ -134,7 +136,7 @@ public class VnfMgrVnfmTest {
new MockUp<ResultRequestUtil>() {
@Mock
- public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson) {
+ public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
JSONObject resultJson = new JSONObject();
resultJson.put("retCode", Constant.HTTP_NOCONTENT);
return resultJson;
@@ -151,7 +153,7 @@ public class VnfMgrVnfmTest {
JSONObject retJson = new JSONObject();
retJson.put("jobId", "vnfId" + "_" + Constant.DELETE);
resultJson.put("data", retJson);
- assertEquals(resultJson, result);
+ assertEquals(Constant.REST_SUCCESS, result.get("retCode"));
}
@Test
@@ -159,7 +161,7 @@ public class VnfMgrVnfmTest {
new MockUp<ResultRequestUtil>() {
@Mock
- public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson) {
+ public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
JSONObject resultJson = new JSONObject();
resultJson.put("retCode", Constant.HTTP_INNERERROR);
return resultJson;
@@ -179,7 +181,7 @@ public class VnfMgrVnfmTest {
public void getJobTestNormal(){
new MockUp<ResultRequestUtil>(){
@Mock
- public JSONObject call(JSONObject vnfmObject, String path, String methodName, String paramsJson) {
+ public JSONObject call(JSONObject vnfmObject, String path, String methodName, String paramsJson, String authModel) {
JSONObject obj = new JSONObject();
JSONObject dataobj = new JSONObject();
dataobj.put("id", "2839");
@@ -187,7 +189,7 @@ public class VnfMgrVnfmTest {
JSONArray basics = new JSONArray();
basics.add("test123");
JSONObject basicsData = new JSONObject();
- basicsData.put("basic", basics);
+ basicsData.put("vnf_list", basics);
obj.put("data", basicsData);
return obj;
}
@@ -205,7 +207,7 @@ public class VnfMgrVnfmTest {
public void getJobTestCreatedNormal(){
new MockUp<ResultRequestUtil>(){
@Mock
- public JSONObject call(JSONObject vnfmObject, String path, String methodName, String paramsJson) {
+ public JSONObject call(JSONObject vnfmObject, String path, String methodName, String paramsJson, String authModel) {
JSONObject obj = new JSONObject();
JSONObject dataobj = new JSONObject();
dataobj.put("id", "2839");
@@ -213,7 +215,7 @@ public class VnfMgrVnfmTest {
JSONArray basics = new JSONArray();
basics.add("test123");
JSONObject basicsData = new JSONObject();
- basicsData.put("basic", basics);
+ basicsData.put("vnf_list", basics);
obj.put("data", basicsData);
return obj;
}
@@ -231,7 +233,7 @@ public class VnfMgrVnfmTest {
public void getJobTestNullData(){
new MockUp<ResultRequestUtil>(){
@Mock
- public JSONObject call(JSONObject vnfmObject, String path, String methodName, String paramsJson) {
+ public JSONObject call(JSONObject vnfmObject, String path, String methodName, String paramsJson, String authModel) {
JSONObject obj = new JSONObject();
JSONObject dataobj = new JSONObject();
dataobj.put("id", "2839");
@@ -257,7 +259,7 @@ public class VnfMgrVnfmTest {
public void getJobTestInternalError(){
new MockUp<ResultRequestUtil>(){
@Mock
- public JSONObject call(JSONObject vnfmObject, String path, String methodName, String paramsJson) {
+ public JSONObject call(JSONObject vnfmObject, String path, String methodName, String paramsJson, String authModel) {
JSONObject obj = new JSONObject();
JSONObject dataobj = new JSONObject();
dataobj.put("id", "2839");
@@ -281,11 +283,11 @@ public class VnfMgrVnfmTest {
@Test
- public void testScaleVnf() {
+ public void testScaleVnfOut() {
new MockUp<ResultRequestUtil>() {
@Mock
- public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson) {
+ public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
JSONObject resultJson = new JSONObject();
resultJson.put("retCode", Constant.HTTP_CREATED);
JSONObject appInfo = new JSONObject();
@@ -297,7 +299,44 @@ public class VnfMgrVnfmTest {
return resultJson;
}
};
- String data = "{\"vnfmInfo\":{\"url\":\"url\"}}";
+ String data = "{\"type\":\"SCALE_OUT\"}}";
+ JSONObject subJsonObject = JSONObject.fromObject(data);
+ JSONObject vnfmObjcet = new JSONObject();
+ VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
+ JSONObject result = vnfMgrVnfm.scaleVnf(subJsonObject,vnfmObjcet,"test123","test123");
+
+ assertEquals(Constant.REST_SUCCESS, result.get("retCode"));
+ }
+
+ @Test
+ public void testScaleVnfIn() {
+ new MockUp<ResultRequestUtil>() {
+
+ @Mock
+ public JSONObject call(JSONObject vnfmObjcet, String path, String methodName, String paramsJson, String authModel) {
+ JSONObject resultJson = new JSONObject();
+ resultJson.put("retCode", Constant.HTTP_CREATED);
+ JSONObject appInfo = new JSONObject();
+ appInfo.put("vnfinstanceid", "id");
+ appInfo.put("project_id", "project_id");
+ JSONObject data = new JSONObject();
+ data.put("app_info", appInfo);
+ resultJson.put("data", data);
+ return resultJson;
+ }
+ };
+
+ new MockUp<AdapterResourceManager>() {
+
+ @Mock
+ public JSONObject readScaleInVmIdFromJson() {
+ JSONObject resultJson = new JSONObject();
+ JSONArray vm_list = new JSONArray();
+ resultJson.put("vm_list", vm_list);
+ return resultJson;
+ }
+ };
+ String data = "{\"type\":\"SCALE_IN\"}}";
JSONObject subJsonObject = JSONObject.fromObject(data);
JSONObject vnfmObjcet = new JSONObject();
VnfMgrVnfm vnfMgrVnfm = new VnfMgrVnfm();
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java
index 4ec0110c..b13b4096 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java
@@ -16,10 +16,14 @@
package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.rest;
-import mockit.Mock;
-import mockit.MockUp;
-import net.sf.json.JSONArray;
-import net.sf.json.JSONObject;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -29,12 +33,10 @@ import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient.ServiceExcepti
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process.VnfMgr;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
public class VnfRoaTest {
@@ -474,6 +476,40 @@ public class VnfRoaTest {
}
@Test
+ public void testHealVnf() throws ServiceException {
+ final JSONObject restJson = new JSONObject();
+ restJson.put("retCode", Constant.REST_SUCCESS);
+ MockUp<HttpServletRequest> proxyStub = new MockUp<HttpServletRequest>() {};
+ HttpServletRequest mockInstance = proxyStub.getMockInstance();
+
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+
+ new MockUp<VnfMgr>() {
+
+ @Mock
+ public JSONObject healVnf(JSONObject jsonObject, String vnfInstanceId, String vnfmId) {
+ JSONObject retJson = new JSONObject();
+ retJson.put("id", "123");
+ restJson.put("data", retJson);
+ return restJson;
+ }
+ };
+ new MockUp<VnfmJsonUtil>() {
+
+ @SuppressWarnings("unchecked")
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest VNFreq) {
+ return (T)restJson;
+ }
+ };
+
+ String result = vnfRoa.healVnf(mockInstance, mockResInstance, "id", "id");
+ assertNotNull(result);
+
+ }
+
+ @Test
public void testScaleVnf() throws ServiceException {
final JSONObject restJson = new JSONObject();
restJson.put("retCode", Constant.REST_SUCCESS);
diff --git a/zte/vmanager/docker/Dockerfile b/zte/vmanager/docker/Dockerfile
index db1c6c9f..71d66bd5 100644
--- a/zte/vmanager/docker/Dockerfile
+++ b/zte/vmanager/docker/Dockerfile
@@ -23,7 +23,7 @@ ADD . /service
WORKDIR /service
# get binary zip from nexus - vfc-nfvo-driver-vnfm-svnfm-zte-vmanager
-RUN wget -q -O vfc-nfvo-driver-vnfm-svnfm-zte-vmanager.zip 'https://nexus.onap.org/service/local/artifact/maven/redirect?r=snapshots&g=org.onap.vfc.nfvo.driver.vnfm.svnfm.zte.vmanager&a=vfc-nfvo-driver-vnfm-svnfm-zte-vmanager&v=LATEST&e=zip' && \
+RUN wget -q -O vfc-nfvo-driver-vnfm-svnfm-zte-vmanager.zip 'https://nexus.onap.org/service/local/artifact/maven/redirect?r=snapshots&g=org.onap.vfc.nfvo.driver.vnfm.svnfm.zte.vmanager&a=vfc-nfvo-driver-vnfm-svnfm-zte-vmanager&v=1.1.0-SNAPSHOT&e=zip' && \
unzip vfc-nfvo-driver-vnfm-svnfm-zte-vmanager.zip && \
rm -rf vfc-nfvo-driver-vnfm-svnfm-zte-vmanager.zip