aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/devicemanager-onap/onf14/provider/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'sdnr/wt/devicemanager-onap/onf14/provider/src/test')
-rw-r--r--sdnr/wt/devicemanager-onap/onf14/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf14/TestOnf14DomNetworkElement.java89
-rw-r--r--sdnr/wt/devicemanager-onap/onf14/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf14/TestOnf14NetworkElement.java98
-rw-r--r--sdnr/wt/devicemanager-onap/onf14/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf14/TestOnf14NetworkElementFactory.java47
3 files changed, 206 insertions, 28 deletions
diff --git a/sdnr/wt/devicemanager-onap/onf14/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf14/TestOnf14DomNetworkElement.java b/sdnr/wt/devicemanager-onap/onf14/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf14/TestOnf14DomNetworkElement.java
new file mode 100644
index 000000000..d07070694
--- /dev/null
+++ b/sdnr/wt/devicemanager-onap/onf14/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf14/TestOnf14DomNetworkElement.java
@@ -0,0 +1,89 @@
+package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import java.util.Optional;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.Onf14Configuration;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.Onf14NetworkElementFactory;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
+import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
+import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
+import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
+import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
+import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.ControlConstruct;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TestOnf14DomNetworkElement {
+
+ private static String NODEIDSTRING = "nSky";
+
+ @Mock
+ NetconfDomAccessor netconfDomAccessor;
+ @Mock
+ NetconfBindingAccessor netconfBindingAccessor;
+ @Mock
+ DataProvider dataProvider;
+ @Mock
+ FaultService faultService;
+ @Mock
+ DeviceManagerServiceProvider serviceProvider;
+ @Mock
+ WebsocketManagerService websocketManagerService;
+ @Mock
+ DataProvider databaseService;
+ @Mock
+ Capabilities capabilities;
+ @Mock
+ BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer;
+
+ NodeId nodeId = new NodeId(NODEIDSTRING);
+
+ @Before
+ public void init() {
+
+ ConfigurationFileRepresentation configurationRepresentation = mock(ConfigurationFileRepresentation.class);
+ when(serviceProvider.getConfigurationFileRepresentation()).thenReturn(configurationRepresentation);
+ Optional<Onf14Configuration> onf14Cfg = Optional.of(new Onf14Configuration(configurationRepresentation));
+ System.out.println(onf14Cfg.isPresent());
+ when(onf14Cfg.get().isUseDomApiEnabled()).thenReturn(true);
+ when(netconfDomAccessor.getCapabilites()).thenReturn(capabilities);
+ when(netconfDomAccessor.getCapabilites().isSupportingNamespace(ControlConstruct.QNAME)).thenReturn(true);
+ when(netconfDomAccessor.getNetconfDomAccessor()).thenReturn(Optional.of(netconfDomAccessor));
+ when(netconfDomAccessor.getBindingNormalizedNodeSerializer()).thenReturn(bindingNormalizedNodeSerializer);
+ when(netconfDomAccessor.getNodeId()).thenReturn(nodeId);
+ when(serviceProvider.getDataProvider()).thenReturn(dataProvider);
+ when(serviceProvider.getFaultService()).thenReturn(faultService);
+ }
+
+ @Test
+ public void test() {
+ Optional<NetworkElement> onfDomNe;
+
+ Onf14NetworkElementFactory factory = new Onf14NetworkElementFactory();
+ factory.init(serviceProvider);
+ onfDomNe = factory.create(netconfDomAccessor, serviceProvider);
+ assertTrue(onfDomNe.isPresent());
+
+ onfDomNe.get().register();
+ onfDomNe.get().deregister();
+ onfDomNe.get().getAcessor();
+ onfDomNe.get().getDeviceType();
+ onfDomNe.get().warmstart();
+ onfDomNe.get().getService(null);
+ assertEquals(onfDomNe.get().getNodeId().getValue(), "nSky");
+ }
+
+}
diff --git a/sdnr/wt/devicemanager-onap/onf14/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf14/TestOnf14NetworkElement.java b/sdnr/wt/devicemanager-onap/onf14/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf14/TestOnf14NetworkElement.java
index 30b4c9b1a..0a39913f6 100644
--- a/sdnr/wt/devicemanager-onap/onf14/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf14/TestOnf14NetworkElement.java
+++ b/sdnr/wt/devicemanager-onap/onf14/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf14/TestOnf14NetworkElement.java
@@ -20,8 +20,11 @@ package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -35,35 +38,47 @@ import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
+import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.dom.api.DOMDataBroker;
+import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.LAYERPROTOCOLNAMETYPEAIRLAYER;
import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.ControlConstruct;
import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.UniversalId;
+import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.Equipment;
+import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.EquipmentKey;
+import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.LogicalTerminationPoint;
+import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.LogicalTerminationPointBuilder;
+import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.LogicalTerminationPointKey;
+import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.logical.termination.point.LayerProtocol;
+import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.logical.termination.point.LayerProtocolBuilder;
+import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.logical.termination.point.LayerProtocolKey;
+import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.LAYERPROTOCOLNAMETYPEETHERNETCONTAINERLAYER;
+import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.LAYERPROTOCOLNAMETYPEWIRELAYER;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
public class TestOnf14NetworkElement extends Mockito {
private static String NODEIDSTRING = "nSky";
- static NetconfDomAccessor accessor;
+ static NetconfBindingAccessor bindingAccessor;
static DeviceManagerServiceProvider serviceProvider;
static Capabilities capabilities;
static DataProvider dataProvider;
static FaultService faultService;
- static DOMDataBroker dataBroker;
+ static DataBroker dataBroker;
static TransactionUtils transactionUtils;
static ControlConstruct controlConstruct;
+ static Equipment equipment;
@Before
public void init() {
capabilities = mock(Capabilities.class);
- accessor = mock(NetconfDomAccessor.class);
+ bindingAccessor = mock(NetconfBindingAccessor.class);
serviceProvider = mock(DeviceManagerServiceProvider.class);
NodeId nNodeId = new NodeId("nSky");
- when(accessor.getCapabilites()).thenReturn(capabilities);
- when(accessor.getNodeId()).thenReturn(nNodeId);
+ when(bindingAccessor.getCapabilites()).thenReturn(capabilities);
+ when(bindingAccessor.getNodeId()).thenReturn(nNodeId);
dataProvider = mock(DataProvider.class);
when(serviceProvider.getDataProvider()).thenReturn(dataProvider);
@@ -71,44 +86,84 @@ public class TestOnf14NetworkElement extends Mockito {
faultService = mock(FaultService.class);
when(serviceProvider.getFaultService()).thenReturn(faultService);
- dataBroker = mock(DOMDataBroker.class);
- when(accessor.getDataBroker()).thenReturn(dataBroker);
+ dataBroker = mock(DataBroker.class);
+ when(bindingAccessor.getDataBroker()).thenReturn(dataBroker);
controlConstruct = mock(ControlConstruct.class);
- YangInstanceIdentifier CONTROLCONSTRUCT_IID =
- YangInstanceIdentifier.builder().node(ControlConstruct.QNAME).build();
-
- when(accessor.readData(LogicalDatastoreType.CONFIGURATION, CONTROLCONSTRUCT_IID, ControlConstruct.class))
- .thenReturn(Optional.of(controlConstruct));
+ InstanceIdentifier<ControlConstruct> CONTROLCONSTRUCT_IID = InstanceIdentifier.builder(ControlConstruct.class).build();
+ when(bindingAccessor.getTransactionUtils()).thenReturn(mock(TransactionUtils.class));
+ when(bindingAccessor.getTransactionUtils().readData(bindingAccessor.getDataBroker(), LogicalDatastoreType.CONFIGURATION, CONTROLCONSTRUCT_IID)).thenReturn(controlConstruct);
List<UniversalId> topLevelEqList = null;
UniversalId uuid = new UniversalId("0Aabcdef-0abc-0cfD-0abC-0123456789AB");
topLevelEqList = Arrays.asList(uuid);
-
when(Optional.of(controlConstruct).get().getTopLevelEquipment()).thenReturn(topLevelEqList);
+
+ InstanceIdentifier<Equipment> equipmentIID = InstanceIdentifier.builder(ControlConstruct.class)
+ .child(Equipment.class, new EquipmentKey(uuid)).build();
+
+ equipment = mock(Equipment.class);
+ when(bindingAccessor.getTransactionUtils().readData(bindingAccessor.getDataBroker(), LogicalDatastoreType.CONFIGURATION,
+ equipmentIID)).thenReturn(equipment);
+ UniversalId eqpUid = new UniversalId("1Aabcdef-1abc-1cfD-1abc-0123456789AB");
+ when(equipment.getUuid()).thenReturn(eqpUid);
+
+ @NonNull Map<LogicalTerminationPointKey, LogicalTerminationPoint> lptMap = new HashMap<LogicalTerminationPointKey, LogicalTerminationPoint>();
+ var lpMap = new HashMap<LayerProtocolKey, LayerProtocol>();
+
+ LayerProtocol lp = new LayerProtocolBuilder().setLayerProtocolName(LAYERPROTOCOLNAMETYPEAIRLAYER.class).setLocalId("TESTAIRLAYER").build();
+ LayerProtocolKey lpKey = new LayerProtocolKey("AIRPROTOCOL");
+ lpMap.put(lpKey, lp);
+ LogicalTerminationPoint ltp = new LogicalTerminationPointBuilder().setLayerProtocol(lpMap).setUuid(uuid).build();
+ UniversalId ltpUuid = new UniversalId("1Aabcdef-1abc-1cfD-1abc-0123456789AB");
+ LogicalTerminationPointKey ltpKey = new LogicalTerminationPointKey(ltpUuid);
+
+ lptMap.put(ltpKey, ltp);
+
+ lp = new LayerProtocolBuilder().setLayerProtocolName(LAYERPROTOCOLNAMETYPEETHERNETCONTAINERLAYER.class).setLocalId("TESTETHCONTAINERLAYER").build();
+ lpKey = new LayerProtocolKey("ETHERNETCONTAINERPROTOCOL");
+ lpMap = new HashMap<LayerProtocolKey, LayerProtocol>();
+ lpMap.put(lpKey, lp);
+ ltp = new LogicalTerminationPointBuilder().setLayerProtocol(lpMap).setUuid(uuid).build();
+ ltpUuid = new UniversalId("1Aabcdef-1abc-1cfD-1abc-0123456789BC");
+ ltpKey = new LogicalTerminationPointKey(ltpUuid);
+
+ lptMap.put(ltpKey, ltp);
+
+ lp = new LayerProtocolBuilder().setLayerProtocolName(LAYERPROTOCOLNAMETYPEWIRELAYER.class).setLocalId("TESTWIRELAYER").build();
+ lpKey = new LayerProtocolKey("WIREPROTOCOL");
+ lpMap = new HashMap<LayerProtocolKey, LayerProtocol>();
+ lpMap.put(lpKey, lp);
+ ltp = new LogicalTerminationPointBuilder().setLayerProtocol(lpMap).setUuid(uuid).build();
+ ltpUuid = new UniversalId("1Aabcdef-1abc-1cfD-1abc-0123456789CD");
+ ltpKey = new LogicalTerminationPointKey(ltpUuid);
+
+ lptMap.put(ltpKey, ltp);
+
+ when(Optional.of(controlConstruct).get().nonnullLogicalTerminationPoint()).thenReturn(lptMap);
+
}
@Test
public void testGeneric() {
Optional<NetworkElement> onfNe;
NodeId nodeId = new NodeId(NODEIDSTRING);
- NetconfBindingAccessor bindingAccessor = mock(NetconfBindingAccessor.class);
- when(bindingAccessor.getTransactionUtils()).thenReturn(mock(TransactionUtils.class));
+
when(bindingAccessor.getNodeId()).thenReturn(nodeId);
NetconfDomAccessor domAccessor = mock(NetconfDomAccessor.class);
when(domAccessor.getNodeId()).thenReturn(nodeId);
- when(accessor.getCapabilites().isSupportingNamespace(ControlConstruct.QNAME)).thenReturn(true);
- when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(bindingAccessor));
- when(accessor.getNetconfDomAccessor()).thenReturn(Optional.of(domAccessor));
+ when(bindingAccessor.getCapabilites().isSupportingNamespace(ControlConstruct.QNAME)).thenReturn(true);
+ when(bindingAccessor.getNetconfBindingAccessor()).thenReturn(Optional.of(bindingAccessor));
+ when(bindingAccessor.getNetconfDomAccessor()).thenReturn(Optional.of(domAccessor));
ConfigurationFileRepresentation configurationRepresentation = mock(ConfigurationFileRepresentation.class);
when(serviceProvider.getConfigurationFileRepresentation()).thenReturn(configurationRepresentation);
Onf14NetworkElementFactory factory = new Onf14NetworkElementFactory();
- onfNe = factory.create(accessor, serviceProvider);
+ onfNe = factory.create(bindingAccessor, serviceProvider);
assertTrue(onfNe.isPresent());
onfNe.get().register();
@@ -119,5 +174,4 @@ public class TestOnf14NetworkElement extends Mockito {
onfNe.get().getService(null);
assertEquals(onfNe.get().getNodeId().getValue(), "nSky");
}
-
}
diff --git a/sdnr/wt/devicemanager-onap/onf14/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf14/TestOnf14NetworkElementFactory.java b/sdnr/wt/devicemanager-onap/onf14/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf14/TestOnf14NetworkElementFactory.java
index f9041eb80..493167ac3 100644
--- a/sdnr/wt/devicemanager-onap/onf14/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf14/TestOnf14NetworkElementFactory.java
+++ b/sdnr/wt/devicemanager-onap/onf14/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf14/TestOnf14NetworkElementFactory.java
@@ -18,8 +18,12 @@
package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14;
import static org.junit.Assert.assertTrue;
+import com.google.common.io.Files;
+import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.Optional;
+import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
@@ -28,24 +32,36 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.Onf14NetworkElementFactory;
import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
+import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.ControlConstruct;
public class TestOnf14NetworkElementFactory extends Mockito {
- private static NetconfBindingAccessor accessor;
+ private static NetconfAccessor accessor;
+ private static Optional<NetconfDomAccessor> domAccessor;
private static Capabilities capabilities;
private static DeviceManagerServiceProvider serviceProvider;
private static ConfigurationFileRepresentation configurationRepresentation;
+ private static String filename = "test.properties";
+
+ // @formatter:off
+ private static final String TESTCONFIG_CONTENT = "[dmonf14]\n"
+ + "useDomApi=true\n"
+ + "";
+ // @formatter:on
@BeforeClass
public static void init() throws InterruptedException, IOException {
+ Files.asCharSink(new File(filename), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT);
+ configurationRepresentation = new ConfigurationFileRepresentation(filename);
capabilities = mock(Capabilities.class);
- accessor = mock(NetconfBindingAccessor.class);
+ accessor = mock(NetconfAccessor.class);
+ domAccessor = Optional.of(mock(NetconfDomAccessor.class));
serviceProvider = mock(DeviceManagerServiceProvider.class);
- configurationRepresentation = mock(ConfigurationFileRepresentation.class);
when(accessor.getCapabilites()).thenReturn(capabilities);
when(serviceProvider.getDataProvider()).thenReturn(mock(DataProvider.class));
@@ -53,19 +69,38 @@ public class TestOnf14NetworkElementFactory extends Mockito {
}
@Test
- public void testCreateOnf14Component() throws Exception {
+ public void testCreateOnf14Dom() throws Exception {
when(accessor.getCapabilites().isSupportingNamespace(ControlConstruct.QNAME)).thenReturn(true);
- when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(mock(NetconfBindingAccessor.class)));
- when(accessor.getNetconfDomAccessor()).thenReturn(Optional.of(mock(NetconfDomAccessor.class)));
+ when(accessor.getNetconfDomAccessor()).thenReturn(domAccessor);
+ when(domAccessor.get().getBindingNormalizedNodeSerializer()).thenReturn(mock(BindingNormalizedNodeSerializer.class));
Onf14NetworkElementFactory factory = new Onf14NetworkElementFactory();
+ factory.init(serviceProvider);
assertTrue((factory.create(accessor, serviceProvider)).isPresent());
}
@Test
+ public void testCreateOnf14Binding() throws Exception {
+ when(accessor.getCapabilites().isSupportingNamespace(ControlConstruct.QNAME)).thenReturn(true);
+ when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(mock(NetconfBindingAccessor.class)));
+ Onf14NetworkElementFactory factory = new Onf14NetworkElementFactory();
+ assertTrue(factory.create(accessor, serviceProvider).isPresent());
+ }
+
+ @Test
public void testCreateNone() throws Exception {
+ when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(mock(NetconfBindingAccessor.class)));
when(accessor.getCapabilites().isSupportingNamespace(ControlConstruct.QNAME)).thenReturn(false);
Onf14NetworkElementFactory factory = new Onf14NetworkElementFactory();
assertTrue(factory.create(accessor, serviceProvider).isEmpty());
}
+
+ @AfterClass
+ public static void cleanUp() {
+ File file = new File(filename);
+ if (file.exists()) {
+ System.out.println("File exists, Deleting it");
+ file.delete();
+ }
+ }
}