summaryrefslogtreecommitdiffstats
path: root/ResmanagementService/service/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'ResmanagementService/service/src/test')
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/ResourceUtilTest.java51
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/VimUtilTest.java48
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/JsonUtilTest.java435
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/RestfulUtilTest.java244
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/StringUtilTest.java143
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/request/RequestUtilTest.java252
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/response/ResponseUtilTest.java90
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/response/RoaResponseUtilTest.java146
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapter2MSBManagerTest.java240
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrServiceTest.java68
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/HostImplTest.java161
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/LocationImplTest.java499
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/NetworkImplTest.java275
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/PortImplTest.java153
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/SitesImplTest.java148
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/VimImplTest.java135
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/HostBusinessImplTest.java87
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/LimitsBusinessImplTest.java71
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/LocationBusinessImplTest.java219
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/SitesBusinessImplTest.java408
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/VimBusinessImplTest.java177
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/HostDaoImplTest.java155
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/LocationDaoImplTest.java85
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/NetworkDaoImplTest.java152
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/PortDaoImplTest.java158
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/SitesDaoImplTest.java132
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/VimDaoImplTest.java77
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/VirtualLinkDaoImplTest.java49
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/VmDaoImplTest.java51
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/HostEntityTest.java38
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/LocationEntityTest.java45
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/NetworkEntityTest.java49
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/PortEntityTest.java47
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/SitesEntityTest.java110
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/VimEntityTest.java42
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/GrantResourseRoaTest.java166
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/HostRoaTest.java200
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/LimitsRoaTest.java68
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/LocationRoaTest.java389
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/NetworkRoaTest.java214
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/PortRoaTest.java214
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/ResOperateRoaTest.java197
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/SitesRoaTest.java279
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/SwaggerRoaTest.java56
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VirtualLinkRoaTest.java192
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VmRoaTest.java193
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VnfInfoRoaTest.java178
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VnfRoaTest.java191
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VnfStatusRoaTest.java178
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/ExceptionMessageTest.java68
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/GenericExceptionMapperTest.java43
-rw-r--r--ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/ServiceExceptionMapperTest.java44
52 files changed, 8110 insertions, 0 deletions
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/ResourceUtilTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/ResourceUtilTest.java
new file mode 100644
index 0000000..d162713
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/ResourceUtilTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2016-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.openo.nfvo.resmanagement.common;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+
+public class ResourceUtilTest {
+
+
+ @Test
+ public void testGetMessage() throws NoSuchMethodException, SecurityException {
+
+
+ String key = "huawei";
+ String result = ResourceUtil.getMessage(key);
+ String expectedResult = "huawei";
+ assertEquals(expectedResult, result);
+ }
+ @Test
+ public void testPrivateConstructor() throws Exception {
+ Constructor constructor = ResourceUtil.class.getDeclaredConstructor();
+ assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers()));
+
+ constructor.setAccessible(true);
+ constructor.newInstance();
+ }
+
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/VimUtilTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/VimUtilTest.java
new file mode 100644
index 0000000..13e12e5
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/VimUtilTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.openo.nfvo.resmanagement.common;
+
+import static org.junit.Assert.*;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+
+import org.junit.Test;
+import org.openo.baseservice.roa.util.restclient.RestfulOptions;
+import org.openo.baseservice.roa.util.restclient.RestfulParametes;
+import org.openo.baseservice.roa.util.restclient.RestfulResponse;
+import org.openo.nfvo.resmanagement.common.constant.UrlConstant;
+import org.openo.nfvo.resmanagement.common.util.RestfulUtil;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+public class VimUtilTest {
+
+
+
+ @Test
+ public void testPrivateConstructor() throws Exception {
+ Constructor constructor = VimUtil.class.getDeclaredConstructor();
+ assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers()));
+
+ constructor.setAccessible(true);
+ constructor.newInstance();
+ }
+
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/JsonUtilTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/JsonUtilTest.java
new file mode 100644
index 0000000..92b499d
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/JsonUtilTest.java
@@ -0,0 +1,435 @@
+/*
+ * Copyright 2016-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.openo.nfvo.resmanagement.common.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+
+import org.junit.Test;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+public class JsonUtilTest {
+
+ @Test
+ public void testGetJsonFieldStr() {
+ JSONObject jsonObj = new JSONObject();
+ String fieldName = "a";
+ jsonObj.put("a", "1");
+ jsonObj.put("b", "2");
+ String result = JsonUtil.getJsonFieldStr(jsonObj, fieldName);
+ String expectedResult = "1";
+ assertEquals(expectedResult, result);
+
+ }
+
+ @Test
+ public void testGetJsonFieldInt() {
+ JSONObject jsonObj = new JSONObject();
+ String fieldName = "a";
+ jsonObj.put("a", "1");
+ jsonObj.put("b", "2");
+ int result = JsonUtil.getJsonFieldInt(jsonObj, fieldName);
+ int expectedResult = 1;
+ assertEquals(expectedResult, result);
+
+ }
+
+ @Test
+ public void testGetJsonFieldArr() {
+ JSONObject jsonObj = new JSONObject();
+ String fieldName = "a";
+ jsonObj.put("a", new JSONArray());
+ jsonObj.put("b", "2");
+ JSONArray result = JsonUtil.getJsonFieldArr(jsonObj, fieldName);
+ JSONArray expectedResult = new JSONArray();
+ assertEquals(expectedResult, result);
+
+ }
+
+ @Test
+ public void testGetJsonFieldJson() {
+ JSONObject jsonObj = new JSONObject();
+ String fieldName = "a";
+ jsonObj.put("a", new JSONObject());
+ jsonObj.put("b", "2");
+ JSONObject result = JsonUtil.getJsonFieldJson(jsonObj, fieldName);
+ JSONObject expectedResult = new JSONObject();
+ assertEquals(expectedResult, result);
+
+ }
+
+ @Test
+ public void testGetJsonFieldLong() {
+ JSONObject jsonObj = new JSONObject();
+ String fieldName = "a";
+ jsonObj.put("a", 1);
+ jsonObj.put("b", 2);
+ Long result = JsonUtil.getJsonFieldLong(jsonObj, fieldName);
+ Long expectedResult = new Long(1);
+ assertEquals(expectedResult, result);
+
+ }
+
+ @Test
+ public void testGetJsonFieldObjectException() {
+ JSONObject jsonObj = new JSONObject();
+ String fieldName = "a";
+ jsonObj.put("a", "1");
+ jsonObj.put("b", "2");
+ JSONObject result = JsonUtil.getJsonFieldJson(jsonObj, fieldName);
+ JSONObject expectedResult = null;
+ assertEquals(expectedResult, result);
+
+ }
+
+ @Test
+ public void testIsNullJson1() {
+ JSONObject jsonObj = new JSONObject();
+ assertTrue(JsonUtil.isNullJson(jsonObj));
+ }
+
+ @Test
+ public void testIsNullJson2() {
+ assertTrue(JsonUtil.isNullJson(null));
+ }
+
+ @Test
+ public void testIsNullJson3() {
+ JSONObject jsonObj = new JSONObject();
+ jsonObj.put("a", "1");
+ assertFalse(JsonUtil.isNullJson(jsonObj));
+ }
+
+ @Test
+ public void testGetStrValueByjsonNULL() {
+ JSONObject jsonObj = new JSONObject();
+ String key = "a";
+ String result = JsonUtil.getStrValueByjson(jsonObj, key);
+ String expectedResult = null;
+ assertEquals(expectedResult, result);
+
+ }
+
+ @Test
+ public void testGetStrValueByjson() {
+ JSONObject jsonObj = new JSONObject();
+ String key = "a";
+ jsonObj.put("a", "1");
+ jsonObj.put("b", "2");
+ new MockUp<JSONObject>() {
+
+ @SuppressWarnings("static-access")
+ @Mock
+ public JSONObject optJSONObject(String key) {
+ return new JSONObject().fromObject("{\"a\":\"1\"}");
+ }
+
+ @Mock
+ public JSONObject getJSONObject(String key) {
+ return new JSONObject();
+ }
+ };
+ String result = JsonUtil.getStrValueByjson(jsonObj, key);
+ String expectedResult = "1";
+ assertEquals(expectedResult, result);
+
+ }
+
+ @Test
+ public void testGetStrValueByjson1() {
+ JSONObject jsonObj = new JSONObject();
+ String key = "a";
+ jsonObj.put("a", "1");
+ jsonObj.put("b", "2");
+ new MockUp<JSONObject>() {
+
+ @Mock
+ public JSONObject optJSONObject(String key) {
+ return null;
+ }
+
+ @SuppressWarnings("static-access")
+ @Mock
+ public JSONArray optJSONArray(String key) {
+ return new JSONArray().fromObject("[\"a\",\"1\"]");
+ }
+
+ @Mock
+ public JSONArray getJSONArray(String key) {
+ return new JSONArray();
+ }
+ };
+ String result = JsonUtil.getStrValueByjson(jsonObj, key);
+ String expectedResult = "1";
+ assertEquals(expectedResult, result);
+
+ }
+
+ @Test
+ public void testGetStrValueByjson2() {
+ JSONObject jsonObj = new JSONObject();
+ String key = "a";
+ jsonObj.put("a", "1");
+ jsonObj.put("b", "2");
+ String result = JsonUtil.getStrValueByjson(jsonObj, key);
+ String expectedResult = "1";
+ assertEquals(expectedResult, result);
+
+ }
+
+ @Test
+ public void testGetStrValueByJArray() {
+ JSONObject jsonObj = new JSONObject();
+ String key = "a";
+ jsonObj.put("a", "1");
+ jsonObj.put("b", "2");
+ new MockUp<JSONObject>() {
+
+ @Mock
+ public JSONObject optJSONObject(String key) {
+ return null;
+ }
+
+ @SuppressWarnings("static-access")
+ @Mock
+ public JSONArray optJSONArray(String key) {
+ return new JSONArray().fromObject("[\"a\",\"1\"]");
+ }
+
+ @SuppressWarnings("static-access")
+ @Mock
+ public JSONArray getJSONArray(String key) {
+ return new JSONArray().fromObject("[\"a\",\"1\"]");
+ }
+
+
+ };
+
+ String result = JsonUtil.getStrValueByjson(jsonObj, key);
+
+ }
+
+ @Test
+ public void testGetStrValueByJArray1() {
+ JSONObject jsonObj = new JSONObject();
+ String key = "a";
+ jsonObj.put("a", "1");
+ jsonObj.put("b", "2");
+ new MockUp<JSONObject>() {
+
+ int count = 1;
+
+ @SuppressWarnings("static-access")
+ @Mock
+ public JSONObject optJSONObject(String key) {
+ if (count == 1) {
+ count += 1;
+ return null;
+ } else
+ return new JSONObject().fromObject("{\"a\":\"1\"}");
+ }
+
+ @SuppressWarnings("static-access")
+ @Mock
+ public JSONArray optJSONArray(String key) {
+ return new JSONArray().fromObject("[\"a\",\"1\"]");
+ }
+
+ @SuppressWarnings("static-access")
+ @Mock
+ public JSONArray getJSONArray(String key) {
+ return new JSONArray().fromObject("[\"a\",\"1\"]");
+ }
+ };
+ String result = JsonUtil.getStrValueByjson(jsonObj, key);
+ String expectedResult = "1";
+ assertEquals(expectedResult, result);
+
+ }
+
+ @Test
+ public void testGetJsonValueByjson() {
+ JSONObject jsonObj = new JSONObject();
+ String key = "a";
+ jsonObj.put("a", "1");
+ jsonObj.put("b", "2");
+ String result = JsonUtil.getJsonValueByjson(jsonObj, key).toString();
+ String expectedResult = "{\"a\":\"1\"}";
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetJsonValueByjsonResultIsNull() {
+ JSONObject jsonObj = new JSONObject();
+ String key = "c";
+ jsonObj.put("a", "1");
+ jsonObj.put("b", "2");
+ JSONObject result = JsonUtil.getJsonValueByjson(jsonObj, key);
+ String expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetStrValueByJsonParentKeyIsNull() {
+ JSONObject jsonObj = new JSONObject();
+ String key = "a";
+ jsonObj.put("a", "1");
+ jsonObj.put("b", "2");
+ String parentKey = "";
+ String result = JsonUtil.getStrValueByJson(jsonObj, parentKey, key);
+ String expectedResult = "1";
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetStrValueByJsonParentJsonIsNull() {
+ JSONObject jsonObj = new JSONObject();
+ String key = "a";
+ jsonObj.put("a", "1");
+ jsonObj.put("b", "2");
+ String parentKey = "b";
+ new MockUp<JsonUtil>() {
+
+ @Mock
+ public JSONObject getJsonValueByjson(JSONObject json, String key) {
+ return new JSONObject();
+ }
+ };
+ String result = JsonUtil.getStrValueByJson(jsonObj, parentKey, key);
+ String expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetStrValueByJson() {
+ JSONObject jsonObj = new JSONObject();
+ String key = "a";
+ jsonObj.put("a", "1");
+ jsonObj.put("b", "2");
+ String parentKey = "b";
+ String result = JsonUtil.getStrValueByJson(jsonObj, parentKey, key);
+ String expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetResponseDataRetcodeError1() {
+ new MockUp<JsonUtil>() {
+
+ @Mock
+ public Integer getJsonFieldInt(JSONObject jsonObj, String fieldName) {
+ return null;
+ }
+ };
+ JSONObject result = JsonUtil.getResponseData(null);
+ String expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetResponseDataRetcodeError2() {
+ new MockUp<JsonUtil>() {
+
+ @Mock
+ public Integer getJsonFieldInt(JSONObject jsonObj, String fieldName) {
+ return -1;
+ }
+ };
+ JSONObject result = JsonUtil.getResponseData(null);
+ String expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetResponseDataResultIsEmpty() {
+ JSONObject obj = new JSONObject();
+ obj.put("data", "1");
+ obj.put("retCode", "1");
+ JSONObject result = JsonUtil.getResponseData(obj);
+ String expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetResponseData() {
+ JSONObject obj = new JSONObject();
+ obj.put("data", new JSONObject());
+ obj.put("retCode", "1");
+ new MockUp<JSONObject>() {
+
+ @SuppressWarnings("static-access")
+ @Mock
+ public JSONObject optJSONObject(String key) {
+ return new JSONObject().fromObject("{\"a\":\"1\"}");
+ }
+ };
+ JSONObject result = JsonUtil.getResponseData(obj);
+ String expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetResponseData1() {
+ JSONObject obj = new JSONObject();
+ obj.put("data", JSONArray.fromObject("[{\"a\":\"1\"},\"1\"]"));
+ obj.put("retCode", "1");
+ new MockUp<JSONObject>() {
+
+ @Mock
+ public JSONObject optJSONObject(String key) {
+ return null;
+ }
+
+ @SuppressWarnings("static-access")
+ @Mock
+ public JSONArray optJSONArray(String key) {
+ return new JSONArray().fromObject("[\"a\",\"1\"]");
+ }
+ };
+ JSONObject result = JsonUtil.getResponseData(obj);
+ String expectedResult = "{\"a\":\"1\"}";
+ assertEquals(expectedResult, result.toString());
+ }
+
+ @Test
+ public void testGetResponseData2() {
+ JSONObject obj = new JSONObject();
+ JSONObject json = new JSONObject();
+ json.put("retCode", "1");
+ obj.put("data", json);
+ obj.put("retCode", "1");
+ JSONObject result = JsonUtil.getResponseData(obj);
+ String expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+ @Test
+ public void testPrivateConstructor() throws Exception {
+ Constructor constructor = JsonUtil.class.getDeclaredConstructor();
+ assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers()));
+
+ constructor.setAccessible(true);
+ constructor.newInstance();
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/RestfulUtilTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/RestfulUtilTest.java
new file mode 100644
index 0000000..69bfd74
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/RestfulUtilTest.java
@@ -0,0 +1,244 @@
+/*
+ * Copyright 2016 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.openo.nfvo.resmanagement.common.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.baseservice.roa.util.restclient.RestfulOptions;
+import org.openo.baseservice.roa.util.restclient.RestfulParametes;
+import org.openo.baseservice.roa.util.restclient.RestfulResponse;
+import org.openo.nfvo.resmanagement.common.constant.Constant;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONArray;
+import net.sf.json.JSONException;
+import net.sf.json.JSONObject;
+
+public class RestfulUtilTest {
+
+ @Test
+ public void testGetResponseObjWithTwoParams() {
+ JSONObject result = RestfulUtil.getResponseObj(null, null);
+ JSONObject expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetResponseObjWithThreeParams() {
+ new MockUp<RestfulUtil>() {
+
+ @Mock
+ public String getResponseContent(String url, RestfulParametes restParametes, RestfulOptions opt,
+ String type) {
+ return "{\"ResponseContent\":\"123\"}";
+ }
+ };
+ JSONObject result = RestfulUtil.getResponseObj(null, null, null);
+ @SuppressWarnings("static-access")
+ JSONObject expectedResult = new JSONObject().fromObject("{\"ResponseContent\":\"123\"}");
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetResponseObjExpections() {
+ new MockUp<RestfulUtil>() {
+
+ @Mock
+ public String getResponseContent(String url, RestfulParametes restParametes, RestfulOptions opt,
+ String type) {
+ throw new JSONException();
+ }
+ };
+ JSONObject result = RestfulUtil.getResponseObj(null, null, null);
+ JSONObject expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetResponseContent() {
+ String result = RestfulUtil.getResponseContent(null, null, null);
+ String expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetResponseMap() {
+ Map<String, Object> result = RestfulUtil.getResponseMap(null, null, null, null);
+ Map<String, Object> expectedResult = new HashMap<String, Object>(10);
+ expectedResult.put(Constant.RESPONSE_CONTENT, null);
+ expectedResult.put(Constant.STATUS_CODE, -1);
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetResponseContentMap() {
+ Map<String, Object> result = RestfulUtil.getResponseContentMap(null, null);
+ Map<String, Object> expectedResult = new HashMap<String, Object>(10);
+ expectedResult.put(Constant.RESPONSE_CONTENT, null);
+ expectedResult.put(Constant.STATUS_CODE, -1);
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetResponseContentWithFourParams() {
+ new MockUp<RestfulResponse>() {
+
+ @Mock
+ public int getStatus() {
+ return 200;
+ }
+ };
+ String result = RestfulUtil.getResponseContent(null, null, null);
+ String expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetRestfulResponse() {
+ RestfulResponse result = RestfulUtil.getRestfulResponse(null, null, null);
+ RestfulResponse expectedResult = new RestfulResponse();
+ assertEquals(expectedResult.getStatus(), result.getStatus());
+ }
+
+ @Test
+ public void testRestfulResponse() {
+ RestfulResponse result = RestfulUtil.getRestfulResponse(null, null, "get");
+ RestfulResponse expectedResult = new RestfulResponse();
+ assertEquals(expectedResult.getStatus(), result.getStatus());
+ }
+
+ @Test
+ public void testRestfulResponse1() {
+ RestfulResponse result = RestfulUtil.getRestfulResponse(null, null, "add");
+ RestfulResponse expectedResult = new RestfulResponse();
+ assertEquals(expectedResult.getStatus(), result.getStatus());
+ }
+
+ @Test
+ public void testRestfulResponse2() {
+ RestfulResponse result = RestfulUtil.getRestfulResponse(null, null, "put");
+ RestfulResponse expectedResult = new RestfulResponse();
+ assertEquals(expectedResult.getStatus(), result.getStatus());
+ }
+
+ @Test
+ public void testRestfulResponse3() {
+ RestfulResponse result = RestfulUtil.getRestfulResponse(null, null, "delete");
+ RestfulResponse expectedResult = new RestfulResponse();
+ assertEquals(expectedResult.getStatus(), result.getStatus());
+ }
+
+ @Test
+ public void testGetRestResObjectsIsNull() {
+ RestfulResponse result = RestfulUtil.getRestRes(null, null);
+ RestfulResponse expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetRestResReflectiveOperationException() {
+ RestfulResponse result = RestfulUtil.getRestRes("123", "get");
+ RestfulResponse expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetRestRes() {
+ RestfulResponse result = RestfulUtil.getRestRes("async123", new RestfulResponse());
+ RestfulResponse expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetResponseResResultIsNull() throws ServiceException {
+ try {
+ RestfulUtil.getResponseRes(null, null);
+ } catch (ServiceException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testGetResponse() throws ServiceException {
+ new MockUp<RestfulUtil>() {
+
+ @Mock
+ public String getResponseContent(String url, RestfulParametes restParametes, String type) {
+ return "{\"ResponseContent\":\"123\",\"data\":[\"datas\"]}";
+ }
+ };
+ JSONArray result = RestfulUtil.getResponseRes(null, null);
+ JSONArray expectedResult = JSONArray.fromObject("[\"datas\"]");
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetResponseExceptions() throws ServiceException {
+ new MockUp<RestfulUtil>() {
+
+ @Mock
+ public String getResponseContent(String url, RestfulParametes restParametes, String type) {
+ return "{\"ResponseContent\":\"123\",}";
+ }
+ };
+ try {
+ RestfulUtil.getResponseRes(null, null);
+ } catch (ServiceException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testGgetResponseRes() throws ServiceException {
+ new MockUp<RestfulUtil>() {
+
+ @Mock
+ public String getResponseContent(String url, RestfulParametes restParametes, String type) {
+ return "{\"ResponseContent\":\"123\",}";
+ }
+ };
+ try {
+ RestfulUtil.getResponseRes(null, null, null);
+ } catch (ServiceException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testGgetResponseResException() throws ServiceException {
+ new MockUp<RestfulUtil>() {
+
+ @Mock
+ public String getResponseContent(String url, RestfulParametes restParametes, String type) {
+ return null;
+ }
+ };
+ try {
+ RestfulUtil.getResponseRes(null, null, null);
+ } catch (ServiceException e) {
+ assertTrue(true);
+ }
+ }
+
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/StringUtilTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/StringUtilTest.java
new file mode 100644
index 0000000..9fb9ef1
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/StringUtilTest.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2016-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.openo.nfvo.resmanagement.common.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+
+import org.junit.Test;
+
+public class StringUtilTest {
+
+ @Test
+ public void testisValidString() {
+ assertTrue(StringUtil.isValidString("abc"));
+ }
+
+ @Test
+ public void testisValidString1() {
+ assertFalse(StringUtil.isValidString(null));
+ }
+
+ @Test
+ public void testisValidString2() {
+ assertFalse(StringUtil.isValidString(""));
+ }
+
+ @Test
+ public void testIsAnyLargeThanZero() {
+ assertFalse(StringUtil.isAnyLargeThanZero(""));
+ }
+
+ @Test
+ public void testIsAnyLargeThanZero1() {
+ assertTrue(StringUtil.isAnyLargeThanZero("123"));
+ }
+
+ @Test
+ public void testIsIntegerExceptions() {
+ assertFalse(StringUtil.isInteger("asd"));
+ }
+
+ @Test
+ public void testIsInteger() {
+ assertTrue(StringUtil.isInteger("123"));
+ }
+
+ @Test
+ public void testIsInteger1() {
+ assertFalse(StringUtil.isInteger("-1"));
+ }
+
+ @Test
+ public void testIsNumericExceptions() {
+ assertFalse(StringUtil.isNumeric("abc"));
+ }
+
+ @Test
+ public void testIsNumeric() {
+ assertTrue(StringUtil.isNumeric("1.456"));
+ }
+
+ @Test
+ public void testIsNumeric1() {
+ assertFalse(StringUtil.isNumeric("-1.456"));
+ }
+
+ @Test
+ public void testCompareZeroByFloat() {
+ assertTrue(StringUtil.compareZeroByFloat("3.0", "1.0", "2.0"));
+ }
+
+ @Test
+ public void testCompareZeroByFloat1() {
+ assertFalse(StringUtil.compareZeroByFloat("3.0", "1.2", "2.5"));
+ }
+
+ @Test
+ public void testCompareZeroByInteger() {
+ assertTrue(StringUtil.compareZeroByInteger("3", "1", "2"));
+ }
+
+ @Test
+ public void testCompareZeroByInteger1() {
+ assertFalse(StringUtil.compareZeroByInteger("3", "1", "3"));
+ }
+
+ @Test
+ public void testNumFormatDataIsNull() {
+ String result = StringUtil.numFormat(null);
+ assertEquals(null, result);
+ }
+
+ @Test
+ public void testNumFormatDataIsEmpty() {
+ String result = StringUtil.numFormat("");
+ assertEquals(null, result);
+ }
+
+ @Test
+ public void testNumFormatInteger() {
+ String result = StringUtil.numFormat("12");
+ String expectedResult = "12";
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testNumFormatFloat() {
+ String result = StringUtil.numFormat("12.5");
+ String expectedResult = "12.5";
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testCheckXss() {
+ assertTrue(StringUtil.checkXss("123"));
+ }
+ @Test
+ public void testPrivateConstructor() throws Exception {
+ Constructor<StringUtil> constructor = StringUtil.class.getDeclaredConstructor();
+ assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers()));
+
+ constructor.setAccessible(true);
+ constructor.newInstance();
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/request/RequestUtilTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/request/RequestUtilTest.java
new file mode 100644
index 0000000..e4d34b8
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/request/RequestUtilTest.java
@@ -0,0 +1,252 @@
+/*
+ * Copyright 2016-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.openo.nfvo.resmanagement.common.util.request;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Constructor;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.cxf.jaxrs.impl.HttpServletRequestFilter;
+import org.junit.Test;
+
+import javassist.Modifier;
+import mockit.Mock;
+import mockit.MockUp;
+import mockit.Mocked;
+import net.sf.json.JSONException;
+import net.sf.json.JSONObject;
+
+public class RequestUtilTest {
+
+ @Test
+ public void testGetStringRequestBody() {
+ HttpServletRequestFilter context = new MockUp<HttpServletRequestFilter>() {
+
+ @Mocked
+ ServletInputStream input;
+
+ @Mock
+ public ServletInputStream getInputStream() throws IOException {
+ return input;
+ }
+ }.getMockInstance();
+ new MockUp<IOUtils>() {
+
+ String data = "{\"NETWORK\":{\"id\": \"123\"}}";
+
+ @Mock
+ public String toString(InputStream input) throws IOException {
+ return data;
+ }
+ };
+ String result = RequestUtil.getStringRequestBody(context);
+ String expectedResult = "{\"NETWORK\":{\"id\": \"123\"}}";
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetStringRequestBodyException() {
+ HttpServletRequestFilter context = new MockUp<HttpServletRequestFilter>() {
+
+ @Mock
+ public ServletInputStream getInputStream() throws IOException {
+ throw new IOException();
+ }
+ }.getMockInstance();
+ String result = RequestUtil.getStringRequestBody(context);
+ String expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetJsonRequestBody() {
+ HttpServletRequestFilter context = new MockUp<HttpServletRequestFilter>() {
+
+ @Mocked
+ ServletInputStream input;
+
+ @Mock
+ public ServletInputStream getInputStream() throws IOException {
+ return input;
+ }
+ }.getMockInstance();
+ new MockUp<IOUtils>() {
+
+ String data = "{\"NETWORK\":{\"id\": \"123\"}}";
+
+ @Mock
+ public String toString(InputStream input) throws IOException {
+ return data;
+ }
+ };
+ JSONObject result = RequestUtil.getJsonRequestBody(context);
+ String data1 = "{\"NETWORK\":{\"id\": \"123\"}}";
+ JSONObject expectedResult = JSONObject.fromObject(data1);
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetJsonRequestBody1() {
+ new MockUp<RequestUtil>() {
+
+ String data1 = "{\"NETWORK\":{\"id\": \"123\"}}";
+
+ @Mock
+ public String getStringRequestBody(HttpServletRequest context) {
+ return data1;
+ }
+ };
+ JSONObject result = RequestUtil.getJsonRequestBody(null);
+ String data1 = "{\"NETWORK\":{\"id\": \"123\"}}";
+ JSONObject expectedResult = JSONObject.fromObject(data1);
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetJsonRequestBodyException() {
+ HttpServletRequestFilter context = new MockUp<HttpServletRequestFilter>() {
+
+ @Mocked
+ ServletInputStream input;
+
+ @Mock
+ public ServletInputStream getInputStream() throws JSONException {
+ throw new JSONException();
+ }
+ }.getMockInstance();
+ JSONObject result = RequestUtil.getJsonRequestBody(context);
+ JSONObject expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Test
+ public void testGetAllJsonRequestBodyRequestBodyIsNull() {
+ HttpServletRequestFilter context = new MockUp<HttpServletRequestFilter>() {
+
+ @Mocked
+ ServletInputStream input;
+
+ @Mock
+ public ServletInputStream getInputStream() throws IOException {
+ return input;
+ }
+
+ @Mock
+ public Enumeration getHeaderNames() {
+ return new Enumeration() {
+
+ List<String> a = Arrays.asList(new String[] { "1", "2" });
+
+ @Override
+ public boolean hasMoreElements() {
+ return false;
+ }
+
+ @Override
+ public Object nextElement() {
+ return null;
+ }
+
+ };
+ }
+
+ }.getMockInstance();
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return null;
+ }
+ };
+ JSONObject result = RequestUtil.getAllJsonRequestBody(context);
+ JSONObject expectedResult = new JSONObject();
+ expectedResult.put("header", new HashMap<String, String>());
+ assertEquals(expectedResult, result);
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Test
+ public void testGetContextHeader() {
+ HttpServletRequestFilter context = new MockUp<HttpServletRequestFilter>() {
+
+ @Mock
+ public String getHeader(String name) {
+ return "1";
+ }
+
+ @Mock
+ public Enumeration getHeaderNames() {
+ return new Enumeration() {
+
+ List<String> a = Arrays.asList(new String[] { "1", "2" });
+
+ int count = 1;
+
+ @Override
+ public boolean hasMoreElements() {
+ if (count == 1) {
+ count += 1;
+ return true;
+ } else
+ return false;
+ }
+
+ @Override
+ public Object nextElement() {
+ return "1";
+ }
+
+ };
+ }
+
+ }.getMockInstance();
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return null;
+ }
+ };
+ JSONObject result = RequestUtil.getAllJsonRequestBody(context);
+ JSONObject expectedResult = new JSONObject();
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("1", "1");
+ expectedResult.put("header", map);
+ assertEquals(expectedResult, result);
+ }
+ @Test
+ public void testPrivateConstructor() throws Exception {
+ Constructor constructor = RequestUtil.class.getDeclaredConstructor();
+ assertTrue("Constructor is private", Modifier.isPrivate(constructor.getModifiers()));
+
+ constructor.setAccessible(true);
+ constructor.newInstance();
+ }
+
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/response/ResponseUtilTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/response/ResponseUtilTest.java
new file mode 100644
index 0000000..b3258f5
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/response/ResponseUtilTest.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2016-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.openo.nfvo.resmanagement.common.util.response;
+
+import static org.junit.Assert.*;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+
+import net.sf.json.JSONObject;
+
+public class ResponseUtilTest {
+
+ @Test
+ public void TestGenHttpResponseWithTwoParam() {
+ int retCode1 = -1;
+ String msg1 = "123";
+ JSONObject result = ResponseUtil.genHttpResponse(retCode1, msg1);
+ JSONObject expectedResult = new JSONObject();
+ expectedResult.put("msg", "123");
+ assertEquals(result.toString(), expectedResult.toString());
+ ;
+ }
+
+ @Test
+ public void TestGenHttpResponseWithThreeParam() {
+ int retCode1 = -1;
+ String msg1 = "123";
+ JSONObject result = ResponseUtil.genHttpResponse(retCode1, msg1, null);
+ JSONObject expectedResult = new JSONObject();
+ expectedResult.put("msg", "123");
+ assertEquals(result.toString(), expectedResult.toString());
+ ;
+ }
+
+ @Test
+ public void TestGenHttpResponseWithFourParam1() {
+ int httpStatusCode = -1;
+ int retCode1 = -1;
+ String msg1 = "123";
+ JSONObject result = ResponseUtil.genHttpResponse(null, httpStatusCode, retCode1, msg1);
+ JSONObject expectedResult = new JSONObject();
+ expectedResult.put("msg", "123");
+ assertEquals(result.toString(), expectedResult.toString());
+ ;
+ }
+
+ @Test
+ public void TestGenHttpResponseWithFourParam2() {
+ Map<String, Integer> codeMap = new HashMap<String, Integer>(5);
+ codeMap.put("httpStatusCode", -1);
+ codeMap.put("retCode", 1);
+ Map<String, Object> map = new HashMap<String, Object>(5);
+ map.put("a", -1);
+ map.put("b", 1);
+ String msg1 = "123";
+ JSONObject result = ResponseUtil.genHttpResponse(null, codeMap, msg1, map);
+ JSONObject expectedResult = new JSONObject();
+ expectedResult.put("msg", "123");
+ expectedResult.put("a", "-1");
+ assertEquals(result.toString(), expectedResult.toString());
+ ;
+ }
+ @Test
+ public void testPrivateConstructor() throws Exception {
+ Constructor constructor = ResponseUtil.class.getDeclaredConstructor();
+ assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers()));
+
+ constructor.setAccessible(true);
+ constructor.newInstance();
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/response/RoaResponseUtilTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/response/RoaResponseUtilTest.java
new file mode 100644
index 0000000..1e30587
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/response/RoaResponseUtilTest.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2016-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.openo.nfvo.resmanagement.common.util.response;
+
+import static org.junit.Assert.*;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+import java.util.Map;
+
+import org.junit.Test;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+public class RoaResponseUtilTest {
+
+ @Test
+ public void testGet() {
+ new MockUp<ResponseUtil>() {
+
+ @Mock
+ public JSONObject genHttpResponse(int retCode, String msg, Map<String, Object> map) {
+ return null;
+ }
+ };
+ JSONObject result = RoaResponseUtil.get(null);
+ JSONObject expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testAdd() {
+ int a = 0;
+ new MockUp<ResponseUtil>() {
+
+ @Mock
+ public JSONObject genHttpResponse(int retCode, String msg) {
+ return null;
+ }
+ };
+ JSONObject result = RoaResponseUtil.add(a);
+ JSONObject expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testAdd1() {
+ int a = 2;
+ new MockUp<ResponseUtil>() {
+
+ @Mock
+ public JSONObject genHttpResponse(int retCode, String msg) {
+ return null;
+ }
+ };
+ JSONObject result = RoaResponseUtil.add(a);
+ JSONObject expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testUpdate() {
+ int a = 0;
+ new MockUp<ResponseUtil>() {
+
+ @Mock
+ public JSONObject genHttpResponse(int retCode, String msg) {
+ return null;
+ }
+ };
+ JSONObject result = RoaResponseUtil.update(a);
+ JSONObject expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testUpdate1() {
+ int a = 2;
+ new MockUp<ResponseUtil>() {
+
+ @Mock
+ public JSONObject genHttpResponse(int retCode, String msg) {
+ return null;
+ }
+ };
+ JSONObject result = RoaResponseUtil.update(a);
+ JSONObject expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testDelete() {
+ int a = -1;
+ new MockUp<ResponseUtil>() {
+
+ @Mock
+ public JSONObject genHttpResponse(int retCode, String msg) {
+ return null;
+ }
+ };
+ JSONObject result = RoaResponseUtil.delete(a);
+ JSONObject expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testDelete1() {
+ int a = 0;
+ new MockUp<ResponseUtil>() {
+
+ @Mock
+ public JSONObject genHttpResponse(int retCode, String msg) {
+ return null;
+ }
+ };
+ JSONObject result = RoaResponseUtil.delete(a);
+ JSONObject expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testPrivateConstructor() throws Exception {
+ Constructor constructor = RoaResponseUtil.class.getDeclaredConstructor();
+ assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers()));
+
+ constructor.setAccessible(true);
+ constructor.newInstance();
+ }
+
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapter2MSBManagerTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapter2MSBManagerTest.java
new file mode 100644
index 0000000..511e509
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapter2MSBManagerTest.java
@@ -0,0 +1,240 @@
+/*
+ * Copyright 2016 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.openo.nfvo.resmanagement.service.adapter.impl;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+import org.openo.baseservice.roa.util.restclient.RestfulResponse;
+import org.openo.nfvo.resmanagement.common.util.RestfulUtil;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Sep 24, 2016
+ */
+public class ResmgrAdapter2MSBManagerTest {
+
+ @Test
+ public void testRegisterResmgr() {
+ new MockUp<RestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rsp = new RestfulResponse();
+ rsp.setStatus(201);
+ rsp.setResponseJson("{\"msg\":\"success!\"}");
+ return rsp;
+ }
+ };
+ Map<String, String> paramsMap = getHashMap();
+ ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager();
+ JSONObject resultObj = resmgr.registerResmgr(paramsMap, new JSONObject());
+ assertNotNull(resultObj);
+ }
+
+ @Test
+ public void testRegisterResmgrByInvalid() {
+ new MockUp<RestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rsp = new RestfulResponse();
+ rsp.setStatus(415);
+ rsp.setResponseJson("{\"msg\":\"invalid parameters\"}");
+ return rsp;
+ }
+ };
+ Map<String, String> paramsMap = getHashMap();
+ ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager();
+ JSONObject resultObj = resmgr.registerResmgr(paramsMap, new JSONObject());
+ assertNotNull(resultObj);
+ }
+
+ @Test
+ public void testRegisterResmgrByInternalError() {
+ new MockUp<RestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rsp = new RestfulResponse();
+ rsp.setStatus(500);
+ rsp.setResponseJson("{\"msg\":\"internal system error\"}");
+ return rsp;
+ }
+ };
+ Map<String, String> paramsMap = getHashMap();
+ ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager();
+ JSONObject resultObj = resmgr.registerResmgr(paramsMap, new JSONObject());
+ assertNotNull(resultObj);
+ }
+
+ @Test
+ public void testRegisterResmgrByFail() {
+ new MockUp<RestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rsp = new RestfulResponse();
+ rsp.setStatus(404);
+ rsp.setResponseJson("{\"msg\":\"not found\"}");
+ return rsp;
+ }
+ };
+ Map<String, String> paramsMap = getHashMap();
+ ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager();
+ JSONObject resultObj = resmgr.registerResmgr(paramsMap, new JSONObject());
+ assertNotNull(resultObj);
+ }
+
+ @Test
+ public void testRegisterResmgrByNull() {
+ new MockUp<RestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ return null;
+ }
+ };
+ Map<String, String> paramsMap = getHashMap();
+ ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager();
+ JSONObject resultObj = resmgr.registerResmgr(paramsMap, new JSONObject());
+ assertNotNull(resultObj);
+ }
+
+ @Test
+ public void testUnRegisterResmgr() {
+ new MockUp<RestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rsp = new RestfulResponse();
+ rsp.setStatus(204);
+ rsp.setResponseJson("{\"msg\":\"success!\"}");
+ return rsp;
+ }
+ };
+ Map<String, String> paramsMap = getHashMap();
+ ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager();
+ JSONObject resultObj = resmgr.unregisterResmgr(paramsMap);
+ assertNotNull(resultObj);
+ }
+
+ @Test
+ public void testUnRegisterResmgrByNotFound() {
+ new MockUp<RestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rsp = new RestfulResponse();
+ rsp.setStatus(404);
+ rsp.setResponseJson("{\"msg\":\"not found!\"}");
+ return rsp;
+ }
+ };
+ Map<String, String> paramsMap = getHashMap();
+ ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager();
+ JSONObject resultObj = resmgr.unregisterResmgr(paramsMap);
+ assertNotNull(resultObj);
+ }
+
+ @Test
+ public void testUnRegisterResmgrByInvalid() {
+ new MockUp<RestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rsp = new RestfulResponse();
+ rsp.setStatus(415);
+ rsp.setResponseJson("{\"msg\":\"invalid parameters!\"}");
+ return rsp;
+ }
+ };
+ Map<String, String> paramsMap = getHashMap();
+ ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager();
+ JSONObject resultObj = resmgr.unregisterResmgr(paramsMap);
+ assertNotNull(resultObj);
+ }
+
+ @Test
+ public void testUnRegisterResmgrByInternalError() {
+ new MockUp<RestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rsp = new RestfulResponse();
+ rsp.setStatus(500);
+ rsp.setResponseJson("{\"msg\":\"internal system error!\"}");
+ return rsp;
+ }
+ };
+ Map<String, String> paramsMap = getHashMap();
+ ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager();
+ JSONObject resultObj = resmgr.unregisterResmgr(paramsMap);
+ assertNotNull(resultObj);
+ }
+
+ @Test
+ public void testUnRegisterResmgrByFail() {
+ new MockUp<RestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ RestfulResponse rsp = new RestfulResponse();
+ rsp.setStatus(203);
+ rsp.setResponseJson("{\"msg\":\"fail!\"}");
+ return rsp;
+ }
+ };
+ Map<String, String> paramsMap = getHashMap();
+ ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager();
+ JSONObject resultObj = resmgr.unregisterResmgr(paramsMap);
+ assertNotNull(resultObj);
+ }
+
+ @Test
+ public void testUnRegisterResmgrByNull() {
+ new MockUp<RestfulUtil>() {
+
+ @Mock
+ public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
+ return null;
+ }
+ };
+ Map<String, String> paramsMap = getHashMap();
+ ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager();
+ JSONObject resultObj = resmgr.unregisterResmgr(paramsMap);
+ assertNotNull(resultObj);
+ }
+
+ private Map<String, String> getHashMap() {
+ Map<String, String> paramsMap = new HashMap<>();
+ paramsMap.put("url", "/openoapi/microservices/v1/services");
+ paramsMap.put("methodType", "post");
+ return paramsMap;
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrServiceTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrServiceTest.java
new file mode 100644
index 0000000..4ed114d
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrServiceTest.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2016 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.openo.nfvo.resmanagement.service.adapter.impl;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+import mockit.Mock;
+import mockit.MockUp;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Sep 24, 2016
+ */
+public class ResmgrAdapterMgrServiceTest {
+
+ @Test
+ public void testRegister() {
+ new MockUp<ResmgrAdapterMgrService>() {
+
+ @Mock
+ public String readVimAdapterInfoFromJson() throws IOException {
+ return "{\"serviceName\": \"resmgr\",\"version\": \"v1\",\"url\": \"/openoapi/resmgr/v1\",\"protocol\": \"REST\",\"visualRange\": \"1\",\"nodes\": [{\"ip\": \"127.0.0.1\",\"port\": \"8080\",\"ttl\": 0}]}";
+ }
+ };
+
+ ResmgrAdapterMgrService resmgrService = new ResmgrAdapterMgrService();
+ resmgrService.register();
+ }
+
+ @Test
+ public void testRegisterByIOException() {
+ new MockUp<ResmgrAdapterMgrService>() {
+
+ @Mock
+ public String readVimAdapterInfoFromJson() throws IOException {
+ throw new IOException();
+ }
+ };
+ ResmgrAdapterMgrService resmgrService = new ResmgrAdapterMgrService();
+ resmgrService.register();
+ }
+
+ @Test
+ public void testRegisterByNoFile() {
+ ResmgrAdapterMgrService resmgrService = new ResmgrAdapterMgrService();
+ resmgrService.register();
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/HostImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/HostImplTest.java
new file mode 100644
index 0000000..446c29f
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/HostImplTest.java
@@ -0,0 +1,161 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.base.openstack.impl;
+
+import static org.junit.Assert.*;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.service.business.impl.HostBusinessImpl;
+import org.openo.nfvo.resmanagement.service.dao.impl.HostDaoImpl;
+import org.openo.nfvo.resmanagement.service.entity.HostEntity;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+public class HostImplTest {
+
+ @Test
+ public void testdeleteHostByVimId() throws ServiceException {
+ new MockUp<HostDaoImpl>() {
+
+ @Mock
+ public int deleteHostByVimId(String vimId) {
+ return 1;
+ }
+
+ };
+ HostImpl hostImpl = new HostImpl();
+ HostBusinessImpl hostBusiness = new HostBusinessImpl();
+ hostBusiness.setHostDao(new HostDaoImpl());
+ hostImpl.setHostBusiness(hostBusiness);
+
+ assertTrue(hostImpl.deleteResByVimId("vimId") == 1);
+ }
+ @Test
+ public void testupdateStatusByVimId() throws ServiceException {
+ HostImpl hostImpl = new HostImpl();
+ hostImpl.setHostBusiness(new HostBusinessImpl());
+ JSONObject json = new JSONObject();
+ json.put("id", "123");
+ json.put("vimId", "vim123");
+ new MockUp<HostBusinessImpl>() {
+
+ @Mock
+ public int updateHostByVimId(HostEntity hostEntity) throws ServiceException {
+ return 1;
+ }
+ };
+ int result = hostImpl.updateStatusByVimId(json);
+ int exceptedResult = 1;
+ assertEquals(exceptedResult, result);
+ }
+
+ @Test
+ public void testDelete() throws ServiceException {
+ HostImpl hostImpl = new HostImpl();
+ hostImpl.setHostBusiness(new HostBusinessImpl());
+ new MockUp<HostBusinessImpl>() {
+ @Mock
+ public int deleteHost(String id) throws ServiceException {
+ return 1;
+ }
+ };
+
+ int result = hostImpl.delete("id");
+ int exceptedResult = 1;
+ assertEquals(exceptedResult, result);
+
+ }
+
+ @Test
+ public void testAdd1() throws ServiceException {
+ HostImpl hostImpl = new HostImpl();
+ hostImpl.setHostBusiness(new HostBusinessImpl());
+ JSONObject json = new JSONObject();
+ json.put("id", "1");
+ new MockUp<HostBusinessImpl>() {
+ @Mock
+ public int addHost(HostEntity hostEntity) throws ServiceException {
+ return 1;
+ }
+
+ };
+ int result = hostImpl.add(json);
+ int exceptedResult = 1;
+ assertEquals(exceptedResult, result);
+ }
+
+ @Test
+ public void testupdate() throws ServiceException {
+ HostImpl hostImpl = new HostImpl();
+ hostImpl.setHostBusiness(new HostBusinessImpl());
+ HostEntity hostEntity = new HostEntity();
+ hostEntity.setId("123");
+ new MockUp<HostBusinessImpl>() {
+ @Mock
+ public int updateHostSelective(HostEntity hostEntity) throws ServiceException {
+ return 1;
+ }
+
+ };
+ int result = hostImpl.update(hostEntity);
+ int exceptedResult = 1;
+ assertEquals(exceptedResult, result);
+ }
+
+ @Test
+ public void testUpdateResource() throws ServiceException {
+ HostImpl hostImpl = new HostImpl();
+ hostImpl.setHostBusiness(new HostBusinessImpl());
+ JSONObject json = new JSONObject();
+ json.put("id", "123");
+ json.put("vimId", "vim123");
+ new MockUp<HostBusinessImpl>() {
+
+ @Mock
+ public int updateHostSelective(HostEntity hostEntity) throws ServiceException {
+ return 1;
+ }
+ };
+ int result = hostImpl.update(json);
+ int exceptedResult = 1;
+ assertEquals(exceptedResult, result);
+ }
+
+ @Test
+ public void testGetList() throws ServiceException {
+ Map<String, Object> condition = new HashMap<>();
+ HostImpl hostImpl = new HostImpl();
+ hostImpl.setHostBusiness(new HostBusinessImpl());
+ new MockUp<HostBusinessImpl>() {
+
+ @Mock
+ public List<HostEntity> getHosts(Map<String, Object> condition) {
+ return null;
+ }
+ };
+ List<HostEntity> result = hostImpl.getList(condition);
+ List<HostEntity> exceptedResult = null;
+ assertEquals(exceptedResult, result);
+ }
+
+} \ No newline at end of file
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/LocationImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/LocationImplTest.java
new file mode 100644
index 0000000..74dfe99
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/LocationImplTest.java
@@ -0,0 +1,499 @@
+/*
+ * Copyright 2016-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.openo.nfvo.resmanagement.service.base.openstack.impl;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.service.business.impl.LocationBusinessImpl;
+import org.openo.nfvo.resmanagement.service.business.impl.SitesBusinessImpl;
+import org.openo.nfvo.resmanagement.service.dao.impl.LocationDaoImpl;
+import org.openo.nfvo.resmanagement.service.entity.LocationEntity;
+import org.openo.nfvo.resmanagement.service.entity.SitesEntity;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+public class LocationImplTest {
+
+ private LocationImpl locationImpl;
+
+ @Before
+ public void setUp() throws ServiceException {
+ locationImpl = new LocationImpl();
+ LocationBusinessImpl locationBusinessImpl = new LocationBusinessImpl();
+ locationBusinessImpl.setLocationDao(new LocationDaoImpl());
+ SitesImpl sitesImpl = new SitesImpl();
+ sitesImpl.setSitesBusiness(new SitesBusinessImpl());
+ locationImpl.setSites(sitesImpl);
+ locationImpl.setLocationBusiness(locationBusinessImpl);
+
+ }
+
+ @Test
+ public void testLocationImpl() throws ServiceException {
+ new MockUp<LocationBusinessImpl>() {
+
+ @Mock
+ public List<LocationEntity> getLocations(Map<String, Object> condition) throws ServiceException {
+ List<LocationEntity> list = new ArrayList<>();
+ LocationEntity localEntity = new LocationEntity();
+
+ list.add(localEntity);
+ return null;
+ }
+ };
+ new MockUp<LocationDaoImpl>() {
+
+ @Mock
+ public int addLocation(LocationEntity locationEntity) {
+ return 1;
+ }
+ };
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("id", "id");
+ jsonObject.put("country", "country");
+ jsonObject.put("location", "location");
+ jsonObject.put("latitude", "3");
+ jsonObject.put("longitude", "12");
+ jsonObject.put("description", "description");
+ assertTrue(locationImpl.add(jsonObject) == 1);
+ }
+
+ @Test
+ public void testLocationImplBranch() throws ServiceException {
+ new MockUp<LocationBusinessImpl>() {
+
+ @Mock
+ public List<LocationEntity> getLocations(Map<String, Object> condition) throws ServiceException {
+ List<LocationEntity> list = new ArrayList<>();
+
+ // list.add(localEntity);
+ return list;
+ }
+ };
+ new MockUp<LocationDaoImpl>() {
+
+ @Mock
+ public int addLocation(LocationEntity locationEntity) {
+ return 1;
+ }
+ };
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("id", "");
+ jsonObject.put("country", "country");
+ jsonObject.put("location", "location");
+ jsonObject.put("latitude", "90");
+ jsonObject.put("longitude", "180");
+ jsonObject.put("description", "description");
+ assertTrue(locationImpl.add(jsonObject) == 1);
+ }
+
+ @Test
+ public void testLocationImplBranch1() throws ServiceException {
+ new MockUp<LocationBusinessImpl>() {
+
+ @Mock
+ public List<LocationEntity> getLocations(Map<String, Object> condition) throws ServiceException {
+ List<LocationEntity> list = new ArrayList<>();
+ LocationEntity localEntity = new LocationEntity();
+
+ list.add(localEntity);
+ return null;
+ }
+ };
+ new MockUp<LocationDaoImpl>() {
+
+ @Mock
+ public int addLocation(LocationEntity locationEntity) {
+ return 1;
+ }
+ };
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("id", null);
+ jsonObject.put("country", "country");
+ jsonObject.put("location", "location");
+ jsonObject.put("latitude", "3");
+ jsonObject.put("longitude", "12");
+ jsonObject.put("description", "description");
+ assertTrue(locationImpl.add(jsonObject) == 1);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testLocationImplException() throws ServiceException {
+ new MockUp<LocationBusinessImpl>() {
+
+ @Mock
+ public List<LocationEntity> getLocations(Map<String, Object> condition) throws ServiceException {
+ List<LocationEntity> list = new ArrayList<>();
+ LocationEntity localEntity = new LocationEntity();
+
+ list.add(localEntity);
+ return list;
+ }
+ };
+
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("id", "2");
+ jsonObject.put("country", "country");
+ jsonObject.put("location", "location");
+ jsonObject.put("latitude", "3");
+ jsonObject.put("longitude", "12");
+ jsonObject.put("description", "description");
+ locationImpl.add(jsonObject);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testLocationImplException1() throws ServiceException {
+
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("id", null);
+ jsonObject.put("country", "");
+ jsonObject.put("location", "location");
+ jsonObject.put("latitude", "81");
+ jsonObject.put("longitude", "12");
+ jsonObject.put("description", "description");
+ locationImpl.add(jsonObject);
+
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testLocationImplException2() throws ServiceException {
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("id", null);
+ jsonObject.put("country", "country");
+ jsonObject.put("location", "");
+ jsonObject.put("latitude", "81");
+ jsonObject.put("longitude", "12");
+ jsonObject.put("description", "description");
+ locationImpl.add(jsonObject);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testLocationImplException3() throws ServiceException {
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("id", null);
+ jsonObject.put("country", "country");
+ jsonObject.put("location", "location");
+ jsonObject.put("latitude", "");
+ jsonObject.put("longitude", "12");
+ jsonObject.put("description", "description");
+ locationImpl.add(jsonObject);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testLocationImplException4() throws ServiceException {
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("id", null);
+ jsonObject.put("country", "country");
+ jsonObject.put("location", "location");
+ jsonObject.put("latitude", "latitude");
+ jsonObject.put("longitude", "");
+ jsonObject.put("description", "description");
+ locationImpl.add(jsonObject);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testLocationImplException5() throws ServiceException {
+ new MockUp<LocationBusinessImpl>() {
+
+ @Mock
+ public List<LocationEntity> getLocations(Map<String, Object> condition) throws ServiceException {
+ List<LocationEntity> list = new ArrayList<>();
+ LocationEntity localEntity = new LocationEntity();
+
+ list.add(localEntity);
+ return null;
+ }
+ };
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("id", "id");
+ jsonObject.put("country", "country");
+ jsonObject.put("location", "location");
+ jsonObject.put("latitude", "95");
+ jsonObject.put("longitude", "185");
+ jsonObject.put("description", "description");
+ locationImpl.add(jsonObject);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testLocationImplException6() throws ServiceException {
+ new MockUp<LocationBusinessImpl>() {
+
+ @Mock
+ public List<LocationEntity> getLocations(Map<String, Object> condition) throws ServiceException {
+ List<LocationEntity> list = new ArrayList<>();
+ LocationEntity localEntity = new LocationEntity();
+
+ list.add(localEntity);
+ return null;
+ }
+ };
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("id", "id");
+ jsonObject.put("country", "country");
+ jsonObject.put("location", "location");
+ jsonObject.put("latitude", "80");
+ jsonObject.put("longitude", "185");
+ jsonObject.put("description", "description");
+ locationImpl.add(jsonObject);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testLocationImplException7() throws ServiceException {
+ new MockUp<LocationBusinessImpl>() {
+
+ @Mock
+ public List<LocationEntity> getLocations(Map<String, Object> condition) throws ServiceException {
+ List<LocationEntity> list = new ArrayList<>();
+ LocationEntity localEntity = new LocationEntity();
+
+ list.add(localEntity);
+ return null;
+ }
+ };
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("id", "id");
+ jsonObject.put("country", "country");
+ jsonObject.put("location", "location");
+ jsonObject.put("latitude", "95");
+ jsonObject.put("longitude", "175");
+ jsonObject.put("description", "description");
+ locationImpl.add(jsonObject);
+ }
+
+ @Test
+ public void testUpdate() throws ServiceException {
+ new MockUp<LocationDaoImpl>() {
+
+ @Mock
+ public LocationEntity getLocation(String id) {
+ LocationEntity localEntity = new LocationEntity();
+ localEntity.setCountry("country");
+ localEntity.setLocation("location");
+
+ return localEntity;
+ }
+ };
+ new MockUp<LocationDaoImpl>() {
+
+ @Mock
+ public int updateLocationSelective(LocationEntity locationEntity) {
+ return 1;
+ }
+ };
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("id", "id");
+ jsonObject.put("country", "country");
+ jsonObject.put("location", "location");
+ jsonObject.put("latitude", "14");
+ jsonObject.put("longitude", "12");
+ jsonObject.put("description", "description");
+ locationImpl.update(jsonObject);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testUpdateException() throws ServiceException {
+
+ new MockUp<LocationDaoImpl>() {
+
+ @Mock
+ public int updateLocationSelective(LocationEntity locationEntity) {
+ return 1;
+ }
+ };
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("id", "id");
+ jsonObject.put("country", "country");
+ jsonObject.put("location", "location");
+ jsonObject.put("latitude", "91");
+ jsonObject.put("longitude", "12");
+ jsonObject.put("description", "description");
+ locationImpl.update(jsonObject);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testUpdateException1() throws ServiceException {
+ new MockUp<LocationDaoImpl>() {
+
+ @Mock
+ public LocationEntity getLocation(String id) {
+ LocationEntity localEntity = new LocationEntity();
+ localEntity.setCountry("countryNew");
+ localEntity.setLocation("location");
+
+ return localEntity;
+ }
+ };
+
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("id", "id");
+ jsonObject.put("country", "country");
+ jsonObject.put("location", "location");
+ jsonObject.put("latitude", "10");
+ jsonObject.put("longitude", "12");
+ jsonObject.put("description", "description");
+ locationImpl.update(jsonObject);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testUpdateException2() throws ServiceException {
+ new MockUp<LocationDaoImpl>() {
+
+ @Mock
+ public LocationEntity getLocation(String id) {
+ LocationEntity localEntity = new LocationEntity();
+ localEntity.setCountry("country");
+ localEntity.setLocation("locationNew");
+
+ return localEntity;
+ }
+ };
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("id", "id");
+ jsonObject.put("country", "country");
+ jsonObject.put("location", "location");
+ jsonObject.put("latitude", "10");
+ jsonObject.put("longitude", "12");
+ jsonObject.put("description", "description");
+ locationImpl.update(jsonObject);
+ }
+
+ @Test
+ public void testDelete() throws ServiceException {
+
+ new MockUp<LocationDaoImpl>() {
+
+ @Mock
+ public int deleteLocation(String id) {
+ return 1;
+ }
+ };
+ assertTrue(locationImpl.delete("location") == 1);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testDeleteException() throws ServiceException {
+
+ locationImpl.delete("");
+ }
+
+ @Test
+ public void testComputeSite() {
+ JSONObject total = new JSONObject();
+ total.put("vcpus", "12");
+ total.put("memory", "23");
+ total.put("disk", "23");
+ JSONObject used = new JSONObject();
+ used.put("vcpus", "12");
+ used.put("memory", "23");
+ used.put("disk", "23");
+ locationImpl.getLocationBusiness();
+
+ assertTrue(locationImpl.computingSite(total, used) != null);
+ }
+
+ @Test
+ public void testGetLocation() throws ServiceException {
+ new MockUp<LocationDaoImpl>() {
+
+ @Mock
+ public List<LocationEntity> getLocations(Map<String, Object> condition) {
+ List<LocationEntity> list = new ArrayList<>();
+ LocationEntity localEntity = new LocationEntity();
+ localEntity.setCountry("country");
+ localEntity.setLocation("locationNew");
+ list.add(localEntity);
+ return list;
+ }
+ };
+ assertTrue(locationImpl.getLocation(new HashMap<>()) != null);
+ }
+
+ @Test
+ public void testGetLocationBranch() throws ServiceException {
+ new MockUp<LocationDaoImpl>() {
+
+ @Mock
+ public List<LocationEntity> getLocations(Map<String, Object> condition) {
+ List<LocationEntity> list = new ArrayList<>();
+ LocationEntity localEntity = new LocationEntity();
+ localEntity.setCountry("country");
+ localEntity.setLocation("locationNew");
+ return list;
+ }
+ };
+ locationImpl.getLocation(new HashMap<>());
+ }
+
+ @Test
+ public void testGetLocationInfo() throws ServiceException {
+ new MockUp<SitesBusinessImpl>() {
+
+ @Mock
+ public List<SitesEntity> getSites(Map<String, Object> condition) {
+ List<SitesEntity> siteList = new ArrayList<>();
+ SitesEntity site = new SitesEntity();
+
+ siteList.add(site);
+ return siteList;
+ }
+ };
+
+ new MockUp<JSONObject>() {
+
+ @Mock
+ public JSONObject getJSONObject(String key) {
+ JSONObject total = new JSONObject();
+ total.put("vcpus", "12");
+ total.put("memory", "23");
+ total.put("disk", "23");
+ return total;
+ }
+ };
+ List<LocationEntity> locationInfo = new ArrayList<>();
+ LocationEntity localEntity = new LocationEntity();
+ locationInfo.add(localEntity);
+ locationImpl.getLocationInfo(locationInfo);
+ }
+
+ @Test
+ public void testGet() throws ServiceException {
+ new MockUp<LocationBusinessImpl>() {
+
+ @Mock
+ public List<LocationEntity> getLocations(Map<String, Object> condition) throws ServiceException {
+ List<LocationEntity> list = new ArrayList<>();
+ LocationEntity localEntity = new LocationEntity();
+
+ list.add(localEntity);
+ return null;
+ }
+ };
+ locationImpl.get(new HashMap<>());
+ assertTrue(locationImpl.get("id") != null);
+ }
+
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/NetworkImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/NetworkImplTest.java
new file mode 100644
index 0000000..6222005
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/NetworkImplTest.java
@@ -0,0 +1,275 @@
+/*
+ * Copyright 2016-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.openo.nfvo.resmanagement.service.base.openstack.impl;
+
+import static org.junit.Assert.*;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.service.business.impl.NetworkBusinessImpl;
+import org.openo.nfvo.resmanagement.service.dao.impl.NetworkDaoImpl;
+import org.openo.nfvo.resmanagement.service.dao.inf.NetworkDao;
+import org.openo.nfvo.resmanagement.service.entity.NetworkEntity;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+public class NetworkImplTest {
+
+
+ @Test
+ public void testAddBranch() throws ServiceException {
+ new MockUp<NetworkDaoImpl>() {
+
+ @Mock
+ public NetworkEntity getNetwork(String id) {
+ return null;
+ }
+
+ @Mock
+ public int addNetwork(NetworkEntity networkEntity) {
+ return 1;
+ }
+ };
+ NetworkImpl networkImpl = new NetworkImpl();
+ NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl();
+ NetworkDao networkDao = new NetworkDaoImpl();
+ networkBusiness.setNetworkDao(networkDao);
+ networkImpl.setNetworkBusiness(networkBusiness);
+ JSONObject json = new JSONObject();
+ json.put("id", "id");
+ json.put("name", "name");
+ json.put("status", "status");
+ json.put("tenant_id", "tenant_id");
+ json.put("vimId", "vimId");
+ json.put("vimName", "vimName");
+ json.put("provider:physical_network", "provider:physical_network");
+ json.put("provider:network_type", "provider:network_type");
+ json.put("provider:segmentation_id", "provider:segmentation_id");
+ assertTrue(networkImpl.add(json) == 1);
+ }
+
+ @Test
+ public void testAddBranch1() throws ServiceException {
+ new MockUp<NetworkDaoImpl>() {
+
+ @Mock
+ public NetworkEntity getNetwork(String id) {
+ return null;
+ }
+
+ @Mock
+ public int addNetwork(NetworkEntity networkEntity) {
+ return 1;
+ }
+ };
+ NetworkImpl networkImpl = new NetworkImpl();
+ NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl();
+ NetworkDao networkDao = new NetworkDaoImpl();
+ networkBusiness.setNetworkDao(networkDao);
+ networkImpl.setNetworkBusiness(networkBusiness);
+ JSONObject json = new JSONObject();
+ json.put("id", "");
+ json.put("name", "name");
+ json.put("status", "status");
+ json.put("tenant_id", "tenant_id");
+ json.put("vimId", "vimId");
+ json.put("vimName", "vimName");
+ json.put("provider:physical_network", "provider:physical_network");
+ json.put("provider:network_type", "provider:network_type");
+ json.put("provider:segmentation_id", "provider:segmentation_id");
+ assertTrue(networkImpl.add(json) == 1);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testAddBranch2() throws ServiceException {
+ new MockUp<NetworkDaoImpl>() {
+ @Mock
+ public NetworkEntity getNetwork(String id) {
+ return null;
+ }
+
+ @Mock
+ public int addNetwork(NetworkEntity networkEntity) {
+ return 1;
+ }
+ };
+ NetworkImpl networkImpl = new NetworkImpl();
+ NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl();
+ NetworkDao networkDao = new NetworkDaoImpl();
+ networkBusiness.setNetworkDao(networkDao);
+ networkImpl.setNetworkBusiness(networkBusiness);
+ NetworkEntity entity = null;
+ networkImpl.add(entity);
+
+ }
+
+
+ @Test
+ public void testDelete() throws ServiceException {
+ new MockUp<NetworkDaoImpl>() {
+
+ @Mock
+ public int deleteNetwork(String id) {
+ return 1;
+ }
+ };
+ NetworkImpl networkImpl = new NetworkImpl();
+ NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl();
+ NetworkDao networkDao = new NetworkDaoImpl();
+ networkBusiness.setNetworkDao(networkDao);
+ networkImpl.setNetworkBusiness(networkBusiness);
+ assertTrue(networkImpl.delete("id") == 1);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testDelete1() throws ServiceException {
+
+ NetworkImpl networkImpl = new NetworkImpl();
+ NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl();
+ NetworkDao networkDao = new NetworkDaoImpl();
+ networkBusiness.setNetworkDao(networkDao);
+ networkImpl.setNetworkBusiness(networkBusiness);
+ networkImpl.delete("");
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testDeleteVimByIdException() throws ServiceException {
+
+ NetworkImpl networkImpl = new NetworkImpl();
+ NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl();
+ NetworkDao networkDao = new NetworkDaoImpl();
+ networkBusiness.setNetworkDao(networkDao);
+ networkImpl.setNetworkBusiness(networkBusiness);
+ networkImpl.deleteResByVimId("");
+ }
+
+ @Test
+ public void testDeleteVimById() throws ServiceException {
+ new MockUp<NetworkDaoImpl>() {
+
+ @Mock
+ public int deleteNetworkByVimId(String vimId) {
+ return 1;
+ }
+ };
+ NetworkImpl networkImpl = new NetworkImpl();
+ NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl();
+ NetworkDao networkDao = new NetworkDaoImpl();
+ networkBusiness.setNetworkDao(networkDao);
+ networkImpl.setNetworkBusiness(networkBusiness);
+ assertTrue(networkImpl.deleteResByVimId("vimId") == 1);
+ }
+
+
+ @Test
+ public void testUpdate() throws ServiceException {
+ new MockUp<NetworkDaoImpl>() {
+
+ @Mock
+ public int updateNetworkSelective(NetworkEntity networkEntity) {
+ return 1;
+ }
+ };
+ NetworkImpl networkImpl = new NetworkImpl();
+ NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl();
+ NetworkDao networkDao = new NetworkDaoImpl();
+ networkBusiness.setNetworkDao(networkDao);
+ networkImpl.setNetworkBusiness(networkBusiness);
+
+ JSONObject json = new JSONObject();
+ json.put("id", "");
+ json.put("name", "name");
+ json.put("status", "status");
+ json.put("tenant_id", "tenant_id");
+ json.put("vimId", "vimId");
+ json.put("vimName", "vimName");
+ json.put("provider:physical_network", "provider:physical_network");
+ json.put("provider:network_type", "provider:network_type");
+ json.put("provider:segmentation_id", "provider:segmentation_id");
+ assertTrue(networkImpl.update(json)==1);
+ }
+
+
+
+ @Test
+ public void testUpdateVimById() throws ServiceException {
+ new MockUp<NetworkDaoImpl>() {
+
+ @Mock
+ public int updateNetworkByVimId(NetworkEntity NetworkEntity) {
+ return 1;
+ }
+ };
+ NetworkImpl networkImpl = new NetworkImpl();
+ NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl();
+ NetworkDao networkDao = new NetworkDaoImpl();
+ networkBusiness.setNetworkDao(networkDao);
+ networkImpl.setNetworkBusiness(networkBusiness);
+ JSONObject json = new JSONObject();
+ json.put("id", "");
+ json.put("name", "name");
+ json.put("status", "status");
+ json.put("tenant_id", "tenant_id");
+ json.put("vimId", "vimId");
+ json.put("vimName", "vimName");
+ json.put("provider:physical_network", "provider:physical_network");
+ json.put("provider:network_type", "provider:network_type");
+ json.put("provider:segmentation_id", "provider:segmentation_id");
+ assertTrue(networkImpl.updateStatusByVimId(json)==1);
+
+ }
+
+ @Test
+ public void testgetList() throws ServiceException {
+ Map<String, Object> condition = new HashMap<>();
+ NetworkImpl networkImpl = new NetworkImpl();
+ networkImpl.setNetworkBusiness(new NetworkBusinessImpl());
+ new MockUp<NetworkBusinessImpl>() {
+
+ @Mock
+ public List<NetworkEntity> getNetworks(Map<String, Object> condition) {
+ return null;
+ }
+ };
+ List<NetworkEntity> result = networkImpl.getList(condition);
+ List<NetworkEntity> exceptedResult = null;
+ assertEquals(exceptedResult, result);
+ }
+ @Test
+ public void testadd() throws ServiceException {
+ NetworkImpl networkImpl = new NetworkImpl();
+ networkImpl.setNetworkBusiness(new NetworkBusinessImpl());
+ NetworkEntity networkEntity =new NetworkEntity();
+ networkEntity.setId("1");
+ new MockUp<NetworkBusinessImpl>() {
+
+ @Mock
+ public int addNetwork(NetworkEntity networkEntity ) {
+ return 1;
+ }
+ };
+ int result = networkImpl.add(networkEntity);
+ int exceptedResult = 1;
+ assertEquals(exceptedResult, result);
+ }
+ }
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/PortImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/PortImplTest.java
new file mode 100644
index 0000000..3d36011
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/PortImplTest.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright 2016-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.openo.nfvo.resmanagement.service.base.openstack.impl;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.common.util.JsonUtil;
+import org.openo.nfvo.resmanagement.service.business.impl.PortBusinessImpl;
+import org.openo.nfvo.resmanagement.service.dao.impl.PortDaoImpl;
+import org.openo.nfvo.resmanagement.service.entity.PortEntity;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+public class PortImplTest {
+
+ @Test
+ public void testAddBranch() throws ServiceException {
+ new MockUp<PortDaoImpl>() {
+
+ @Mock
+ public PortEntity getPort(String id) {
+ return null;
+ }
+
+ @Mock
+ public int addPort(PortEntity portEntity) {
+ return 1;
+ }
+ };
+ PortImpl portImpl = new PortImpl();
+ PortBusinessImpl portBusiness = new PortBusinessImpl();
+ portBusiness.setPortDao(new PortDaoImpl());
+ portImpl.setPortBusiness(portBusiness);
+ JSONObject json = new JSONObject();
+ json.put("id", "");
+ json.put("name", "name");
+ json.put("status", "status");
+ json.put("tenant_id", "tenant_id");
+ json.put("vimId", "vimId");
+ json.put("vimName", "vimName");
+ json.put("network_id", "network_id");
+ assertTrue(portImpl.add(json) == 1);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testAddBranch1() throws ServiceException {
+
+ PortImpl portImpl = new PortImpl();
+ PortBusinessImpl portBusiness = new PortBusinessImpl();
+ portBusiness.setPortDao(new PortDaoImpl());
+ portImpl.setPortBusiness(portBusiness);
+ PortEntity portEntity = null;
+ portImpl.add(portEntity);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testUpdateException() throws ServiceException {
+
+ PortImpl portImpl = new PortImpl();
+ PortBusinessImpl portBusiness = new PortBusinessImpl();
+ portBusiness.setPortDao(new PortDaoImpl());
+ portImpl.setPortBusiness(portBusiness);
+ PortEntity portEntity = null;
+ portImpl.update(portEntity);
+ }
+
+ @Test
+ public void testUpdate() throws ServiceException {
+ new MockUp<PortDaoImpl>() {
+
+ @Mock
+ public int updatePortSelective(PortEntity portEntity) {
+ return 1;
+ }
+
+ };
+ PortImpl portImpl = new PortImpl();
+ PortBusinessImpl portBusiness = new PortBusinessImpl();
+ portBusiness.setPortDao(new PortDaoImpl());
+ portImpl.setPortBusiness(portBusiness);
+ assertTrue(portImpl.update(new JSONObject()) == 1);
+ }
+
+ @Test
+ public void testdelete() throws ServiceException {
+ new MockUp<PortDaoImpl>() {
+
+ @Mock
+ public int deletePort(String id) {
+ return 1;
+ }
+
+ };
+ PortImpl portImpl = new PortImpl();
+ PortBusinessImpl portBusiness = new PortBusinessImpl();
+ portBusiness.setPortDao(new PortDaoImpl());
+ portImpl.setPortBusiness(portBusiness);
+
+ }
+
+ @Test
+ public void testDeleteResByVimId() throws ServiceException {
+ new MockUp<PortDaoImpl>() {
+
+ @Mock
+ public int deletePortByVimId(String vimId) {
+ return 1;
+ }
+
+ };
+ PortImpl portImpl = new PortImpl();
+ PortBusinessImpl portBusiness = new PortBusinessImpl();
+ portBusiness.setPortDao(new PortDaoImpl());
+ portImpl.setPortBusiness(portBusiness);
+ assertTrue(portImpl.deleteResByVimId("vimId") == 1);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testDeleteResByVimIdException() throws ServiceException {
+ PortImpl portImpl = new PortImpl();
+ PortBusinessImpl portBusiness = new PortBusinessImpl();
+ portBusiness.setPortDao(new PortDaoImpl());
+ portImpl.setPortBusiness(portBusiness);
+ portImpl.deleteResByVimId("");
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testDelete() throws ServiceException {
+ PortImpl portImpl = new PortImpl();
+ PortBusinessImpl portBusiness = new PortBusinessImpl();
+ portBusiness.setPortDao(new PortDaoImpl());
+ portImpl.setPortBusiness(portBusiness);
+ portImpl.delete("");
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/SitesImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/SitesImplTest.java
new file mode 100644
index 0000000..5db06a8
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/SitesImplTest.java
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2016-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.openo.nfvo.resmanagement.service.base.openstack.impl;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.service.business.impl.SitesBusinessImpl;
+import org.openo.nfvo.resmanagement.service.entity.SitesEntity;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+public class SitesImplTest {
+
+
+
+ @Test
+ public void testUpdate1() throws ServiceException {
+ SitesImpl sitesImpl = new SitesImpl();
+ sitesImpl.setSitesBusiness(new SitesBusinessImpl());
+ SitesEntity sitesEntity = new SitesEntity();
+ sitesEntity.setId("123");
+ new MockUp<SitesBusinessImpl>() {
+
+ @Mock
+ public int updateSiteSelective(SitesEntity sitesEntity) throws ServiceException {
+ return 1;
+ }
+ };
+ int result = sitesImpl.update(sitesEntity);
+ int exceptedResult = 1;
+ assertEquals(exceptedResult, result);
+ }
+
+ @Test
+ public void testUpdateResource() throws ServiceException {
+ SitesImpl sitesImpl = new SitesImpl();
+ sitesImpl.setSitesBusiness(new SitesBusinessImpl());
+ JSONObject json = new JSONObject();
+ json.put("id", "123");
+ json.put("vimId", "vim123");
+ new MockUp<SitesBusinessImpl>() {
+
+ @Mock
+ public int updateSiteResource(SitesEntity sitesEntity) throws ServiceException {
+ return 1;
+ }
+ };
+ int result = sitesImpl.updateResource(json);
+ int exceptedResult = 1;
+ assertEquals(exceptedResult, result);
+ }
+
+ @Test
+ public void testUpdateStatusByVimId() throws ServiceException {
+ SitesImpl sitesImpl = new SitesImpl();
+ sitesImpl.setSitesBusiness(new SitesBusinessImpl());
+ JSONObject json = new JSONObject();
+ json.put("id", "123");
+ json.put("vimId", "vim123");
+ new MockUp<SitesBusinessImpl>() {
+
+ @Mock
+ public int updateSiteByVimId(SitesEntity sitesEntity) throws ServiceException {
+ return 1;
+ }
+ };
+ int result = sitesImpl.updateStatusByVimId(json);
+ int exceptedResult = 1;
+ assertEquals(exceptedResult, result);
+ }
+
+ @Test
+ public void testGetList() throws ServiceException {
+ Map<String, Object> condition = new HashMap<>();
+ SitesImpl sitesImpl = new SitesImpl();
+ sitesImpl.setSitesBusiness(new SitesBusinessImpl());
+ new MockUp<SitesBusinessImpl>() {
+
+ @Mock
+ public List<SitesEntity> getSites(Map<String, Object> condition) {
+ return null;
+ }
+ };
+ List<SitesEntity> result = sitesImpl.getList(condition);
+ List<SitesEntity> exceptedResult = null;
+ assertEquals(exceptedResult, result);
+ }
+
+ @Test
+ public void testGetNull() throws ServiceException {
+ Map<String, Object> condition = new HashMap<>();
+ SitesImpl sitesImpl = new SitesImpl();
+ sitesImpl.setSitesBusiness(new SitesBusinessImpl());
+ new MockUp<SitesBusinessImpl>() {
+
+ @Mock
+ public List<SitesEntity> getSites(Map<String, Object> condition) {
+ return null;
+ }
+ };
+ SitesEntity result = sitesImpl.get(condition);
+ SitesEntity exceptedResult = null;
+ assertEquals(exceptedResult, result);
+ }
+
+ @Test
+ public void testGet() throws ServiceException {
+ Map<String, Object> condition = new HashMap<>();
+ SitesImpl sitesImpl = new SitesImpl();
+ sitesImpl.setSitesBusiness(new SitesBusinessImpl());
+ new MockUp<SitesBusinessImpl>() {
+
+ @Mock
+ public List<SitesEntity> getSites(Map<String, Object> condition) {
+ List<SitesEntity> list = new ArrayList<SitesEntity>();
+ return list;
+ }
+ };
+ SitesEntity sitesEntity = new SitesEntity();
+ sitesEntity.setId("123");
+ sitesImpl.deleteResByVimId("vimId");
+ SitesEntity result = sitesImpl.get(condition);
+ }
+
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/VimImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/VimImplTest.java
new file mode 100644
index 0000000..b21525c
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/VimImplTest.java
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2016 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.openo.nfvo.resmanagement.service.base.openstack.impl;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.service.base.openstack.impl.VimImpl;
+import org.openo.nfvo.resmanagement.service.business.impl.VimBusinessImpl;
+import org.openo.nfvo.resmanagement.service.entity.VimEntity;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+public class VimImplTest {
+
+ @Test
+ public void testAdd() throws ServiceException {
+ VimImpl vimImpl = new VimImpl();
+ vimImpl.setVimBusiness(new VimBusinessImpl());
+ new MockUp<VimBusinessImpl>() {
+
+ @Mock
+ public int addVim(String id) throws ServiceException {
+ return 1;
+ }
+ };
+ int result = vimImpl.add("id");
+ int exceptedResult = 1;
+ assertEquals(exceptedResult, result);
+ }
+
+ @Test
+ public void testAdd1() throws ServiceException {
+ VimImpl vimImpl = new VimImpl();
+ vimImpl.setVimBusiness(new VimBusinessImpl());
+ JSONObject json = new JSONObject();
+ json.put("id", "123");
+ new MockUp<VimBusinessImpl>() {
+
+ @Mock
+ public int addVim(String id) throws ServiceException {
+ return 1;
+ }
+ };
+ int result = vimImpl.add(json);
+ int exceptedResult = 1;
+ assertEquals(exceptedResult, result);
+ }
+
+ @Test
+ public void testUpdate() throws ServiceException {
+ VimImpl vimImpl = new VimImpl();
+ vimImpl.setVimBusiness(new VimBusinessImpl());
+ JSONObject json = new JSONObject();
+ json.put("id", "123");
+ json.put("vimId", "vim123");
+ int result = vimImpl.update(json);
+ int exceptedResult = 0;
+ assertEquals(exceptedResult, result);
+ }
+
+ @Test
+ public void testDelete() throws ServiceException {
+ VimImpl vimImpl = new VimImpl();
+ vimImpl.setVimBusiness(new VimBusinessImpl());
+ new MockUp<VimBusinessImpl>() {
+
+ @Mock
+ public int deleteVim(String id) throws ServiceException {
+ return 1;
+ }
+ };
+ int result = vimImpl.delete("id");
+ int exceptedResult = 1;
+ assertEquals(exceptedResult, result);
+ }
+
+ @Test
+ public void testGetVim() throws ServiceException {
+ VimImpl vimImpl = new VimImpl();
+ vimImpl.setVimBusiness(new VimBusinessImpl());
+ new MockUp<VimBusinessImpl>() {
+
+ @Mock
+ public VimEntity getVim(String id) {
+ return null;
+ }
+ };
+ VimEntity result = vimImpl.getVim("id");
+ VimEntity exceptedResult = null;
+ assertEquals(exceptedResult, result);
+ }
+
+ @Test
+ public void testGetList() throws ServiceException {
+ VimImpl vimImpl = new VimImpl();
+ vimImpl.setVimBusiness(new VimBusinessImpl());
+ new MockUp<VimBusinessImpl>() {
+
+ @Mock
+ public List<VimEntity> getVims() {
+ return null;
+ }
+ };
+ List<VimEntity> result = vimImpl.getList();
+ List<VimEntity> exceptedResult = null;
+ assertEquals(exceptedResult, result);
+ }
+
+ @Test
+ public void testSetVimBusiness() throws ServiceException {
+ VimImpl vimImpl = new VimImpl();
+ vimImpl.setVimBusiness(new VimBusinessImpl());
+ }
+
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/HostBusinessImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/HostBusinessImplTest.java
new file mode 100644
index 0000000..1a1d142
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/HostBusinessImplTest.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2016-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.openo.nfvo.resmanagement.service.business.impl;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.service.dao.impl.HostDaoImpl;
+import org.openo.nfvo.resmanagement.service.entity.HostEntity;
+
+import mockit.Mock;
+import mockit.MockUp;
+
+public class HostBusinessImplTest {
+
+ @Test
+ public void testGetHost() {
+ HostBusinessImpl hostBussinessImp = new HostBusinessImpl();
+ assertTrue(hostBussinessImp.getHost("") == null);
+ }
+
+ @Test
+ public void testGetHostBranch() {
+ new MockUp<HostDaoImpl>() {
+
+ @Mock
+ public HostEntity getHost(String id) {
+ return new HostEntity();
+ }
+
+ };
+ HostBusinessImpl hostBussinessImp = new HostBusinessImpl();
+ hostBussinessImp.setHostDao(new HostDaoImpl());
+ assertTrue(hostBussinessImp.getHost("id") != null);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testDelete() throws ServiceException {
+ HostBusinessImpl hostBussinessImp = new HostBusinessImpl();
+ hostBussinessImp.deleteHost("");
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testUpdateHost() throws ServiceException {
+ HostBusinessImpl hostBussinessImp = new HostBusinessImpl();
+ hostBussinessImp.updateHost(null);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testDeleteHostByVimId() throws ServiceException {
+ HostBusinessImpl hostBussinessImp = new HostBusinessImpl();
+ hostBussinessImp.deleteHostByVimId("");
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testUpdateHostByVimId() throws ServiceException {
+ HostBusinessImpl hostBussinessImp = new HostBusinessImpl();
+ hostBussinessImp.updateHostByVimId(null);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testAddHost() throws ServiceException {
+ HostBusinessImpl hostBussinessImp = new HostBusinessImpl();
+ hostBussinessImp.addHost(null);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testAddHostSelective() throws ServiceException {
+ HostBusinessImpl hostBussinessImp = new HostBusinessImpl();
+ hostBussinessImp.addHostSelective(null);
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/LimitsBusinessImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/LimitsBusinessImplTest.java
new file mode 100644
index 0000000..32ec28a
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/LimitsBusinessImplTest.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2016-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.openo.nfvo.resmanagement.service.business.impl;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.baseservice.roa.util.restclient.HttpRest;
+import org.openo.baseservice.roa.util.restclient.RestfulOptions;
+import org.openo.baseservice.roa.util.restclient.RestfulParametes;
+import org.openo.baseservice.roa.util.restclient.RestfulResponse;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+public class LimitsBusinessImplTest {
+
+ private LimitsBusinessImpl limitsBusinessImpl;
+
+ @Before
+ public void setUp() throws ServiceException {
+ limitsBusinessImpl = new LimitsBusinessImpl();
+ }
+
+ @Test
+ public void testGetCpuLimits() throws ServiceException {
+ new MockUp<HttpRest>() {
+
+ @Mock
+ public RestfulResponse get(String servicePath, RestfulParametes restParametes, RestfulOptions option)
+ throws ServiceException {
+ RestfulResponse rsp = new RestfulResponse();
+ rsp.setStatus(200);
+ return rsp;
+ }
+ };
+ JSONObject paramJson = new JSONObject();
+ paramJson.put("vimId", "vimId");
+ paramJson.put("tenantId", "tenantId");
+ }
+
+ @Test
+ public void testgetLimits() throws ServiceException {
+ new MockUp<HttpRest>() {
+
+ @Mock
+ public RestfulResponse get(String servicePath, RestfulParametes restParametes, RestfulOptions option)
+ throws ServiceException {
+ RestfulResponse rsp = new RestfulResponse();
+ rsp.setStatus(200);
+ return rsp;
+ }
+
+ };
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/LocationBusinessImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/LocationBusinessImplTest.java
new file mode 100644
index 0000000..03f17b3
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/LocationBusinessImplTest.java
@@ -0,0 +1,219 @@
+/*
+ * Copyright 2016 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.openo.nfvo.resmanagement.service.business.impl;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.service.dao.impl.LocationDaoImpl;
+import org.openo.nfvo.resmanagement.service.entity.LocationEntity;
+
+import mockit.Mock;
+import mockit.MockUp;
+
+public class LocationBusinessImplTest {
+
+ private LocationBusinessImpl locationBusinessImpl;
+
+ @Before
+ public void setUp() throws ServiceException {
+ locationBusinessImpl = new LocationBusinessImpl();
+ locationBusinessImpl.setLocationDao(new LocationDaoImpl());
+ }
+
+ @Test
+ public void testGet() throws ServiceException {
+ new MockUp<LocationDaoImpl>() {
+
+ @Mock
+ public LocationEntity getLocation(String id) {
+ LocationEntity localEntity = new LocationEntity();
+ localEntity.setCountry("country");
+ localEntity.setLocation("location");
+
+ return localEntity;
+ }
+ };
+ assertTrue(locationBusinessImpl.getLocation("id") != null);
+ }
+
+ @Test
+ public void testGetBranch() throws ServiceException {
+
+ assertTrue(locationBusinessImpl.getLocation("") == null);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testAddLocationSelectiveExceptio() throws ServiceException {
+ locationBusinessImpl.addLocationSelective(null);
+ }
+
+ @Test
+ public void testAddLocationSelective() throws ServiceException {
+ new MockUp<LocationDaoImpl>() {
+
+ @Mock
+ public int addLocationSelective(LocationEntity locationEntity) {
+ return 1;
+ }
+ };
+ LocationEntity locationEntity = new LocationEntity();
+ locationEntity.setCountry("country");
+ locationEntity.setDescription("description");
+ locationEntity.setId("id");
+ locationEntity.setLatitude("1");
+ locationEntity.setLongitude("12");
+ locationEntity.setLocation("location");
+ locationBusinessImpl.addLocationSelective(locationEntity);
+ }
+
+ @Test
+ public void testAddLocationSelectiveBranch() throws ServiceException {
+ new MockUp<LocationDaoImpl>() {
+
+ @Mock
+ public int addLocationSelective(LocationEntity locationEntity) {
+ return 1;
+ }
+ };
+ LocationEntity locationEntity = new LocationEntity();
+ locationEntity.setCountry("country");
+ locationEntity.setDescription("description");
+ locationEntity.setId("");
+ locationEntity.setLatitude("1");
+ locationEntity.setLongitude("12");
+ locationEntity.setLocation("location");
+ locationBusinessImpl.addLocationSelective(locationEntity);
+ }
+
+ @Test
+ public void testAddLocationSelectiveBranch1() throws ServiceException {
+ new MockUp<LocationDaoImpl>() {
+
+ @Mock
+ public int addLocationSelective(LocationEntity locationEntity) {
+ return 1;
+ }
+ };
+ LocationEntity locationEntity = new LocationEntity();
+ locationEntity.setCountry("country");
+ locationEntity.setDescription("description");
+ locationEntity.setId(null);
+ locationEntity.setLatitude("1");
+ locationEntity.setLongitude("12");
+ locationEntity.setLocation("location");
+ locationBusinessImpl.addLocationSelective(locationEntity);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testAddLocationSelectiveException1() throws ServiceException {
+ LocationEntity locationEntity = new LocationEntity();
+ locationEntity.setCountry("");
+ locationEntity.setDescription("description");
+ locationEntity.setId("id");
+ locationEntity.setLatitude("1");
+ locationEntity.setLongitude("12");
+ locationEntity.setLocation("location");
+ locationBusinessImpl.addLocationSelective(locationEntity);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testAddLocationSelectiveException2() throws ServiceException {
+ LocationEntity locationEntity = new LocationEntity();
+ locationEntity.setCountry("country");
+ locationEntity.setDescription("description");
+ locationEntity.setId("id");
+ locationEntity.setLatitude("1");
+ locationEntity.setLongitude("12");
+ locationEntity.setLocation("");
+ locationBusinessImpl.addLocationSelective(locationEntity);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testAddLocationSelectiveException3() throws ServiceException {
+ LocationEntity locationEntity = new LocationEntity();
+ locationEntity.setCountry("country");
+ locationEntity.setDescription("description");
+ locationEntity.setId("id");
+ locationEntity.setLatitude("");
+ locationEntity.setLongitude("12");
+ locationEntity.setLocation("location");
+ locationBusinessImpl.addLocationSelective(locationEntity);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testAddLocationSelectiveException4() throws ServiceException {
+ LocationEntity locationEntity = new LocationEntity();
+ locationEntity.setCountry("country");
+ locationEntity.setDescription("description");
+ locationEntity.setId("id");
+ locationEntity.setLatitude("1");
+ locationEntity.setLongitude("");
+ locationEntity.setLocation("location");
+ locationBusinessImpl.addLocationSelective(locationEntity);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testUpdateLocationSelective() throws ServiceException {
+ locationBusinessImpl.updateLocationSelective(null);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testAddLocation() throws ServiceException {
+ locationBusinessImpl.addLocation(null);
+ }
+
+ @Test
+ public void testUpdateLocation() throws ServiceException {
+ new MockUp<LocationDaoImpl>() {
+
+ @Mock
+ public int updateLocation(LocationEntity locationEntity) {
+ return 1;
+ }
+ };
+ locationBusinessImpl.getLocationDao();
+ LocationEntity locationEntity = new LocationEntity();
+ locationEntity.setLatitude("1");
+ locationEntity.setLongitude("2");
+ locationBusinessImpl.updateLocation(locationEntity);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testUpdateLocationException() throws ServiceException {
+ new MockUp<LocationDaoImpl>() {
+
+ @Mock
+ public int updateLocation(LocationEntity locationEntity) {
+ return 1;
+ }
+ };
+ locationBusinessImpl.getLocationDao();
+ LocationEntity locationEntity = new LocationEntity();
+ locationEntity.setLatitude("100");
+ locationEntity.setLongitude("2");
+ locationBusinessImpl.updateLocation(locationEntity);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testUpdateLocationException1() throws ServiceException {
+ locationBusinessImpl.getLocationDao();
+ locationBusinessImpl.updateLocation(null);
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/SitesBusinessImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/SitesBusinessImplTest.java
new file mode 100644
index 0000000..94a0dad
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/SitesBusinessImplTest.java
@@ -0,0 +1,408 @@
+/*
+ * Copyright 2016-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.openo.nfvo.resmanagement.service.business.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.service.dao.impl.SitesDaoImpl;
+import org.openo.nfvo.resmanagement.service.entity.SitesEntity;
+
+import mockit.Mock;
+import mockit.MockUp;
+
+/**
+ * <br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 2016年8月16日
+ */
+public class SitesBusinessImplTest {
+
+ private SitesBusinessImpl sitesBusinessImpl;
+
+ @Before
+ public void setUp() {
+ sitesBusinessImpl = new SitesBusinessImpl();
+ sitesBusinessImpl.setSitesDao(new SitesDaoImpl());
+ }
+
+ @Test
+ public void testGetSitesIdIsNull() throws ServiceException {
+ try {
+ sitesBusinessImpl.getSite(null);
+ } catch(ServiceException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testGetSite() throws ServiceException {
+ SitesEntity sitesEntity = new SitesEntity();
+ sitesEntity.setId("123");
+ new MockUp<SitesDaoImpl>() {
+
+ @Mock
+ public SitesEntity getSite(String id) {
+ SitesEntity sitesEntity = new SitesEntity();
+ sitesEntity.setId("123");
+ return sitesEntity;
+ }
+ };
+ SitesEntity result = sitesBusinessImpl.getSite("id");
+ SitesEntity expectedResult = sitesEntity;
+ assertEquals(expectedResult.toString(), result.toString());
+ }
+
+ @Test
+ public void testGetSites() throws ServiceException {
+ Map<String, Object> condition = new HashMap<String, Object>();
+ SitesBusinessImpl sitesBusinessImpl = new SitesBusinessImpl();
+ sitesBusinessImpl.setSitesDao(new SitesDaoImpl());
+ new MockUp<SitesDaoImpl>() {
+
+ @Mock
+ public List<SitesEntity> getSites(Map<String, Object> condition) {
+ return null;
+ }
+ };
+ List<SitesEntity> result = sitesBusinessImpl.getSites(condition);
+ assertNull(result);
+ }
+
+ @Test
+ public void testDeleteSiteEmpty() throws ServiceException {
+ SitesBusinessImpl sitesBusinessImpl = new SitesBusinessImpl();
+ sitesBusinessImpl.setSitesDao(new SitesDaoImpl());
+ try {
+ sitesBusinessImpl.deleteSite("");
+ } catch(ServiceException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testDeleteSite() throws ServiceException {
+ new MockUp<SitesDaoImpl>() {
+
+ @Mock
+ public SitesEntity getSite(String id) {
+ return null;
+ }
+
+ @Mock
+ public int deleteSite(String id) {
+ return 1;
+ }
+ };
+ int result = sitesBusinessImpl.deleteSite("007");
+ int expectedResult = 1;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testAddSiteSitesEntityIsNull() throws ServiceException {
+ try {
+ sitesBusinessImpl.addSite(null);
+ } catch(ServiceException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testCheckSiteExceptions() throws ServiceException {
+ SitesEntity sitesEntity = new SitesEntity();
+ sitesEntity.setCountry("country");
+ sitesEntity.setId("id");
+ sitesEntity.setLocation("location");
+ sitesEntity.setName("name");
+ sitesEntity.setStatus("siteStatus");
+ sitesEntity.setTotalCPU("12");
+ sitesEntity.setTotalDisk("12");
+ sitesEntity.setTotalMemory("134");
+ sitesEntity.setUsedCPU("12");
+ sitesEntity.setUsedDisk("23");
+ sitesEntity.setUsedMemory("10");
+ sitesEntity.setVimId("siteVimId");
+ sitesEntity.setVimName("siteVimName");
+ new MockUp<SitesDaoImpl>() {
+
+ int count1 = 0;
+
+ @Mock
+ public SitesEntity getSite(String id) {
+ return null;
+ }
+
+ @Mock
+ public List<SitesEntity> getSites(Map<String, Object> condition) {
+ if(count1 == 0) {
+ count1 += 1;
+ return null;
+ }
+ return new ArrayList<SitesEntity>();
+
+ }
+ };
+ new MockUp<SitesEntity>() {
+
+ @Mock
+ public boolean checkResource(SitesEntity siteEntity) {
+ return false;
+ }
+ };
+ try {
+ sitesBusinessImpl.addSite(sitesEntity);
+ } catch(ServiceException se) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testCheckSiteExceptions1() throws ServiceException {
+ SitesEntity sitesEntity = new SitesEntity();
+ sitesEntity.setCountry("country");
+ sitesEntity.setId("id");
+ sitesEntity.setLocation("location");
+ sitesEntity.setName("name");
+ sitesEntity.setStatus("siteStatus");
+ sitesEntity.setTotalCPU("12");
+ sitesEntity.setTotalDisk("12");
+ sitesEntity.setTotalMemory("134");
+ sitesEntity.setUsedCPU("12");
+ sitesEntity.setUsedDisk("23");
+ sitesEntity.setUsedMemory("10");
+ sitesEntity.setVimId("siteVimId");
+ sitesEntity.setVimName("siteVimName");
+ new MockUp<SitesDaoImpl>() {
+
+ int count1 = 0;
+
+ @Mock
+ public SitesEntity getSite(String id) {
+ return null;
+ }
+
+ @Mock
+ public List<SitesEntity> getSites(Map<String, Object> condition) {
+
+ return null;
+
+ }
+ };
+ new MockUp<SitesEntity>() {
+
+ @Mock
+ public boolean checkResource(SitesEntity siteEntity) {
+ return false;
+ }
+ };
+ try {
+ sitesBusinessImpl.addSite(sitesEntity);
+ } catch(ServiceException se) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testCheckSiteExceptions2() throws ServiceException {
+ SitesEntity sitesEntity = new SitesEntity();
+ sitesEntity.setCountry("");
+ sitesEntity.setId("id");
+ sitesEntity.setLocation("");
+ sitesEntity.setName("");
+ sitesEntity.setStatus("siteStatus");
+ sitesEntity.setTotalCPU("12");
+ sitesEntity.setTotalDisk("12");
+ sitesEntity.setTotalMemory("134");
+ sitesEntity.setUsedCPU("12");
+ sitesEntity.setUsedDisk("23");
+ sitesEntity.setUsedMemory("10");
+ sitesEntity.setVimId("siteVimId");
+ sitesEntity.setVimName("siteVimName");
+ new MockUp<SitesDaoImpl>() {
+
+ int count1 = 0;
+
+ @Mock
+ public SitesEntity getSite(String id) {
+ return null;
+ }
+
+ @Mock
+ public List<SitesEntity> getSites(Map<String, Object> condition) {
+
+ return null;
+
+ }
+ };
+ new MockUp<SitesEntity>() {
+
+ @Mock
+ public boolean checkResource(SitesEntity siteEntity) {
+ return false;
+ }
+ };
+ try {
+ sitesBusinessImpl.addSite(sitesEntity);
+ } catch(ServiceException se) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testCheckSiteNameExceptions() throws ServiceException {
+ SitesEntity sitesEntity = new SitesEntity();
+ sitesEntity.setId("123");
+ sitesEntity.setCountry("china");
+ sitesEntity.setName("openstack");
+ sitesEntity.setLocation("xian");
+ new MockUp<SitesDaoImpl>() {
+
+ @Mock
+ public SitesEntity getSite(String id) {
+ return null;
+ }
+
+ @Mock
+ public List<SitesEntity> getSites(Map<String, Object> condition) {
+ List<SitesEntity> list = new ArrayList<SitesEntity>();
+ list.add(new SitesEntity());
+ return list;
+
+ }
+ };
+ try {
+ sitesBusinessImpl.addSite(sitesEntity);
+ } catch(ServiceException se) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testCheckIdExceptions() throws ServiceException {
+ SitesEntity sitesEntity = new SitesEntity();
+ sitesEntity.setId("123");
+ sitesEntity.setCountry("china");
+ sitesEntity.setName("openstack");
+ sitesEntity.setLocation("xian");
+ new MockUp<SitesDaoImpl>() {
+
+ @Mock
+ public SitesEntity getSite(String id) {
+ return new SitesEntity();
+ }
+ };
+ try {
+ sitesBusinessImpl.addSite(sitesEntity);
+ } catch(ServiceException se) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testAddSiteSelectiveSitesEntityIsNull() throws ServiceException {
+ try {
+ sitesBusinessImpl.addSiteSelective(null);
+ } catch(ServiceException se) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testUpdateSiteSelectiveSitesEntityIsNull() throws ServiceException {
+ try {
+ sitesBusinessImpl.updateSiteSelective(null);
+ } catch(ServiceException se) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testUpdateSiteSitesEntityIsNull() throws ServiceException {
+ try {
+ sitesBusinessImpl.updateSite(null);
+ } catch(ServiceException se) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testUpdateSiteByVimIdSitesEntityIsNull() throws ServiceException {
+ try {
+ sitesBusinessImpl.updateSiteByVimId(null);
+ } catch(ServiceException se) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testUpdateSiteByVimId() throws ServiceException {
+ SitesEntity sitesEntity = new SitesEntity();
+ sitesEntity.setCountry("china");
+ sitesEntity.setName("openstack");
+ sitesEntity.setLocation("xian");
+ new MockUp<SitesDaoImpl>() {
+
+ @Mock
+ public int updateSiteByVimId(SitesEntity sitesEntity) {
+ return 1;
+ }
+ };
+ int result = sitesBusinessImpl.updateSiteByVimId(sitesEntity);
+ int expectedResult = 1;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testUpdateSiteResourceSitesEntityIsNull() throws ServiceException {
+ try {
+ sitesBusinessImpl.updateSiteResource(null);
+ } catch(ServiceException se) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testUpdateSiteResource() throws ServiceException {
+ SitesEntity sitesEntity = new SitesEntity();
+ sitesEntity.setCountry("china");
+ sitesEntity.setName("openstack");
+ sitesEntity.setLocation("xian");
+ new MockUp<SitesDaoImpl>() {
+
+ @Mock
+ public int updateSiteSelective(SitesEntity sitesEntity) {
+ return 1;
+ }
+ };
+ int result = sitesBusinessImpl.updateSiteResource(sitesEntity);
+ int expectedResult = 1;
+ assertEquals(expectedResult, result);
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/VimBusinessImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/VimBusinessImplTest.java
new file mode 100644
index 0000000..1e35569
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/VimBusinessImplTest.java
@@ -0,0 +1,177 @@
+/*
+ * Copyright 2016 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.openo.nfvo.resmanagement.service.business.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.service.dao.impl.VimDaoImpl;
+import org.openo.nfvo.resmanagement.service.entity.VimEntity;
+
+import mockit.Mock;
+import mockit.MockUp;
+
+/**
+ * <br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 2016年8月18日
+ */
+public class VimBusinessImplTest {
+
+ @Test
+ public void testGetVimIdIsNull() {
+ VimBusinessImpl vimBusinessImpl = new VimBusinessImpl();
+ vimBusinessImpl.setVimDao(new VimDaoImpl());
+ VimEntity result = vimBusinessImpl.getVim(null);
+ VimEntity expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testGetVim() {
+ VimBusinessImpl vimBusinessImpl = new VimBusinessImpl();
+ vimBusinessImpl.setVimDao(new VimDaoImpl());
+ VimEntity vimEntity = new VimEntity();
+ vimEntity.setId("123");
+ new MockUp<VimDaoImpl>() {
+
+ @Mock
+ public VimEntity getVim(String id) {
+ VimEntity vimEntity = new VimEntity();
+ vimEntity.setId("123");
+ return vimEntity;
+ }
+ };
+ VimEntity result = vimBusinessImpl.getVim("id");
+ VimEntity expectedResult = vimEntity;
+ assertEquals(expectedResult.toString(), result.toString());
+ }
+
+ @Test
+ public void testGetVims() throws ServiceException {
+ VimBusinessImpl vimBusinessImpl = new VimBusinessImpl();
+ vimBusinessImpl.setVimDao(new VimDaoImpl());
+ new MockUp<VimDaoImpl>() {
+
+ @Mock
+ public List<VimEntity> getVims() {
+ return null;
+ }
+ };
+ List<VimEntity> result = vimBusinessImpl.getVims();
+ List<VimEntity> expectedResult = null;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testDeleteVimEmpty() throws ServiceException {
+ VimBusinessImpl vimBusinessImpl = new VimBusinessImpl();
+ vimBusinessImpl.setVimDao(new VimDaoImpl());
+ try {
+ vimBusinessImpl.deleteVim("");
+ } catch (ServiceException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testDeleteVim() throws ServiceException {
+ VimBusinessImpl vimBusinessImpl = new VimBusinessImpl();
+ vimBusinessImpl.setVimDao(new VimDaoImpl());
+ new MockUp<VimDaoImpl>() {
+
+ @Mock
+ public int deleteVim(String id) {
+ return 1;
+ }
+ };
+ int result = vimBusinessImpl.deleteVim("xian");
+ int expectedResult = 1;
+ assertEquals(expectedResult, result);
+ }
+
+ @Test
+ public void testAddVimExceptions() throws ServiceException {
+ VimBusinessImpl vimBusinessImpl = new VimBusinessImpl();
+ vimBusinessImpl.setVimDao(new VimDaoImpl());
+ try {
+ vimBusinessImpl.addVim(null);
+ } catch (ServiceException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testAddVimExceptions1() throws ServiceException {
+ VimBusinessImpl vimBusinessImpl = new VimBusinessImpl();
+ vimBusinessImpl.setVimDao(new VimDaoImpl());
+ new MockUp<VimDaoImpl>() {
+
+ @Mock
+ public VimEntity getVim(String id) {
+ return new VimEntity();
+ }
+ };
+ try {
+ vimBusinessImpl.addVim("id");
+ } catch (ServiceException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testAddVimExceptions2() throws ServiceException {
+ VimBusinessImpl vimBusinessImpl = new VimBusinessImpl();
+ vimBusinessImpl.setVimDao(new VimDaoImpl());
+ VimEntity vimEntity = new VimEntity();
+ vimEntity.setId("123");
+ try {
+ vimBusinessImpl.addVim("");
+ } catch (ServiceException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testAddVim() throws ServiceException {
+ VimBusinessImpl vimBusinessImpl = new VimBusinessImpl();
+ vimBusinessImpl.setVimDao(new VimDaoImpl());
+ new MockUp<VimDaoImpl>() {
+
+ @Mock
+ public VimEntity getVim(String id) {
+ return null;
+ }
+
+ @Mock
+ public int addVim(VimEntity vimEntity) {
+ return 1;
+ }
+ };
+ int result = vimBusinessImpl.addVim("123");
+ int expectedResult = 1;
+ assertEquals(expectedResult, result);
+ }
+
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/HostDaoImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/HostDaoImplTest.java
new file mode 100644
index 0000000..65e7b97
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/HostDaoImplTest.java
@@ -0,0 +1,155 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.dao.impl;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.service.entity.HostEntity;
+import org.openo.nfvo.resmanagement.service.entity.NetworkEntity;
+import org.openo.nfvo.resmanagement.service.mapper.HostMapper;
+import org.openo.nfvo.resmanagement.service.mapper.NetworkMapper;
+
+import mockit.Expectations;
+import mockit.Mock;
+import mockit.MockUp;
+import mockit.Mocked;
+
+public class HostDaoImplTest {
+ @Mocked
+ HostMapper mapper;
+ @Test
+ public void testdeleteHost() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ HostDaoImpl impl = new HostDaoImpl();
+ assertEquals(0, impl.deleteHost("123"));
+ }
+
+ @Test
+ public void testdeleteHostByVimId() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ HostDaoImpl impl = new HostDaoImpl();
+ assertEquals(0, impl.deleteHostByVimId("123"));
+ }
+
+ @Test
+ public void testaddHost() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ HostDaoImpl impl = new HostDaoImpl();
+ HostEntity hostEntity =new HostEntity();
+ hostEntity.setId("1");
+ assertEquals(0, impl.addHost(hostEntity));
+
+ }
+
+ @Test
+ public void testaddHostSelective() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ HostDaoImpl impl = new HostDaoImpl();
+ HostEntity hostEntity =new HostEntity();
+ hostEntity.setId("1");
+ assertEquals(0, impl.addHostSelective(hostEntity));
+
+ }
+
+ @Test
+ public void testupdateHostSelective() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ HostDaoImpl impl = new HostDaoImpl();
+ HostEntity hostEntity =new HostEntity();
+ hostEntity.setId("1");
+ assertEquals(0, impl.updateHostSelective(hostEntity));
+
+ }
+
+ @Test
+ public void testupdateHost() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ HostDaoImpl impl = new HostDaoImpl();
+ HostEntity hostEntity =new HostEntity();
+ hostEntity.setId("1");
+ assertEquals(0, impl.updateHost(hostEntity));
+
+ }
+
+ @Test
+ public void testupdateHostByVimId() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ HostDaoImpl impl = new HostDaoImpl();
+ HostEntity hostEntity =new HostEntity();
+ hostEntity.setId("1");
+ assertEquals(0, impl.updateHostByVimId(hostEntity));
+
+ }
+
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/LocationDaoImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/LocationDaoImplTest.java
new file mode 100644
index 0000000..fa56c24
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/LocationDaoImplTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.dao.impl;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.service.entity.LocationEntity;
+import org.openo.nfvo.resmanagement.service.entity.NetworkEntity;
+import org.openo.nfvo.resmanagement.service.mapper.LocationMapper;
+
+import mockit.Mock;
+import mockit.MockUp;
+
+public class LocationDaoImplTest {
+ LocationMapper mapper;
+ @Test
+ public void testaddHost() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ LocationDaoImpl impl = new LocationDaoImpl();
+ LocationEntity locationEntity =new LocationEntity();
+ locationEntity.setId("locationEntity");
+
+
+ }
+
+ @Test
+ public void testaddLocationSelective() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ LocationDaoImpl impl = new LocationDaoImpl();
+ LocationEntity locationEntity =new LocationEntity();
+ locationEntity.setId("1");
+
+
+ }
+
+ @Test
+ public void testupdateNetwork() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ NetworkDaoImpl impl = new NetworkDaoImpl();
+ NetworkEntity networkEntity =new NetworkEntity();
+ networkEntity.setId("1");
+
+ }
+
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/NetworkDaoImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/NetworkDaoImplTest.java
new file mode 100644
index 0000000..d0fd3fe
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/NetworkDaoImplTest.java
@@ -0,0 +1,152 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.dao.impl;
+
+import static org.junit.Assert.*;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.service.entity.NetworkEntity;
+import org.openo.nfvo.resmanagement.service.mapper.NetworkMapper;
+import mockit.Expectations;
+import mockit.Mock;
+import mockit.MockUp;
+import mockit.Mocked;
+
+public class NetworkDaoImplTest {
+ @Mocked
+ NetworkMapper mapper;
+ @Test
+ public void testdeleteNetwork() throws ServiceException {
+
+ new Expectations() {{
+ mapper.deleteNetwork("123");
+ }};
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ NetworkDaoImpl impl = new NetworkDaoImpl();
+ assertEquals(0, impl.deleteNetwork("123"));
+
+ }
+ @Test
+ public void testdeleteNetworkByVimId() throws ServiceException {
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ NetworkDaoImpl impl = new NetworkDaoImpl();
+ assertEquals(0, impl.deleteNetworkByVimId("123"));
+
+ }
+ @Test
+ public void testaddNetwork() throws ServiceException {
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ NetworkDaoImpl impl = new NetworkDaoImpl();
+ NetworkEntity networkEntity =new NetworkEntity();
+ networkEntity.setId("1");
+ assertEquals(0, impl.addNetwork(networkEntity));
+
+ }
+
+ @Test
+ public void testaddNetworkSelective() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ NetworkDaoImpl impl = new NetworkDaoImpl();
+ NetworkEntity networkEntity =new NetworkEntity();
+ networkEntity.setId("1");
+ assertEquals(0, impl.addNetworkSelective(networkEntity));
+ }
+ @Test
+ public void testupdateNetworkSelective() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ NetworkDaoImpl impl = new NetworkDaoImpl();
+ NetworkEntity networkEntity =new NetworkEntity();
+ networkEntity.setId("1");
+ assertEquals(0, impl.updateNetworkSelective(networkEntity));
+ }
+ @Test
+ public void testupdateNetwork() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ NetworkDaoImpl impl = new NetworkDaoImpl();
+ NetworkEntity networkEntity =new NetworkEntity();
+ networkEntity.setId("1");
+ assertEquals(0, impl.updateNetwork(networkEntity));
+
+ }
+ @Test
+ public void testupdateNetworkByVimId() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ NetworkDaoImpl impl = new NetworkDaoImpl();
+ NetworkEntity networkEntity =new NetworkEntity();
+ networkEntity.setId("1");
+ assertEquals(0, impl.updateNetworkByVimId(networkEntity));
+
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/PortDaoImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/PortDaoImplTest.java
new file mode 100644
index 0000000..4edcdf3
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/PortDaoImplTest.java
@@ -0,0 +1,158 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.dao.impl;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.service.entity.HostEntity;
+import org.openo.nfvo.resmanagement.service.entity.NetworkEntity;
+import org.openo.nfvo.resmanagement.service.entity.PortEntity;
+import org.openo.nfvo.resmanagement.service.mapper.NetworkMapper;
+import org.openo.nfvo.resmanagement.service.mapper.PortMapper;
+
+import mockit.Expectations;
+import mockit.Mock;
+import mockit.MockUp;
+import mockit.Mocked;
+
+public class PortDaoImplTest {
+ @Mocked
+ PortMapper mapper;
+
+
+ @Test
+ public void testdeletePort() throws ServiceException {
+
+ new Expectations() {{
+ mapper.deletePort("123");
+ }};
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ PortDaoImpl impl = new PortDaoImpl();
+ assertEquals(0, impl.deletePort("123"));
+
+
+ }
+ @Test
+ public void testdeletePortByVimId() throws ServiceException {
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ PortDaoImpl impl = new PortDaoImpl();
+ assertEquals(0, impl.deletePortByVimId("123"));
+
+ }
+
+ @Test
+ public void testaddPort() throws ServiceException {
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ PortDaoImpl impl = new PortDaoImpl();
+ PortEntity portEntity =new PortEntity();
+ portEntity.setId("1");
+ assertEquals(0, impl.addPort(portEntity));
+
+ }
+
+ @Test
+ public void testaddPortSelective() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ PortDaoImpl impl = new PortDaoImpl();
+ PortEntity portEntity =new PortEntity();
+ portEntity.setId("1");
+ assertEquals(0, impl.addPortSelective(portEntity));
+
+ }
+
+ @Test
+ public void testupdatePortSelective() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ PortDaoImpl impl = new PortDaoImpl();
+ PortEntity portEntity =new PortEntity();
+ portEntity.setId("1");
+ assertEquals(0, impl.updatePortSelective(portEntity));
+ }
+ @Test
+ public void testupdatePort() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ PortDaoImpl impl = new PortDaoImpl();
+ PortEntity portEntity =new PortEntity();
+ portEntity.setId("1");
+ assertEquals(0, impl.updatePort(portEntity));
+
+ }
+ @Test
+ public void testupdatePortByVimId() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ PortDaoImpl impl = new PortDaoImpl();
+ PortEntity portEntity =new PortEntity();
+ portEntity.setId("1");
+ assertEquals(0, impl.updatePortByVimId(portEntity));
+
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/SitesDaoImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/SitesDaoImplTest.java
new file mode 100644
index 0000000..4deb71e
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/SitesDaoImplTest.java
@@ -0,0 +1,132 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.dao.impl;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.service.entity.NetworkEntity;
+import org.openo.nfvo.resmanagement.service.entity.SitesEntity;
+import org.openo.nfvo.resmanagement.service.mapper.NetworkMapper;
+import org.openo.nfvo.resmanagement.service.mapper.SitesMapper;
+
+import mockit.Expectations;
+import mockit.Mock;
+import mockit.MockUp;
+import mockit.Mocked;
+
+public class SitesDaoImplTest {
+ @Mocked
+ SitesMapper mapper;
+ @Test
+ public void testdeleteSite() throws ServiceException {
+
+ new Expectations() {{
+ mapper.deleteSite("123");
+ }};
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ SitesDaoImpl impl = new SitesDaoImpl();
+ assertEquals(0, impl.deleteSite("123"));
+ }
+ @Test
+ public void testaddSite() throws ServiceException {
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ SitesDaoImpl impl = new SitesDaoImpl();
+ SitesEntity sitesEntity =new SitesEntity();
+ sitesEntity.setId("1");
+ assertEquals(0, impl.addSite(sitesEntity));
+ }
+ @Test
+ public void testaddSiteSelective() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ SitesDaoImpl impl = new SitesDaoImpl();
+ SitesEntity sitesEntity =new SitesEntity();
+ sitesEntity.setId("1");
+ assertEquals(0, impl.addSiteSelective(sitesEntity));
+ }
+ @Test
+ public void testupdateSiteSelective() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ SitesDaoImpl impl = new SitesDaoImpl();
+ SitesEntity sitesEntity =new SitesEntity();
+ sitesEntity.setId("1");
+ assertEquals(0, impl.updateSiteSelective(sitesEntity));
+ }
+ @Test
+ public void testupdateNetwork() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ SitesDaoImpl impl = new SitesDaoImpl();
+ SitesEntity sitesEntity =new SitesEntity();
+ sitesEntity.setId("1");
+ assertEquals(0, impl.updateSite(sitesEntity));
+ }
+ @Test
+ public void testupdateSiteByVimId() throws ServiceException {
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ SitesDaoImpl impl = new SitesDaoImpl();
+ SitesEntity sitesEntity =new SitesEntity();
+ sitesEntity.setId("1");
+ assertEquals(0, impl.updateSiteByVimId(sitesEntity));
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/VimDaoImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/VimDaoImplTest.java
new file mode 100644
index 0000000..736a844
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/VimDaoImplTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.dao.impl;
+
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.service.entity.NetworkEntity;
+import org.openo.nfvo.resmanagement.service.entity.VimEntity;
+import org.openo.nfvo.resmanagement.service.mapper.VimMapper;
+
+import mockit.Expectations;
+import mockit.Mock;
+import mockit.MockUp;
+import mockit.Mocked;
+
+public class VimDaoImplTest {
+
+ @Mocked
+ VimMapper mapper;
+
+
+ @Test
+ public void testdeleteVim() throws ServiceException {
+
+ new Expectations() {{
+ mapper.deleteVim("123");
+ }};
+
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ VimDaoImpl impl = new VimDaoImpl();
+ assertEquals(0, impl.deleteVim("123"));
+
+
+ }
+
+ @Test
+ public void testaddVim() throws ServiceException {
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ VimDaoImpl impl = new VimDaoImpl();
+ VimEntity vimEntity =new VimEntity();
+ vimEntity.setId("1");
+ assertEquals(0, impl.addVim(vimEntity));
+
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/VirtualLinkDaoImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/VirtualLinkDaoImplTest.java
new file mode 100644
index 0000000..c3a3b98
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/VirtualLinkDaoImplTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.dao.impl;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.service.entity.NetworkEntity;
+import org.openo.nfvo.resmanagement.service.entity.VirtualLinkEntity;
+import org.openo.nfvo.resmanagement.service.mapper.SitesMapper;
+import org.openo.nfvo.resmanagement.service.mapper.VirtualLinkMapper;
+
+import mockit.Mock;
+import mockit.MockUp;
+import mockit.Mocked;
+
+public class VirtualLinkDaoImplTest {
+ @Mocked
+ VirtualLinkMapper mapper;
+ @Test
+ public void testdeleteVlById() throws ServiceException {
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ VirtualLinkDaoImpl impl = new VirtualLinkDaoImpl();
+
+ assertEquals(0, impl.deleteVlById("1"));
+
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/VmDaoImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/VmDaoImplTest.java
new file mode 100644
index 0000000..afb9917
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/VmDaoImplTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.dao.impl;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.service.entity.VmEntity;
+import org.openo.nfvo.resmanagement.service.mapper.SitesMapper;
+import org.openo.nfvo.resmanagement.service.mapper.VmMapper;
+
+import mockit.Mock;
+import mockit.MockUp;
+import mockit.Mocked;
+
+public class VmDaoImplTest {
+ @Mocked
+ VmMapper mapper;
+ @Test
+ public void TestaddVm() throws ServiceException {
+ new MockUp<AbstractDao>() {
+
+ @Mock
+ public <T> T getMapperManager(Class<T> type) {
+ return (T) mapper;
+
+ }
+ };
+ VmDaoImpl impl = new VmDaoImpl();
+ VmEntity vmEntity =new VmEntity();
+ vmEntity.setVmId("1");
+ //assertEquals(0, impl.addVm(vmEntity));
+
+ }
+
+
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/HostEntityTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/HostEntityTest.java
new file mode 100644
index 0000000..119d4f2
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/HostEntityTest.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2016 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.openo.nfvo.resmanagement.service.entity;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import net.sf.json.JSONObject;
+
+public class HostEntityTest {
+ private HostEntity hostEntity;
+
+ @Before
+ public void setUp() {
+ hostEntity = new HostEntity();
+ }
+
+ @Test
+ public void testHostEntity() {
+ assertTrue(hostEntity.toString() != null);
+ assertTrue(HostEntity.toEntity(new JSONObject()) != null);
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/LocationEntityTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/LocationEntityTest.java
new file mode 100644
index 0000000..7998905
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/LocationEntityTest.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2016 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.openo.nfvo.resmanagement.service.entity;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import net.sf.json.JSONObject;
+
+public class LocationEntityTest {
+
+ private LocationEntity locationEntity;
+
+ @Before
+ public void setUp() {
+ locationEntity = new LocationEntity();
+ }
+
+ @Test
+ public void testLocationEntity() {
+ locationEntity.setCountry("country");
+ locationEntity.setDescription("description");
+ locationEntity.setLocation("location");
+ locationEntity.setLatitude("latitude");
+ locationEntity.setLongitude("longitude");
+ assertTrue(locationEntity.toString() != null);
+ assertTrue(LocationEntity.toEntity(new JSONObject()) != null);
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/NetworkEntityTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/NetworkEntityTest.java
new file mode 100644
index 0000000..35f1fdc
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/NetworkEntityTest.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2016 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.openo.nfvo.resmanagement.service.entity;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import net.sf.json.JSONObject;
+
+public class NetworkEntityTest {
+
+ private NetworkEntity networkEntity;
+
+ @Before
+ public void setUp() {
+ networkEntity = new NetworkEntity();
+ }
+
+ @Test
+ public void testSetId() {
+ networkEntity.setId("123");
+ networkEntity.setName("name");
+ networkEntity.setNetworkType("networkType");
+ networkEntity.setPhysicalNetwork("physicalNetwork");
+ networkEntity.setSegmentationId("segmentationId");
+ networkEntity.setStatus("networkStatus");
+ networkEntity.setTenantId("tenantId");
+ networkEntity.setVimId("networkVimId");
+ networkEntity.setVimName("networkVimName");
+ assertTrue(networkEntity.toString() != null);
+ assertTrue(NetworkEntity.toEntity(new JSONObject()) != null);
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/PortEntityTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/PortEntityTest.java
new file mode 100644
index 0000000..70fa7ad
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/PortEntityTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2016 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.openo.nfvo.resmanagement.service.entity;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import net.sf.json.JSONObject;
+
+public class PortEntityTest {
+
+ private PortEntity portEntity;
+
+ @Before
+ public void setUp() {
+ portEntity = new PortEntity();
+ }
+
+ @Test
+ public void testPortEntiry() {
+ portEntity.setId("id:");
+ portEntity.setName("name");
+ portEntity.setNetworkId("networkId");
+ portEntity.setTenantId("tenantId");
+ portEntity.setVimId("vimID");
+ portEntity.setVimName("vimName");
+ assertTrue(portEntity.toString() != null);
+ assertTrue(PortEntity.toEntity(new JSONObject()) != null);
+
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/SitesEntityTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/SitesEntityTest.java
new file mode 100644
index 0000000..44d4dce
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/SitesEntityTest.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2016 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.openo.nfvo.resmanagement.service.entity;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import net.sf.json.JSONObject;
+
+public class SitesEntityTest {
+
+ private SitesEntity sitesEntity;
+
+ @Before
+ public void setUp() {
+ sitesEntity = new SitesEntity();
+ }
+
+ @Test
+ public void testSitesEntity() {
+ sitesEntity.setCountry("country");
+ sitesEntity.setId("id");
+ sitesEntity.setLocation("location");
+ sitesEntity.setName("name");
+ sitesEntity.setStatus("siteStatus");
+ sitesEntity.setTotalCPU("12");
+ sitesEntity.setTotalDisk("12");
+ sitesEntity.setTotalMemory("134");
+ sitesEntity.setUsedCPU("12");
+ sitesEntity.setUsedDisk("23");
+ sitesEntity.setUsedMemory("10");
+ sitesEntity.setVimId("siteVimId");
+ sitesEntity.setVimName("siteVimName");
+ assertTrue(sitesEntity.toString() != null);
+ assertTrue(SitesEntity.toEntity(new JSONObject()) != null);
+ SitesEntity.checkResource(sitesEntity);
+ SitesEntity.checkResourceIsZero(sitesEntity);
+ }
+
+ @Test
+ public void testSitesEntityBranch() {
+ sitesEntity.setCountry("country");
+ sitesEntity.setId("id");
+ sitesEntity.setLocation("location");
+ sitesEntity.setName("name");
+ sitesEntity.setStatus("siteStatus");
+ sitesEntity.setTotalCPU("");
+ sitesEntity.setTotalDisk("");
+ sitesEntity.setTotalMemory("");
+ sitesEntity.setUsedCPU("");
+ sitesEntity.setUsedDisk("");
+ sitesEntity.setUsedMemory("");
+ sitesEntity.setVimId("siteVimId");
+ sitesEntity.setVimName("siteVimName");
+ SitesEntity.checkResource(sitesEntity);
+ SitesEntity.checkResourceIsZero(sitesEntity);
+ }
+
+ @Test
+ public void testSitesEntityBranch1() {
+ sitesEntity.setCountry("country");
+ sitesEntity.setId("id");
+ sitesEntity.setLocation("location");
+ sitesEntity.setName("name");
+ sitesEntity.setStatus("siteStatus");
+ sitesEntity.setTotalCPU("s");
+ sitesEntity.setTotalDisk("");
+ sitesEntity.setTotalMemory("s");
+ sitesEntity.setUsedCPU("s");
+ sitesEntity.setUsedDisk("s");
+ sitesEntity.setUsedMemory("s");
+ sitesEntity.setVimId("siteVimId");
+ sitesEntity.setVimName("siteVimName");
+ SitesEntity.checkResource(sitesEntity);
+ }
+
+ @Test
+ public void testSitesEntityBranch2() {
+ sitesEntity.setCountry("country");
+ sitesEntity.setId("id");
+ sitesEntity.setLocation("location");
+ sitesEntity.setName("name");
+ sitesEntity.setStatus("siteStatus");
+ sitesEntity.setTotalCPU("23");
+ sitesEntity.setTotalDisk("");
+ sitesEntity.setTotalMemory("s");
+ sitesEntity.setUsedCPU("1");
+ sitesEntity.setUsedDisk("s");
+ sitesEntity.setUsedMemory("s");
+ sitesEntity.setVimId("siteVimId");
+ sitesEntity.setVimName("siteVimName");
+ SitesEntity.checkResource(sitesEntity);
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/VimEntityTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/VimEntityTest.java
new file mode 100644
index 0000000..a21642d
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/VimEntityTest.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2016 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.openo.nfvo.resmanagement.service.entity;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import net.sf.json.JSONObject;
+
+public class VimEntityTest {
+
+ private VimEntity vimEntity;
+
+ @Before
+ public void setUp() {
+ vimEntity = new VimEntity();
+ }
+
+ @Test
+ public void testSitesEntity() {
+ vimEntity.setId("id");
+ vimEntity.setName("name");
+ assertTrue(vimEntity.toString() != null);
+ assertTrue(VimEntity.toEntity(new JSONObject()) != null);
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/GrantResourseRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/GrantResourseRoaTest.java
new file mode 100644
index 0000000..1629f8e
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/GrantResourseRoaTest.java
@@ -0,0 +1,166 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.rest;
+
+import static org.junit.Assert.assertNotNull;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.common.util.request.RequestUtil;
+import org.openo.nfvo.resmanagement.service.group.impl.GrantResServiceImpl;
+import org.openo.nfvo.resmanagement.service.group.inf.GrantResService;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Mar 16, 2017
+ */
+public class GrantResourseRoaTest {
+
+ private GrantResourseRoa roa;
+
+ private GrantResService grantResService;
+
+ @Before
+ public void setUp() {
+ roa = new GrantResourseRoa();
+ grantResService = new GrantResServiceImpl();
+ roa.setGrantResService(grantResService);
+ }
+
+ @Test
+ public void testGrantResource() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<GrantResServiceImpl>() {
+
+ @Mock
+ public JSONObject grantResource(JSONObject object) throws ServiceException {
+ return new JSONObject();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.grantResource(mock);
+ assertNotNull(result);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testGrantResourceByNull() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return null;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.grantResource(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGrantResourceFail() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<GrantResServiceImpl>() {
+
+ @Mock
+ public JSONObject grantResource(JSONObject object) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.grantResource(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGrantResourceReal() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<GrantResServiceImpl>() {
+
+ @Mock
+ public JSONObject grantResourceReal(JSONObject object) throws ServiceException {
+ return new JSONObject();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.grantResourceReal(mock);
+ assertNotNull(result);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testGrantResourceRealByNull() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return null;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ roa.grantResourceReal(mock);
+ }
+
+ @Test
+ public void testGrantResourceRealFail() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<GrantResServiceImpl>() {
+
+ @Mock
+ public JSONObject grantResourceReal(JSONObject object) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.grantResourceReal(mock);
+ assertNotNull(result);
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/HostRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/HostRoaTest.java
new file mode 100644
index 0000000..bc0b8b7
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/HostRoaTest.java
@@ -0,0 +1,200 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.rest;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.common.util.request.RequestUtil;
+import org.openo.nfvo.resmanagement.service.base.openstack.impl.HostImpl;
+import org.openo.nfvo.resmanagement.service.base.openstack.inf.Host;
+import org.openo.nfvo.resmanagement.service.entity.HostEntity;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Feb 9, 2017
+ */
+public class HostRoaTest {
+
+ private HostRoa roa;
+
+ private Host host;
+
+ @Before
+ public void setUp() {
+ roa = new HostRoa();
+ host = new HostImpl();
+ roa.setHost(host);
+ }
+
+ @Test
+ public void testGetHosts() throws ServiceException {
+ new MockUp<HostImpl>() {
+
+ @Mock
+ public List<HostEntity> getList(Map<String, Object> condition) throws ServiceException {
+ return new ArrayList<HostEntity>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.getHosts(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGetHost() throws ServiceException {
+ new MockUp<HostImpl>() {
+
+ @Mock
+ public List<HostEntity> getList(Map<String, Object> condition) throws ServiceException {
+ return new ArrayList<HostEntity>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.getHost(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddHost() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<HostImpl>() {
+
+ @Mock
+ public int add(JSONObject jsonObject) throws ServiceException {
+ return 1;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.addHost(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddHostByException() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<HostImpl>() {
+
+ @Mock
+ public int add(JSONObject jsonObject) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.addHost(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testDeleteHost() throws ServiceException {
+ new MockUp<HostImpl>() {
+
+ @Mock
+ public int delete(String id) throws ServiceException {
+ return 1;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteHost(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testDeleteHostByException() throws ServiceException {
+ new MockUp<HostImpl>() {
+
+ @Mock
+ public int delete(String id) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteHost(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testUpdateHost() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<HostImpl>() {
+
+ @Mock
+ public int update(JSONObject jsonObject) throws ServiceException {
+ return 1;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.updateHost(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testUpdateHostByException() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<HostImpl>() {
+
+ @Mock
+ public int update(JSONObject jsonObject) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.updateHost(mock);
+ assertNotNull(result);
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/LimitsRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/LimitsRoaTest.java
new file mode 100644
index 0000000..3c028dc
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/LimitsRoaTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.rest;
+
+import static org.junit.Assert.assertNotNull;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.service.business.impl.LimitsBusinessImpl;
+import org.openo.nfvo.resmanagement.service.business.inf.LimitsBusiness;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Feb 9, 2017
+ */
+public class LimitsRoaTest {
+
+ private LimitsRoa roa;
+
+ private LimitsBusiness limitsBusiness;
+
+ @Before
+ public void setUp() {
+ roa = new LimitsRoa();
+ limitsBusiness = new LimitsBusinessImpl();
+ roa.setLimitsBusiness(limitsBusiness);
+ }
+
+ @Test
+ public void testGetLimitsResource() throws ServiceException {
+ new MockUp<LimitsBusinessImpl>() {
+
+ @Mock
+ public JSONObject getLimits(String vimId) throws ServiceException {
+ return new JSONObject();
+ }
+ };
+ HttpServletRequest context = new MockHttpServletRequest();
+ JSONObject result = roa.getLimits(context, "vimId");
+ assertNotNull(result);
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/LocationRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/LocationRoaTest.java
new file mode 100644
index 0000000..2a3c062
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/LocationRoaTest.java
@@ -0,0 +1,389 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.rest;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.common.util.request.RequestUtil;
+import org.openo.nfvo.resmanagement.service.base.openstack.impl.LocationImpl;
+import org.openo.nfvo.resmanagement.service.base.openstack.impl.SitesImpl;
+import org.openo.nfvo.resmanagement.service.base.openstack.inf.Location;
+import org.openo.nfvo.resmanagement.service.base.openstack.inf.Sites;
+import org.openo.nfvo.resmanagement.service.entity.LocationEntity;
+import org.openo.nfvo.resmanagement.service.entity.SitesEntity;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Feb 9, 2017
+ */
+public class LocationRoaTest {
+
+ private LocationRoa roa;
+
+ private Location location;
+
+ private Sites sites;
+
+ @Before
+ public void setUp() {
+ roa = new LocationRoa();
+ location = new LocationImpl();
+ sites = new SitesImpl();
+ roa.setLocation(location);
+ roa.setSites(sites);
+ }
+
+ @Test
+ public void testGetLocationsbase() throws ServiceException {
+ new MockUp<LocationImpl>() {
+
+ @Mock
+ public List<LocationEntity> get(Map<String, Object> condition) throws ServiceException {
+ return new ArrayList<LocationEntity>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.getLocationsbase(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGetLocationbase() throws ServiceException {
+ new MockUp<LocationImpl>() {
+
+ @Mock
+ public List<LocationEntity> get(Map<String, Object> condition) throws ServiceException {
+ return new ArrayList<LocationEntity>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.getLocationbase(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGetCountry() throws ServiceException {
+ new MockUp<LocationImpl>() {
+
+ @Mock
+ public List<String> getCountry() throws ServiceException {
+ return new ArrayList<String>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.getCountry(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGetLocationByCountry() throws ServiceException {
+ new MockUp<LocationImpl>() {
+
+ @Mock
+ public List<String> getLocationByCountry(Map<String, Object> condition) throws ServiceException {
+ return new ArrayList<String>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.getLocationByCountry(mock, "country");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGetLocation() throws ServiceException {
+ new MockUp<LocationImpl>() {
+
+ @Mock
+ public List<LocationEntity> get(Map<String, Object> condition) throws ServiceException {
+ return new ArrayList<LocationEntity>();
+ }
+
+ @Mock
+ public List<JSONObject> getLocationInfo(List<LocationEntity> locationInfo) throws ServiceException {
+ return new ArrayList<JSONObject>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.getLocation(mock, "locations");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddLocation() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<LocationImpl>() {
+
+ @Mock
+ public int add(JSONObject jsonObject) throws ServiceException {
+ return 1;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.addLocation(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddLocationByException() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<LocationImpl>() {
+
+ @Mock
+ public int add(JSONObject jsonObject) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.addLocation(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testDeleteLocationbase() throws ServiceException {
+ new MockUp<LocationImpl>() {
+
+ @Mock
+ public int delete(String location) throws ServiceException {
+ return 1;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteLocationbase(mock, "locations");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testDeleteLocationbaseByException() throws ServiceException {
+ new MockUp<LocationImpl>() {
+
+ @Mock
+ public int delete(String location) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteLocationbase(mock, "locations");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testDeleteLocation() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ JSONObject object = new JSONObject();
+ object.put("location", "location");
+ object.put("id", "id");
+ return object;
+ }
+ };
+ new MockUp<SitesImpl>() {
+
+ @Mock
+ public SitesEntity get(Map<String, Object> condition) throws ServiceException {
+ return null;
+ }
+ };
+ new MockUp<LocationImpl>() {
+
+ @Mock
+ public int delete(String location) throws ServiceException {
+ return 1;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteLocation(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testDeleteLocationByException() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ JSONObject object = new JSONObject();
+ object.put("location", "location");
+ object.put("id", "id");
+ return object;
+ }
+ };
+ new MockUp<SitesImpl>() {
+
+ @Mock
+ public SitesEntity get(Map<String, Object> condition) throws ServiceException {
+ return null;
+ }
+ };
+ new MockUp<LocationImpl>() {
+
+ @Mock
+ public int delete(String location) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteLocation(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testDeleteLocationBySitesEntity() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ JSONObject object = new JSONObject();
+ object.put("location", "location");
+ object.put("id", "id");
+ return object;
+ }
+ };
+ new MockUp<SitesImpl>() {
+
+ @Mock
+ public SitesEntity get(Map<String, Object> condition) throws ServiceException {
+ return new SitesEntity();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteLocation(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testUpdateLocation() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ JSONObject object = new JSONObject();
+ object.put("location", "location");
+ return object;
+ }
+ };
+ new MockUp<SitesImpl>() {
+
+ @Mock
+ public SitesEntity get(Map<String, Object> condition) throws ServiceException {
+ return null;
+ }
+ };
+ new MockUp<LocationImpl>() {
+
+ @Mock
+ public int update(JSONObject jsonObject) throws ServiceException {
+ return 1;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.updateLocation(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testUpdateLocationByException() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ JSONObject object = new JSONObject();
+ object.put("location", "location");
+ return object;
+ }
+ };
+ new MockUp<SitesImpl>() {
+
+ @Mock
+ public SitesEntity get(Map<String, Object> condition) throws ServiceException {
+ return null;
+ }
+ };
+ new MockUp<LocationImpl>() {
+
+ @Mock
+ public int update(JSONObject jsonObject) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.updateLocation(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testUpdateLocationBySitesEntity() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ JSONObject object = new JSONObject();
+ object.put("location", "location");
+ return object;
+ }
+ };
+ new MockUp<SitesImpl>() {
+
+ @Mock
+ public SitesEntity get(Map<String, Object> condition) throws ServiceException {
+ return new SitesEntity();
+ }
+ };
+ new MockUp<LocationImpl>() {
+
+ @Mock
+ public int update(JSONObject jsonObject) throws ServiceException {
+ return 1;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.updateLocation(mock);
+ assertNotNull(result);
+ }
+
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/NetworkRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/NetworkRoaTest.java
new file mode 100644
index 0000000..b838e27
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/NetworkRoaTest.java
@@ -0,0 +1,214 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.rest;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.common.util.request.RequestUtil;
+import org.openo.nfvo.resmanagement.service.base.openstack.impl.NetworkImpl;
+import org.openo.nfvo.resmanagement.service.base.openstack.inf.Network;
+import org.openo.nfvo.resmanagement.service.entity.NetworkEntity;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Feb 9, 2017
+ */
+public class NetworkRoaTest {
+
+ private NetworkRoa roa;
+
+ private Network network;
+
+ @Before
+ public void setUp() {
+ roa = new NetworkRoa();
+ network = new NetworkImpl();
+ roa.setNetwork(network);
+ }
+
+ @Test
+ public void testGetNetworks() throws ServiceException {
+ new MockUp<NetworkImpl>() {
+
+ @Mock
+ public List<NetworkEntity> getList(Map<String, Object> condition) throws ServiceException {
+ return new ArrayList<NetworkEntity>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.getNetworks(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGetNetwork() throws ServiceException {
+ new MockUp<NetworkImpl>() {
+
+ @Mock
+ public List<NetworkEntity> getList(Map<String, Object> condition) throws ServiceException {
+ return new ArrayList<NetworkEntity>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.getNetwork(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddNetwork() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<NetworkEntity>() {
+
+ @Mock
+ public NetworkEntity toEntity(JSONObject jsonObject) {
+ return new NetworkEntity();
+ }
+ };
+ new MockUp<NetworkImpl>() {
+
+ @Mock
+ public int add(NetworkEntity entity) throws ServiceException {
+ return 1;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.addNetwork(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddNetworkByException() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<NetworkEntity>() {
+
+ @Mock
+ public NetworkEntity toEntity(JSONObject jsonObject) {
+ return new NetworkEntity();
+ }
+ };
+ new MockUp<NetworkImpl>() {
+
+ @Mock
+ public int add(NetworkEntity entity) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.addNetwork(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testDeleteNetwork() throws ServiceException {
+ new MockUp<NetworkImpl>() {
+
+ @Mock
+ public int delete(String id) throws ServiceException {
+ return 1;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteNetwork(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testDeleteNetworkByException() throws ServiceException {
+ new MockUp<NetworkImpl>() {
+
+ @Mock
+ public int delete(String id) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteNetwork(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testUpdateNetwork() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<NetworkImpl>() {
+
+ @Mock
+ public int update(JSONObject jsonObject) throws ServiceException {
+ return 1;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.updateNetwork(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testUpdateNetworkByException() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<NetworkImpl>() {
+
+ @Mock
+ public int update(JSONObject jsonObject) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.updateNetwork(mock);
+ assertNotNull(result);
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/PortRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/PortRoaTest.java
new file mode 100644
index 0000000..9e4d127
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/PortRoaTest.java
@@ -0,0 +1,214 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.rest;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.common.util.request.RequestUtil;
+import org.openo.nfvo.resmanagement.service.base.openstack.impl.PortImpl;
+import org.openo.nfvo.resmanagement.service.base.openstack.inf.Port;
+import org.openo.nfvo.resmanagement.service.entity.PortEntity;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Feb 9, 2017
+ */
+public class PortRoaTest {
+
+ private PortRoa roa;
+
+ private Port port;
+
+ @Before
+ public void setUp() {
+ roa = new PortRoa();
+ port = new PortImpl();
+ roa.setPort(port);
+ }
+
+ @Test
+ public void testGetPorts() throws ServiceException {
+ new MockUp<PortImpl>() {
+
+ @Mock
+ public List<PortEntity> getList(Map<String, Object> condition) throws ServiceException {
+ return new ArrayList<PortEntity>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.getPorts(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGetPort() throws ServiceException {
+ new MockUp<PortImpl>() {
+
+ @Mock
+ public List<PortEntity> getList(Map<String, Object> condition) throws ServiceException {
+ return new ArrayList<PortEntity>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.getPort(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddPort() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<PortEntity>() {
+
+ @Mock
+ public PortEntity toEntity(JSONObject jsonObject) {
+ return new PortEntity();
+ }
+ };
+ new MockUp<PortImpl>() {
+
+ @Mock
+ public int add(PortEntity portEntity) throws ServiceException {
+ return 1;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.addPort(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddPortByException() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<PortEntity>() {
+
+ @Mock
+ public PortEntity toEntity(JSONObject jsonObject) {
+ return new PortEntity();
+ }
+ };
+ new MockUp<PortImpl>() {
+
+ @Mock
+ public int add(PortEntity portEntity) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.addPort(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testDeletePort() throws ServiceException {
+ new MockUp<PortImpl>() {
+
+ @Mock
+ public int delete(String id) throws ServiceException {
+ return 1;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deletePort(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testDeletePortByException() throws ServiceException {
+ new MockUp<PortImpl>() {
+
+ @Mock
+ public int delete(String id) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deletePort(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testUpdatePort() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<PortImpl>() {
+
+ @Mock
+ public int update(JSONObject jsonObject) throws ServiceException {
+ return 1;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.updatePort(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testUpdatePortByException() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<PortImpl>() {
+
+ @Mock
+ public int update(JSONObject jsonObject) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.updatePort(mock);
+ assertNotNull(result);
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/ResOperateRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/ResOperateRoaTest.java
new file mode 100644
index 0000000..eddd61d
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/ResOperateRoaTest.java
@@ -0,0 +1,197 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.rest;
+
+import static org.junit.Assert.assertNotNull;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.common.VimUtil;
+import org.openo.nfvo.resmanagement.common.util.request.RequestUtil;
+import org.openo.nfvo.resmanagement.service.group.impl.ResOperateServiceImpl;
+import org.openo.nfvo.resmanagement.service.group.inf.ResOperateService;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Mar 16, 2017
+ */
+public class ResOperateRoaTest {
+
+ private ResOperateRoa roa;
+
+ private ResOperateService resOperateService;
+
+ @Before
+ public void setUp() {
+ roa = new ResOperateRoa();
+ resOperateService = new ResOperateServiceImpl();
+ roa.setResOperateService(resOperateService);
+ }
+
+ @Test
+ public void testUpdateIResPool() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<VimUtil>() {
+
+ @Mock
+ public JSONObject getVimById(String vimId) {
+ JSONObject vimInfo = new JSONObject();
+ vimInfo.put("tenant", "tenant");
+ return vimInfo;
+ }
+
+ @Mock
+ public String getTenantIdByName(String tenant, String vimId) {
+ return "";
+ }
+ };
+ new MockUp<ResOperateServiceImpl>() {
+
+ @Mock
+ public void updateIRes(String tenantId, String vimId, JSONObject header) throws ServiceException {
+ }
+
+ @Mock
+ public void sendMsgMonitor(String operateType, String vimId) throws ServiceException {
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.updateIResPool(mock, "vimId");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testUpdateIResPoolFail() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<VimUtil>() {
+
+ @Mock
+ public JSONObject getVimById(String vimId) {
+ JSONObject vimInfo = new JSONObject();
+ vimInfo.put("tenant", "tenant");
+ return vimInfo;
+ }
+
+ @Mock
+ public String getTenantIdByName(String tenant, String vimId) {
+ return "";
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.updateIResPool(mock, null);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddAllResPool() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<ResOperateServiceImpl>() {
+
+ @Mock
+ public void addIRes(String tenantId, String vimId, JSONObject header) throws ServiceException {
+ }
+
+ @Mock
+ public void sendMsgMonitor(String operateType, String vimId) throws ServiceException {
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.addAllResPool(mock, "tenantId", "vimId");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddAllResPoolFail() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.addAllResPool(mock, null, null);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testDeleteIRes() throws ServiceException {
+ new MockUp<ResOperateServiceImpl>() {
+
+ @Mock
+ public int deleteIRes(String vimId) throws ServiceException {
+ return 1;
+ }
+
+ @Mock
+ public void sendMsgMonitor(String operateType, String vimId) throws ServiceException {
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteIRes(mock, "vimId");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testDeleteIResFail() throws ServiceException {
+ new MockUp<ResOperateServiceImpl>() {
+
+ @Mock
+ public int deleteIRes(String vimId) throws ServiceException {
+ throw new ServiceException();
+ }
+
+ @Mock
+ public void sendMsgMonitor(String operateType, String vimId) throws ServiceException {
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteIRes(mock, null);
+ assertNotNull(result);
+ }
+
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/SitesRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/SitesRoaTest.java
new file mode 100644
index 0000000..ad21b19
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/SitesRoaTest.java
@@ -0,0 +1,279 @@
+/*
+ * Copyright 2016-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.openo.nfvo.resmanagement.service.rest;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.common.VimUtil;
+import org.openo.nfvo.resmanagement.common.util.request.RequestUtil;
+import org.openo.nfvo.resmanagement.service.base.openstack.impl.SitesImpl;
+import org.openo.nfvo.resmanagement.service.entity.SitesEntity;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+/**
+ * <br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 2016年8月16日
+ */
+public class SitesRoaTest {
+
+ private SitesRoa sitesRoa;
+
+ @Before
+ public void setUp() {
+ sitesRoa = new SitesRoa();
+ sitesRoa.setSites(new SitesImpl());
+ }
+
+ @Test
+ public void testGetSites() throws ServiceException {
+ new MockUp<SitesImpl>() {
+
+ @Mock
+ public List<SitesEntity> getList(Map<String, Object> condition) throws ServiceException {
+ return new ArrayList<SitesEntity>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = sitesRoa.getSites(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGetSite() throws ServiceException {
+ new MockUp<SitesImpl>() {
+
+ @Mock
+ public List<SitesEntity> getList(Map<String, Object> condition) throws ServiceException {
+ return new ArrayList<SitesEntity>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = sitesRoa.getSite(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddSites() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getAllJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<SitesImpl>() {
+
+ @Mock
+ public int add(JSONObject jsonObject) throws ServiceException {
+ return 1;
+ }
+
+ @Mock
+ public void sendToMonitor(JSONObject jsonObject) throws ServiceException {
+
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = sitesRoa.addSites(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddSitesExceptions() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getAllJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<SitesImpl>() {
+
+ @Mock
+ public int add(JSONObject jsonObject) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ JSONObject result = sitesRoa.addSites(null);
+ JSONObject expectedResult = new JSONObject();
+ expectedResult.put("msg", "");
+ assertEquals(expectedResult.toString(), result.toString());
+ }
+
+ @Test
+ public void testDeleteSites() throws ServiceException {
+ new MockUp<SitesImpl>() {
+
+ @Mock
+ public int delete(String id) throws ServiceException {
+ return 1;
+ }
+ };
+ JSONObject result = sitesRoa.deleteSites(null, "123");
+ JSONObject expectedResult = new JSONObject();
+ expectedResult.put("msg", "org.openo.nfvo.resmanage.common.del.success");
+ assertEquals(expectedResult.toString(), result.toString());
+ }
+
+ @Test
+ public void testDeleteSitesExceptions() throws ServiceException {
+ new MockUp<SitesImpl>() {
+
+ @Mock
+ public int delete(String id) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ JSONObject result = sitesRoa.deleteSites(null, "123");
+ JSONObject expectedResult = new JSONObject();
+ expectedResult.put("msg", "");
+ assertEquals(expectedResult.toString(), result.toString());
+ }
+
+ @Test
+ public void testUpdateSites() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getAllJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<SitesImpl>() {
+
+ @Mock
+ public int update(SitesEntity sitesEntity) throws ServiceException {
+ return 1;
+ }
+ };
+ JSONObject result = sitesRoa.updateSites(null);
+ JSONObject expectedResult = new JSONObject();
+ expectedResult.put("msg", "org.openo.nfvo.resmanage.common.update.success");
+ assertEquals(expectedResult.toString(), result.toString());
+ }
+
+ @Test
+ public void testUpdateISitesExceptions() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getAllJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<SitesImpl>() {
+
+ @Mock
+ public int update(SitesEntity sitesEntity) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ JSONObject result = sitesRoa.updateSites(null);
+ JSONObject expectedResult = new JSONObject();
+ expectedResult.put("msg", "");
+ assertEquals(expectedResult.toString(), result.toString());
+ }
+
+ @Test
+ public void testGrantResource() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getAllJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<SitesImpl>() {
+
+ @Mock
+ public int update(JSONObject jsonObject) throws ServiceException {
+ return 1;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = sitesRoa.grantResource(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGrantResourceByException() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getAllJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<SitesImpl>() {
+
+ @Mock
+ public int update(JSONObject jsonObject) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = sitesRoa.grantResource(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGetVims() throws ServiceException {
+ new MockUp<VimUtil>() {
+
+ @Mock
+ public JSONArray getVims() {
+ return new JSONArray();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ String result = sitesRoa.getVims(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGetVim() throws ServiceException {
+ new MockUp<VimUtil>() {
+
+ @Mock
+ public JSONObject getVimById(String vimId) {
+ return new JSONObject();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ String result = sitesRoa.getVim(mock, "id");
+ assertNotNull(result);
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/SwaggerRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/SwaggerRoaTest.java
new file mode 100644
index 0000000..7cd0b97
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/SwaggerRoaTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.rest;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+
+import mockit.Mock;
+import mockit.MockUp;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Feb 9, 2017
+ */
+public class SwaggerRoaTest {
+
+ private SwaggerRoa roa;
+
+ @Test
+ public void testApidoc() throws IOException {
+ new MockUp<IOUtils>() {
+
+ @Mock
+ public String toString(InputStream input) {
+ return "";
+ }
+ };
+ roa = new SwaggerRoa();
+ String result = roa.apidoc();
+ assertNotNull(result);
+ }
+
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VirtualLinkRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VirtualLinkRoaTest.java
new file mode 100644
index 0000000..f8054ae
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VirtualLinkRoaTest.java
@@ -0,0 +1,192 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.rest;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.common.util.request.RequestUtil;
+import org.openo.nfvo.resmanagement.service.entity.VirtualLinkEntity;
+import org.openo.nfvo.resmanagement.service.group.impl.VirtualLinkServiceImpl;
+import org.openo.nfvo.resmanagement.service.group.inf.VirtualLinkService;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Feb 9, 2017
+ */
+public class VirtualLinkRoaTest {
+
+ private VirtualLinkRoa roa;
+
+ private VirtualLinkService virtualLink;
+
+ @Before
+ public void setUp() {
+ roa = new VirtualLinkRoa();
+ virtualLink = new VirtualLinkServiceImpl();
+ roa.setVirtualLink(virtualLink);
+ }
+
+ @Test
+ public void testGetVls() throws ServiceException {
+ new MockUp<VirtualLinkServiceImpl>() {
+
+ @Mock
+ public List<VirtualLinkEntity> getList(Map<String, Object> map) throws ServiceException {
+ return new ArrayList<VirtualLinkEntity>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.getVls(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGetVl() throws ServiceException {
+ new MockUp<VirtualLinkServiceImpl>() {
+
+ @Mock
+ public List<VirtualLinkEntity> getList(Map<String, Object> map) throws ServiceException {
+ return new ArrayList<VirtualLinkEntity>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.getVl(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddVl() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<VirtualLinkEntity>() {
+
+ @Mock
+ public VirtualLinkEntity toEntity(JSONObject jsonObject) {
+ return new VirtualLinkEntity();
+ }
+ };
+ new MockUp<VirtualLinkServiceImpl>() {
+
+ @Mock
+ public JSONObject addVl(VirtualLinkEntity virtualLinkEntity) throws ServiceException {
+ return new JSONObject();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.addVl(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddVlByException() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<VirtualLinkEntity>() {
+
+ @Mock
+ public VirtualLinkEntity toEntity(JSONObject jsonObject) {
+ return new VirtualLinkEntity();
+ }
+ };
+ new MockUp<VirtualLinkServiceImpl>() {
+
+ @Mock
+ public JSONObject addVl(VirtualLinkEntity virtualLinkEntity) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.addVl(mock);
+ assertNotNull(result);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testAddVlByExceptionByNull() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return null;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ roa.addVl(mock);
+ }
+
+ @Test
+ public void testDeleteVl() throws ServiceException {
+ new MockUp<VirtualLinkServiceImpl>() {
+
+ @Mock
+ public int delete(String id) throws ServiceException {
+ return 1;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteVl(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testDeleteVlByException() throws ServiceException {
+ new MockUp<VirtualLinkServiceImpl>() {
+
+ @Mock
+ public int delete(String id) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteVl(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testDeleteVlByNull() throws ServiceException {
+ HttpServletRequest mock = new MockHttpServletRequest();
+ roa.deleteVl(mock, null);
+ }
+
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VmRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VmRoaTest.java
new file mode 100644
index 0000000..111a330
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VmRoaTest.java
@@ -0,0 +1,193 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.rest;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.common.util.request.RequestUtil;
+import org.openo.nfvo.resmanagement.service.entity.VmEntity;
+import org.openo.nfvo.resmanagement.service.group.impl.VmServiceImpl;
+import org.openo.nfvo.resmanagement.service.group.inf.VmService;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Feb 9, 2017
+ */
+public class VmRoaTest {
+
+ private VmRoa roa;
+
+ private VmService vmService;
+
+ @Before
+ public void setUp() {
+ roa = new VmRoa();
+ vmService = new VmServiceImpl();
+ roa.setVmService(vmService);
+ }
+
+ @Test
+ public void testGetVms() throws ServiceException {
+ new MockUp<VmServiceImpl>() {
+
+ @Mock
+ public List<VmEntity> getList(Map<String, Object> map) throws ServiceException {
+ return new ArrayList<VmEntity>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.getVms(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGetVm() throws ServiceException {
+ new MockUp<VmServiceImpl>() {
+
+ @Mock
+ public List<VmEntity> getList(Map<String, Object> map) throws ServiceException {
+ return new ArrayList<VmEntity>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.getVm(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddVm() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<VmEntity>() {
+
+ @Mock
+ public VmEntity toEntity(JSONObject jsonObject) {
+ return new VmEntity();
+ }
+ };
+ new MockUp<VmServiceImpl>() {
+
+ @Mock
+ public JSONObject addVm(VmEntity vmEntity) throws ServiceException {
+ return new JSONObject();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.addVm(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddVmByException() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<VmEntity>() {
+
+ @Mock
+ public VmEntity toEntity(JSONObject jsonObject) {
+ return new VmEntity();
+ }
+ };
+ new MockUp<VmServiceImpl>() {
+
+ @Mock
+ public JSONObject addVm(VmEntity vmEntity) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.addVm(mock);
+ assertNotNull(result);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testAddVmByNull() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return null;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ roa.addVm(mock);
+ }
+
+ @Test
+ public void testDeleteVm() throws ServiceException {
+ new MockUp<VmServiceImpl>() {
+
+ @Mock
+ public int delete(String id) throws ServiceException {
+ return 1;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteVm(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testDeleteVmByException() throws ServiceException {
+ new MockUp<VmServiceImpl>() {
+
+ @Mock
+ public int delete(String id) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteVm(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testDeleteVmByNull() throws ServiceException {
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteVm(mock, null);
+ assertNotNull(result);
+ }
+
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VnfInfoRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VnfInfoRoaTest.java
new file mode 100644
index 0000000..2128d3a
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VnfInfoRoaTest.java
@@ -0,0 +1,178 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.rest;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.common.util.request.RequestUtil;
+import org.openo.nfvo.resmanagement.service.entity.VnfInfoEntity;
+import org.openo.nfvo.resmanagement.service.group.impl.VnfInfoServiceImpl;
+import org.openo.nfvo.resmanagement.service.group.inf.VnfInfoService;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Feb 9, 2017
+ */
+public class VnfInfoRoaTest {
+
+ private VnfInfoRoa roa;
+
+ private VnfInfoService vnfInfoService;
+
+ @Before
+ public void setUp() {
+ roa = new VnfInfoRoa();
+ vnfInfoService = new VnfInfoServiceImpl();
+ roa.setVnfInfoService(vnfInfoService);
+ }
+
+ @Test
+ public void testGetVnfInfos() throws ServiceException {
+ new MockUp<VnfInfoServiceImpl>() {
+
+ @Mock
+ public List<VnfInfoEntity> getList(Map<String, Object> map) throws ServiceException {
+ return new ArrayList<VnfInfoEntity>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.getVnfInfos(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGetVnfInfo() throws ServiceException {
+ new MockUp<VnfInfoServiceImpl>() {
+
+ @Mock
+ public List<VnfInfoEntity> getList(Map<String, Object> map) throws ServiceException {
+ return new ArrayList<VnfInfoEntity>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.getVnfInfo(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddVnfInfo() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<VnfInfoServiceImpl>() {
+
+ @Mock
+ public JSONObject addVnfInfo(JSONObject object) throws ServiceException {
+ return new JSONObject();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.addVnfInfo(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddVnfInfoByException() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<VnfInfoServiceImpl>() {
+
+ @Mock
+ public JSONObject addVnfInfo(JSONObject object) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.addVnfInfo(mock);
+ assertNotNull(result);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testAddVnfInfoByNull() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return null;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ roa.addVnfInfo(mock);
+ }
+
+ @Test
+ public void testDeleteVnfInfo() throws ServiceException {
+ new MockUp<VnfInfoServiceImpl>() {
+
+ @Mock
+ public int delete(String id) throws ServiceException {
+ return 1;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteVnfInfo(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testDeleteVnfInfoByException() throws ServiceException {
+ new MockUp<VnfInfoServiceImpl>() {
+
+ @Mock
+ public int delete(String id) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteVnfInfo(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testDeleteVnfInfoByNull() throws ServiceException {
+ HttpServletRequest mock = new MockHttpServletRequest();
+ roa.deleteVnfInfo(mock, null);
+ }
+
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VnfRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VnfRoaTest.java
new file mode 100644
index 0000000..332cf2d
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VnfRoaTest.java
@@ -0,0 +1,191 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.rest;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.common.util.request.RequestUtil;
+import org.openo.nfvo.resmanagement.service.entity.VnfEntity;
+import org.openo.nfvo.resmanagement.service.group.impl.VnfServiceImpl;
+import org.openo.nfvo.resmanagement.service.group.inf.VnfService;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Feb 10, 2017
+ */
+public class VnfRoaTest {
+
+ private VnfRoa roa;
+
+ private VnfService vnfService;
+
+ @Before
+ public void setUp() {
+ roa = new VnfRoa();
+ vnfService = new VnfServiceImpl();
+ roa.setVnfService(vnfService);
+ }
+
+ @Test
+ public void testGetVnfs() throws ServiceException {
+ new MockUp<VnfServiceImpl>() {
+
+ @Mock
+ public List<VnfEntity> getList(Map<String, Object> map) throws ServiceException {
+ return new ArrayList<VnfEntity>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.getVnfs(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGetVnf() throws ServiceException {
+ new MockUp<VnfServiceImpl>() {
+
+ @Mock
+ public List<VnfEntity> getList(Map<String, Object> map) throws ServiceException {
+ return new ArrayList<VnfEntity>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.getVnf(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddVnf() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<VnfEntity>() {
+
+ @Mock
+ public VnfEntity toEntity(JSONObject jsonObject) {
+ return new VnfEntity();
+ }
+ };
+ new MockUp<VnfServiceImpl>() {
+
+ @Mock
+ public JSONObject addVnf(VnfEntity vnfEntity) throws ServiceException {
+ return new JSONObject();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.addVnf(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddVnfByException() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<VnfEntity>() {
+
+ @Mock
+ public VnfEntity toEntity(JSONObject jsonObject) {
+ return new VnfEntity();
+ }
+ };
+ new MockUp<VnfServiceImpl>() {
+
+ @Mock
+ public JSONObject addVnf(VnfEntity vnfEntity) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.addVnf(mock);
+ assertNotNull(result);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testAddVnfByNull() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return null;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ roa.addVnf(mock);
+ }
+
+ @Test
+ public void testDeleteVnf() throws ServiceException {
+ new MockUp<VnfServiceImpl>() {
+
+ @Mock
+ public int delete(String id) throws ServiceException {
+ return 1;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteVnf(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testDeleteVnfByException() throws ServiceException {
+ new MockUp<VnfServiceImpl>() {
+
+ @Mock
+ public int delete(String id) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteVnf(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testDeleteVnfByNull() throws ServiceException {
+ HttpServletRequest mock = new MockHttpServletRequest();
+ roa.deleteVnf(mock, null);
+ }
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VnfStatusRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VnfStatusRoaTest.java
new file mode 100644
index 0000000..1629271
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VnfStatusRoaTest.java
@@ -0,0 +1,178 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.rest;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+import org.openo.nfvo.resmanagement.common.util.request.RequestUtil;
+import org.openo.nfvo.resmanagement.service.entity.VnfStatusEntity;
+import org.openo.nfvo.resmanagement.service.group.impl.VnfStatusServiceImpl;
+import org.openo.nfvo.resmanagement.service.group.inf.VnfStatusService;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Feb 10, 2017
+ */
+public class VnfStatusRoaTest {
+
+ private VnfStatusRoa roa;
+
+ private VnfStatusService vnfStatusService;
+
+ @Before
+ public void setUp() {
+ roa = new VnfStatusRoa();
+ vnfStatusService = new VnfStatusServiceImpl();
+ roa.setVnfStatusService(vnfStatusService);
+ }
+
+ @Test
+ public void testGetVnfStatuss() throws ServiceException {
+ new MockUp<VnfStatusServiceImpl>() {
+
+ @Mock
+ public List<VnfStatusEntity> getList(Map<String, Object> map) throws ServiceException {
+ return new ArrayList<VnfStatusEntity>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.getVnfStatuss(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGetVnfStatus() throws ServiceException {
+ new MockUp<VnfStatusServiceImpl>() {
+
+ @Mock
+ public List<VnfStatusEntity> getList(Map<String, Object> map) throws ServiceException {
+ return new ArrayList<VnfStatusEntity>();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.getVnfStatus(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddVnfStatus() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<VnfStatusServiceImpl>() {
+
+ @Mock
+ public JSONObject addVnfStatus(JSONObject object) throws ServiceException {
+ return new JSONObject();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.addVnfStatus(mock);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testAddVnfStatusByException() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return new JSONObject();
+ }
+ };
+ new MockUp<VnfStatusServiceImpl>() {
+
+ @Mock
+ public JSONObject addVnfStatus(JSONObject object) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.addVnfStatus(mock);
+ assertNotNull(result);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testAddVnfStatusByNull() throws ServiceException {
+ new MockUp<RequestUtil>() {
+
+ @Mock
+ public JSONObject getJsonRequestBody(HttpServletRequest context) {
+ return null;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ roa.addVnfStatus(mock);
+ }
+
+ @Test
+ public void testDeleteVnfStatus() throws ServiceException {
+ new MockUp<VnfStatusServiceImpl>() {
+
+ @Mock
+ public int delete(String id) throws ServiceException {
+ return 1;
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteVnfStatus(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testDeleteVnfStatusByException() throws ServiceException {
+ new MockUp<VnfStatusServiceImpl>() {
+
+ @Mock
+ public int delete(String id) throws ServiceException {
+ throw new ServiceException();
+ }
+ };
+ HttpServletRequest mock = new MockHttpServletRequest();
+ JSONObject result = roa.deleteVnfStatus(mock, "id");
+ assertNotNull(result);
+ }
+
+ @Test(expected = ServiceException.class)
+ public void testDeleteVnfStatusByNull() throws ServiceException {
+ HttpServletRequest mock = new MockHttpServletRequest();
+ roa.deleteVnfStatus(mock, null);
+ }
+
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/ExceptionMessageTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/ExceptionMessageTest.java
new file mode 100644
index 0000000..5409ada
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/ExceptionMessageTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.rest.exceptionmapper;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Feb 9, 2017
+ */
+public class ExceptionMessageTest {
+
+ @Test
+ public void testToString() {
+ ExceptionMessage message = new ExceptionMessage();
+ message.setErrorCode("1");
+ message.setHttpCode(200);
+ message.setMessage("Success!");
+ String str = message.toString();
+ assertNotNull(str);
+ }
+
+ @Test
+ public void testGetErrorCode() {
+ ExceptionMessage message = new ExceptionMessage();
+ message.setErrorCode("1");
+ String str = message.getErrorCode();
+ assertEquals("1", str);
+ }
+
+ @Test
+ public void testHttpCode() {
+ ExceptionMessage message = new ExceptionMessage();
+ message.setHttpCode(200);
+ int str = message.getHttpCode();
+ assertEquals(200, str);
+ }
+
+ @Test
+ public void testGetMessage() {
+ ExceptionMessage message = new ExceptionMessage();
+ message.setMessage("Success!");
+ String str = message.getMessage();
+ assertEquals("Success!", str);
+ }
+
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/GenericExceptionMapperTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/GenericExceptionMapperTest.java
new file mode 100644
index 0000000..7a90d9e
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/GenericExceptionMapperTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.rest.exceptionmapper;
+
+import static org.junit.Assert.assertNotNull;
+
+import javax.ws.rs.core.Response;
+
+import org.junit.Test;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Feb 9, 2017
+ */
+public class GenericExceptionMapperTest {
+
+ @Test
+ public void testToResponse() {
+ GenericExceptionMapper excep = new GenericExceptionMapper();
+ Exception exception = new Exception("message");
+ Response res = excep.toResponse(exception);
+ assertNotNull(res);
+ }
+
+}
diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/ServiceExceptionMapperTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/ServiceExceptionMapperTest.java
new file mode 100644
index 0000000..fc4378b
--- /dev/null
+++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/ServiceExceptionMapperTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.openo.nfvo.resmanagement.service.rest.exceptionmapper;
+
+import static org.junit.Assert.assertNotNull;
+
+import javax.ws.rs.core.Response;
+
+import org.junit.Test;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version NFVO 0.5 Feb 9, 2017
+ */
+public class ServiceExceptionMapperTest {
+
+ @Test
+ public void testToResponse() {
+ ServiceExceptionMapper mapper = new ServiceExceptionMapper();
+ ServiceException exception = new ServiceException();
+ Response res = mapper.toResponse(exception);
+ assertNotNull(res);
+ }
+
+}