Add NFVO Manager Utility Code
[aai/esr-server.git] / esr-mgr / src / test / java / org / onap / aai / esr / util / NfvoManagerUtilTest.java
1 /**
2  * Copyright 2019 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  * Submit by HePeng 10064135
16  */
17 package org.onap.aai.esr.util;
18
19 import com.google.gson.Gson;
20 import org.junit.Test;
21 import org.onap.aai.esr.entity.aai.EsrNfvoDetail;
22 import org.onap.aai.esr.entity.rest.NfvoRegisterInfo;
23
24 import static org.junit.Assert.assertEquals;
25
26 public class NfvoManagerUtilTest {
27     @Test
28     public void nfvoRegisterInfo2EsrNfvoTest()
29     {
30         NfvoManagerUtil nfvoManagerUtil=new NfvoManagerUtil();
31         NfvoRegisterInfo nfvoRegisterInfo=new NfvoRegisterInfo();
32         ExtsysUtil extsysUtil=new ExtsysUtil();
33         nfvoRegisterInfo.setNfvoId("123456");
34         nfvoRegisterInfo.setApiroot("/api/v1/test");
35         nfvoRegisterInfo.setName("NFVO_TEST");
36         nfvoRegisterInfo.setVendor("ZTE");
37         nfvoRegisterInfo.setVersion("v1");
38         nfvoRegisterInfo.setUrl("127.0.0.1");
39         nfvoRegisterInfo.setUserName("root");
40         nfvoRegisterInfo.setPassword("root");
41         EsrNfvoDetail esrNfvoDetail=nfvoManagerUtil.nfvoRegisterInfo2EsrNfvo(nfvoRegisterInfo);
42         esrNfvoDetail.setNfvoId("123456");
43         esrNfvoDetail.setResourceVersion("v2");
44         esrNfvoDetail.getEsrSystemInfoList().getEsrSystemInfo().get(0).setEsrSystemInfoId("654321");
45         String esrnfvoStr = extsysUtil.objectToString(esrNfvoDetail);
46         String expect = "{\"nfvo-id\":\"123456\"," + "\"resource-version\":\"v2\"," +"\"api-root\":\"/api/v1/test\","
47                 + "\"esr-system-info-list\":" + "{\"esr-system-info\":" + "[{\"esr-system-info-id\":\"654321\","
48                 + "\"system-name\":\"NFVO_TEST\"," + "\"vendor\":\"ZTE\"," + "\"version\":\"v1\"," + "\"service-url\":\"127.0.0.1\","
49                 + "\"user-name\":\"root\"," + "\"password\":\"root\","+ "\"system-type\":\"NFVO\"}]}}";
50         assertEquals(expect,esrnfvoStr);
51
52     }
53     @Test
54     public void esrNfvo2NfvoRegisterInfoTest()
55     {
56         EsrNfvoDetail esrNfvoDetail=new EsrNfvoDetail();
57         NfvoRegisterInfo nfvoRegisterInfo = new NfvoRegisterInfo();
58         NfvoManagerUtil nfvoManagerUtil = new NfvoManagerUtil();
59         String esrnfvoStr = "{\"nfvo-id\":\"123456\"," + "\"resource-version\":\"v2\"," +"\"api-root\":\"/api/v1/test\","
60                 + "\"esr-system-info-list\":" + "{\"esr-system-info\":" + "[{\"esr-system-info-id\":\"654321\","
61                 + "\"system-name\":\"NFVO_TEST\"," + "\"vendor\":\"ZTE\","+ "\"version\":\"v1\"," + "\"service-url\":\"127.0.0.1\","
62                 + "\"user-name\":\"root\"," + "\"password\":\"root\","+ "\"system-type\":\"NFVO\"}]}}";
63        esrNfvoDetail=new Gson().fromJson(esrnfvoStr,EsrNfvoDetail.class);
64        nfvoRegisterInfo=nfvoManagerUtil.esrNfvo2NfvoRegisterInfo(esrNfvoDetail);
65        String registerInfoStr = new ExtsysUtil().objectToString(nfvoRegisterInfo);
66        String expect= "{\"nfvoId\":\"123456\"," + "\"name\":\"NFVO_TEST\"," + "\"apiroot\":\"/api/v1/test\","
67                + "\"vendor\":\"ZTE\"," + "\"version\":\"v1\"," +"\"url\":\"127.0.0.1\","+"\"userName\":\"root\","
68                + "\"password\":\"root\"}";
69        assertEquals(registerInfoStr, expect);
70     }
71 }