summaryrefslogtreecommitdiffstats
path: root/esr-mgr
diff options
context:
space:
mode:
authorLizi <li.zi30@zte.com.cn>2018-01-26 07:46:04 +0000
committerLizi <li.zi30@zte.com.cn>2018-01-26 07:46:15 +0000
commit2e2b4f785ebf9e7c61e598cc743e70177a2f80f6 (patch)
tree7eb7bc7209f03f1e0d84cdf0fb18ad39fd3ba57a /esr-mgr
parent374c870c299e915ae705c202a0a5f0fef024542c (diff)
Add the unit test for Vim manage function.
Change-Id: Ibe4ed95512af0b67674f2ee14e20924050c1875f Issue-ID: AAI-500 Signed-off-by: Lizi <li.zi30@zte.com.cn>
Diffstat (limited to 'esr-mgr')
-rw-r--r--esr-mgr/src/test/java/org/onap/aai/esr/wrapper/VimManagerWrapperTest.java179
1 files changed, 179 insertions, 0 deletions
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
new file mode 100644
index 0000000..74fbde0
--- /dev/null
+++ b/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/VimManagerWrapperTest.java
@@ -0,0 +1,179 @@
+/**
+ * Copyright 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.aai.esr.wrapper;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.ws.rs.core.Response;
+import org.junit.Assert;
+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.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;
+
+public class VimManagerWrapperTest {
+
+ static {
+ MsbConfig.setMsbServerAddr("http://127.0.0.1:80");
+ }
+
+ @Test
+ public void test_registerVim() throws ExtsysException {
+ VimRegisterInfo vimRegisterInfo = new VimRegisterInfo();
+ List<VimAuthInfo> vimAuthInfos = new ArrayList<>();
+ vimRegisterInfo.setCloudExtraInfo("{}");
+ vimRegisterInfo.setCloudOwner("zte");
+ vimRegisterInfo.setCloudRegionId("RegionOne");
+ vimRegisterInfo.setCloudRegionVersion("mitaca");
+ vimRegisterInfo.setCloudType("openstack");
+ vimRegisterInfo.setCloudZone("default");
+ vimRegisterInfo.setComplexName("complex");
+ vimRegisterInfo.setOwnerDefinedType("test");
+ vimRegisterInfo.setStatus("normal");
+ VimAuthInfo vimAuthInfo = new VimAuthInfo();
+ vimAuthInfo.setAuthUrl("http://10.11.22.33:5000/v3");
+ vimAuthInfo.setCloudDomain("default");
+ vimAuthInfo.setPassword("123456");
+ vimAuthInfo.setSslCacert("test");
+ vimAuthInfo.setSslInsecure(true);
+ vimAuthInfo.setUserName("onap");
+ vimAuthInfo.setDefaultTenant("admin");
+ vimAuthInfos.add(vimAuthInfo);
+ vimRegisterInfo.setVimAuthInfos(vimAuthInfos);
+ CloudRegionProxy mockCloudRegionProxy = Mockito.mock(CloudRegionProxy.class);
+ Mockito.doNothing().when(mockCloudRegionProxy).registerVim(Mockito.anyString(), Mockito.anyString(),
+ (CloudRegionDetail) Mockito.anyObject());
+ VimManagerWrapper vimManagerWrapper = new VimManagerWrapper(mockCloudRegionProxy);
+ Response response = vimManagerWrapper.registerVim(vimRegisterInfo);
+ if (response != null) {
+ Assert.assertTrue(response.getStatus() == 200);
+ }
+ }
+
+ @Test
+ public void test_queryVimById() throws ExtsysException {
+ CloudRegionProxy mockCloudRegionProxy = Mockito.mock(CloudRegionProxy.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\","
+ + "\"cloud-extra-info\":\"{}\"," + "\"esr-system-info-list\":{" + "\"esr-system-info\":[{"
+ + "\"esr-system-info-id\":\"123456\"," + "\"service-url\":\"http://10.11.22.33:5000/v3\","
+ + "\"user-name\":\"onap\"," + "\"password\":\"123456\"," + "\"system-type\":\"VIM\","
+ + "\"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);
+ Response response = vimManagerWrapper.queryVimById("zte", "RegionOne");
+ if (response != null) {
+ Assert.assertTrue(response.getStatus() == 200);
+ }
+ }
+
+ @Test
+ public void test_queryVimListDetails() throws ExtsysException {
+ CloudRegionProxy mockCloudRegionProxy = Mockito.mock(CloudRegionProxy.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\","
+ + "\"cloud-extra-info\":\"{}\"," + "\"esr-system-info-list\":{" + "\"esr-system-info\":[{"
+ + "\"esr-system-info-id\":\"123456\"," + "\"service-url\":\"http://10.11.22.33:5000/v3\","
+ + "\"user-name\":\"onap\"," + "\"password\":\"123456\"," + "\"system-type\":\"VIM\","
+ + "\"ssl-cassert\":\"test\"," + "\"ssl-insecure\":true," + "\"cloud-domain\":\"default\","
+ + "\"default-tenant\":\"admin\"," + "\"system-status\":\"normal\"}]}}";
+ String vimListStr = "{\"cloud-region\": [{\"cloud-owner\": \"zte\"," + "\"cloud-region-id\": \"RegionOne\","
+ + "\"cloud-type\": \"openstack\"," + "\"owner-defined-type\": \"test\","
+ + "\"cloud-region-version\": \"mitaca\"," + "\"identity-url\": \"http://10.11.22.33:5000/v3\","
+ + "\"cloud-zone\": \"default\"," + "\"complex-name\": \"complex\"," + "\"sriov-automation\": true,"
+ + "\"cloud-extra-info\": \"{}\"," + "\"resource-version\": \"123456\"}]}";
+ Mockito.when(mockCloudRegionProxy.queryVimDetail(Mockito.anyString(), Mockito.anyString()))
+ .thenReturn(vimdetail);
+ Mockito.when(mockCloudRegionProxy.qureyVimList()).thenReturn(vimListStr);
+
+ VimManagerWrapper vimManagerWrapper = new VimManagerWrapper(mockCloudRegionProxy);
+ Response response = vimManagerWrapper.queryVimById("zte", "RegionOne");
+ if (response != null) {
+ Assert.assertTrue(response.getStatus() == 200);
+ }
+ }
+
+ @Test
+ public void test_updateVim() throws ExtsysException {
+ VimRegisterInfo vimRegisterInfo = new VimRegisterInfo();
+ List<VimAuthInfo> vimAuthInfos = new ArrayList<>();
+ VimAuthInfo vimAuthInfo = new VimAuthInfo();
+ vimAuthInfo.setAuthUrl("http://10.11.22.33:5000/v3");
+ vimAuthInfo.setCloudDomain("default");
+ vimAuthInfo.setPassword("123456");
+ vimAuthInfo.setSslCacert("test");
+ vimAuthInfo.setSslInsecure(true);
+ vimAuthInfo.setUserName("onap");
+ vimAuthInfo.setDefaultTenant("admin");
+ vimRegisterInfo.setCloudExtraInfo("{}");
+ vimRegisterInfo.setCloudOwner("zte");
+ vimRegisterInfo.setCloudRegionId("RegionOne");
+ vimRegisterInfo.setCloudRegionVersion("mitaca");
+ vimRegisterInfo.setCloudType("openstack");
+ vimRegisterInfo.setCloudZone("default");
+ vimRegisterInfo.setComplexName("complex");
+ vimRegisterInfo.setOwnerDefinedType("test");
+ vimRegisterInfo.setStatus("normal");
+ vimAuthInfos.add(vimAuthInfo);
+ vimRegisterInfo.setVimAuthInfos(vimAuthInfos);
+ CloudRegionProxy mockCloudRegionProxy = Mockito.mock(CloudRegionProxy.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\","
+ + "\"cloud-extra-info\":\"{}\"," + "\"esr-system-info-list\":{" + "\"esr-system-info\":[{"
+ + "\"esr-system-info-id\":\"123456\"," + "\"service-url\":\"http://10.11.22.33:5000/v3\","
+ + "\"user-name\":\"onap\"," + "\"password\":\"123456\"," + "\"system-type\":\"VIM\","
+ + "\"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);
+ Mockito.doNothing().when(mockCloudRegionProxy).registerVim(Mockito.anyString(), Mockito.anyString(),
+ (CloudRegionDetail) Mockito.anyObject());
+ VimManagerWrapper vimManagerWrapper = new VimManagerWrapper(mockCloudRegionProxy);
+ Response response = vimManagerWrapper.updateVim("zte", "RegionOne", vimRegisterInfo);
+ if (response != null) {
+ Assert.assertTrue(response.getStatus() == 200);
+ }
+ }
+
+ @Test
+ public void test_delVim() throws ExtsysException {
+ CloudRegionProxy mockCloudRegionProxy = Mockito.mock(CloudRegionProxy.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\","
+ + "\"cloud-extra-info\":\"{}\"," + "\"esr-system-info-list\":{" + "\"esr-system-info\":[{"
+ + "\"esr-system-info-id\":\"123456\"," + "\"service-url\":\"http://10.11.22.33:5000/v3\","
+ + "\"user-name\":\"onap\"," + "\"password\":\"123456\"," + "\"system-type\":\"VIM\","
+ + "\"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);
+ Mockito.doNothing().when(mockCloudRegionProxy).deleteVim(Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
+ VimManagerWrapper vimManagerWrapper = new VimManagerWrapper(mockCloudRegionProxy);
+ Response response = vimManagerWrapper.delVim("zte", "RegionOne");
+ if (response != null) {
+ Assert.assertTrue(response.getStatus() == 204);
+ }
+ }
+}