Fix the java code style issue.
[aai/esr-server.git] / esr-mgr / src / test / java / org / onap / aai / esr / util / VimManagerUtilTest.java
1 /**
2  * Copyright 2017 ZTE Corporation.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.aai.esr.util;
17
18 import static org.junit.Assert.assertEquals;
19 import java.util.ArrayList;
20 import java.util.List;
21 import org.junit.Test;
22 import org.onap.aai.esr.entity.aai.CloudRegionDetail;
23 import org.onap.aai.esr.entity.rest.VimAuthInfo;
24 import org.onap.aai.esr.entity.rest.VimRegisterInfo;
25 import com.google.gson.Gson;
26
27 public class VimManagerUtilTest {
28
29     @Test
30     public void vimRegisterInfo2CloudRegionTest() {
31         VimManagerUtil vimManagerUtil = new VimManagerUtil();
32         CloudRegionDetail cloudRegionDetail = new CloudRegionDetail();
33         VimRegisterInfo vimRegisterInfo = new VimRegisterInfo();
34         List<VimAuthInfo> vimAuthInfos = new ArrayList<>();
35         VimAuthInfo vimAuthInfo = new VimAuthInfo();
36         vimAuthInfo.setAuthUrl("http://10.11.22.33:5000/v3");
37         vimAuthInfo.setCloudDomain("default");
38         vimAuthInfo.setPassword("123456");
39         vimAuthInfo.setSslCacert("test");
40         vimAuthInfo.setSslInsecure(true);
41         vimAuthInfo.setUserName("onap");
42         vimAuthInfo.setDefaultTenant("admin");
43         vimRegisterInfo.setCloudExtraInfo("{}");
44         vimRegisterInfo.setCloudOwner("zte");
45         vimRegisterInfo.setCloudRegionId("RegionOne");
46         vimRegisterInfo.setCloudRegionVersion("mitaca");
47         vimRegisterInfo.setCloudType("openstack");
48         vimRegisterInfo.setCloudZone("default");
49         vimRegisterInfo.setComplexName("complex");
50         vimRegisterInfo.setOwnerDefinedType("test");
51         vimRegisterInfo.setStatus("normal");
52         vimAuthInfos.add(vimAuthInfo);
53         vimRegisterInfo.setVimAuthInfos(vimAuthInfos);
54         cloudRegionDetail = vimManagerUtil.vimRegisterInfo2CloudRegion(vimRegisterInfo);
55         cloudRegionDetail.getEsrSystemInfoList().getEsrSystemInfo().get(0).setEsrSystemInfoId("123456");
56         String cloudRegionDetailStr = new ExtsysUtil().objectToString(cloudRegionDetail);
57         String expectResult = "{\"cloud-owner\":\"zte\"," + "\"cloud-region-id\":\"RegionOne\","
58                 + "\"cloud-type\":\"openstack\"," + "\"cloud-region-version\":\"mitaca\","
59                 + "\"owner-defined-type\":\"test\"," + "\"cloud-zone\":\"default\"," + "\"complex-name\":\"complex\","
60                 + "\"cloud-extra-info\":\"{}\"," + "\"esr-system-info-list\":{" + "\"esr-system-info\":[{"
61                 + "\"esr-system-info-id\":\"123456\"," + "\"service-url\":\"http://10.11.22.33:5000/v3\","
62                 + "\"user-name\":\"onap\"," + "\"password\":\"123456\"," + "\"system-type\":\"VIM\","
63                 + "\"ssl-cassert\":\"test\"," + "\"ssl-insecure\":true," + "\"cloud-domain\":\"default\","
64                 + "\"default-tenant\":\"admin\"," + "\"system-status\":\"normal\"}]}}";
65         assertEquals(expectResult, cloudRegionDetailStr);
66     }
67
68     @Test
69     public void cloudRegion2VimRegisterInfoTest() {
70         VimManagerUtil vimManagerUtil = new VimManagerUtil();
71         CloudRegionDetail cloudRegionDetail = new CloudRegionDetail();
72         VimRegisterInfo vimRegisterInfo = new VimRegisterInfo();
73         String cloudRegionDetailStr = "{\"cloud-owner\":\"zte\"," + "\"cloud-region-id\":\"RegionOne\","
74                 + "\"cloud-type\":\"openstack\"," + "\"cloud-region-version\":\"mitaca\","
75                 + "\"owner-defined-type\":\"test\"," + "\"cloud-zone\":\"default\"," + "\"complex-name\":\"complex\","
76                 + "\"cloud-extra-info\":\"{}\"," + "\"esr-system-info-list\":{" + "\"esr-system-info\":[{"
77                 + "\"esr-system-info-id\":\"123456\"," + "\"service-url\":\"http://10.11.22.33:5000/v3\","
78                 + "\"user-name\":\"onap\"," + "\"password\":\"123456\"," + "\"default-tenant\":\"admin\","
79                 + "\"system-type\":\"VIM\"," + "\"ssl-cassert\":\"test\"," + "\"ssl-insecure\":true,"
80                 + "\"cloud-domain\":\"default\"," + "\"system-status\":\"normal\"}]}}";
81         cloudRegionDetail = new Gson().fromJson(cloudRegionDetailStr, CloudRegionDetail.class);
82         vimRegisterInfo = vimManagerUtil.cloudRegion2VimRegisterInfo(cloudRegionDetail);
83         String vimRegisterInfoStr = new ExtsysUtil().objectToString(vimRegisterInfo);
84         String expectResult = "{\"cloudOwner\":\"zte\"," + "\"cloudRegionId\":\"RegionOne\","
85                 + "\"cloudType\":\"openstack\"," + "\"cloudRegionVersion\":\"mitaca\","
86                 + "\"ownerDefinedType\":\"test\"," + "\"cloudZone\":\"default\"," + "\"complexName\":\"complex\","
87                 + "\"cloudExtraInfo\":\"{}\"," + "\"status\":\"normal\"," + "\"vimAuthInfos\":[{"
88                 + "\"cloudDomain\":\"default\"," + "\"userName\":\"onap\"," + "\"password\":\"123456\","
89                 + "\"authUrl\":\"http://10.11.22.33:5000/v3\"," + "\"defaultTenant\":\"admin\","
90                 + "\"sslCacert\":\"test\"," + "\"sslInsecure\":true}]}";
91         assertEquals(expectResult, vimRegisterInfoStr);
92     }
93 }