summaryrefslogtreecommitdiffstats
path: root/ResmanagementService
diff options
context:
space:
mode:
authorluxin <luxin7@huawei.com>2018-02-11 15:09:13 +0800
committerluxin <luxin7@huawei.com>2018-02-11 15:24:19 +0800
commit277abfdf9bfd9a2e342584fc6f4700a25534d7f2 (patch)
tree12387668bcc72f85d5cc8c80f2000f07545a29ab /ResmanagementService
parent86e1ac9541a1dd6bfe6d1e3c7a4b9b679a26b904 (diff)
UT case increase for grant resource
Change-Id: Ia077192aa8cc4b781fc1b107debcdad158ac6f13 Issue-ID: VFC-747 Signed-off-by: luxin <luxin7@huawei.com>
Diffstat (limited to 'ResmanagementService')
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/VimUtil.java3
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrService.java2
-rw-r--r--ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/GrantResServiceImplTest.java173
3 files changed, 178 insertions, 0 deletions
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/VimUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/VimUtil.java
index d9e8867..fbd779d 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/VimUtil.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/VimUtil.java
@@ -73,6 +73,9 @@ public class VimUtil {
*/
public static String getVimIdByName(String name) {
JSONArray vims = getVims();
+ if(vims == null) {
+ return "";
+ }
for(int i = 0; i < vims.size(); i++) {
JSONObject vim = vims.getJSONObject(i);
LOG.info("vimInfo: " + vim);
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrService.java
index ead1f5d..2feaba3 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrService.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrService.java
@@ -166,6 +166,8 @@ public class ResmgrAdapterMgrService implements IResmgrAdapterMgrService {
}
} catch(InterruptedException e) {
LOG.error(e.getMessage(), e);
+ // Restore interrupted state...
+ Thread.currentThread().interrupt();
}
sendRequest(this.paramsMap, this.adapterInfo);
diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/GrantResServiceImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/GrantResServiceImplTest.java
index 15906b1..9e1c1ce 100644
--- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/GrantResServiceImplTest.java
+++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/GrantResServiceImplTest.java
@@ -102,6 +102,158 @@ public class GrantResServiceImplTest {
assertNotNull(result);
}
+ @Test
+ public void testGrantResourceRealByCpu() throws ServiceException {
+ GrantResServiceImpl impl = new GrantResServiceImpl();
+ JSONObject obj = new JSONObject();
+ JSONObject vimObj = getVimObj();
+ obj.put("additionalParam", vimObj);
+ obj.put("vimId", "vimId");
+ JSONArray addResource = new JSONArray();
+ addResource.add(getAddResObj());
+ obj.put("addResource", addResource);
+ new MockUp<VimUtil>() {
+
+ @Mock
+ public JSONObject getVimById(String vimId) {
+ return getVimObj();
+ }
+ };
+ new MockUp<LimitsBusinessImpl>() {
+
+ @Mock
+ public JSONObject getLimits(String vimId) throws ServiceException {
+ JSONObject result = new JSONObject();
+ result.put("vimId", "vimId");
+ result.put("vimName", "vimName");
+ result.put("totalCPU", "10");
+ result.put("totalMemory", "10");
+ result.put("totalDisk", "10");
+ result.put("usedCPU", "10");
+ result.put("usedMemory", "1");
+ result.put("usedDisk", "1");
+ return result;
+ }
+ };
+
+ JSONObject result = impl.grantResourceReal(obj);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGrantResourceRealByMem() throws ServiceException {
+ GrantResServiceImpl impl = new GrantResServiceImpl();
+ JSONObject obj = new JSONObject();
+ JSONObject vimObj = getVimObj();
+ obj.put("additionalParam", vimObj);
+ obj.put("vimId", "vimId");
+ JSONArray addResource = new JSONArray();
+ addResource.add(getAddResObj());
+ obj.put("addResource", addResource);
+ new MockUp<VimUtil>() {
+
+ @Mock
+ public JSONObject getVimById(String vimId) {
+ return getVimObj();
+ }
+ };
+ new MockUp<LimitsBusinessImpl>() {
+
+ @Mock
+ public JSONObject getLimits(String vimId) throws ServiceException {
+ JSONObject result = new JSONObject();
+ result.put("vimId", "vimId");
+ result.put("vimName", "vimName");
+ result.put("totalCPU", "10");
+ result.put("totalMemory", "10");
+ result.put("totalDisk", "10");
+ result.put("usedCPU", "1");
+ result.put("usedMemory", "10");
+ result.put("usedDisk", "1");
+ return result;
+ }
+ };
+
+ JSONObject result = impl.grantResourceReal(obj);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGrantResourceRealByDisk() throws ServiceException {
+ GrantResServiceImpl impl = new GrantResServiceImpl();
+ JSONObject obj = new JSONObject();
+ JSONObject vimObj = getVimObj();
+ obj.put("additionalParam", vimObj);
+ obj.put("vimId", "vimId");
+ JSONArray addResource = new JSONArray();
+ addResource.add(getAddResObj());
+ obj.put("addResource", addResource);
+ new MockUp<VimUtil>() {
+
+ @Mock
+ public JSONObject getVimById(String vimId) {
+ return getVimObj();
+ }
+ };
+ new MockUp<LimitsBusinessImpl>() {
+
+ @Mock
+ public JSONObject getLimits(String vimId) throws ServiceException {
+ JSONObject result = new JSONObject();
+ result.put("vimId", "vimId");
+ result.put("vimName", "vimName");
+ result.put("totalCPU", "10");
+ result.put("totalMemory", "10");
+ result.put("totalDisk", "10");
+ result.put("usedCPU", "1");
+ result.put("usedMemory", "1");
+ result.put("usedDisk", "10");
+ return result;
+ }
+ };
+
+ JSONObject result = impl.grantResourceReal(obj);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGrantResourceRealByRemoveRes() throws ServiceException {
+ GrantResServiceImpl impl = new GrantResServiceImpl();
+ JSONObject obj = new JSONObject();
+ JSONObject vimObj = getVimObj();
+ obj.put("additionalParam", vimObj);
+ obj.put("vimId", "vimId");
+ JSONArray addResource = new JSONArray();
+ addResource.add(getAddResObj());
+ obj.put("removeResource", addResource);
+ new MockUp<VimUtil>() {
+
+ @Mock
+ public JSONObject getVimById(String vimId) {
+ return getVimObj();
+ }
+ };
+ new MockUp<LimitsBusinessImpl>() {
+
+ @Mock
+ public JSONObject getLimits(String vimId) throws ServiceException {
+ JSONObject result = new JSONObject();
+ result.put("vimId", "vimId");
+ result.put("vimName", "vimName");
+ result.put("totalCPU", "10");
+ result.put("totalMemory", "10");
+ result.put("totalDisk", "10");
+ result.put("usedCPU", "1");
+ result.put("usedMemory", "1");
+ result.put("usedDisk", "1");
+ return result;
+ }
+ };
+
+ JSONObject result = impl.grantResourceReal(obj);
+ assertNotNull(result);
+ }
+
/**
* {
* "vimId": "57674786-5b2e-4c92-bb68-578dbd79e2f5",
@@ -186,4 +338,25 @@ public class GrantResServiceImplTest {
return addResObj;
}
+ private JSONObject getRemoveResObj() {
+ JSONObject addResObj = new JSONObject();
+ JSONObject virtualCpu = new JSONObject();
+ virtualCpu.put("numVirtualCpu", 1);
+ JSONObject virtualMemory = new JSONObject();
+ virtualMemory.put("virtualMemSize", 1);
+ JSONObject virtualComputeDescriptor = new JSONObject();
+ virtualComputeDescriptor.put("virtualCpu", virtualCpu);
+ virtualComputeDescriptor.put("virtualMemory", virtualMemory);
+ JSONObject virtualStorageDescriptor = new JSONObject();
+ virtualStorageDescriptor.put("typeOfStorage", "");
+ virtualStorageDescriptor.put("sizeOfStorage", "1");
+ JSONObject resourceTemplate = new JSONObject();
+ resourceTemplate.put("virtualComputeDescriptor", virtualComputeDescriptor);
+ resourceTemplate.put("virtualStorageDescriptor", virtualStorageDescriptor);
+ addResObj.put("resourceDefinitionId", "1");
+ addResObj.put("resourceTemplate", resourceTemplate);
+
+ return addResObj;
+ }
+
}