From 1c4ad2b1a689d309d456a6ada894d1e8b1971b3c Mon Sep 17 00:00:00 2001 From: Ravi Pendurty Date: Mon, 9 Aug 2021 16:03:02 +0530 Subject: Update devicemanager-openroadm unit tests and some minor changes Issue-ID: CCSDK-3419 Signed-off-by: Ravi Pendurty Change-Id: I3382de7a9b1f863c0eb31eb4787b402330ce6516 Signed-off-by: Ravi Pendurty --- .../TestOpenRoadmDeviceChangeNotification.java | 9 +---- .../openroadm/test/TestOpenRoadmInventory.java | 2 +- .../test/TestOpenRoadmNetworkElement.java | 9 ++--- .../test/TestOpenRoadmNetworkElementFactory.java | 38 +++++++++--------- .../openroadm/test/TestOpenRoadmPMDataBuilder.java | 46 ++++++++++++++++------ 5 files changed, 60 insertions(+), 44 deletions(-) (limited to 'sdnr/wt/devicemanager-onap/openroadm/provider/src/test') diff --git a/sdnr/wt/devicemanager-onap/openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmDeviceChangeNotification.java b/sdnr/wt/devicemanager-onap/openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmDeviceChangeNotification.java index a6d276d48..ca9ce351c 100644 --- a/sdnr/wt/devicemanager-onap/openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmDeviceChangeNotification.java +++ b/sdnr/wt/devicemanager-onap/openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmDeviceChangeNotification.java @@ -21,6 +21,7 @@ */ package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.test; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -91,13 +92,7 @@ public class TestOpenRoadmDeviceChangeNotification { public void testOnCreateTechInfoNotification() { when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID)); deviceChangeListener.onCreateTechInfoNotification(createTechInfoNotification()); - EventlogEntity event = new EventlogBuilder().setNodeId(NODEID).setCounter(1) - .setId(createTechInfoNotification().getShelfId()) - .setAttributeName(createTechInfoNotification().getShelfId()) - .setObjectId(createTechInfoNotification().getShelfId()) - .setNewValue(createTechInfoNotification().getStatus().getName()).setSourceType(SourceType.Netconf) - .setTimestamp(ncTimeConverter.getTimeStamp()).build(); - verify(databaseService).writeEventLog(event); + verify(databaseService).writeEventLog(any(EventlogEntity.class)); } /** diff --git a/sdnr/wt/devicemanager-onap/openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmInventory.java b/sdnr/wt/devicemanager-onap/openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmInventory.java index e856511e5..1924bc665 100644 --- a/sdnr/wt/devicemanager-onap/openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmInventory.java +++ b/sdnr/wt/devicemanager-onap/openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmInventory.java @@ -66,7 +66,7 @@ public class TestOpenRoadmInventory { .setMaxNumBin15minHistoricalPm(Uint16.valueOf(32)).setMaxNumBin24hourHistoricalPm(Uint16.valueOf(7)) .setOpenroadmVersion(OpenroadmVersionType._20).build(); - private OrgOpenroadmDevice device = mock(OrgOpenroadmDevice.class);; + private OrgOpenroadmDevice device = mock(OrgOpenroadmDevice.class); private Shelves shelf = mock(Shelves.class); private Interface interfaces = mock(Interface.class); private CircuitPacks cp = mock(CircuitPacks.class); diff --git a/sdnr/wt/devicemanager-onap/openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElement.java b/sdnr/wt/devicemanager-onap/openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElement.java index f5b40d050..4119ff904 100644 --- a/sdnr/wt/devicemanager-onap/openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElement.java +++ b/sdnr/wt/devicemanager-onap/openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElement.java @@ -29,7 +29,6 @@ import java.util.HashMap; import java.util.Map; import org.eclipse.jdt.annotation.Nullable; import org.junit.Before; -import org.junit.Ignore; 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; @@ -296,15 +295,15 @@ public class TestOpenRoadmNetworkElement { } - - - @Ignore @Test public void test() { OpenroadmNetworkElement optionalNe = new OpenroadmNetworkElement(accessor, serviceProvider); optionalNe.initialReadFromNetworkElement(); verify(dataprovider).writeInventory(accessor.getNodeId().getValue(), - Arrays.asList(inventoryData.getInventoryData(Uint32.valueOf(1)))); + Arrays.asList(inventoryData.getInventoryData(Uint32.valueOf(0)), + inventoryData.getShelvesInventory(shelf, Uint32.valueOf(1)), + inventoryData.getXponderInventory(xpdr, Uint32.valueOf(1)), + inventoryData.getCircuitPackInventory(cp3, Uint32.valueOf(2)))); } } diff --git a/sdnr/wt/devicemanager-onap/openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElementFactory.java b/sdnr/wt/devicemanager-onap/openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElementFactory.java index 40a48c358..8d3bfd9fa 100644 --- a/sdnr/wt/devicemanager-onap/openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElementFactory.java +++ b/sdnr/wt/devicemanager-onap/openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmNetworkElementFactory.java @@ -28,7 +28,7 @@ import static org.mockito.Mockito.when; import java.io.IOException; import java.util.Optional; import org.junit.After; -import org.junit.BeforeClass; +import org.junit.Before; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.OpenroadmNetworkElementFactory; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider; @@ -43,54 +43,56 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class TestOpenRoadmNetworkElementFactory { - private static NetconfBindingAccessor accessor; + private static NetconfBindingAccessor bindingAccessor; private static DeviceManagerServiceProvider serviceProvider; private static Capabilities capabilities; private static TransactionUtils transactionUtils; private static DataBroker dataBroker; - @BeforeClass - public static void init() throws InterruptedException, IOException { - accessor = mock(NetconfBindingAccessor.class); + @Before + public void init() throws InterruptedException, IOException { + bindingAccessor = mock(NetconfBindingAccessor.class); capabilities = mock(Capabilities.class); dataBroker = mock(DataBroker.class); transactionUtils = mock(TransactionUtils.class); serviceProvider = mock(DeviceManagerServiceProvider.class); - when(accessor.getNodeId()).thenReturn(new NodeId("RoadmA2")); - when(accessor.getCapabilites()).thenReturn(capabilities); - when(accessor.getDataBroker()).thenReturn(dataBroker); - when(accessor.getTransactionUtils()).thenReturn(transactionUtils); - when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(accessor)); + + when(bindingAccessor.getCapabilites()).thenReturn(capabilities); + when(bindingAccessor.getNetconfBindingAccessor()).thenReturn(Optional.of(bindingAccessor)); + when(bindingAccessor.getNodeId()).thenReturn(new NodeId("RoadmA2")); + when(bindingAccessor.getNodeId()).thenReturn(new NodeId("RoadmA2")); + when(bindingAccessor.getDataBroker()).thenReturn(dataBroker); + when(bindingAccessor.getTransactionUtils()).thenReturn(transactionUtils); when(serviceProvider.getDataProvider()).thenReturn(null); final Class openRoadmDev = OrgOpenroadmDevice.class; InstanceIdentifier deviceId = InstanceIdentifier.builder(openRoadmDev).build(); - when(accessor.getTransactionUtils().readData(accessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, + when(bindingAccessor.getTransactionUtils().readData(bindingAccessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, deviceId)).thenReturn(mock(OrgOpenroadmDevice.class)); - when(accessor.getTransactionUtils()).thenReturn(mock(TransactionUtils.class)); + when(bindingAccessor.getTransactionUtils()).thenReturn(mock(TransactionUtils.class)); } @Test public void testCapabiltiesAvailable1() { - when(accessor.getCapabilites().isSupportingNamespaceAndRevision(OrgOpenroadmDevice.QNAME)).thenReturn(true); + when(bindingAccessor.getCapabilites().isSupportingNamespaceAndRevision(OrgOpenroadmDevice.QNAME)).thenReturn(true); OpenroadmNetworkElementFactory factory = new OpenroadmNetworkElementFactory(); - assertTrue((factory.create(accessor, serviceProvider)).isPresent()); + assertTrue((factory.create(bindingAccessor, serviceProvider)).isPresent()); } @Test public void testCapabiltiesAvailable2() { - when(accessor.getCapabilites().isSupportingNamespaceAndRevision("http://org/openroadm/device", "2018-10-19")) + when(bindingAccessor.getCapabilites().isSupportingNamespaceAndRevision("http://org/openroadm/device", "2018-10-19")) .thenReturn(true); OpenroadmNetworkElementFactory factory = new OpenroadmNetworkElementFactory(); - assertTrue((factory.create(accessor, serviceProvider)).isPresent()); + assertTrue((factory.create(bindingAccessor, serviceProvider)).isPresent()); } @Test public void testCapabiltiesNotAvailable() throws Exception { - when(accessor.getCapabilites().isSupportingNamespaceAndRevision(OrgOpenroadmDevice.QNAME)).thenReturn(false); + when(bindingAccessor.getCapabilites().isSupportingNamespaceAndRevision(OrgOpenroadmDevice.QNAME)).thenReturn(false); OpenroadmNetworkElementFactory factory = new OpenroadmNetworkElementFactory(); - assertFalse(factory.create(accessor, serviceProvider).isPresent()); + assertFalse(factory.create(bindingAccessor, serviceProvider).isPresent()); } @After diff --git a/sdnr/wt/devicemanager-onap/openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmPMDataBuilder.java b/sdnr/wt/devicemanager-onap/openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmPMDataBuilder.java index 9d80e8f75..2a70ec7b6 100644 --- a/sdnr/wt/devicemanager-onap/openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmPMDataBuilder.java +++ b/sdnr/wt/devicemanager-onap/openroadm/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/openroadm/test/TestOpenRoadmPMDataBuilder.java @@ -66,6 +66,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.common.Uint16; import org.opendaylight.yangtools.yang.common.Uint64; + public class TestOpenRoadmPMDataBuilder { // variables // end of variables @@ -87,16 +88,8 @@ public class TestOpenRoadmPMDataBuilder { private Map historicalPMCollection = new HashMap(); private Map historicalPmEntryCollection = new HashMap(); - private PathArgument pa =new PathArgument() { - @Override - public int compareTo(PathArgument o) { - return 0; - } - @Override - public @NonNull Class getType() { - return Pmdata15mEntity.class; - } - }; + + // public methods @Before @@ -138,8 +131,22 @@ public class TestOpenRoadmPMDataBuilder { when(historicalPm.getMeasurement()).thenReturn(measurementData); historicalPMCollection.put(historicalPmBuilder.key(), historicalPmBuilder.build()); + PathArgument pa =new PathArgument() { + + @Override + public int compareTo(PathArgument o) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public @NonNull Class getType() { + // TODO Auto-generated method stub + return Pmdata15mEntity.class; + } + }; historicalPmEntryBuiler.setPmResourceInstance(InstanceIdentifier.create(Arrays.asList(pa))) - .setPmResourceTypeExtension("dshjdekjdewkk") + .setPmResourceTypeExtension("dshjdekjdewkk") .setPmResourceType(ResourceTypeEnum.CircuitPack).setHistoricalPm(historicalPMCollection); historicalPmEntryCollection.put(historicalPmEntryBuiler.key(), historicalPmEntryBuiler.build()); @@ -161,10 +168,23 @@ public class TestOpenRoadmPMDataBuilder { historicalPmBuilder.setType(PmNamesEnum.ErroredSeconds).setDirection(Direction.Rx) .setExtension("sajhsiwiduwugdhegdeuz").setLocation(Location.FarEnd).setMeasurement(measurementData); when(historicalPm.getMeasurement()).thenReturn(measurementData); - + PathArgument pa =new PathArgument() { + + @Override + public int compareTo(PathArgument o) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public Class getType() { + // TODO Auto-generated method stub + return Pmdata15mEntity.class; + } + }; historicalPMCollection.put(historicalPmBuilder.key(), historicalPmBuilder.build()); historicalPmEntryBuiler.setPmResourceInstance(InstanceIdentifier.create(Arrays.asList(pa))) - .setPmResourceTypeExtension("dshjdekjdewkk") + .setPmResourceTypeExtension("dshjdekjdewkk") .setPmResourceType(ResourceTypeEnum.Device).setHistoricalPm(historicalPMCollection); historicalPmEntryCollection.put(historicalPmEntryBuiler.key(), historicalPmEntryBuiler.build()); -- cgit 1.2.3-korg