diff options
Diffstat (limited to 'sdnr/wt/devicemanager-openroadm/provider/src/test')
11 files changed, 1062 insertions, 0 deletions
diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestChangeNotificationListener.java b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestChangeNotificationListener.java new file mode 100644 index 000000000..c79ed698f --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestChangeNotificationListener.java @@ -0,0 +1,89 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.test; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import java.util.Arrays; +import java.util.List; +import org.eclipse.jdt.annotation.NonNull; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.OpenroadmChangeNotificationListener; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditOperationType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfigChange; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.Edit; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.EditBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogEntity; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument; + +public class TestChangeNotificationListener { + + private static final String NODEID = "node1"; + + //@Test + public void test() { + + NetconfAccessor netconfAccessor = mock(NetconfAccessor.class); + DataProvider databaseService = mock(DataProvider.class); + OpenroadmChangeNotificationListener notifListener = + new OpenroadmChangeNotificationListener(netconfAccessor, databaseService); + when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID)); + Iterable<? extends PathArgument> pathArguments = Arrays.asList(new PathArgument() { + + @Override + public int compareTo(PathArgument arg0) { + return 0; + } + + @Override + public Class<? extends DataObject> getType() { + return DataObject.class; + } + }); + InstanceIdentifier<?> target = InstanceIdentifier.create(pathArguments); + + notifListener.onNetconfConfigChange(createNotification(EditOperationType.Create, target)); + EventlogEntity event = new EventlogBuilder().setNodeId(NODEID) + .setNewValue(String.valueOf(EditOperationType.Create)).setObjectId(target.toString()).build(); + verify(databaseService).writeEventLog(event); + + } + + /** + * @param type + * @return + */ + private static NetconfConfigChange createNotification(EditOperationType type, InstanceIdentifier<?> target) { + NetconfConfigChange change = mock(NetconfConfigChange.class); + + @SuppressWarnings("null") + final @NonNull List<Edit> edits = Arrays.asList(new EditBuilder().setOperation(type).setTarget(target).build()); + when(change.nonnullEdit()).thenReturn(edits); + return change; + } +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestDeviceManagerOpenRoadmImpl.java b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestDeviceManagerOpenRoadmImpl.java new file mode 100644 index 000000000..0f3401bb0 --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestDeviceManagerOpenRoadmImpl.java @@ -0,0 +1,81 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.test; + +import static org.mockito.Mockito.mock; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.DeviceManagerOpenroadmImpl; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TestDeviceManagerOpenRoadmImpl { + private static Path KARAF_ETC = Paths.get("etc"); + private static final Logger log = LoggerFactory.getLogger(TestDeviceManagerOpenRoadmImpl.class); + DeviceManagerOpenroadmImpl devMgrOpenRdmImpl; + NetconfNetworkElementService netcnfNtwrkElmntSrvc; + + @Before + public void init() { + netcnfNtwrkElmntSrvc = mock(NetconfNetworkElementService.class); + devMgrOpenRdmImpl = new DeviceManagerOpenroadmImpl(); + } + + @Test + public void test() throws Exception { + + devMgrOpenRdmImpl.setNetconfNetworkElementService(netcnfNtwrkElmntSrvc); + + } + + @After + public void cleanUp() throws Exception { + devMgrOpenRdmImpl.close(); + } + + private static void delete(Path etc) throws IOException { + if (Files.exists(etc)) { + System.out.println("Found, removing:" + etc.toString()); + delete(etc.toFile()); + } + } + + private static void delete(File f) throws IOException { + if (f.isDirectory()) { + for (File c : f.listFiles()) { + delete(c); + } + } + if (!f.delete()) { + throw new FileNotFoundException("Failed to delete file: " + f); + } + } + +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmAlarmNotification.java b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmAlarmNotification.java new file mode 100644 index 000000000..90b706374 --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmAlarmNotification.java @@ -0,0 +1,101 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.test; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import java.io.IOException; +import org.eclipse.jdt.annotation.NonNull; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.OpenroadmFaultNotificationListener; +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.NetconfAccessor; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.AlarmNotification; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.Severity; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.alarm.ProbableCause; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.alarm.ProbableCauseBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.alarm.Resource; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.alarm.ResourceBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev191129.NodeIdType; +import org.opendaylight.yang.gen.v1.http.org.openroadm.probablecause.rev191129.ProbableCauseEnum; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev191129.resource.Device; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev191129.resource.DeviceBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; + +public class TestOpenRoadmAlarmNotification { + private static final String myCircuitId = "Test_Id"; + private static final String myId = "Alarm_Id"; + DateAndTime myRaiseTime = new DateAndTime("2020-02-25T10:08:06.7Z"); + ProbableCause myProbableCause = + new ProbableCauseBuilder().setCause(ProbableCauseEnum.AutomaticLaserShutdown).build(); + Device device = new DeviceBuilder().setNodeId(NodeIdType.getDefaultInstance("zNhe2i5")).build(); + Resource myResource = new ResourceBuilder().setDevice(device).build(); + static DeviceManagerServiceProvider serviceProvider; + static @NonNull FaultService faultService; + static AlarmNotification notification; + Severity severity; + static NetconfAccessor accessor; + + @BeforeClass + public static void init() throws InterruptedException, IOException { + + accessor = mock(NetconfAccessor.class); + serviceProvider = mock(DeviceManagerServiceProvider.class); + faultService = mock(FaultService.class); + + } + + @Test + public void test() { + System.out.println("Shabnam"); + } + + @Test + public void testNotification() { + severity = Severity.Critical; + when(serviceProvider.getFaultService()).thenReturn(faultService); + OpenroadmFaultNotificationListener alarmListener = + new OpenroadmFaultNotificationListener(accessor, serviceProvider); + notification = mock(AlarmNotification.class); + + when(notification.getId()).thenReturn(myId); + when(notification.getCircuitId()).thenReturn(myCircuitId); + when(notification.getRaiseTime()).thenReturn(myRaiseTime); + when(notification.getProbableCause()).thenReturn(myProbableCause); + when(notification.getResource()).thenReturn(myResource); + when(notification.getSeverity()).thenReturn(severity); + alarmListener.onAlarmNotification(notification); + System.out.println(notification.getId()); + assertEquals(notification.getId(), myId); + assertEquals(notification.getCircuitId(), myCircuitId); + assertEquals(notification.getRaiseTime(), myRaiseTime); + assertEquals(notification.getProbableCause(), myProbableCause); + assertEquals(notification.getResource(), myResource); + assertEquals(notification.getSeverity(), severity); + + + } + +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmDeviceChangeNotification.java b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmDeviceChangeNotification.java new file mode 100644 index 000000000..64333e1d6 --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmDeviceChangeNotification.java @@ -0,0 +1,76 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.test; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.OpenroadmDeviceChangeNotificationListener; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev191129.RpcStatus; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.ChangeNotification; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.CreateTechInfoNotification; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OrgOpenroadmDevice; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.change.notification.Edit; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditOperationType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class TestOpenRoadmDeviceChangeNotification { + + private NetconfAccessor accessor = mock(NetconfAccessor.class); + private DataProvider databaseProvider = mock(DataProvider.class); + static ChangeNotification notification = mock(ChangeNotification.class); + static CreateTechInfoNotification notificationTechInfo = mock(CreateTechInfoNotification.class); + final EditOperationType operation = EditOperationType.Merge; + private NodeId nodeId = new NodeId("RoadmA2"); + Edit change = mock(Edit.class); + final Class<OrgOpenroadmDevice> clazzRoadm = OrgOpenroadmDevice.class; + OpenroadmDeviceChangeNotificationListener changeListener = + new OpenroadmDeviceChangeNotificationListener(accessor, databaseProvider); + InstanceIdentifier<?> target = InstanceIdentifier.builder(clazzRoadm).build(); + + @Before + public void init() { + doReturn(target).when(change).getTarget(); + when(change.getOperation()).thenReturn(operation); + when(accessor.getNodeId()).thenReturn(nodeId); + } + + @Test + public void testOnChangeNotification() { + when(notification.getChangeTime()).thenReturn(new DateAndTime("2017-10-22T15:23:43Z")); + changeListener.onChangeNotification(notification); + } + + @Test + public void testCreateTechInfoNotification() { + when(notificationTechInfo.getShelfId()).thenReturn("Shelf688"); + when(notificationTechInfo.getStatus()).thenReturn(RpcStatus.Successful); + changeListener.onCreateTechInfoNotification(notificationTechInfo); + } + +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmInventory.java b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmInventory.java new file mode 100644 index 000000000..f63eeb8b3 --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmInventory.java @@ -0,0 +1,138 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.test; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.OpenroadmInventoryInput; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev191129.NodeIdType; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.LifecycleState; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev191129.OpenroadmVersionType; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OrgOpenroadmDevice; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.circuit.packs.CircuitPacks; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.interfaces.grp.Interface; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.openroadm.device.Info; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.openroadm.device.InfoBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.openroadm.device.Xponder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelves.Shelves; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.XpdrNodeTypes; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TestOpenRoadmInventory { + private static final Logger LOG = LoggerFactory.getLogger(OpenroadmInventoryInput.class); + private NetconfAccessor accessor = mock(NetconfAccessor.class); + private long value1 = 1; + private IpAddress ipAddress = new IpAddress(new Ipv4Address("127.0.0.11")); + private NodeId nodeId = new NodeId("RoadmA2"); + private Info info = new InfoBuilder().setNodeId(NodeIdType.getDefaultInstance("zNhe2i5")).setClli("NodeB") + .setSerialId("0002").setModel("model2").setVendor("VendorA").setCurrentIpAddress(ipAddress) + .setCurrentIpAddress(ipAddress).setCurrentDefaultGateway(new IpAddress(new Ipv4Address("127.0.0.20"))) + .setCurrentDefaultGateway(new IpAddress(new Ipv4Address("127.0.0.20"))).setNodeType(NodeTypes.Rdm) + .setCurrentDatetime(new DateAndTime("2017-10-22T15:23:43Z")).setSoftwareVersion("swversion1234") + .setPrefixLength((short) 28).setMaxDegrees(2).setMaxSrgs(3).setMaxNumBin15minHistoricalPm(32) + .setMaxNumBin24hourHistoricalPm(7).setOpenroadmVersion(OpenroadmVersionType._20).build(); + + private OrgOpenroadmDevice device = mock(OrgOpenroadmDevice.class);; + private Shelves shelf = mock(Shelves.class); + private Interface interfaces = mock(Interface.class); + private CircuitPacks cp = mock(CircuitPacks.class); + private Xponder xpdr = mock(Xponder.class); + OpenroadmInventoryInput roadmInventory = new OpenroadmInventoryInput(accessor, device); + + @Test + public void TestDevice() { + when(accessor.getNodeId()).thenReturn(nodeId); + when(device.getInfo()).thenReturn(info); + + roadmInventory.getInventoryData(value1); + assertEquals(device.getInfo(), info); + + } + + @Test + public void TestShelves() { + when(accessor.getNodeId()).thenReturn(nodeId); + when(device.getInfo()).thenReturn(info); + when(shelf.getShelfPosition()).thenReturn("10"); + when(shelf.getOperationalState()).thenReturn(State.InService); + when(shelf.getSerialId()).thenReturn("nodeid-1"); + when(shelf.getShelfName()).thenReturn("Shelf1"); + when(shelf.getShelfType()).thenReturn("Shelf"); + when(shelf.getClei()).thenReturn("1234567890"); + when(shelf.getVendor()).thenReturn("vendorA"); + when(shelf.getModel()).thenReturn("1"); + when(shelf.getHardwareVersion()).thenReturn("0.1"); + when(shelf.getManufactureDate()).thenReturn(new DateAndTime("2017-10-22T15:23:43Z")); + roadmInventory.getShelvesInventory(shelf, (value1 + 1)); + LOG.info("Shelves test completed"); + + } + + @Test + public void TestCircuitPacks() { + when(accessor.getNodeId()).thenReturn(nodeId); + when(cp.getCircuitPackName()).thenReturn("1/0"); + when(cp.getVendor()).thenReturn("VendorA"); + when(cp.getModel()).thenReturn("Model1"); + when(cp.getSerialId()).thenReturn("46277sgh6"); + when(cp.getClei()).thenReturn("136268785"); + when(cp.getHardwareVersion()).thenReturn("0.1"); + when(cp.getType()).thenReturn("WSS"); + when(cp.getProductCode()).thenReturn("oooooo"); + when(cp.getCircuitPackMode()).thenReturn("inServiceMode"); + when(device.getInfo()).thenReturn(info); + roadmInventory.getCircuitPackInventory(cp, value1 + 1); + + } + + @Test + public void TestInterfaces() { + when(accessor.getNodeId()).thenReturn(nodeId); + when(interfaces.getName()).thenReturn("1GE-interface-1"); + when(interfaces.getDescription()).thenReturn("Ethernet Interface"); + when(interfaces.getSupportingCircuitPackName()).thenReturn("1/0"); + when(device.getInfo()).thenReturn(info); + roadmInventory.getInterfacesInventory(interfaces, value1 + 2); + } + + @Test + public void TestXponder() { + when(xpdr.getXpdrNumber()).thenReturn(1); + when(xpdr.getXpdrType()).thenReturn(XpdrNodeTypes.Mpdr); + when(xpdr.getLifecycleState()).thenReturn(LifecycleState.Deployed); + when(accessor.getNodeId()).thenReturn(nodeId); + when(device.getInfo()).thenReturn(info); + roadmInventory.getXponderInventory(xpdr, value1 + 1); + + } + +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElement.java b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElement.java new file mode 100644 index 000000000..34d61da12 --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElement.java @@ -0,0 +1,272 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.test; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.OpenroadmInventoryInput; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.OpenroadmNetworkElement; +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.NetconfAccessor; +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.yang.gen.v1.http.org.openroadm.alarm.rev191129.ActiveAlarmList; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.Severity; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.active.alarm.list.ActiveAlarms; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.alarm.ProbableCauseBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.alarm.ResourceBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev191129.NodeIdType; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.LifecycleState; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev191129.OpenroadmVersionType; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OrgOpenroadmDevice; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.circuit.pack.ParentCircuitPack; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.circuit.packs.CircuitPacks; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.interfaces.grp.Interface; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.openroadm.device.Info; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.openroadm.device.InfoBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.org.openroadm.device.Xponder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelf.Slots; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.shelves.Shelves; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.XpdrNodeTypes; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.HistoricalPmList; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.group.HistoricalPm; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.list.HistoricalPmEntry; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.rev191129.historical.pm.val.group.Measurement; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmDataType; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmGranularity; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmNamesEnum; +import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.Validity; +import org.opendaylight.yang.gen.v1.http.org.openroadm.probablecause.rev191129.ProbableCauseEnum; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev191129.resource.DeviceBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev191129.ResourceTypeEnum; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Inventory; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class TestOpenRoadmNetworkElement { + + NetconfAccessor accessor = mock(NetconfAccessor.class); + DeviceManagerServiceProvider serviceProvider = mock(DeviceManagerServiceProvider.class); + DataProvider dataprovider = mock(DataProvider.class); + Capabilities capabilities = mock(Capabilities.class); + TransactionUtils transactionUtils = mock(TransactionUtils.class); + DataBroker dataBroker = mock(DataBroker.class); + // OscaNetworkElement optionalNe = mock(OscaNetworkElement.class); + + FaultService faultService = mock(FaultService.class); + OrgOpenroadmDevice device; + // OscaInventoryInput inventoryData = mock(OscaInventoryInput.class); + OpenroadmInventoryInput inventoryData; + private Inventory equipment = mock(Inventory.class); + long level = 1; + private Shelves shelf = mock(Shelves.class); + private List<Shelves> shelfList; + private CircuitPacks cp, cp1, cp2, cp3; + private Interface interfaces = mock(Interface.class); + private Xponder xpdr = mock(Xponder.class); + private IpAddress ipAddress = new IpAddress(new Ipv4Address("127.0.0.11")); + private Info info = new InfoBuilder().setNodeId(NodeIdType.getDefaultInstance("zNhe2i5")).setClli("NodeB") + .setSerialId("0002").setModel("model2").setVendor("VendorA").setCurrentIpAddress(ipAddress) + .setCurrentIpAddress(ipAddress).setCurrentDefaultGateway(new IpAddress(new Ipv4Address("127.0.0.20"))) + .setCurrentDefaultGateway(new IpAddress(new Ipv4Address("127.0.0.20"))).setNodeType(NodeTypes.Rdm) + .setCurrentDatetime(new DateAndTime("2017-10-22T15:23:43Z")).setSoftwareVersion("swversion1234") + .setPrefixLength((short) 28).setMaxDegrees(2).setMaxSrgs(3).setMaxNumBin15minHistoricalPm(32) + .setMaxNumBin24hourHistoricalPm(7).setOpenroadmVersion(OpenroadmVersionType._20).build(); + private ActiveAlarmList alarmList = mock(ActiveAlarmList.class); + private ActiveAlarms activeAlarms = mock(ActiveAlarms.class); + private HistoricalPmList pmDataList = mock(HistoricalPmList.class); + private HistoricalPm historicalPm = mock(HistoricalPm.class); + @Before + public void init() { + when(accessor.getCapabilites()).thenReturn(capabilities); + when(serviceProvider.getFaultService()).thenReturn(faultService); + when(serviceProvider.getDataProvider()).thenReturn(dataprovider); + NodeId nNodeId = new NodeId("RoadmA"); + when(accessor.getNodeId()).thenReturn(nNodeId); + when(accessor.getDataBroker()).thenReturn(dataBroker); + when(accessor.getTransactionUtils()).thenReturn(transactionUtils); + when(accessor.getCapabilites().isSupportingNamespaceAndRevision(OrgOpenroadmDevice.QNAME)).thenReturn(true); + final Class<OrgOpenroadmDevice> openRoadmDev = OrgOpenroadmDevice.class; + // Reading data from device + InstanceIdentifier<OrgOpenroadmDevice> deviceId = InstanceIdentifier.builder(openRoadmDev).build(); + device = mock(OrgOpenroadmDevice.class); + when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, + deviceId)).thenReturn(device); + + when(device.getInfo()).thenReturn(info); + inventoryData = new OpenroadmInventoryInput(accessor, device); + // Reading the shelfs data; + when(shelf.getShelfPosition()).thenReturn("10"); + when(shelf.getOperationalState()).thenReturn(State.InService); + when(shelf.getSerialId()).thenReturn("nodeid-1"); + when(shelf.getShelfName()).thenReturn("Shelf1"); + when(shelf.getShelfType()).thenReturn("Shelf"); + when(shelf.getClei()).thenReturn("1234567890"); + when(shelf.getVendor()).thenReturn("vendorA"); + when(shelf.getModel()).thenReturn("1"); + when(shelf.getHardwareVersion()).thenReturn("0.1"); + when(shelf.getManufactureDate()).thenReturn(new DateAndTime("2017-10-22T15:23:43Z")); + List<Slots> slotList = null; + Slots slots = mock(Slots.class); + when(slots.getLabel()).thenReturn("Slot56746"); + when(slots.getSlotName()).thenReturn("slotofRoadmA"); + when(slots.getProvisionedCircuitPack()).thenReturn("1/0"); + slotList = Arrays.asList(slots); + when(shelf.getSlots()).thenReturn(slotList); + shelfList = Arrays.asList(shelf); + when(device.getShelves()).thenReturn(shelfList); + + // Reading data from CircuitPacks + cp = mock(CircuitPacks.class); + when(cp.getCircuitPackName()).thenReturn("1/0"); + when(cp.getVendor()).thenReturn("VendorA"); + when(cp.getModel()).thenReturn("Model1"); + when(cp.getSerialId()).thenReturn("46277sgh6"); + when(cp.getClei()).thenReturn("136268785"); + when(cp.getHardwareVersion()).thenReturn("0.1"); + when(cp.getType()).thenReturn("WSS"); + when(cp.getProductCode()).thenReturn("oooooo"); + when(cp.getCircuitPackMode()).thenReturn("inServiceMode"); + + ParentCircuitPack parentCp = mock(ParentCircuitPack.class); + when(parentCp.getCircuitPackName()).thenReturn("1/0"); + when(parentCp.getCpSlotName()).thenReturn("Slot1"); + cp1 = mock(CircuitPacks.class); + when(cp1.getCircuitPackName()).thenReturn("1/0 EThernet"); + when(cp1.getVendor()).thenReturn("VendorA"); + when(cp1.getModel()).thenReturn("Model1678"); + when(cp1.getSerialId()).thenReturn("4627dgs7sgh6"); + when(cp1.getClei()).thenReturn("1362d68785"); + when(cp1.getHardwareVersion()).thenReturn("0.1"); + when(cp1.getType()).thenReturn("EthPlug"); + when(cp1.getProductCode()).thenReturn("oooooo"); + when(cp1.getCircuitPackMode()).thenReturn("inServiceMode"); + when(cp1.getParentCircuitPack()).thenReturn(parentCp); + + cp2 = mock(CircuitPacks.class); + when(cp2.getCircuitPackName()).thenReturn("2/0"); + when(cp2.getVendor()).thenReturn("VendorA"); + when(cp2.getModel()).thenReturn("Model1678"); + when(cp2.getSerialId()).thenReturn("4sads7sgh6"); + when(cp2.getClei()).thenReturn("1wew362d68785"); + when(cp2.getHardwareVersion()).thenReturn("0.1"); + when(cp2.getType()).thenReturn("WSS"); + when(cp2.getProductCode()).thenReturn("osooooo"); + when(cp2.getCircuitPackMode()).thenReturn("inServiceMode"); + + cp3 = mock(CircuitPacks.class); + when(parentCp.getCircuitPackName()).thenReturn("2/0"); + when(parentCp.getCpSlotName()).thenReturn("Slot1"); + when(cp3.getCircuitPackName()).thenReturn("2/0 OCS"); + when(cp3.getVendor()).thenReturn("VendorA"); + when(cp3.getModel()).thenReturn("Model1678"); + when(cp3.getSerialId()).thenReturn("dswsads7sgh6"); + when(cp3.getClei()).thenReturn("1ew62d68785"); + when(cp3.getHardwareVersion()).thenReturn("0.1"); + when(cp3.getType()).thenReturn("OCS Plug"); + when(cp3.getProductCode()).thenReturn("osooooo"); + when(cp3.getCircuitPackMode()).thenReturn("inServiceMode"); + when(cp3.getParentCircuitPack()).thenReturn(parentCp); + List<CircuitPacks> cpList = Arrays.asList(cp, cp1, cp2, cp3); + when(device.getCircuitPacks()).thenReturn(cpList); + + // Reading Interface Data + when(interfaces.getName()).thenReturn("1GE-interface-1"); + when(interfaces.getDescription()).thenReturn("Ethernet Interface"); + when(interfaces.getSupportingCircuitPackName()).thenReturn("1/0 EThernet"); + List<Interface> interfacesList = Arrays.asList(interfaces); + when(device.getInterface()).thenReturn(interfacesList); + + // Reading Xponder Data + when(xpdr.getXpdrNumber()).thenReturn(1); + when(xpdr.getXpdrType()).thenReturn(XpdrNodeTypes.Mpdr); + when(xpdr.getLifecycleState()).thenReturn(LifecycleState.Deployed); + List<Xponder> xpnderList = Arrays.asList(xpdr); + when(device.getXponder()).thenReturn(xpnderList); + + // Read initial Alarm data + final Class<ActiveAlarmList> classAlarm = ActiveAlarmList.class; + InstanceIdentifier<ActiveAlarmList> alarmDataIid = InstanceIdentifier.builder(classAlarm).build(); + when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, + alarmDataIid)).thenReturn(alarmList); + when(activeAlarms.getId()).thenReturn("Alarm1"); + when(activeAlarms.getCircuitId()).thenReturn("1/0"); + when(activeAlarms.getRaiseTime()).thenReturn(new DateAndTime("2017-10-22T15:23:43Z")); + when(activeAlarms.getSeverity()).thenReturn(Severity.Critical); + when(activeAlarms.getProbableCause()) + .thenReturn(new ProbableCauseBuilder().setCause(ProbableCauseEnum.AutomaticLaserShutdown).build()); + when(activeAlarms.getAdditionalDetail()).thenReturn("LaserShutdown"); + when(activeAlarms.getResource()).thenReturn(new ResourceBuilder() + .setDevice(new DeviceBuilder().setNodeId(NodeIdType.getDefaultInstance("zNhe2i5")).build()).build()); + List<ActiveAlarms> activeAlarmlist = Arrays.asList(activeAlarms); + when(alarmList.getActiveAlarms()).thenReturn(activeAlarmlist); + + // Read PM Data + final Class<HistoricalPmList> pmDataClass = HistoricalPmList.class; + InstanceIdentifier<HistoricalPmList> pmDataIid = InstanceIdentifier.builder(pmDataClass).build(); + when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, + pmDataIid)).thenReturn(pmDataList); + + Measurement measurement = mock(Measurement.class); + PmDataType pmDataType = mock(PmDataType.class); + when(pmDataType.getUint64()).thenReturn(BigInteger.valueOf(2425425)); + when(measurement.getBinNumber()).thenReturn(1452); + when(measurement.getCompletionTime()).thenReturn(new DateAndTime("2018-10-22T15:23:43Z")); + when(measurement.getGranularity()).thenReturn(PmGranularity._24Hour); + when(measurement.getPmParameterUnit()).thenReturn("6824545199534863756"); + when(measurement.getPmParameterValue()).thenReturn(pmDataType); + when(measurement.getValidity()).thenReturn(Validity.Partial); + + List<Measurement> measurementList = Arrays.asList(measurement); + when(historicalPm.getMeasurement()).thenReturn(measurementList); + when(historicalPm.getType()).thenReturn(PmNamesEnum.DelayTCM1Down); + when(historicalPm.getExtension()).thenReturn("OpticalPowerOutput"); + List<HistoricalPm> historicalPmList = Arrays.asList(historicalPm); + HistoricalPmEntry histPmEntry = mock(HistoricalPmEntry.class); + when(histPmEntry.getHistoricalPm()).thenReturn(historicalPmList); + when(histPmEntry.getPmResourceType()).thenReturn(ResourceTypeEnum.CircuitPack); + List<HistoricalPmEntry> histPmList = Arrays.asList(histPmEntry); + when(pmDataList.getHistoricalPmEntry()).thenReturn(histPmList); + + } + + @Test + public void test() { + OpenroadmNetworkElement optionalNe = new OpenroadmNetworkElement(accessor, serviceProvider); + optionalNe.initialReadFromNetworkElement(); + } + +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElementFactory.java b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElementFactory.java new file mode 100644 index 000000000..901a7b376 --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElementFactory.java @@ -0,0 +1,97 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.test; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import java.io.IOException; +import org.junit.After; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.OpenroadmNetworkElementFactory; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.test.mock.NetconfAccessorMock; +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.TransactionUtils; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.OrgOpenroadmDevice; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.QName; + +public class TestOpenRoadmNetworkElementFactory { + + static NetconfAccessor accessor; + static DeviceManagerServiceProvider serviceProvider; + static Capabilities capabilities; + QName qCapability; + private NodeId nodeId = new NodeId("RoadmA2"); + static OrgOpenroadmDevice device; + static TransactionUtils transactionUtils; + static DataBroker dataBroker; + + @BeforeClass + public static void init() throws InterruptedException, IOException { + accessor = mock(NetconfAccessorMock.class); + capabilities = mock(Capabilities.class); + dataBroker = mock(DataBroker.class); + transactionUtils = mock(TransactionUtils.class); + serviceProvider = mock(DeviceManagerServiceProvider.class); + when(accessor.getCapabilites()).thenReturn(capabilities); + when(accessor.getDataBroker()).thenReturn(dataBroker); + when(accessor.getTransactionUtils()).thenReturn(transactionUtils); + when(serviceProvider.getDataProvider()).thenReturn(null); + device = mock(OrgOpenroadmDevice.class); + final Class<OrgOpenroadmDevice> openRoadmDev = OrgOpenroadmDevice.class; + InstanceIdentifier<OrgOpenroadmDevice> deviceId = InstanceIdentifier.builder(openRoadmDev).build(); + when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, + deviceId)).thenReturn(device); + } + + @Test + public void testCapabilties() { + when(accessor.getNodeId()).thenReturn(nodeId); + when(accessor.getCapabilites().isSupportingNamespace(OrgOpenroadmDevice.QNAME)).thenReturn(true); + + // when(accessor.getCapabilites().isSupportingNamespace(SimulatorStatus.QNAME)).thenReturn(false); + OpenroadmNetworkElementFactory factory = new OpenroadmNetworkElementFactory(); + assertTrue((factory.create(accessor, serviceProvider)).isPresent()); + } + + @Test + public void testCreateNone() throws Exception { + when(accessor.getCapabilites().isSupportingNamespace(OrgOpenroadmDevice.QNAME)).thenReturn(false); + // when(accessor.getCapabilites().isSupportingNamespace(SimulatorStatus.QNAME)).thenReturn(false); + OpenroadmNetworkElementFactory factory = new OpenroadmNetworkElementFactory(); + assertTrue(!(factory.create(accessor, serviceProvider).isPresent())); + } + + @After + public void cleanUp() throws Exception { + + } + + +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/mock/NetconfAccessorMock.java b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/mock/NetconfAccessorMock.java new file mode 100644 index 000000000..8b13b000f --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/mock/NetconfAccessorMock.java @@ -0,0 +1,96 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.test.mock; + +import com.google.common.util.concurrent.ListenableFuture; +import org.eclipse.jdt.annotation.NonNull; +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.TransactionUtils; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.MountPoint; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.NotificationListener; +import org.opendaylight.yangtools.yang.common.RpcResult; + +/** + */ +public class NetconfAccessorMock implements NetconfAccessor { + + private final NodeId nNodeId; + private final NetconfNode netconfNode; + private final MountPoint mountpoint; + private final DataBroker netconfNodeDataBroker; + + public NetconfAccessorMock(NodeId nNodeId, NetconfNode netconfNode, MountPoint mountpoint, + DataBroker netconfNodeDataBroker) { + this.nNodeId = nNodeId; + this.netconfNode = netconfNode; + this.mountpoint = mountpoint; + this.netconfNodeDataBroker = netconfNodeDataBroker; + } + + @Override + public NodeId getNodeId() { + return nNodeId; + } + + @Override + public NetconfNode getNetconfNode() { + return netconfNode; + } + + @Override + public Capabilities getCapabilites() { + return null; + } + + @Override + public DataBroker getDataBroker() { + return netconfNodeDataBroker; + } + + @Override + public MountPoint getMountpoint() { + return mountpoint; + } + + @Override + public TransactionUtils getTransactionUtils() { + return null; + } + + @Override + public <T extends NotificationListener> ListenerRegistration<NotificationListener> doRegisterNotificationListener( + @NonNull T listener) { + return null; + } + + @Override + public ListenableFuture<RpcResult<CreateSubscriptionOutput>> registerNotificationsStream(String streamName) { + return null; + } + +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/mock/TransactionUtilsMock.java b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/mock/TransactionUtilsMock.java new file mode 100644 index 000000000..68383e68f --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/mock/TransactionUtilsMock.java @@ -0,0 +1,50 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.test.mock; + +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; +import org.eclipse.jdt.annotation.Nullable; +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.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class TransactionUtilsMock implements TransactionUtils { + + @Override + public <T extends DataObject> @Nullable T readData(DataBroker dataBroker, LogicalDatastoreType dataStoreType, + InstanceIdentifier<T> iid) { + // TODO Auto-generated method stub + return null; + } + + @Override + public <T extends DataObject> @Nullable T readDataOptionalWithStatus(DataBroker dataBroker, + LogicalDatastoreType dataStoreType, InstanceIdentifier<T> iid, AtomicBoolean noErrorIndication, + AtomicReference<String> statusIndicator) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/sdnr/wt/devicemanager-openroadm/provider/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 000000000..ca6ee9cea --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline
\ No newline at end of file diff --git a/sdnr/wt/devicemanager-openroadm/provider/src/test/resources/simplelogger.properties b/sdnr/wt/devicemanager-openroadm/provider/src/test/resources/simplelogger.properties new file mode 100644 index 000000000..9af26dc96 --- /dev/null +++ b/sdnr/wt/devicemanager-openroadm/provider/src/test/resources/simplelogger.properties @@ -0,0 +1,61 @@ +# +# ============LICENSE_START======================================================= +# ONAP : ccsdk features +# ================================================================================ +# Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END======================================================= +# +# + +# SLF4J's SimpleLogger configuration file +# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err. + +# Default logging detail level for all instances of SimpleLogger. +# Must be one of ("trace", "debug", "info", "warn", or "error"). +# If not specified, defaults to "info". +org.slf4j.simpleLogger.defaultLogLevel=info + +# Logging detail level for a SimpleLogger instance named "xxx.yyy.zzz". +# Must be one of ("trace", "debug", "info", "warn", or "error"). +# If not specified, the default logging detail level is used. +# org.slf4j.simpleLogger.log.xxx.yyy=debug +org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager=info +org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager.test=debug +org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.database=debug +org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager.archiveservice=info +org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.Resources=info +org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container=info + +# Set to true if you want the current date and time to be included in output messages. +# Default is false, and will output the number of milliseconds elapsed since startup. +#org.slf4j.simpleLogger.showDateTime=false + +# The date and time format to be used in the output messages. +# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat. +# If the format is not specified or is invalid, the default format is used. +# The default format is yyyy-MM-dd HH:mm:ss:SSS Z. +#org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z + +# Set to true if you want to output the current thread name. +# Defaults to true. +#org.slf4j.simpleLogger.showThreadName=true + +# Set to true if you want the Logger instance name to be included in output messages. +# Defaults to true. +#org.slf4j.simpleLogger.showLogName=true + +# Set to true if you want the last component of the name to be included in output messages. +# Defaults to false. +#org.slf4j.simpleLogger.showShortLogName=false |