From 5cf15b27796b68b3edbfc1e59f258dee1e10b2b9 Mon Sep 17 00:00:00 2001 From: highstreetherbert Date: Wed, 17 Feb 2021 16:32:31 +0100 Subject: Increase coverage of netconfnode-state-service Add junit tests to provider Issue-ID: CCSDK-3171 Signed-off-by: highstreetherbert Change-Id: I3c32859f1e30b9d715d74d9125f3603805ea7808 Signed-off-by: highstreetherbert --- .../impl/access/NetconfAccessorImpl.java | 8 ++--- .../binding/NetconfBindingNotificationsImpl.java | 36 ++++++++++++++++------ 2 files changed, 31 insertions(+), 13 deletions(-) (limited to 'sdnr/wt/netconfnode-state-service/provider/src/main') diff --git a/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/NetconfAccessorImpl.java b/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/NetconfAccessorImpl.java index 5ff6caf56..189845831 100644 --- a/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/NetconfAccessorImpl.java +++ b/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/NetconfAccessorImpl.java @@ -80,10 +80,10 @@ public class NetconfAccessorImpl implements NetconfAccessor { this(new NodeId(nodeId), netconfNode, netconfCommunicatorManager, domContext); } - protected NetconfAccessorImpl(NetconfAccessorImpl accessor) { - this.nodeId = accessor.nodeId; - this.netconfNode = accessor.netconfNode; - this.capabilities = accessor.capabilities; + public NetconfAccessorImpl(NetconfAccessorImpl accessor) { + this.nodeId = accessor.getNodeId(); + this.netconfNode = accessor.getNetconfNode(); + this.capabilities = accessor.getCapabilites(); this.netconfCommunicatorManager = accessor.netconfCommunicatorManager; this.domContext = accessor.domContext; } diff --git a/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/binding/NetconfBindingNotificationsImpl.java b/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/binding/NetconfBindingNotificationsImpl.java index 6716581a2..46ff07b2c 100644 --- a/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/binding/NetconfBindingNotificationsImpl.java +++ b/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/binding/NetconfBindingNotificationsImpl.java @@ -23,9 +23,11 @@ package org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access.bind import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; +import java.util.Collections; import java.util.List; import java.util.Optional; import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; import org.onap.ccsdk.features.sdnr.wt.common.YangHelper; import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNotifications; import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access.NetconfAccessorImpl; @@ -57,12 +59,14 @@ public class NetconfBindingNotificationsImpl extends NetconfBindingAccessorImpl } @Override - public ListenableFuture> registerNotificationsStream(@NonNull String streamName) { + public ListenableFuture> registerNotificationsStream( + @NonNull String streamName) { String failMessage = ""; final Optional optionalRpcConsumerService = getMountpoint().getService(RpcConsumerRegistry.class); if (optionalRpcConsumerService.isPresent()) { - final NotificationsService rpcService = optionalRpcConsumerService.get().getRpcService(NotificationsService.class); + final NotificationsService rpcService = + optionalRpcConsumerService.get().getRpcService(NotificationsService.class); final CreateSubscriptionInputBuilder createSubscriptionInputBuilder = new CreateSubscriptionInputBuilder(); createSubscriptionInputBuilder.setStream(new StreamNameType(streamName)); @@ -72,6 +76,7 @@ public class NetconfBindingNotificationsImpl extends NetconfBindingAccessorImpl if (createSubscriptionInput == null) { failMessage = "createSubscriptionInput is null for mountpoint " + getNodeId(); } else { + // Regular case, return value return rpcService.createSubscription(createSubscriptionInput); } } catch (NullPointerException e) { @@ -80,6 +85,7 @@ public class NetconfBindingNotificationsImpl extends NetconfBindingAccessorImpl } else { failMessage = "No RpcConsumerRegistry avaialble."; } + //Be here only in case of problem and return failed indication log.warn(failMessage); RpcResultBuilder result = RpcResultBuilder.failed(); result.withError(ErrorType.APPLICATION, failMessage); @@ -91,9 +97,17 @@ public class NetconfBindingNotificationsImpl extends NetconfBindingAccessorImpl @Override public void registerNotificationsStream(List streamList) { for (Stream stream : streamList) { - log.info("Stream Name = {}, Stream Description = {}", stream.getName().getValue(), stream.getDescription()); - if (!(stream.getName().getValue().equals(NetconfNotifications.DefaultNotificationsStream))) // Since this stream is already registered - registerNotificationsStream(stream.getName().getValue()); + @Nullable + StreamNameType streamName = stream.getName(); + if (streamName != null) { + String streamNameValue = stream.getName().getValue(); + log.info("Stream Name = {}, Stream Description = {}", streamNameValue, stream.getDescription()); + if (!(streamNameValue.equals(NetconfNotifications.DefaultNotificationsStream))) + // Register any not default stream. Default stream is already registered + registerNotificationsStream(streamNameValue); + } else { + log.warn("Ignore a stream without name"); + } } } @@ -116,10 +130,14 @@ public class NetconfBindingNotificationsImpl extends NetconfBindingAccessorImpl final Class netconfClazz = Netconf.class; InstanceIdentifier streamsIID = InstanceIdentifier.builder(netconfClazz).build(); - Netconf res = getTransactionUtils().readData(getDataBroker(), - LogicalDatastoreType.OPERATIONAL, streamsIID); - Streams streams = res.getStreams(); - return YangHelper.getList(streams.getStream()); + Netconf res = getTransactionUtils().readData(getDataBroker(), LogicalDatastoreType.OPERATIONAL, streamsIID); + if (res != null) { + Streams streams = res.getStreams(); + if (streams != null) { + return YangHelper.getList(streams.nonnullStream()); + } + } + return Collections.emptyList(); } @Override -- cgit 1.2.3-korg