summaryrefslogtreecommitdiffstats
path: root/esr-mgr/src/test/java/org/onap/aai/esr/util/NfvoManagerUtilTest.java
blob: 1a7e4c8d8ccbe481e8e7a77094637a3c1a721a62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
 * Copyright 2019 ZTE Corporation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * Submit by HePeng 10064135
 */
package org.onap.aai.esr.util;

import com.google.gson.Gson;
import org.junit.Test;
import org.onap.aai.esr.entity.aai.EsrNfvoDetail;
import org.onap.aai.esr.entity.rest.NfvoRegisterInfo;

import static org.junit.Assert.assertEquals;

public class NfvoManagerUtilTest {
    @Test
    public void nfvoRegisterInfo2EsrNfvoTest()
    {
        NfvoManagerUtil nfvoManagerUtil=new NfvoManagerUtil();
        NfvoRegisterInfo nfvoRegisterInfo=new NfvoRegisterInfo();
        ExtsysUtil extsysUtil=new ExtsysUtil();
        nfvoRegisterInfo.setNfvoId("123456");
        nfvoRegisterInfo.setApiroot("/api/v1/test");
        nfvoRegisterInfo.setName("NFVO_TEST");
        nfvoRegisterInfo.setVendor("ZTE");
        nfvoRegisterInfo.setVersion("v1");
        nfvoRegisterInfo.setUrl("127.0.0.1");
        nfvoRegisterInfo.setUserName("root");
        nfvoRegisterInfo.setPassword("root");
        EsrNfvoDetail esrNfvoDetail=nfvoManagerUtil.nfvoRegisterInfo2EsrNfvo(nfvoRegisterInfo);
        esrNfvoDetail.setNfvoId("123456");
        esrNfvoDetail.setResourceVersion("v2");
        esrNfvoDetail.getEsrSystemInfoList().getEsrSystemInfo().get(0).setEsrSystemInfoId("654321");
        String esrnfvoStr = extsysUtil.objectToString(esrNfvoDetail);
        String expect = "{\"nfvo-id\":\"123456\"," + "\"resource-version\":\"v2\"," +"\"api-root\":\"/api/v1/test\","
                + "\"esr-system-info-list\":" + "{\"esr-system-info\":" + "[{\"esr-system-info-id\":\"654321\","
                + "\"system-name\":\"NFVO_TEST\"," + "\"vendor\":\"ZTE\"," + "\"version\":\"v1\"," + "\"service-url\":\"127.0.0.1\","
                + "\"user-name\":\"root\"," + "\"password\":\"root\","+ "\"system-type\":\"NFVO\"}]}}";
        assertEquals(expect,esrnfvoStr);

    }
    @Test
    public void esrNfvo2NfvoRegisterInfoTest()
    {
        EsrNfvoDetail esrNfvoDetail=new EsrNfvoDetail();
        NfvoRegisterInfo nfvoRegisterInfo = new NfvoRegisterInfo();
        NfvoManagerUtil nfvoManagerUtil = new NfvoManagerUtil();
        String esrnfvoStr = "{\"nfvo-id\":\"123456\"," + "\"resource-version\":\"v2\"," +"\"api-root\":\"/api/v1/test\","
                + "\"esr-system-info-list\":" + "{\"esr-system-info\":" + "[{\"esr-system-info-id\":\"654321\","
                + "\"system-name\":\"NFVO_TEST\"," + "\"vendor\":\"ZTE\","+ "\"version\":\"v1\"," + "\"service-url\":\"127.0.0.1\","
                + "\"user-name\":\"root\"," + "\"password\":\"root\","+ "\"system-type\":\"NFVO\"}]}}";
       esrNfvoDetail=new Gson().fromJson(esrnfvoStr,EsrNfvoDetail.class);
       nfvoRegisterInfo=nfvoManagerUtil.esrNfvo2NfvoRegisterInfo(esrNfvoDetail);
       String registerInfoStr = new ExtsysUtil().objectToString(nfvoRegisterInfo);
       String expect= "{\"nfvoId\":\"123456\"," + "\"name\":\"NFVO_TEST\"," + "\"apiroot\":\"/api/v1/test\","
               + "\"vendor\":\"ZTE\"," + "\"version\":\"v1\"," +"\"url\":\"127.0.0.1\","+"\"userName\":\"root\","
               + "\"password\":\"root\"}";
       assertEquals(registerInfoStr, expect);
    }
}