From d2ef8edac288371db8bf049a7a82b3e084862743 Mon Sep 17 00:00:00 2001 From: Ravi Pendurty Date: Tue, 31 Aug 2021 11:45:05 +0530 Subject: Fix Sonar reported bugs Improve code coverage Issue-ID: SDNC-1603 Signed-off-by: Ravi Pendurty Change-Id: Icb38a02ce62f327c114054c2a1db40d4cb242b6c Signed-off-by: Ravi Pendurty --- .../onf/impl/ONFCoreNetworkElementFactory.java | 27 +++++++++++++--------- .../onf/ne/ONFCoreNetworkElement12Microwave.java | 14 +++++++---- 2 files changed, 25 insertions(+), 16 deletions(-) (limited to 'sdnr/wt/devicemanager-onap/onf12') diff --git a/sdnr/wt/devicemanager-onap/onf12/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf/impl/ONFCoreNetworkElementFactory.java b/sdnr/wt/devicemanager-onap/onf12/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf/impl/ONFCoreNetworkElementFactory.java index 06558ad5a..b0125f4f0 100644 --- a/sdnr/wt/devicemanager-onap/onf12/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf/impl/ONFCoreNetworkElementFactory.java +++ b/sdnr/wt/devicemanager-onap/onf12/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf/impl/ONFCoreNetworkElementFactory.java @@ -61,19 +61,24 @@ public class ONFCoreNetworkElementFactory implements NetworkElementFactory { if (capabilities.isSupportingNamespaceAndRevision(NetworkElement.QNAME)) { OnfMicrowaveModel onfMicrowaveModel = null; Optional bindingAccessor = accessor.getNetconfBindingAccessor(); - if (capabilities.isSupportingNamespaceAndRevision(WrapperMicrowaveModelRev170324.QNAME)) { - onfMicrowaveModel = new WrapperMicrowaveModelRev170324(bindingAccessor.get(), serviceProvider); - } else if (capabilities.isSupportingNamespaceAndRevision(WrapperMicrowaveModelRev180907.QNAME)) { - onfMicrowaveModel = new WrapperMicrowaveModelRev180907(bindingAccessor.get(), serviceProvider); - } else if (capabilities.isSupportingNamespaceAndRevision(WrapperMicrowaveModelRev181010.QNAME)) { - onfMicrowaveModel = new WrapperMicrowaveModelRev181010(bindingAccessor.get(), serviceProvider); - } + if (bindingAccessor.isPresent()) { + if (capabilities.isSupportingNamespaceAndRevision(WrapperMicrowaveModelRev170324.QNAME)) { + onfMicrowaveModel = new WrapperMicrowaveModelRev170324(bindingAccessor.get(), serviceProvider); + } else if (capabilities.isSupportingNamespaceAndRevision(WrapperMicrowaveModelRev180907.QNAME)) { + onfMicrowaveModel = new WrapperMicrowaveModelRev180907(bindingAccessor.get(), serviceProvider); + } else if (capabilities.isSupportingNamespaceAndRevision(WrapperMicrowaveModelRev181010.QNAME)) { + onfMicrowaveModel = new WrapperMicrowaveModelRev181010(bindingAccessor.get(), serviceProvider); + } - if (onfMicrowaveModel != null) { - return Optional.of(new ONFCoreNetworkElement12Microwave(bindingAccessor.get(), serviceProvider, configuration, - onfMicrowaveModel)); + if (onfMicrowaveModel != null) { + return Optional.of(new ONFCoreNetworkElement12Microwave(bindingAccessor.get(), serviceProvider, + configuration, onfMicrowaveModel)); + } else { + return Optional.of( + new ONFCoreNetworkElement12Basic(bindingAccessor.get(), serviceProvider, configuration)); + } } else { - return Optional.of(new ONFCoreNetworkElement12Basic(bindingAccessor.get(), serviceProvider, configuration)); + log.error("Netconf Bindingaccessor is not present. This is a fatal issue and needs to be corrected for devicemanagers to work correctly."); } } diff --git a/sdnr/wt/devicemanager-onap/onf12/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf/ne/ONFCoreNetworkElement12Microwave.java b/sdnr/wt/devicemanager-onap/onf12/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf/ne/ONFCoreNetworkElement12Microwave.java index 836f36214..736fd4742 100644 --- a/sdnr/wt/devicemanager-onap/onf12/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf/ne/ONFCoreNetworkElement12Microwave.java +++ b/sdnr/wt/devicemanager-onap/onf12/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/onf/ne/ONFCoreNetworkElement12Microwave.java @@ -380,11 +380,15 @@ public class ONFCoreNetworkElement12Microwave extends ONFCoreNetworkElement12Bas LOG.info("Begin registration listener for Mountpoint"); final Optional optionalNotificationService = mountPoint.getService(NotificationService.class); - final NotificationService notificationService = optionalNotificationService.get(); - // notificationService.registerNotificationListener(microwaveEventListener); - listenerRegistrationresult = - notificationService.registerNotificationListener(microwaveModel.getNotificationListener()); - LOG.info("End registration listener for Mountpoint Result: {}", listenerRegistrationresult); + if (optionalNotificationService.isPresent()) { + final NotificationService notificationService = optionalNotificationService.get(); + // notificationService.registerNotificationListener(microwaveEventListener); + listenerRegistrationresult = + notificationService.registerNotificationListener(microwaveModel.getNotificationListener()); + LOG.info("End registration listener for Mountpoint Result: {}", listenerRegistrationresult); + } else { + LOG.error("Could not get NotificationService, hence microwave notification listener not registered"); + } } /*------------------------------------------------------------ -- cgit 1.2.3-korg