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