ca36f7946b9ce00a414042f927e097d351faba51
[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.ArrayList;
22 import java.util.List;
23 import org.junit.BeforeClass;
24 import org.junit.Test;
25 import org.mockito.Mockito;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.Onf14ToInternalDataModel;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
28 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.Equipment;
29 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.UniversalId;
30 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.equipment.ActualEquipment;
31 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.equipment.ContainedHolder;
32 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.equipment.detail.ManufacturedThing;
33 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.manufactured.thing.EquipmentInstance;
34 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.manufactured.thing.EquipmentType;
35 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.manufactured.thing.ManufacturerProperties;
36 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
37
38 public class TestOnf14ToInternalDataModel2 extends Mockito {
39
40     private static NodeId nodeId;
41     private static Equipment currentEq;
42     private static Equipment parentEq;
43     private static ActualEquipment component;
44     private static ContainedHolder holder;
45     private static ManufacturedThing manThing;
46     private static ManufacturerProperties manProperties;
47     private static EquipmentInstance eqInstance;
48     private static EquipmentType eqType;
49
50     @BeforeClass
51     public static void init() {
52         nodeId = mock(NodeId.class);
53         currentEq = mock(Equipment.class);
54         parentEq = mock(Equipment.class);
55         component = mock(ActualEquipment.class);
56         holder = mock(ContainedHolder.class);
57         manThing = mock(ManufacturedThing.class);
58         manProperties = mock(ManufacturerProperties.class);
59         eqInstance = mock(EquipmentInstance.class);
60         eqType = mock(EquipmentType.class);
61
62         when(nodeId.getValue()).thenReturn("CoreModel-1-4-node");
63
64         when(component.getLocalId()).thenReturn("actLocalEq");
65         when(currentEq.getUuid()).thenReturn(new UniversalId("0Aabcdef-0abc-0cfD-0abC-0123456789AB"));
66         when(parentEq.getUuid()).thenReturn(new UniversalId("0Aabcdef-0123-0abc-abcd-0123456789AB"));
67
68         List<ContainedHolder> containedHolderList = new ArrayList<ContainedHolder>();
69         containedHolderList.add(holder);
70         when(currentEq.nonnullContainedHolder()).thenReturn(containedHolderList);
71
72     }
73
74     @Test
75     public void test1() {
76
77         Onf14ToInternalDataModel model = new Onf14ToInternalDataModel();
78
79         when(currentEq.getActualEquipment()).thenReturn(component);
80         when(holder.getOccupyingFru()).thenReturn(new UniversalId("12345678-0123-0abc-abcd-0123456789AB"));
81         when(component.getManufacturedThing()).thenReturn(manThing);
82         when(manThing.getManufacturerProperties()).thenReturn(manProperties);
83         when(manThing.getEquipmentInstance()).thenReturn(eqInstance);
84         when(eqInstance.getManufactureDate()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
85         when(manThing.getEquipmentType()).thenReturn(eqType);
86
87         model.getInternalEquipment(nodeId, currentEq, parentEq, 0);
88         assertEquals(currentEq.getActualEquipment().getLocalId(), "actLocalEq");
89     }
90
91     @Test
92     public void test2() {
93
94         Onf14ToInternalDataModel model = new Onf14ToInternalDataModel();
95
96         when(holder.getOccupyingFru()).thenReturn(null);
97         when(component.getManufacturedThing()).thenReturn(null);
98         when(manThing.getManufacturerProperties()).thenReturn(null);
99         when(manThing.getEquipmentInstance()).thenReturn(null);
100         when(manThing.getEquipmentType()).thenReturn(null);
101
102         model.getInternalEquipment(nodeId, currentEq, null, 0);
103     }
104
105
106     @Test
107     public void test3() {
108         Onf14ToInternalDataModel model = new Onf14ToInternalDataModel();
109
110         when(component.getManufacturedThing()).thenReturn(manThing);
111         when(manThing.getManufacturerProperties()).thenReturn(null);
112         when(manThing.getEquipmentInstance()).thenReturn(null);
113         when(manThing.getEquipmentType()).thenReturn(null);
114
115         model.getInternalEquipment(nodeId, currentEq, null, 0);
116     }
117
118     @Test
119     public void test4() {
120         Onf14ToInternalDataModel model = new Onf14ToInternalDataModel();
121
122         when(currentEq.getActualEquipment()).thenReturn(null);
123         model.getInternalEquipment(nodeId, currentEq, null, 0);
124     }
125 }