aboutsummaryrefslogtreecommitdiffstats
path: root/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/api/AaiPnfResultModelTest.java
blob: aa193e8a45185b667eb3ff9b01e0ee4a11a0b1b1 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * ============LICENSE_START=======================================================
 * PNF-REGISTRATION-HANDLER
 * ================================================================================
 * Copyright (C) 2019 NOKIA Intellectual Property. All rights reserved.
 * ================================================================================
 * 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.
 * ============LICENSE_END=========================================================
 */

package org.onap.dcaegen2.services.prh.adapter.aai.api;

import static org.assertj.core.api.Assertions.assertThat;

import com.google.gson.Gson;
import java.io.InputStreamReader;
import java.util.Objects;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.prh.model.RelationshipData;
import org.onap.dcaegen2.services.prh.model.RelationshipDict;
import org.onap.dcaegen2.services.prh.model.utils.PrhModelAwareGsonBuilder;

class AaiPnfResultModelTest {

    @Test
    void shouldParseAaiPnf() {
        Gson gson = PrhModelAwareGsonBuilder.createGson();
        AaiPnfResultModel pnf = gson.fromJson(new InputStreamReader(Objects.requireNonNull(
                ClassLoader.getSystemResourceAsStream("some_aai_pnf.json"))), AaiPnfResultModel.class);

        assertThat(pnf.getPnfName()).isEqualTo("some pnfName");
        assertThat(pnf.getPnfName2()).isEqualTo("some pnfName2");
        assertThat(pnf.getSelflink()).isEqualTo("some selflink");
        assertThat(pnf.getPnfName2Source()).isEqualTo("some pnfName2Source");
        assertThat(pnf.getPnfId()).isEqualTo("some pnfId");
        assertThat(pnf.getEquipType()).isEqualTo("some equipType");
        assertThat(pnf.getEquipVendor()).isEqualTo("some equipVendor");
        assertThat(pnf.getEquipModel()).isEqualTo("some equipModel");
        assertThat(pnf.getManagementOption()).isEqualTo("some managementOption");
        assertThat(pnf.getIpaddressV4Oam()).isEqualTo("some ipaddressV4Oam");
        assertThat(pnf.getSwVersion()).isEqualTo("some swVersion");
        assertThat(pnf.isInMaint()).isFalse();
        assertThat(pnf.getFrameId()).isEqualTo("some frameId");
        assertThat(pnf.getSerialNumber()).isEqualTo("some serialNumber");
        assertThat(pnf.getIpaddressV4Loopback0()).isEqualTo("some ipaddressV4Loopback0");
        assertThat(pnf.getIpaddressV6Loopback0()).isEqualTo("some ipaddressV6Loopback0");
        assertThat(pnf.getIpaddressV4Aim()).isEqualTo("some ipaddressV4Aim");
        assertThat(pnf.getIpaddressV6Aim()).isEqualTo("some ipaddressV6Aim");
        assertThat(pnf.getIpaddressV6Oam()).isEqualTo("some ipaddressV6Oam");
        assertThat(pnf.getInvStatus()).isEqualTo("some invStatus");
        assertThat(pnf.getResourceVersion()).isEqualTo("some resourceVersion");
        assertThat(pnf.getProvStatus()).isEqualTo("some provStatus");
        assertThat(pnf.getNfRole()).isEqualTo("some nfRole");

        assertThat(pnf.getRelationshipList().getRelationship()).hasSize(1);
        RelationshipDict relationshipDict = pnf.getRelationshipList().getRelationship().get(0);
        assertThat(relationshipDict.getRelatedTo()).isEqualTo("some relatedTo");
        assertThat(relationshipDict.getRelationshipData()).hasSize(1);
        RelationshipData relationshipData = relationshipDict.getRelationshipData().get(0);
        assertThat(relationshipData.getRelationshipKey()).isEqualTo("some relationshipKey");
        assertThat(relationshipData.getRelationshipValue()).isEqualTo("some relationshipValue");
    }

    @Test
    void shouldProvideEmptyRelationshipListForEmptyJson() {
        Gson gson = PrhModelAwareGsonBuilder.createGson();
        AaiPnfResultModel pnf = gson.fromJson("{}", AaiPnfResultModel.class);
        assertThat(pnf.getRelationshipList()).isNotNull();
        assertThat(pnf.getRelationshipList().getRelationship()).isEmpty();
    }

    @Test
    void shouldIgnoreUnexpectedFieldsInJson() {
        Gson gson = PrhModelAwareGsonBuilder.createGson();
        gson.fromJson("{\"foo\":\"bar\"}", AaiPnfResultModel.class);
    }

}