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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14;
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertTrue;
22 import java.util.Arrays;
23 import java.util.List;
24 import java.util.Optional;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.Mockito;
28 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
29 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.Onf14NetworkElementFactory;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
34 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
35 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
36 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
37 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
38 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
39 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
40 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.ControlConstruct;
41 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.UniversalId;
42 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
43 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
45 public class TestOnf14NetworkElement extends Mockito {
47 private static String NODEIDSTRING = "nSky";
49 static NetconfDomAccessor accessor;
50 static DeviceManagerServiceProvider serviceProvider;
51 static Capabilities capabilities;
52 static DataProvider dataProvider;
53 static FaultService faultService;
54 static DOMDataBroker dataBroker;
55 static TransactionUtils transactionUtils;
56 static ControlConstruct controlConstruct;
60 capabilities = mock(Capabilities.class);
61 accessor = mock(NetconfDomAccessor.class);
62 serviceProvider = mock(DeviceManagerServiceProvider.class);
64 NodeId nNodeId = new NodeId("nSky");
65 when(accessor.getCapabilites()).thenReturn(capabilities);
66 when(accessor.getNodeId()).thenReturn(nNodeId);
68 dataProvider = mock(DataProvider.class);
69 when(serviceProvider.getDataProvider()).thenReturn(dataProvider);
71 faultService = mock(FaultService.class);
72 when(serviceProvider.getFaultService()).thenReturn(faultService);
74 dataBroker = mock(DOMDataBroker.class);
75 when(accessor.getDataBroker()).thenReturn(dataBroker);
77 controlConstruct = mock(ControlConstruct.class);
79 YangInstanceIdentifier CONTROLCONSTRUCT_IID =
80 YangInstanceIdentifier.builder().node(ControlConstruct.QNAME).build();
82 when(accessor.readData(LogicalDatastoreType.CONFIGURATION, CONTROLCONSTRUCT_IID, ControlConstruct.class))
83 .thenReturn(Optional.of(controlConstruct));
85 List<UniversalId> topLevelEqList = null;
86 UniversalId uuid = new UniversalId("0Aabcdef-0abc-0cfD-0abC-0123456789AB");
87 topLevelEqList = Arrays.asList(uuid);
89 when(Optional.of(controlConstruct).get().getTopLevelEquipment()).thenReturn(topLevelEqList);
93 public void testGeneric() {
94 Optional<NetworkElement> onfNe;
95 NodeId nodeId = new NodeId(NODEIDSTRING);
96 NetconfBindingAccessor bindingAccessor = mock(NetconfBindingAccessor.class);
97 when(bindingAccessor.getTransactionUtils()).thenReturn(mock(TransactionUtils.class));
98 when(bindingAccessor.getNodeId()).thenReturn(nodeId);
100 NetconfDomAccessor domAccessor = mock(NetconfDomAccessor.class);
101 when(domAccessor.getNodeId()).thenReturn(nodeId);
103 when(accessor.getCapabilites().isSupportingNamespace(ControlConstruct.QNAME)).thenReturn(true);
104 when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(bindingAccessor));
105 when(accessor.getNetconfDomAccessor()).thenReturn(Optional.of(domAccessor));
107 ConfigurationFileRepresentation configurationRepresentation = mock(ConfigurationFileRepresentation.class);
108 when(serviceProvider.getConfigurationFileRepresentation()).thenReturn(configurationRepresentation);
110 Onf14NetworkElementFactory factory = new Onf14NetworkElementFactory();
111 onfNe = factory.create(accessor, serviceProvider);
112 assertTrue(onfNe.isPresent());
114 onfNe.get().register();
115 onfNe.get().deregister();
116 onfNe.get().getAcessor();
117 onfNe.get().getDeviceType();
118 onfNe.get().warmstart();
119 onfNe.get().getService(null);
120 assertEquals(onfNe.get().getNodeId().getValue(), "nSky");