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