summaryrefslogtreecommitdiffstats
path: root/esr-mgr
diff options
context:
space:
mode:
authorLiZi <li.zi30@zte.com.cn>2018-03-02 01:14:49 -0500
committerLiZi <li.zi30@zte.com.cn>2018-03-02 01:14:58 -0500
commit0ab46140874180b586d578c79c75621697b7a3b1 (patch)
treeca8b7df39a5022bf616c15a1b97e2e6cb2177c38 /esr-mgr
parent1d8aafe77787e3c86ec53075cd0eaf3536316aef (diff)
Add unit test for the newly API.
Add unit test for the API of query complexes and create relationship between cloud region and complex Change-Id: I1a5b4b53346e820f66946482ce27f4273d842e88 Issue-ID: AAI-830 Signed-off-by: LiZi <li.zi30@zte.com.cn>
Diffstat (limited to 'esr-mgr')
-rw-r--r--esr-mgr/src/main/java/org/onap/aai/esr/externalservice/cloud/VimManagerProxy.java10
-rw-r--r--esr-mgr/src/main/java/org/onap/aai/esr/wrapper/VimManagerWrapper.java9
-rw-r--r--esr-mgr/src/test/java/org/onap/aai/esr/externalservice/cloud/VimManagerProxyTest.java5
-rw-r--r--esr-mgr/src/test/java/org/onap/aai/esr/wrapper/VimManagerWrapperTest.java37
4 files changed, 46 insertions, 15 deletions
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/cloud/VimManagerProxy.java b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/cloud/VimManagerProxy.java
index 8e086a9..4822e27 100644
--- a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/cloud/VimManagerProxy.java
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/cloud/VimManagerProxy.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2018 ZTE Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,11 +22,11 @@ import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
public class VimManagerProxy {
- private VimManagerProxy() {
-
- }
+// private VimManagerProxy() {
+//
+// }
- public static void updateVim(String cloudOwner, String cloudRegionId, Tenant tenant) throws ExtsysException {
+ public void updateVim(String cloudOwner, String cloudRegionId, Tenant tenant) throws ExtsysException {
ClientConfig config = new ClientConfig(new VimUpdateProvider());
IVimManage updateVimServiceproxy =
ConsumerFactory.createConsumer(MsbConfig.getMultiCloudAddr(), config, IVimManage.class);
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/VimManagerWrapper.java b/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/VimManagerWrapper.java
index 3003159..82c6f77 100644
--- a/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/VimManagerWrapper.java
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/VimManagerWrapper.java
@@ -46,6 +46,8 @@ public class VimManagerWrapper {
private static VimManagerUtil vimManagerUtil = new VimManagerUtil();
private static CloudRegionProxy cloudRegionProxy = new CloudRegionProxy();
+
+ private static VimManagerProxy vimManagerProxy = new VimManagerProxy();
private static ExtsysUtil extsysUtil = new ExtsysUtil();
@@ -56,13 +58,14 @@ public class VimManagerWrapper {
*/
public static VimManagerWrapper getInstance() {
if (vimManagerWrapper == null) {
- vimManagerWrapper = new VimManagerWrapper(cloudRegionProxy);
+ vimManagerWrapper = new VimManagerWrapper(cloudRegionProxy, vimManagerProxy);
}
return vimManagerWrapper;
}
- public VimManagerWrapper(CloudRegionProxy cloudRegionProxy) {
+ public VimManagerWrapper(CloudRegionProxy cloudRegionProxy, VimManagerProxy vimManagerProxy) {
VimManagerWrapper.cloudRegionProxy = cloudRegionProxy;
+ VimManagerWrapper.vimManagerProxy = vimManagerProxy;
}
public Response registerVim(VimRegisterInfo vimRegisterInfo) {
@@ -91,7 +94,7 @@ public class VimManagerWrapper {
Tenant tenant = new Tenant();
tenant.setDefaultTenant(cloudRegion.getEsrSystemInfoList().getEsrSystemInfo().get(0).getDefaultTenant());
try {
- VimManagerProxy.updateVim(cloudOwner, cloudRegionId, tenant);
+ vimManagerProxy.updateVim(cloudOwner, cloudRegionId, tenant);
} catch (ExtsysException e) {
LOG.error("Update VIM by Multi-cloud failed !", e);
}
diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/externalservice/cloud/VimManagerProxyTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/externalservice/cloud/VimManagerProxyTest.java
index 664f44c..c4ff540 100644
--- a/esr-mgr/src/test/java/org/onap/aai/esr/externalservice/cloud/VimManagerProxyTest.java
+++ b/esr-mgr/src/test/java/org/onap/aai/esr/externalservice/cloud/VimManagerProxyTest.java
@@ -23,9 +23,12 @@ import org.onap.aai.esr.exception.ExtsysException;
public class VimManagerProxyTest {
+ VimManagerProxy proxy;
+
@Before
public void init() {
MsbConfig.setMsbServerAddr("http://msb-server");
+ proxy = new VimManagerProxy();
}
@Test(expected = ExtsysException.class)
@@ -33,6 +36,6 @@ public class VimManagerProxyTest {
Tenant tenant = new Tenant();
tenant.setDefaultTenant("defaultTenant");
Assert.assertEquals(tenant.getDefaultTenant(), "defaultTenant");
- VimManagerProxy.updateVim("owner-1", "region-1", tenant);
+ proxy.updateVim("owner-1", "region-1", tenant);
}
}
diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/VimManagerWrapperTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/VimManagerWrapperTest.java
index 4c82147..3531852 100644
--- a/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/VimManagerWrapperTest.java
+++ b/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/VimManagerWrapperTest.java
@@ -23,10 +23,13 @@ import org.junit.Test;
import org.mockito.Mockito;
import org.onap.aai.esr.common.MsbConfig;
import org.onap.aai.esr.entity.aai.CloudRegionDetail;
+import org.onap.aai.esr.entity.aai.Relationship;
import org.onap.aai.esr.entity.rest.VimAuthInfo;
import org.onap.aai.esr.entity.rest.VimRegisterInfo;
import org.onap.aai.esr.exception.ExtsysException;
import org.onap.aai.esr.externalservice.aai.CloudRegionProxy;
+import org.onap.aai.esr.externalservice.cloud.Tenant;
+import org.onap.aai.esr.externalservice.cloud.VimManagerProxy;
public class VimManagerWrapperTest {
@@ -60,10 +63,14 @@ public class VimManagerWrapperTest {
vimRegisterInfo.setVimAuthInfos(vimAuthInfos);
String complexStr = "{\"physical-location-id\": \"complex\", \"data-center-code\": \"test\", \"complex-name\": \"complex\"}";
CloudRegionProxy mockCloudRegionProxy = Mockito.mock(CloudRegionProxy.class);
+ VimManagerProxy mockVimManagerProxy = Mockito.mock(VimManagerProxy.class);
Mockito.doNothing().when(mockCloudRegionProxy).registerVim(Mockito.anyString(), Mockito.anyString(),
(CloudRegionDetail) Mockito.anyObject());
+ Mockito.doNothing().when(mockCloudRegionProxy).createCloudRegionRelationShip(Mockito.anyString(), Mockito.anyString(),
+ (Relationship) Mockito.anyObject());
Mockito.when(mockCloudRegionProxy.queryComplex(Mockito.anyString())).thenReturn(complexStr);
- VimManagerWrapper vimManagerWrapper = new VimManagerWrapper(mockCloudRegionProxy);
+ Mockito.doNothing().when(mockVimManagerProxy).updateVim(Mockito.anyString(), Mockito.anyString(), (Tenant) Mockito.anyObject());
+ VimManagerWrapper vimManagerWrapper = new VimManagerWrapper(mockCloudRegionProxy, mockVimManagerProxy);
Response response = vimManagerWrapper.registerVim(vimRegisterInfo);
if (response != null) {
Assert.assertTrue(response.getStatus() == 200);
@@ -73,6 +80,7 @@ public class VimManagerWrapperTest {
@Test
public void test_queryVimById() throws ExtsysException {
CloudRegionProxy mockCloudRegionProxy = Mockito.mock(CloudRegionProxy.class);
+ VimManagerProxy mockVimManagerProxy = Mockito.mock(VimManagerProxy.class);
String vimdetail = "{\"cloud-owner\":\"zte\"," + "\"cloud-region-id\":\"RegionOne\","
+ "\"cloud-type\":\"openstack\"," + "\"cloud-region-version\":\"mitaca\","
+ "\"owner-defined-type\":\"test\"," + "\"cloud-zone\":\"default\"," + "\"complex-name\":\"complex\","
@@ -82,7 +90,7 @@ public class VimManagerWrapperTest {
+ "\"ssl-cassert\":\"test\"," + "\"ssl-insecure\":true," + "\"cloud-domain\":\"default\","
+ "\"default-tenant\":\"admin\"," + "\"system-status\":\"normal\"}]}}";
Mockito.when(mockCloudRegionProxy.queryVimDetail(Mockito.anyString(),Mockito.anyString())).thenReturn(vimdetail);
- VimManagerWrapper vimManagerWrapper = new VimManagerWrapper(mockCloudRegionProxy);
+ VimManagerWrapper vimManagerWrapper = new VimManagerWrapper(mockCloudRegionProxy, mockVimManagerProxy);
Response response = vimManagerWrapper.queryVimById("zte", "RegionOne");
if (response != null) {
Assert.assertTrue(response.getStatus() == 200);
@@ -92,6 +100,7 @@ public class VimManagerWrapperTest {
@Test
public void test_queryVimListDetails() throws ExtsysException {
CloudRegionProxy mockCloudRegionProxy = Mockito.mock(CloudRegionProxy.class);
+ VimManagerProxy mockVimManagerProxy = Mockito.mock(VimManagerProxy.class);
String vimdetail = "{\"cloud-owner\":\"zte\"," + "\"cloud-region-id\":\"RegionOne\","
+ "\"cloud-type\":\"openstack\"," + "\"cloud-region-version\":\"mitaca\","
+ "\"owner-defined-type\":\"test\"," + "\"cloud-zone\":\"default\"," + "\"complex-name\":\"complex\","
@@ -108,8 +117,7 @@ public class VimManagerWrapperTest {
Mockito.when(mockCloudRegionProxy.queryVimDetail(Mockito.anyString(), Mockito.anyString()))
.thenReturn(vimdetail);
Mockito.when(mockCloudRegionProxy.qureyVimList()).thenReturn(vimListStr);
-
- VimManagerWrapper vimManagerWrapper = new VimManagerWrapper(mockCloudRegionProxy);
+ VimManagerWrapper vimManagerWrapper = new VimManagerWrapper(mockCloudRegionProxy, mockVimManagerProxy);
Response response = vimManagerWrapper.queryVimListDetails();
if (response != null) {
Assert.assertTrue(response.getStatus() == 200);
@@ -141,6 +149,7 @@ public class VimManagerWrapperTest {
vimAuthInfos.add(vimAuthInfo);
vimRegisterInfo.setVimAuthInfos(vimAuthInfos);
CloudRegionProxy mockCloudRegionProxy = Mockito.mock(CloudRegionProxy.class);
+ VimManagerProxy mockVimManagerProxy = Mockito.mock(VimManagerProxy.class);
String vimdetail = "{\"cloud-owner\":\"zte\"," + "\"cloud-region-id\":\"RegionOne\","
+ "\"cloud-type\":\"openstack\"," + "\"cloud-region-version\":\"mitaca\","
+ "\"owner-defined-type\":\"test\"," + "\"cloud-zone\":\"default\"," + "\"complex-name\":\"complex\","
@@ -153,7 +162,7 @@ public class VimManagerWrapperTest {
.thenReturn(vimdetail);
Mockito.doNothing().when(mockCloudRegionProxy).registerVim(Mockito.anyString(), Mockito.anyString(),
(CloudRegionDetail) Mockito.anyObject());
- VimManagerWrapper vimManagerWrapper = new VimManagerWrapper(mockCloudRegionProxy);
+ VimManagerWrapper vimManagerWrapper = new VimManagerWrapper(mockCloudRegionProxy, mockVimManagerProxy);
Response response = vimManagerWrapper.updateVim("zte", "RegionOne", vimRegisterInfo);
if (response != null) {
Assert.assertTrue(response.getStatus() == 200);
@@ -163,6 +172,7 @@ public class VimManagerWrapperTest {
@Test
public void test_delVim() throws ExtsysException {
CloudRegionProxy mockCloudRegionProxy = Mockito.mock(CloudRegionProxy.class);
+ VimManagerProxy mockVimManagerProxy = Mockito.mock(VimManagerProxy.class);
String vimdetail = "{\"cloud-owner\":\"zte\"," + "\"cloud-region-id\":\"RegionOne\","
+ "\"cloud-type\":\"openstack\"," + "\"cloud-region-version\":\"mitaca\","
+ "\"owner-defined-type\":\"test\"," + "\"cloud-zone\":\"default\"," + "\"complex-name\":\"complex\","
@@ -174,10 +184,25 @@ public class VimManagerWrapperTest {
Mockito.when(mockCloudRegionProxy.queryVimDetail(Mockito.anyString(), Mockito.anyString()))
.thenReturn(vimdetail);
Mockito.doNothing().when(mockCloudRegionProxy).deleteVim(Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
- VimManagerWrapper vimManagerWrapper = new VimManagerWrapper(mockCloudRegionProxy);
+ VimManagerWrapper vimManagerWrapper = new VimManagerWrapper(mockCloudRegionProxy, mockVimManagerProxy);
Response response = vimManagerWrapper.delVim("zte", "RegionOne");
if (response != null) {
Assert.assertTrue(response.getStatus() == 204);
}
}
+
+ @Test
+ public void test_queryComplexes() throws ExtsysException {
+ CloudRegionProxy mockCloudRegionProxy = Mockito.mock(CloudRegionProxy.class);
+ VimManagerProxy mockVimManagerProxy = Mockito.mock(VimManagerProxy.class);
+ String complexListStr =
+ "{\"complex\": [{\"physical-location-id\": \"123\",\"complex-name\": \"complex1\"},"
+ + "{\"physical-location-id\": \"test\",\"complex-name\": \"complex\"}]}";
+ Mockito.when(mockCloudRegionProxy.qureyComplexes()).thenReturn(complexListStr);
+ VimManagerWrapper vimManagerWrapper = new VimManagerWrapper(mockCloudRegionProxy, mockVimManagerProxy);
+ Response response = vimManagerWrapper.queryComplexes();
+ if (response != null) {
+ Assert.assertTrue(response.getStatus() == 200);
+ }
+ }
}