2 * Copyright 2017 ZTE Corporation.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.aai.esr.util;
18 import static org.junit.Assert.assertEquals;
19 import org.junit.Test;
20 import org.onap.aai.esr.entity.aai.EsrVnfmDetail;
21 import org.onap.aai.esr.entity.rest.VnfmRegisterInfo;
22 import com.google.gson.Gson;
24 public class VnfmManagerUtilTest {
27 public void vnfmRegisterInfo2EsrVnfmTest() {
28 VnfmManagerUtil vnfmManagerUtil = new VnfmManagerUtil();
29 VnfmRegisterInfo vnfmRegisterInfo = new VnfmRegisterInfo();
30 EsrVnfmDetail esrVnfmDetail = new EsrVnfmDetail();
31 vnfmRegisterInfo.setVimId("987654");
32 vnfmRegisterInfo.setVersion("v1");
33 vnfmRegisterInfo.setVendor("zte");
34 vnfmRegisterInfo.setUserName("onap");
35 vnfmRegisterInfo.setUrl("http://10.11.22.33:8000");
36 vnfmRegisterInfo.setType("vnfm");
37 vnfmRegisterInfo.setPassword("987654");
38 vnfmRegisterInfo.setName("ONAP VNFM");
39 vnfmRegisterInfo.setCertificateUrl("http://11.22.33.44:5000/v3");
40 esrVnfmDetail = vnfmManagerUtil.vnfmRegisterInfo2EsrVnfm(vnfmRegisterInfo);
41 esrVnfmDetail.setVnfmId("123456");
42 esrVnfmDetail.getEsrSystemInfoList().getEsrSystemInfo().get(0).setEsrSystemInfoId("qwerty");
43 String esrVnfmDetailStr = new ExtsysUtil().objectToString(esrVnfmDetail);
44 String expectResult = "{\"vnfm-id\":\"123456\"," + "\"vim-id\":\"987654\","
45 + "\"certificate-url\":\"http://11.22.33.44:5000/v3\"," + "\"esr-system-info-list\":{"
46 + "\"esr-system-info\":[{" + "\"esr-system-info-id\":\"qwerty\"," + "\"system-name\":\"ONAP VNFM\","
47 + "\"type\":\"vnfm\"," + "\"vendor\":\"zte\"," + "\"version\":\"v1\","
48 + "\"service-url\":\"http://10.11.22.33:8000\"," + "\"user-name\":\"onap\","
49 + "\"password\":\"987654\"," + "\"system-type\":\"VNFM\"}]}}";
50 assertEquals(expectResult, esrVnfmDetailStr);
54 public void esrVnfm2VnfmRegisterInfoTest() {
55 VnfmManagerUtil vnfmManagerUtil = new VnfmManagerUtil();
56 VnfmRegisterInfo vnfmRegisterInfo = new VnfmRegisterInfo();
57 EsrVnfmDetail esrVnfmDetail = new EsrVnfmDetail();
58 String esrVnfmDetailStr = "{\"vnfm-id\":\"123456\"," + "\"vim-id\":\"987654\","
59 + "\"certificate-url\":\"http://11.22.33.44:5000/v3\"," + "\"esr-system-info-list\":{"
60 + "\"esr-system-info\":[{" + "\"esr-system-info-id\":\"qwerty\"," + "\"system-name\":\"ONAP VNFM\","
61 + "\"type\":\"vnfm\"," + "\"vendor\":\"zte\"," + "\"version\":\"v1\","
62 + "\"service-url\":\"http://10.11.22.33:8000\"," + "\"user-name\":\"onap\","
63 + "\"password\":\"987654\"," + "\"system-type\":\"VNFM\"}]}}";
64 esrVnfmDetail = new Gson().fromJson(esrVnfmDetailStr, EsrVnfmDetail.class);
65 vnfmRegisterInfo = vnfmManagerUtil.esrVnfm2VnfmRegisterInfo(esrVnfmDetail);
66 String vnfmRegisterInfoStr = new ExtsysUtil().objectToString(vnfmRegisterInfo);
67 String expectResult = "{\"vnfmId\":\"123456\"," + "\"name\":\"ONAP VNFM\"," + "\"type\":\"vnfm\","
68 + "\"vimId\":\"987654\"," + "\"vendor\":\"zte\"," + "\"version\":\"v1\","
69 + "\"certificateUrl\":\"http://11.22.33.44:5000/v3\"," + "\"url\":\"http://10.11.22.33:8000\","
70 + "\"userName\":\"onap\"," + "\"password\":\"987654\"}";
71 assertEquals(expectResult, vnfmRegisterInfoStr);