ba16be7732403383a6329a8a43031a614ea9a5a8
[aai/esr-server.git] / esr-mgr / src / test / java / org / onap / aai / esr / util / EmsManagerUtilTest.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
20
21 import org.junit.Test;
22 import org.onap.aai.esr.entity.aai.EsrEmsDetail;
23 import org.onap.aai.esr.entity.rest.AlarmAddr;
24 import org.onap.aai.esr.entity.rest.EmsRegisterInfo;
25 import org.onap.aai.esr.entity.rest.FtpAddr;
26
27 import com.google.gson.Gson;
28
29 public class EmsManagerUtilTest {
30   
31   @Test
32   public void getEsrSystemInfoListFromAuthInfoTest() {
33     EmsManagerUtil emsManagerUtil = new EmsManagerUtil();
34     EmsRegisterInfo emsRegisterInfo = new EmsRegisterInfo();
35     EsrEmsDetail esrEms = new EsrEmsDetail();
36     AlarmAddr alarmAddr = new AlarmAddr();
37     FtpAddr resourceAddr = new FtpAddr();
38     FtpAddr performanceAddr = new FtpAddr();
39     alarmAddr.setIp("127.0.0.1");
40     alarmAddr.setPassword("987654");
41     alarmAddr.setPort("5000");
42     alarmAddr.setUser("nancy");
43     resourceAddr.setFtptype("sftp");
44     resourceAddr.setIp("127.0.0.1");
45     resourceAddr.setPassive(true);
46     resourceAddr.setPassword("asdf");
47     resourceAddr.setPort("5000");
48     resourceAddr.setRemotepath("/home/per");
49     resourceAddr.setUser("nancy");
50     performanceAddr.setFtptype("sftp");
51     performanceAddr.setIp("127.0.0.1");
52     performanceAddr.setPassive(true);
53     performanceAddr.setPassword("asdf");
54     performanceAddr.setPort("5000");
55     performanceAddr.setRemotepath("/home/per");
56     performanceAddr.setUser("nancy");
57     emsRegisterInfo.setName("EMS_TEST");
58     emsRegisterInfo.setVendor("ZTE");
59     emsRegisterInfo.setVersion("V1");
60     emsRegisterInfo.setAlarmAddr(alarmAddr);
61     emsRegisterInfo.setResourceAddr(resourceAddr);
62     emsRegisterInfo.setPerformanceAddr(performanceAddr);
63     esrEms = emsManagerUtil.emsRegisterInfo2EsrEms(emsRegisterInfo);
64     esrEms.setEmsId("123456");
65     esrEms.getEsrSystemInfoList().getEsrSystemInfo().get(0).setEsrSystemInfoId("234567");
66     esrEms.getEsrSystemInfoList().getEsrSystemInfo().get(1).setEsrSystemInfoId("345678");
67     esrEms.getEsrSystemInfoList().getEsrSystemInfo().get(2).setEsrSystemInfoId("456789");
68     String esremsStr = new ExtsysUtil().objectToString(esrEms);
69     String expect = "{\"ems-id\":\"123456\","
70         + "\"esr-system-info-list\":"
71         + "{\"esr-system-info\":"
72         + "[{\"esr-system-info-id\":\"234567\","
73         + "\"system-name\":\"EMS_TEST\","
74         + "\"type\":\"sftp\","
75         + "\"vendor\":\"ZTE\","
76         + "\"version\":\"V1\","
77         + "\"user-name\":\"nancy\","
78         + "\"password\":\"asdf\","
79         + "\"system-type\":\"EMS_RESOUCE\","
80         + "\"ip-address\":\"127.0.0.1\","
81         + "\"port\":\"5000\","
82         + "\"passive\":true,"
83         + "\"remote-path\":\"/home/per\"},"
84         + "{\"esr-system-info-id\":\"345678\","
85         + "\"system-name\":\"EMS_TEST\","
86         + "\"type\":\"sftp\","
87         + "\"vendor\":\"ZTE\","
88         + "\"version\":\"V1\","
89         + "\"user-name\":\"nancy\","
90         + "\"password\":\"asdf\","
91         + "\"system-type\":\"EMS_PERFORMANCE\","
92         + "\"ip-address\":\"127.0.0.1\","
93         + "\"port\":\"5000\","
94         + "\"passive\":true,"
95         + "\"remote-path\":\"/home/per\"},"
96         + "{\"esr-system-info-id\":\"456789\","
97         + "\"system-name\":\"EMS_TEST\","
98         + "\"vendor\":\"ZTE\","
99         + "\"version\":\"V1\","
100         + "\"user-name\":\"nancy\","
101         + "\"password\":\"987654\","
102         + "\"system-type\":\"EMS_ALARM\","
103         + "\"ip-address\":\"127.0.0.1\","
104         + "\"port\":\"5000\"}]}}";    
105     assertEquals(expect, esremsStr);
106   }
107   
108   @Test
109   public void EsrEms2EmsRegisterInfoTest() {
110     EsrEmsDetail esrEms = new EsrEmsDetail();
111     EmsRegisterInfo emsRegisterInfo = new EmsRegisterInfo();
112     EmsManagerUtil emsManagerUtil = new EmsManagerUtil();
113     String esrEmsStr = "{\"ems-id\":\"123456\","
114         + "\"esr-system-info-list\":"
115         + "{\"esr-system-info\":"
116         + "[{\"esr-system-info-id\":\"234567\","
117         + "\"system-name\":\"EMS_TEST\","
118         + "\"type\":\"sftp\","
119         + "\"vendor\":\"ZTE\","
120         + "\"version\":\"V1\","
121         + "\"user-name\":\"nancy\","
122         + "\"password\":\"asdf\","
123         + "\"system-type\":\"EMS_RESOUCE\","
124         + "\"ip-address\":\"127.0.0.1\","
125         + "\"port\":\"5000\","
126         + "\"passive\":true,"
127         + "\"remote-path\":\"/home/per\"},"
128         + "{\"esr-system-info-id\":\"345678\","
129         + "\"system-name\":\"EMS_TEST\","
130         + "\"type\":\"sftp\","
131         + "\"vendor\":\"ZTE\","
132         + "\"version\":\"V1\","
133         + "\"user-name\":\"nancy\","
134         + "\"password\":\"asdf\","
135         + "\"system-type\":\"EMS_PERFORMANCE\","
136         + "\"ip-address\":\"127.0.0.1\","
137         + "\"port\":\"5000\","
138         + "\"passive\":true,"
139         + "\"remote-path\":\"/home/per\"},"
140         + "{\"esr-system-info-id\":\"456789\","
141         + "\"system-name\":\"EMS_TEST\","
142         + "\"vendor\":\"ZTE\","
143         + "\"version\":\"V1\","
144         + "\"user-name\":\"nancy\","
145         + "\"password\":\"987654\","
146         + "\"system-type\":\"EMS_ALARM\","
147         + "\"ip-address\":\"127.0.0.1\","
148         + "\"port\":\"5000\"}]}}";
149     esrEms = new Gson().fromJson(esrEmsStr, EsrEmsDetail.class);
150     emsRegisterInfo = emsManagerUtil.EsrEms2EmsRegisterInfo(esrEms);
151     String registerInfoStr = new ExtsysUtil().objectToString(emsRegisterInfo);
152     String expectRegisterInfo = "{\"emsId\":\"123456\","
153         + "\"name\":\"EMS_TEST\","
154         + "\"vendor\":\"ZTE\","
155         + "\"version\":\"V1\","
156         + "\"resourceAddr\":{"
157         + "\"ftptype\":\"sftp\","
158         + "\"ip\":\"127.0.0.1\","
159         + "\"port\":\"5000\","
160         + "\"user\":\"nancy\","
161         + "\"password\":\"asdf\","
162         + "\"remotepath\":\"/home/per\","
163         + "\"passive\":true},"
164         + "\"performanceAddr\":{"
165         + "\"ftptype\":\"sftp\","
166         + "\"ip\":\"127.0.0.1\","
167         + "\"port\":\"5000\","
168         + "\"user\":\"nancy\","
169         + "\"password\":\"asdf\","
170         + "\"remotepath\":\"/home/per\","
171         + "\"passive\":true},"
172         + "\"alarmAddr\":{"
173         + "\"ip\":\"127.0.0.1\","
174         + "\"port\":\"5000\","
175         + "\"user\":\"nancy\","
176         + "\"password\":\"987654\"}}";
177     assertEquals(registerInfoStr, expectRegisterInfo);
178   }
179 }