b0b00d93524f80e0c5d6f13d3c98819816bf1909
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14;
19
20 import static org.junit.Assert.assertEquals;
21 import java.util.HashMap;
22 import java.util.Map;
23 import org.eclipse.jdt.annotation.NonNull;
24 import org.junit.BeforeClass;
25 import org.junit.Test;
26 import org.mockito.Mockito;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.dataprovider.Onf14ToInternalDataModel;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
29 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.Equipment;
30 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.UniversalId;
31 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.equipment.ActualEquipment;
32 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.equipment.ContainedHolder;
33 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.equipment.ContainedHolderKey;
34 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.equipment.detail.ManufacturedThing;
35 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.manufactured.thing.EquipmentInstance;
36 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.manufactured.thing.EquipmentType;
37 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.manufactured.thing.ManufacturerProperties;
38 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
39
40 public class TestOnf14ToInternalDataModel2 extends Mockito {
41
42     private static NodeId nodeId;
43     private static Equipment currentEq;
44     private static Equipment parentEq;
45     private static ActualEquipment component;
46     private static ContainedHolder holder;
47     private static ManufacturedThing manThing;
48     private static ManufacturerProperties manProperties;
49     private static EquipmentInstance eqInstance;
50     private static EquipmentType eqType;
51
52     @BeforeClass
53     public static void init() {
54         nodeId = mock(NodeId.class);
55         currentEq = mock(Equipment.class);
56         parentEq = mock(Equipment.class);
57         component = mock(ActualEquipment.class);
58         holder = mock(ContainedHolder.class);
59         manThing = mock(ManufacturedThing.class);
60         manProperties = mock(ManufacturerProperties.class);
61         eqInstance = mock(EquipmentInstance.class);
62         eqType = mock(EquipmentType.class);
63
64         when(nodeId.getValue()).thenReturn("CoreModel-1-4-node");
65
66         when(component.getLocalId()).thenReturn("actLocalEq");
67         when(currentEq.getUuid()).thenReturn(new UniversalId("0Aabcdef-0abc-0cfD-0abC-0123456789AB"));
68         when(parentEq.getUuid()).thenReturn(new UniversalId("0Aabcdef-0123-0abc-abcd-0123456789AB"));
69
70         @NonNull Map<ContainedHolderKey, ContainedHolder> containedHolderList = new HashMap<>();
71         containedHolderList.put(holder.key(),holder);
72         when(currentEq.nonnullContainedHolder()).thenReturn(containedHolderList);
73
74     }
75
76     @Test
77     public void test1() {
78
79         Onf14ToInternalDataModel model = new Onf14ToInternalDataModel();
80
81         when(currentEq.getActualEquipment()).thenReturn(component);
82         when(holder.getOccupyingFru()).thenReturn(new UniversalId("12345678-0123-0abc-abcd-0123456789AB"));
83         when(component.getManufacturedThing()).thenReturn(manThing);
84         when(manThing.getManufacturerProperties()).thenReturn(manProperties);
85         when(manThing.getEquipmentInstance()).thenReturn(eqInstance);
86         when(eqInstance.getManufactureDate()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
87         when(manThing.getEquipmentType()).thenReturn(eqType);
88
89         model.getInternalEquipment(nodeId, currentEq, parentEq, 0);
90         assertEquals(currentEq.getActualEquipment().getLocalId(), "actLocalEq");
91     }
92
93     @Test
94     public void test2() {
95
96         Onf14ToInternalDataModel model = new Onf14ToInternalDataModel();
97
98         when(holder.getOccupyingFru()).thenReturn(null);
99         when(component.getManufacturedThing()).thenReturn(null);
100         when(manThing.getManufacturerProperties()).thenReturn(null);
101         when(manThing.getEquipmentInstance()).thenReturn(null);
102         when(manThing.getEquipmentType()).thenReturn(null);
103
104         model.getInternalEquipment(nodeId, currentEq, null, 0);
105     }
106
107
108     @Test
109     public void test3() {
110         Onf14ToInternalDataModel model = new Onf14ToInternalDataModel();
111
112         when(component.getManufacturedThing()).thenReturn(manThing);
113         when(manThing.getManufacturerProperties()).thenReturn(null);
114         when(manThing.getEquipmentInstance()).thenReturn(null);
115         when(manThing.getEquipmentType()).thenReturn(null);
116
117         model.getInternalEquipment(nodeId, currentEq, null, 0);
118     }
119
120     @Test
121     public void test4() {
122         Onf14ToInternalDataModel model = new Onf14ToInternalDataModel();
123
124         when(currentEq.getActualEquipment()).thenReturn(null);
125         model.getInternalEquipment(nodeId, currentEq, null, 0);
126     }
127 }