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