2 * Copyright 2017 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.aai.esr.util;
18 import static org.junit.Assert.assertEquals;
20 import java.util.ArrayList;
21 import java.util.List;
23 import org.junit.Test;
24 import org.onap.aai.esr.entity.aai.CloudRegionDetail;
25 import org.onap.aai.esr.entity.rest.VimAuthInfo;
26 import org.onap.aai.esr.entity.rest.VimRegisterInfo;
28 import com.google.gson.Gson;
30 public class VimManagerUtilTest {
33 public void vimRegisterInfo2CloudRegionTest() {
34 VimManagerUtil vimManagerUtil = new VimManagerUtil();
35 CloudRegionDetail cloudRegionDetail = new CloudRegionDetail();
36 VimRegisterInfo vimRegisterInfo = new VimRegisterInfo();
37 List<VimAuthInfo> vimAuthInfos = new ArrayList<>();
38 VimAuthInfo vimAuthInfo = new VimAuthInfo();
39 vimAuthInfo.setAuthUrl("http://10.11.22.33:5000/v3");
40 vimAuthInfo.setCloudDomain("default");
41 vimAuthInfo.setPassword("123456");
42 vimAuthInfo.setSslCacert("test");
43 vimAuthInfo.setSslInsecure(true);
44 vimAuthInfo.setUserName("onap");
45 vimAuthInfo.setDefaultTenant("admin");
46 vimRegisterInfo.setCloudExtraInfo("{}");
47 vimRegisterInfo.setCloudOwner("zte");
48 vimRegisterInfo.setCloudRegionId("RegionOne");
49 vimRegisterInfo.setCloudRegionVersion("mitaca");
50 vimRegisterInfo.setCloudType("openstack");
51 vimRegisterInfo.setCloudZone("default");
52 vimRegisterInfo.setComplexName("complex");
53 vimRegisterInfo.setOwnerDefinedType("test");
54 vimRegisterInfo.setStatus("normal");
55 vimAuthInfos.add(vimAuthInfo);
56 vimRegisterInfo.setVimAuthInfos(vimAuthInfos);
57 cloudRegionDetail = vimManagerUtil.vimRegisterInfo2CloudRegion(vimRegisterInfo);
58 cloudRegionDetail.getEsrSystemInfoList().getEsrSystemInfo().get(0).setEsrSystemInfoId("123456");
59 String cloudRegionDetailStr = new ExtsysUtil().objectToString(cloudRegionDetail);
60 String expectResult = "{\"cloud-owner\":\"zte\","
61 + "\"cloud-region-id\":\"RegionOne\","
62 + "\"cloud-type\":\"openstack\","
63 + "\"cloud-region-version\":\"mitaca\","
64 + "\"owner-defined-type\":\"test\","
65 + "\"cloud-zone\":\"default\","
66 + "\"complex-name\":\"complex\","
67 + "\"cloud-extra-info\":\"{}\","
68 + "\"esr-system-info-list\":{"
69 + "\"esr-system-info\":[{"
70 + "\"esr-system-info-id\":\"123456\","
71 + "\"service-url\":\"http://10.11.22.33:5000/v3\","
72 + "\"user-name\":\"onap\","
73 + "\"password\":\"123456\","
74 + "\"system-type\":\"VIM\","
75 + "\"ssl-cassert\":\"test\","
76 + "\"ssl-insecure\":true,"
77 + "\"cloud-domain\":\"default\","
78 + "\"default-tenant\":\"admin\","
79 + "\"system-status\":\"normal\"}]}}";
80 assertEquals(expectResult, cloudRegionDetailStr);
84 public void cloudRegion2VimRegisterInfoTest() {
85 VimManagerUtil vimManagerUtil = new VimManagerUtil();
86 CloudRegionDetail cloudRegionDetail = new CloudRegionDetail();
87 VimRegisterInfo vimRegisterInfo = new VimRegisterInfo();
88 String cloudRegionDetailStr = "{\"cloud-owner\":\"zte\","
89 + "\"cloud-region-id\":\"RegionOne\","
90 + "\"cloud-type\":\"openstack\","
91 + "\"cloud-region-version\":\"mitaca\","
92 + "\"owner-defined-type\":\"test\","
93 + "\"cloud-zone\":\"default\","
94 + "\"complex-name\":\"complex\","
95 + "\"cloud-extra-info\":\"{}\","
96 + "\"esr-system-info-list\":{"
97 + "\"esr-system-info\":[{"
98 + "\"esr-system-info-id\":\"123456\","
99 + "\"service-url\":\"http://10.11.22.33:5000/v3\","
100 + "\"user-name\":\"onap\","
101 + "\"password\":\"123456\","
102 + "\"default-tenant\":\"admin\","
103 + "\"system-type\":\"VIM\","
104 + "\"ssl-cassert\":\"test\","
105 + "\"ssl-insecure\":true,"
106 + "\"cloud-domain\":\"default\","
107 + "\"system-status\":\"normal\"}]}}";
108 cloudRegionDetail = new Gson().fromJson(cloudRegionDetailStr, CloudRegionDetail.class);
109 vimRegisterInfo = vimManagerUtil.cloudRegion2VimRegisterInfo(cloudRegionDetail);
110 String vimRegisterInfoStr = new ExtsysUtil().objectToString(vimRegisterInfo);
111 String expectResult = "{\"cloudOwner\":\"zte\","
112 + "\"cloudRegionId\":\"RegionOne\","
113 + "\"cloudType\":\"openstack\","
114 + "\"cloudRegionVersion\":\"mitaca\","
115 + "\"ownerDefinedType\":\"test\","
116 + "\"cloudZone\":\"default\","
117 + "\"complexName\":\"complex\","
118 + "\"cloudExtraInfo\":\"{}\","
119 + "\"status\":\"normal\","
120 + "\"vimAuthInfos\":[{"
121 + "\"cloudDomain\":\"default\","
122 + "\"userName\":\"onap\","
123 + "\"password\":\"123456\","
124 + "\"authUrl\":\"http://10.11.22.33:5000/v3\","
125 + "\"defaultTenant\":\"admin\","
126 + "\"sslCacert\":\"test\","
127 + "\"sslInsecure\":true}]}";
128 assertEquals(expectResult, vimRegisterInfoStr);