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.EsrSystemInfo;
25 import org.onap.aai.esr.entity.aai.EsrSystemInfoList;
26 import org.onap.aai.esr.externalservice.cloud.Tenant;
28 public class ExtsysUtilTest {
31 public void objectToStringTest() {
32 ExtsysUtil extsysUtil = new ExtsysUtil();
33 Tenant tenant = new Tenant();
34 tenant.setDefaultTenant("admin");
35 String tenantStr = "{\"defaultTenant\":\"admin\"}";
36 String result = extsysUtil.objectToString(tenant);
37 assertEquals(tenantStr, result);
42 public void getEsrSystemInfoListFromAuthInfoTest() {
43 EsrSystemInfo esrSystemInfoObj = new EsrSystemInfo();
44 ExtsysUtil extsysUtil = new ExtsysUtil();
45 EsrSystemInfoList result = new EsrSystemInfoList();
46 esrSystemInfoObj.setCloudDomain("cloudDomain");
47 esrSystemInfoObj.setDefaultTenant("admin");
48 esrSystemInfoObj.setEsrSystemInfoId("123456");
49 esrSystemInfoObj.setIpAddress("127.0.0.1");
50 esrSystemInfoObj.setPassive(true);
51 esrSystemInfoObj.setPassword("qwelk");
52 esrSystemInfoObj.setPort("5000");
53 esrSystemInfoObj.setProtocol("http");
54 esrSystemInfoObj.setRemotePath("/root/test");
55 esrSystemInfoObj.setServiceUrl("http://127.0.0.1:8080");
56 esrSystemInfoObj.setSslCassert("sslCassert");
57 esrSystemInfoObj.setSslInsecure(false);
58 esrSystemInfoObj.setSystemName("vnfm");
59 esrSystemInfoObj.setSystemStatus("normal");
60 esrSystemInfoObj.setSystemType("VNFM");
61 esrSystemInfoObj.setType("test");
62 esrSystemInfoObj.setUserName("root");
63 esrSystemInfoObj.setVendor("zte");
64 esrSystemInfoObj.setVersion("v1.0");
65 result = extsysUtil.getEsrSystemInfoListFromAuthInfo(esrSystemInfoObj);
67 String listStr = "{\"esr-system-info\":[{"
68 + "\"esr-system-info-id\":\"123456\","
69 + "\"system-name\":\"vnfm\","
70 + "\"type\":\"test\","
71 + "\"vendor\":\"zte\","
72 + "\"version\":\"v1.0\","
73 + "\"service-url\":\"http://127.0.0.1:8080\","
74 + "\"user-name\":\"root\","
75 + "\"password\":\"qwelk\","
76 + "\"system-type\":\"VNFM\","
77 + "\"protocol\":\"http\","
78 + "\"ssl-cassert\":\"sslCassert\","
79 + "\"ssl-insecure\":false,"
80 + "\"ip-address\":\"127.0.0.1\","
81 + "\"port\":\"5000\","
82 + "\"cloud-domain\":\"cloudDomain\","
83 + "\"default-tenant\":\"admin\","
85 + "\"remote-path\":\"/root/test\","
86 + "\"system-status\":\"normal\"}]}";
87 assertEquals(extsysUtil.objectToString(result), listStr);
91 public void getEsrSystemInfoListFromAuthInfoListTest() {
92 List<EsrSystemInfo> esrSystemInfos = new ArrayList<>();
93 EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList();
94 EsrSystemInfo esrSystemInfoObj = new EsrSystemInfo();
95 ExtsysUtil extsysUtil = new ExtsysUtil();
96 esrSystemInfoObj.setCloudDomain("cloudDomain");
97 esrSystemInfoObj.setDefaultTenant("admin");
98 esrSystemInfoObj.setEsrSystemInfoId("123456");
99 esrSystemInfoObj.setIpAddress("127.0.0.1");
100 esrSystemInfoObj.setPassive(true);
101 esrSystemInfoObj.setPassword("qwelk");
102 esrSystemInfoObj.setPort("5000");
103 esrSystemInfoObj.setProtocol("http");
104 esrSystemInfoObj.setRemotePath("/root/test");
105 esrSystemInfoObj.setServiceUrl("http://127.0.0.1:8080");
106 esrSystemInfoObj.setSslCassert("sslCassert");
107 esrSystemInfoObj.setSslInsecure(false);
108 esrSystemInfoObj.setSystemName("vnfm");
109 esrSystemInfoObj.setSystemStatus("normal");
110 esrSystemInfoObj.setSystemType("VNFM");
111 esrSystemInfoObj.setType("test");
112 esrSystemInfoObj.setUserName("root");
113 esrSystemInfoObj.setVendor("zte");
114 esrSystemInfoObj.setVersion("v1.0");
115 esrSystemInfos.add(esrSystemInfoObj);
116 esrSystemInfoList.setEsrSystemInfo(esrSystemInfos);
118 String listStr = "{\"esr-system-info\":[{"
119 + "\"esr-system-info-id\":\"123456\","
120 + "\"system-name\":\"vnfm\","
121 + "\"type\":\"test\","
122 + "\"vendor\":\"zte\","
123 + "\"version\":\"v1.0\","
124 + "\"service-url\":\"http://127.0.0.1:8080\","
125 + "\"user-name\":\"root\","
126 + "\"password\":\"qwelk\","
127 + "\"system-type\":\"VNFM\","
128 + "\"protocol\":\"http\","
129 + "\"ssl-cassert\":\"sslCassert\","
130 + "\"ssl-insecure\":false,"
131 + "\"ip-address\":\"127.0.0.1\","
132 + "\"port\":\"5000\","
133 + "\"cloud-domain\":\"cloudDomain\","
134 + "\"default-tenant\":\"admin\","
135 + "\"passive\":true,"
136 + "\"remote-path\":\"/root/test\","
137 + "\"system-status\":\"normal\"}]}";
138 assertEquals(extsysUtil.objectToString(esrSystemInfoList), listStr);