0a39913f63e5e441297d289796cffb4ad9dc697d
[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 static org.junit.Assert.assertTrue;
22 import java.util.Arrays;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Optional;
27 import org.eclipse.jdt.annotation.NonNull;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.mockito.Mockito;
31 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
32 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.Onf14NetworkElementFactory;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
37 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
38 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
39 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
40 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
41 import org.opendaylight.mdsal.binding.api.DataBroker;
42 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
43 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.LAYERPROTOCOLNAMETYPEAIRLAYER;
44 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.ControlConstruct;
45 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.UniversalId;
46 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.Equipment;
47 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.EquipmentKey;
48 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.LogicalTerminationPoint;
49 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.LogicalTerminationPointBuilder;
50 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.LogicalTerminationPointKey;
51 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.logical.termination.point.LayerProtocol;
52 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.logical.termination.point.LayerProtocolBuilder;
53 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.logical.termination.point.LayerProtocolKey;
54 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.LAYERPROTOCOLNAMETYPEETHERNETCONTAINERLAYER;
55 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.LAYERPROTOCOLNAMETYPEWIRELAYER;
56 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
57 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
58
59 public class TestOnf14NetworkElement extends Mockito {
60
61     private static String NODEIDSTRING = "nSky";
62
63     static NetconfBindingAccessor bindingAccessor;
64     static DeviceManagerServiceProvider serviceProvider;
65     static Capabilities capabilities;
66     static DataProvider dataProvider;
67     static FaultService faultService;
68     static DataBroker dataBroker;
69     static TransactionUtils transactionUtils;
70     static ControlConstruct controlConstruct;
71     static Equipment equipment;
72
73     @Before
74     public void init() {
75         capabilities = mock(Capabilities.class);
76         bindingAccessor = mock(NetconfBindingAccessor.class);
77         serviceProvider = mock(DeviceManagerServiceProvider.class);
78
79         NodeId nNodeId = new NodeId("nSky");
80         when(bindingAccessor.getCapabilites()).thenReturn(capabilities);
81         when(bindingAccessor.getNodeId()).thenReturn(nNodeId);
82
83         dataProvider = mock(DataProvider.class);
84         when(serviceProvider.getDataProvider()).thenReturn(dataProvider);
85
86         faultService = mock(FaultService.class);
87         when(serviceProvider.getFaultService()).thenReturn(faultService);
88
89         dataBroker = mock(DataBroker.class);
90         when(bindingAccessor.getDataBroker()).thenReturn(dataBroker);
91
92         controlConstruct = mock(ControlConstruct.class);
93
94         InstanceIdentifier<ControlConstruct> CONTROLCONSTRUCT_IID = InstanceIdentifier.builder(ControlConstruct.class).build();
95         when(bindingAccessor.getTransactionUtils()).thenReturn(mock(TransactionUtils.class));
96         when(bindingAccessor.getTransactionUtils().readData(bindingAccessor.getDataBroker(), LogicalDatastoreType.CONFIGURATION, CONTROLCONSTRUCT_IID)).thenReturn(controlConstruct);
97
98         List<UniversalId> topLevelEqList = null;
99         UniversalId uuid = new UniversalId("0Aabcdef-0abc-0cfD-0abC-0123456789AB");
100         topLevelEqList = Arrays.asList(uuid);
101         when(Optional.of(controlConstruct).get().getTopLevelEquipment()).thenReturn(topLevelEqList);
102
103         InstanceIdentifier<Equipment> equipmentIID = InstanceIdentifier.builder(ControlConstruct.class)
104                 .child(Equipment.class, new EquipmentKey(uuid)).build();
105
106         equipment = mock(Equipment.class);
107         when(bindingAccessor.getTransactionUtils().readData(bindingAccessor.getDataBroker(), LogicalDatastoreType.CONFIGURATION,
108                 equipmentIID)).thenReturn(equipment);
109         UniversalId eqpUid = new UniversalId("1Aabcdef-1abc-1cfD-1abc-0123456789AB");
110         when(equipment.getUuid()).thenReturn(eqpUid);
111
112         @NonNull Map<LogicalTerminationPointKey, LogicalTerminationPoint> lptMap = new HashMap<LogicalTerminationPointKey, LogicalTerminationPoint>();
113         var lpMap = new HashMap<LayerProtocolKey, LayerProtocol>();
114
115         LayerProtocol lp = new LayerProtocolBuilder().setLayerProtocolName(LAYERPROTOCOLNAMETYPEAIRLAYER.class).setLocalId("TESTAIRLAYER").build();
116         LayerProtocolKey lpKey = new LayerProtocolKey("AIRPROTOCOL");
117         lpMap.put(lpKey, lp);
118         LogicalTerminationPoint ltp = new LogicalTerminationPointBuilder().setLayerProtocol(lpMap).setUuid(uuid).build();
119         UniversalId ltpUuid = new UniversalId("1Aabcdef-1abc-1cfD-1abc-0123456789AB");
120         LogicalTerminationPointKey ltpKey = new LogicalTerminationPointKey(ltpUuid);
121
122         lptMap.put(ltpKey, ltp);
123
124         lp = new LayerProtocolBuilder().setLayerProtocolName(LAYERPROTOCOLNAMETYPEETHERNETCONTAINERLAYER.class).setLocalId("TESTETHCONTAINERLAYER").build();
125         lpKey = new LayerProtocolKey("ETHERNETCONTAINERPROTOCOL");
126         lpMap = new HashMap<LayerProtocolKey, LayerProtocol>();
127         lpMap.put(lpKey, lp);
128         ltp = new LogicalTerminationPointBuilder().setLayerProtocol(lpMap).setUuid(uuid).build();
129         ltpUuid = new UniversalId("1Aabcdef-1abc-1cfD-1abc-0123456789BC");
130         ltpKey = new LogicalTerminationPointKey(ltpUuid);
131
132         lptMap.put(ltpKey, ltp);
133
134         lp = new LayerProtocolBuilder().setLayerProtocolName(LAYERPROTOCOLNAMETYPEWIRELAYER.class).setLocalId("TESTWIRELAYER").build();
135         lpKey = new LayerProtocolKey("WIREPROTOCOL");
136         lpMap = new HashMap<LayerProtocolKey, LayerProtocol>();
137         lpMap.put(lpKey, lp);
138         ltp = new LogicalTerminationPointBuilder().setLayerProtocol(lpMap).setUuid(uuid).build();
139         ltpUuid = new UniversalId("1Aabcdef-1abc-1cfD-1abc-0123456789CD");
140         ltpKey = new LogicalTerminationPointKey(ltpUuid);
141
142         lptMap.put(ltpKey, ltp);
143
144         when(Optional.of(controlConstruct).get().nonnullLogicalTerminationPoint()).thenReturn(lptMap);
145
146     }
147
148     @Test
149     public void testGeneric() {
150         Optional<NetworkElement> onfNe;
151         NodeId nodeId = new NodeId(NODEIDSTRING);
152
153         when(bindingAccessor.getNodeId()).thenReturn(nodeId);
154
155         NetconfDomAccessor domAccessor = mock(NetconfDomAccessor.class);
156         when(domAccessor.getNodeId()).thenReturn(nodeId);
157
158         when(bindingAccessor.getCapabilites().isSupportingNamespace(ControlConstruct.QNAME)).thenReturn(true);
159         when(bindingAccessor.getNetconfBindingAccessor()).thenReturn(Optional.of(bindingAccessor));
160         when(bindingAccessor.getNetconfDomAccessor()).thenReturn(Optional.of(domAccessor));
161
162         ConfigurationFileRepresentation configurationRepresentation = mock(ConfigurationFileRepresentation.class);
163         when(serviceProvider.getConfigurationFileRepresentation()).thenReturn(configurationRepresentation);
164
165         Onf14NetworkElementFactory factory = new Onf14NetworkElementFactory();
166         onfNe = factory.create(bindingAccessor, serviceProvider);
167         assertTrue(onfNe.isPresent());
168
169         onfNe.get().register();
170         onfNe.get().deregister();
171         onfNe.get().getAcessor();
172         onfNe.get().getDeviceType();
173         onfNe.get().warmstart();
174         onfNe.get().getService(null);
175         assertEquals(onfNe.get().getNodeId().getValue(), "nSky");
176     }
177 }