Add unit test for sdnc register util.
[aai/esr-server.git] / esr-mgr / src / test / java / org / onap / aai / esr / util / ThirdpartySdncManagerUtilTest.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 import org.junit.Test;
21 import org.onap.aai.esr.entity.aai.EsrEmsDetail;
22 import org.onap.aai.esr.entity.aai.EsrThirdpartySdncDetail;
23 import org.onap.aai.esr.entity.rest.ThirdpartySdncRegisterInfo;
24
25 import com.google.gson.Gson;
26
27 public class ThirdpartySdncManagerUtilTest {
28   
29   @Test
30   public void sdncRegisterInfo2EsrSdncTest() {
31     ThirdpartySdncManagerUtil thirdpartySdncManagerUtil = new ThirdpartySdncManagerUtil();
32     ThirdpartySdncRegisterInfo sdncRegisterInfo = new ThirdpartySdncRegisterInfo();
33     EsrThirdpartySdncDetail esrSdncDetail = new EsrThirdpartySdncDetail();
34     sdncRegisterInfo.setLocation("edge");
35     sdncRegisterInfo.setName("SDNC_TEST");
36     sdncRegisterInfo.setPassword("123987");
37     sdncRegisterInfo.setProductName("thirdparty SDNC");
38     sdncRegisterInfo.setProtocol("protocol");
39     sdncRegisterInfo.setThirdpartySdncId("123456");
40     sdncRegisterInfo.setType("SDNC");
41     sdncRegisterInfo.setUrl("http://127.0.0.1:8000");
42     sdncRegisterInfo.setUserName("nancy");
43     sdncRegisterInfo.setVendor("zte");
44     sdncRegisterInfo.setVersion("v1");
45     esrSdncDetail = thirdpartySdncManagerUtil.sdncRegisterInfo2EsrSdnc(sdncRegisterInfo);
46     esrSdncDetail.setThirdpartySdncId("123456");
47     esrSdncDetail.getEsrSystemInfoList().getEsrSystemInfo().get(0).setEsrSystemInfoId("987654");
48     String esrSdncDetailStr = new ExtsysUtil().objectToString(esrSdncDetail);
49     String expectResult = "{\"thirdparty-sdnc-id\":\"123456\","
50         + "\"location\":\"edge\","
51         + "\"product-name\":\"thirdparty SDNC\","
52         + "\"esr-system-info-list\":{"
53         + "\"esr-system-info\":"
54         + "[{\"esr-system-info-id\":\"987654\","
55         + "\"system-name\":\"SDNC_TEST\","
56         + "\"type\":\"SDNC\","
57         + "\"vendor\":\"zte\","
58         + "\"version\":\"v1\","
59         + "\"service-url\":\"http://127.0.0.1:8000\","
60         + "\"user-name\":\"nancy\","
61         + "\"password\":\"123987\","
62         + "\"system-type\":\"thirdparty_SDNC\","
63         + "\"protocol\":\"protocol\"}]}}";
64     assertEquals(expectResult, esrSdncDetailStr);
65   }
66   
67   @Test
68   public void esrSdnc2SdncRegisterInfoTest() {
69     EsrThirdpartySdncDetail esrSdnc = new EsrThirdpartySdncDetail();
70     String esrSdncStr = "{\"thirdparty-sdnc-id\":\"123456\","
71         + "\"location\":\"edge\","
72         + "\"product-name\":\"thirdparty SDNC\","
73         + "\"esr-system-info-list\":{"
74         + "\"esr-system-info\":"
75         + "[{\"esr-system-info-id\":\"987654\","
76         + "\"system-name\":\"SDNC_TEST\","
77         + "\"type\":\"SDNC\","
78         + "\"vendor\":\"zte\","
79         + "\"version\":\"v1\","
80         + "\"service-url\":\"http://127.0.0.1:8000\","
81         + "\"user-name\":\"nancy\","
82         + "\"password\":\"123987\","
83         + "\"system-type\":\"thirdparty_SDNC\","
84         + "\"protocol\":\"protocol\"}]}}";
85     esrSdnc = new Gson().fromJson(esrSdncStr, EsrThirdpartySdncDetail.class);
86     ThirdpartySdncRegisterInfo registerInfo = new ThirdpartySdncManagerUtil().esrSdnc2SdncRegisterInfo(esrSdnc);
87     String registerInfoStr = new ExtsysUtil().objectToString(registerInfo);
88     String expectResult = "{\"thirdpartySdncId\":\"123456\","
89         + "\"name\":\"SDNC_TEST\","
90         + "\"vendor\":\"zte\","
91         + "\"version\":\"v1\","
92         + "\"type\":\"SDNC\","
93         + "\"location\":\"edge\","
94         + "\"url\":\"http://127.0.0.1:8000\","
95         + "\"userName\":\"nancy\","
96         + "\"password\":\"123987\","
97         + "\"productName\":\"thirdparty SDNC\","
98         + "\"protocol\":\"protocol\"}";
99     assertEquals(expectResult, registerInfoStr);
100   }
101 }