From dadb9010c712e92b430b38aa3ab2de250c48947f Mon Sep 17 00:00:00 2001 From: "matus.kubica" Date: Wed, 19 Apr 2017 14:52:45 +0200 Subject: [PATCH] Bug 8153: Enforce check-style on messagebus-netconf Organize Imports for Checkstyle compliance. Checkstyle compliance: line length. Checkstyle compliance: various types of small changes. Checkstyle compliant Exception handling. Checkstyle final clean up & enforcement. Change-Id: I51b121d8aec45999cef18a960c4b4a0a1c00c57c Signed-off-by: matus.kubica --- netconf/messagebus-netconf/pom.xml | 12 ++++ ...nnectionNotificationTopicRegistration.java | 32 +++++----- .../netconf/NetconfEventSource.java | 63 ++++++++++++------- .../netconf/NetconfEventSourceManager.java | 24 ++++--- .../netconf/NetconfEventSourceMount.java | 46 ++++++++------ .../NetconfEventSourceRegistration.java | 26 ++++---- .../NotificationTopicRegistration.java | 10 ++- .../StreamNotificationTopicRegistration.java | 30 +++++---- ...tionNotificationTopicRegistrationTest.java | 12 ++-- .../NetconfEventSourceManagerTest.java | 42 ++++++++----- .../netconf/NetconfEventSourceMountTest.java | 31 +++++---- .../netconf/NetconfEventSourceTest.java | 32 ++++++---- .../netconf/NetconfTestUtils.java | 23 ++++--- ...reamNotificationTopicRegistrationTest.java | 15 +++-- 14 files changed, 245 insertions(+), 153 deletions(-) diff --git a/netconf/messagebus-netconf/pom.xml b/netconf/messagebus-netconf/pom.xml index d5876e69ca..b38ee885e4 100644 --- a/netconf/messagebus-netconf/pom.xml +++ b/netconf/messagebus-netconf/pom.xml @@ -93,4 +93,16 @@ and is available at http://www.eclipse.org/legal/epl-v10.html hamcrest-core + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + checkstyle.violationSeverity=error + + + + diff --git a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistration.java b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistration.java index cf340c60fe..3e6573d243 100644 --- a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistration.java +++ b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistration.java @@ -39,18 +39,18 @@ class ConnectionNotificationTopicRegistration extends NotificationTopicRegistrat private static final Logger LOG = LoggerFactory.getLogger(ConnectionNotificationTopicRegistration.class); public static final SchemaPath EVENT_SOURCE_STATUS_PATH = SchemaPath - .create(true, QName.create(EventSourceStatusNotification.QNAME, "event-source-status")); + .create(true, QName.create(EventSourceStatusNotification.QNAME, "event-source-status")); private static final NodeIdentifier EVENT_SOURCE_STATUS_ARG = NodeIdentifier.create( - EventSourceStatusNotification.QNAME); + EventSourceStatusNotification.QNAME); private static final String XMLNS_ATTRIBUTE_KEY = "xmlns"; private static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/"; private final DOMNotificationListener domNotificationListener; - public ConnectionNotificationTopicRegistration(final String SourceName, - final DOMNotificationListener domNotificationListener) { - super(NotificationSourceType.ConnectionStatusChange, SourceName, - EVENT_SOURCE_STATUS_PATH.getLastComponent().getNamespace().toString()); + ConnectionNotificationTopicRegistration(final String sourceName, + final DOMNotificationListener domNotificationListener) { + super(NotificationSourceType.ConnectionStatusChange, sourceName, + EVENT_SOURCE_STATUS_PATH.getLastComponent().getNamespace().toString()); this.domNotificationListener = Preconditions.checkNotNull(domNotificationListener); LOG.info("Connection notification source has been initialized."); setActive(true); @@ -117,20 +117,22 @@ class ConnectionNotificationTopicRegistration extends NotificationTopicRegistrat private void publishNotification(final EventSourceStatus eventSourceStatus) { final EventSourceStatusNotification notification = new EventSourceStatusNotificationBuilder() - .setStatus(eventSourceStatus).build(); + .setStatus(eventSourceStatus).build(); domNotificationListener.onNotification(createNotification(notification)); } private static DOMNotification createNotification(final EventSourceStatusNotification notification) { final ContainerNode cn = Builders.containerBuilder().withNodeIdentifier(EVENT_SOURCE_STATUS_ARG) - .withChild(encapsulate(notification)).build(); + .withChild(encapsulate(notification)).build(); DOMNotification dn = new DOMNotification() { - @Override public SchemaPath getType() { + @Override + public SchemaPath getType() { return EVENT_SOURCE_STATUS_PATH; } - @Override public ContainerNode getBody() { + @Override + public ContainerNode getBody() { return cn; } }; @@ -148,14 +150,14 @@ class ConnectionNotificationTopicRegistration extends NotificationTopicRegistrat rootElement.appendChild(sourceElement); return Builders.anyXmlBuilder().withNodeIdentifier(EVENT_SOURCE_STATUS_ARG) - .withValue(new DOMSource(rootElement)).build(); + .withValue(new DOMSource(rootElement)).build(); } // Helper to create root XML element with correct namespace and attribute - private static Element createElement(final Document document, final String qName, - final Optional namespaceURI) { + private static Element createElement(final Document document, final String qualifiedName, + final Optional namespaceURI) { if (namespaceURI.isPresent()) { - final Element element = document.createElementNS(namespaceURI.get(), qName); + final Element element = document.createElementNS(namespaceURI.get(), qualifiedName); String name = XMLNS_ATTRIBUTE_KEY; if (element.getPrefix() != null) { name += ":" + element.getPrefix(); @@ -163,6 +165,6 @@ class ConnectionNotificationTopicRegistration extends NotificationTopicRegistrat element.setAttributeNS(XMLNS_URI, name, namespaceURI.get()); return element; } - return document.createElement(qName); + return document.createElement(qualifiedName); } } diff --git a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSource.java b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSource.java index 31246bbea0..347278c301 100644 --- a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSource.java +++ b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSource.java @@ -78,30 +78,34 @@ public class NetconfEventSource implements EventSource, DOMNotificationListener private static final NodeIdentifier TOPIC_NOTIFICATION_ARG = NodeIdentifier.create(TopicNotification.QNAME); private static final NodeIdentifier EVENT_SOURCE_ARG = NodeIdentifier.create( - QName.create(TopicNotification.QNAME, "node-id")); + QName.create(TopicNotification.QNAME, "node-id")); private static final NodeIdentifier TOPIC_ID_ARG = NodeIdentifier.create( - QName.create(TopicNotification.QNAME, "topic-id")); + QName.create(TopicNotification.QNAME, "topic-id")); private static final NodeIdentifier PAYLOAD_ARG = NodeIdentifier.create( - QName.create(TopicNotification.QNAME, "payload")); - private static final String ConnectionNotificationSourceName = "ConnectionNotificationSource"; + QName.create(TopicNotification.QNAME, "payload")); + private static final String CONNECTION_NOTIFICATION_SOURCE_NAME = "ConnectionNotificationSource"; private final DOMNotificationPublishService domPublish; private final Map urnPrefixToStreamMap; // key = urnPrefix, value = StreamName /** - * Map notification uri -> registrations + * Map notification uri -> registrations. */ private final Multimap notificationTopicRegistrations = Multimaps.synchronizedListMultimap(ArrayListMultimap.create()); private final NetconfEventSourceMount mount; /** - * Creates new NetconfEventSource for node. Topic notifications will be published via provided {@link DOMNotificationPublishService} - * @param streamMap netconf streams from device + * Creates new NetconfEventSource for node. Topic notifications will be published via provided + * {@link DOMNotificationPublishService} + * + * @param streamMap netconf streams from device * @param publishService publish service */ - public NetconfEventSource(final Map streamMap, NetconfEventSourceMount mount, final DOMNotificationPublishService publishService) { + public NetconfEventSource(final Map streamMap, + final NetconfEventSourceMount mount, + final DOMNotificationPublishService publishService) { this.mount = mount; this.urnPrefixToStreamMap = Preconditions.checkNotNull(streamMap); this.domPublish = Preconditions.checkNotNull(publishService); @@ -115,9 +119,10 @@ public class NetconfEventSource implements EventSource, DOMNotificationListener * {@link StreamNotificationTopicRegistration} for every prefix and available stream as defined in config file. */ private void initializeNotificationTopicRegistrationList() { - final ConnectionNotificationTopicRegistration cntr = new ConnectionNotificationTopicRegistration(ConnectionNotificationSourceName, this); + final ConnectionNotificationTopicRegistration cntr = + new ConnectionNotificationTopicRegistration(CONNECTION_NOTIFICATION_SOURCE_NAME, this); notificationTopicRegistrations - .put(cntr.getNotificationUrnPrefix(), cntr); + .put(cntr.getNotificationUrnPrefix(), cntr); Map availableStreams = getAvailableStreams(); LOG.debug("Stream configuration compare..."); for (String urnPrefix : this.urnPrefixToStreamMap.keySet()) { @@ -126,7 +131,8 @@ public class NetconfEventSource implements EventSource, DOMNotificationListener if (availableStreams.containsKey(streamName)) { LOG.debug("Stream containig on device"); notificationTopicRegistrations - .put(urnPrefix, new StreamNotificationTopicRegistration(availableStreams.get(streamName), urnPrefix, this)); + .put(urnPrefix, new StreamNotificationTopicRegistration(availableStreams.get(streamName), + urnPrefix, this)); } } } @@ -149,7 +155,8 @@ public class NetconfEventSource implements EventSource, DOMNotificationListener return streamMap; } - @Override public Future> joinTopic(final JoinTopicInput input) { + @Override + public Future> joinTopic(final JoinTopicInput input) { LOG.debug("Join topic {} on {}", input.getTopicId().getValue(), mount.getNodeId()); final NotificationPattern notificationPattern = input.getNotificationPattern(); final List matchingNotifications = getMatchingNotifications(notificationPattern); @@ -157,15 +164,17 @@ public class NetconfEventSource implements EventSource, DOMNotificationListener } - @Override public Future> disJoinTopic(DisJoinTopicInput input) { + @Override + public Future> disJoinTopic(DisJoinTopicInput input) { for (NotificationTopicRegistration reg : notificationTopicRegistrations.values()) { reg.unRegisterNotificationTopic(input.getTopicId()); } return Util.resultRpcSuccessFor((Void) null); } - private synchronized Future> registerTopic(final TopicId topicId, - final List notificationsToSubscribe) { + private synchronized Future> registerTopic( + final TopicId topicId, + final List notificationsToSubscribe) { Preconditions.checkNotNull(notificationsToSubscribe); LOG.debug("Join topic {} - register", topicId); JoinTopicStatus joinTopicStatus = JoinTopicStatus.Down; @@ -206,7 +215,8 @@ public class NetconfEventSource implements EventSource, DOMNotificationListener } } - @Override public void onNotification(final DOMNotification notification) { + @Override + public void onNotification(final DOMNotification notification) { SchemaPath notificationPath = notification.getType(); Date notificationEventTime = null; if (notification instanceof DOMEvent) { @@ -219,16 +229,17 @@ public class NetconfEventSource implements EventSource, DOMNotificationListener for (TopicId topicId : topicIdsForNotification) { publishNotification(notification, topicId); LOG.debug("Notification {} has been published for TopicId {}", notification.getType(), - topicId.getValue()); + topicId.getValue()); } } } private void publishNotification(final DOMNotification notification, TopicId topicId) { final ContainerNode topicNotification = Builders.containerBuilder().withNodeIdentifier(TOPIC_NOTIFICATION_ARG) - .withChild(ImmutableNodes.leafNode(TOPIC_ID_ARG, topicId)) - .withChild(ImmutableNodes.leafNode(EVENT_SOURCE_ARG, mount.getNodeId())).withChild(encapsulate(notification)) - .build(); + .withChild(ImmutableNodes.leafNode(TOPIC_ID_ARG, topicId)) + .withChild(ImmutableNodes.leafNode(EVENT_SOURCE_ARG, mount.getNodeId())) + .withChild(encapsulate(notification)) + .build(); try { domPublish.putNotification(new TopicDOMNotification(topicNotification)); } catch (final InterruptedException e) { @@ -257,6 +268,7 @@ public class NetconfEventSource implements EventSource, DOMNotificationListener /** * Returns all available notification paths that matches given pattern. + * * @param notificationPattern pattern * @return notification paths */ @@ -268,24 +280,27 @@ public class NetconfEventSource implements EventSource, DOMNotificationListener return Util.expandQname(availableNotifications, pattern); } - @Override public void close() throws Exception { + @Override + public void close() throws Exception { for (NotificationTopicRegistration streamReg : notificationTopicRegistrations.values()) { streamReg.close(); } } - @Override public NodeKey getSourceNodeKey() { + @Override + public NodeKey getSourceNodeKey() { return mount.getNode().getKey(); } - @Override public List getAvailableNotifications() { + @Override + public List getAvailableNotifications() { final List availNotifList = new ArrayList<>(); // add Event Source Connection status notification availNotifList.add(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH); final Set availableNotifications = mount.getSchemaContext() - .getNotifications(); + .getNotifications(); // add all known notifications from netconf device for (final NotificationDefinition nd : availableNotifications) { availNotifList.add(nd.getPath()); diff --git a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManager.java b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManager.java index cdbd8d4e43..516c595ef7 100644 --- a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManager.java +++ b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManager.java @@ -40,12 +40,13 @@ public final class NetconfEventSourceManager implements DataChangeListener, Auto private static final Logger LOG = LoggerFactory.getLogger(NetconfEventSourceManager.class); private static final TopologyKey NETCONF_TOPOLOGY_KEY = new TopologyKey( - new TopologyId(TopologyNetconf.QNAME.getLocalName())); + new TopologyId(TopologyNetconf.QNAME.getLocalName())); private static final InstanceIdentifier NETCONF_DEVICE_PATH = InstanceIdentifier.create(NetworkTopology.class) - .child(Topology.class, NETCONF_TOPOLOGY_KEY).child(Node.class); + .child(Topology.class, NETCONF_TOPOLOGY_KEY).child(Node.class); private Map streamMap; - private final ConcurrentHashMap, NetconfEventSourceRegistration> registrationMap = new ConcurrentHashMap<>(); + private final ConcurrentHashMap, NetconfEventSourceRegistration> registrationMap = + new ConcurrentHashMap<>(); private final DOMNotificationPublishService publishService; private final DOMMountPointService domMounts; private ListenerRegistration listenerRegistration; @@ -67,17 +68,18 @@ public final class NetconfEventSourceManager implements DataChangeListener, Auto } /** - * Invoke by blueprint + * Invoked by blueprint. */ public void initialize() { Preconditions.checkNotNull(dataBroker); listenerRegistration = dataBroker - .registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, NETCONF_DEVICE_PATH, this, - DataChangeScope.SUBTREE); + .registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, NETCONF_DEVICE_PATH, this, + DataChangeScope.SUBTREE); LOG.info("NetconfEventSourceManager initialized."); } - @Override public void onDataChanged(final AsyncDataChangeEvent, DataObject> event) { + @Override + public void onDataChanged(final AsyncDataChangeEvent, DataObject> event) { LOG.debug("[DataChangeEvent, DataObject>: {}]", event); for (final Map.Entry, DataObject> changeEntry : event.getCreatedData().entrySet()) { @@ -166,8 +168,9 @@ public final class NetconfEventSourceManager implements DataChangeListener, Auto } /** - * Invoke by blueprint - * @param streamMap + * Invoked by blueprint. + * + * @param streamMap Stream map */ public void setStreamMap(Map streamMap) { this.streamMap = streamMap; @@ -177,7 +180,8 @@ public final class NetconfEventSourceManager implements DataChangeListener, Auto return node.getAugmentation(NetconfNode.class) != null; } - @Override public void close() { + @Override + public void close() { listenerRegistration.close(); for (final NetconfEventSourceRegistration reg : registrationMap.values()) { reg.close(); diff --git a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceMount.java b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceMount.java index 1701afea53..0524bdfbc6 100644 --- a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceMount.java +++ b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceMount.java @@ -49,25 +49,28 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; /** - * Facade of mounted netconf device + * Facade of mounted netconf device. */ class NetconfEventSourceMount { private static final BindingNormalizedNodeCodecRegistry CODEC_REGISTRY; - private static final YangInstanceIdentifier STREAMS_PATH = YangInstanceIdentifier.builder().node(Netconf.QNAME).node(Streams.QNAME).build(); + private static final YangInstanceIdentifier STREAMS_PATH = YangInstanceIdentifier.builder().node(Netconf.QNAME) + .node(Streams.QNAME).build(); private static final SchemaPath CREATE_SUBSCRIPTION = SchemaPath .create(true, QName.create(CreateSubscriptionInput.QNAME, "create-subscription")); - static{ + static { final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create(); - moduleInfoBackedContext.addModuleInfos(Collections.singletonList(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.$YangModuleInfoImpl.getInstance())); + moduleInfoBackedContext.addModuleInfos(Collections.singletonList(org.opendaylight.yang.gen.v1.urn.ietf.params + .xml.ns.netmod.notification.rev080714.$YangModuleInfoImpl.getInstance())); final Optional schemaContextOptional = moduleInfoBackedContext.tryToCreateSchemaContext(); Preconditions.checkState(schemaContextOptional.isPresent()); - SchemaContext NOTIFICATIONS_SCHEMA_CTX = schemaContextOptional.get(); + SchemaContext notificationsSchemaCtx = schemaContextOptional.get(); final JavassistUtils javassist = JavassistUtils.forClassPool(ClassPool.getDefault()); CODEC_REGISTRY = new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create(javassist)); - CODEC_REGISTRY.onBindingRuntimeContextUpdated(BindingRuntimeContext.create(moduleInfoBackedContext, NOTIFICATIONS_SCHEMA_CTX)); + CODEC_REGISTRY.onBindingRuntimeContextUpdated(BindingRuntimeContext.create(moduleInfoBackedContext, + notificationsSchemaCtx)); } private final DOMMountPoint mountPoint; @@ -77,7 +80,7 @@ class NetconfEventSourceMount { private final Node node; private final String nodeId; - public NetconfEventSourceMount(final Node node, final DOMMountPoint mountPoint) { + NetconfEventSourceMount(final Node node, final DOMMountPoint mountPoint) { this.mountPoint = mountPoint; this.node = node; this.nodeId = node.getNodeId().getValue(); @@ -101,16 +104,19 @@ class NetconfEventSourceMount { } /** - * Invokes create-subscription rpc on mounted device stream. If lastEventTime is provided and stream supports replay, + * Invokes create-subscription rpc on mounted device stream. If lastEventTime is provided and stream supports + * replay, * rpc will be invoked with start time parameter. - * @param stream stream + * + * @param stream stream * @param lastEventTime last event time * @return rpc result */ - CheckedFuture invokeCreateSubscription(final Stream stream, final Optional lastEventTime) { + CheckedFuture invokeCreateSubscription(final Stream stream, + final Optional lastEventTime) { final CreateSubscriptionInputBuilder inputBuilder = new CreateSubscriptionInputBuilder() .setStream(stream.getName()); - if(lastEventTime.isPresent() && stream.isReplaySupport()) { + if (lastEventTime.isPresent() && stream.isReplaySupport()) { final ZonedDateTime dateTime = lastEventTime.get().toInstant().atZone(ZoneId.systemDefault()); final String formattedDate = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(dateTime); inputBuilder.setStartTime(new DateAndTime(formattedDate)); @@ -122,6 +128,7 @@ class NetconfEventSourceMount { /** * Invokes create-subscription rpc on mounted device stream. + * * @param stream stream * @return rpc result */ @@ -130,7 +137,8 @@ class NetconfEventSourceMount { } /** - * Returns list of streams avaliable on device + * Returns list of streams avaliable on device. + * * @return list of streams * @throws ReadFailedException if data read fails */ @@ -140,8 +148,8 @@ class NetconfEventSourceMount { .read(LogicalDatastoreType.OPERATIONAL, STREAMS_PATH); Optional> streams = checkFeature.checkedGet(); if (streams.isPresent()) { - Streams s = (Streams) CODEC_REGISTRY.fromNormalizedNode(STREAMS_PATH, streams.get()).getValue(); - return s.getStream(); + Streams streams1 = (Streams) CODEC_REGISTRY.fromNormalizedNode(STREAMS_PATH, streams.get()).getValue(); + return streams1.getStream(); } return Collections.emptyList(); } @@ -152,12 +160,14 @@ class NetconfEventSourceMount { /** * Registers notification listener to receive a set of notifications. - * @see DOMNotificationService#registerNotificationListener(DOMNotificationListener, SchemaPath...) - * @param listener listener + * + * @param listener listener * @param notificationPath notification path - * @return + * @return ListenerRegistration + * @see DOMNotificationService#registerNotificationListener(DOMNotificationListener, SchemaPath...) */ - ListenerRegistration registerNotificationListener(DOMNotificationListener listener, SchemaPath notificationPath) { + ListenerRegistration registerNotificationListener(DOMNotificationListener listener, + SchemaPath notificationPath) { return notificationService.registerNotificationListener(listener, notificationPath); } diff --git a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceRegistration.java b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceRegistration.java index c667976989..9089e92ee1 100644 --- a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceRegistration.java +++ b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceRegistration.java @@ -27,17 +27,18 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Helper class to keep connection status of netconf node and event source registration object + * Helper class to keep connection status of netconf node and event source registration object. */ public class NetconfEventSourceRegistration implements AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(NetconfEventSourceRegistration.class); private static final YangInstanceIdentifier NETCONF_DEVICE_DOM_PATH = YangInstanceIdentifier.builder() - .node(NetworkTopology.QNAME).node(Topology.QNAME) - .nodeWithKey(Topology.QNAME, QName.create(Topology.QNAME, "topology-id"), TopologyNetconf.QNAME.getLocalName()) - .node(Node.QNAME).build(); + .node(NetworkTopology.QNAME).node(Topology.QNAME) + .nodeWithKey(Topology.QNAME, QName.create(Topology.QNAME, "topology-id"), TopologyNetconf.QNAME + .getLocalName()) + .node(Node.QNAME).build(); private static final QName NODE_ID_QNAME = QName.create(Node.QNAME, "node-id"); - private static final String NotificationCapabilityPrefix = "(urn:ietf:params:xml:ns:netconf:notification"; + private static final String NOTIFICATION_CAPABILITY_PREFIX = "(urn:ietf:params:xml:ns:netconf:notification"; private final Node node; private final NetconfEventSourceManager netconfEventSourceManager; @@ -45,7 +46,7 @@ public class NetconfEventSourceRegistration implements AutoCloseable { private EventSourceRegistration eventSourceRegistration; public static NetconfEventSourceRegistration create(final InstanceIdentifier instanceIdent, final Node node, - final NetconfEventSourceManager netconfEventSourceManager) { + final NetconfEventSourceManager netconfEventSourceManager) { Preconditions.checkNotNull(instanceIdent); Preconditions.checkNotNull(node); Preconditions.checkNotNull(netconfEventSourceManager); @@ -71,7 +72,7 @@ public class NetconfEventSourceRegistration implements AutoCloseable { return false; } for (final AvailableCapability capability : netconfNode.getAvailableCapabilities().getAvailableCapability()) { - if (capability.getCapability().startsWith(NotificationCapabilityPrefix)) { + if (capability.getCapability().startsWith(NOTIFICATION_CAPABILITY_PREFIX)) { return true; } } @@ -140,14 +141,14 @@ public class NetconfEventSourceRegistration implements AutoCloseable { private void registrationEventSource() { final Optional domMountPoint = netconfEventSourceManager.getDomMounts() - .getMountPoint(domMountPath(node.getNodeId())); + .getMountPoint(domMountPath(node.getNodeId())); EventSourceRegistration registration = null; if (domMountPoint.isPresent()/* && mountPoint.isPresent()*/) { NetconfEventSourceMount mount = new NetconfEventSourceMount(node, domMountPoint.get()); final NetconfEventSource netconfEventSource = new NetconfEventSource( - netconfEventSourceManager.getStreamMap(), + netconfEventSourceManager.getStreamMap(), mount, - netconfEventSourceManager.getPublishService()); + netconfEventSourceManager.getPublishService()); registration = netconfEventSourceManager.getEventSourceRegistry().registerEventSource(netconfEventSource); LOG.info("Event source {} has been registered", node.getNodeId().getValue()); } @@ -156,7 +157,7 @@ public class NetconfEventSourceRegistration implements AutoCloseable { private YangInstanceIdentifier domMountPath(final NodeId nodeId) { return YangInstanceIdentifier.builder(NETCONF_DEVICE_DOM_PATH) - .nodeWithKey(Node.QNAME, NODE_ID_QNAME, nodeId.getValue()).build(); + .nodeWithKey(Node.QNAME, NODE_ID_QNAME, nodeId.getValue()).build(); } private void closeEventSourceRegistration() { @@ -165,7 +166,8 @@ public class NetconfEventSourceRegistration implements AutoCloseable { } } - @Override public void close() { + @Override + public void close() { closeEventSourceRegistration(); } diff --git a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NotificationTopicRegistration.java b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NotificationTopicRegistration.java index b7bfda3432..d10ce66249 100644 --- a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NotificationTopicRegistration.java +++ b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NotificationTopicRegistration.java @@ -38,7 +38,7 @@ abstract class NotificationTopicRegistration implements AutoCloseable { protected final ConcurrentHashMap> notificationTopicMap = new ConcurrentHashMap<>(); protected NotificationTopicRegistration(NotificationSourceType notificationSourceType, String sourceName, - String notificationUrnPrefix) { + String notificationUrnPrefix) { this.notificationSourceType = notificationSourceType; this.sourceName = sourceName; this.notificationUrnPrefix = notificationUrnPrefix; @@ -68,6 +68,7 @@ abstract class NotificationTopicRegistration implements AutoCloseable { /** * Returns registered topics for given notification path. + * * @param notificationPath path * @return topicIds */ @@ -78,6 +79,7 @@ abstract class NotificationTopicRegistration implements AutoCloseable { /** * Checks, if notification is from namespace belonging to this registration. + * * @param notificationPath path * @return true, if notification belongs to registration namespace */ @@ -87,7 +89,7 @@ abstract class NotificationTopicRegistration implements AutoCloseable { } String nameSpace = notificationPath.getLastComponent().getNamespace().toString(); LOG.debug("CheckNotification - name space {} - NotificationUrnPrefix {}", nameSpace, - getNotificationUrnPrefix()); + getNotificationUrnPrefix()); return nameSpace.startsWith(getNotificationUrnPrefix()); } @@ -107,14 +109,16 @@ abstract class NotificationTopicRegistration implements AutoCloseable { /** * Registers associated event source notification to topic. + * * @param notificationPath notification path - * @param topicId topic id + * @param topicId topic id * @return true, if successful */ abstract boolean registerNotificationTopic(SchemaPath notificationPath, TopicId topicId); /** * Registers associated event source notification to topic. + * * @param topicId topic id * @return true, if successful */ diff --git a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/StreamNotificationTopicRegistration.java b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/StreamNotificationTopicRegistration.java index d163a777cd..a77dbdc2e1 100644 --- a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/StreamNotificationTopicRegistration.java +++ b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/StreamNotificationTopicRegistration.java @@ -32,17 +32,19 @@ class StreamNotificationTopicRegistration extends NotificationTopicRegistration private final String nodeId; private final NetconfEventSource netconfEventSource; private final NetconfEventSourceMount mountPoint; - private final ConcurrentHashMap> notificationRegistrationMap = new ConcurrentHashMap<>(); + private final ConcurrentHashMap> + notificationRegistrationMap = new ConcurrentHashMap<>(); private final Stream stream; /** * Creates registration to notification stream. - * @param stream stream + * + * @param stream stream * @param notificationPrefix notifications namespace * @param netconfEventSource event source */ - public StreamNotificationTopicRegistration(final Stream stream, final String notificationPrefix, - NetconfEventSource netconfEventSource) { + StreamNotificationTopicRegistration(final Stream stream, final String notificationPrefix, + NetconfEventSource netconfEventSource) { super(NotificationSourceType.NetconfDeviceStream, stream.getName().getValue(), notificationPrefix); this.netconfEventSource = netconfEventSource; this.mountPoint = netconfEventSource.getMount(); @@ -73,7 +75,8 @@ class StreamNotificationTopicRegistration extends NotificationTopicRegistration } /** - * Subscribes to notification stream associated with this registration. If replay is supported, notifications from last + * Subscribes to notification stream associated with this registration. If replay is supported, notifications + * from last * received event time will be requested. */ void reActivateNotificationSource() { @@ -91,7 +94,8 @@ class StreamNotificationTopicRegistration extends NotificationTopicRegistration } } - @Override void deActivateNotificationSource() { + @Override + void deActivateNotificationSource() { // no operations need } @@ -110,7 +114,8 @@ class StreamNotificationTopicRegistration extends NotificationTopicRegistration return getSourceName(); } - @Override boolean registerNotificationTopic(SchemaPath notificationPath, TopicId topicId) { + @Override + boolean registerNotificationTopic(SchemaPath notificationPath, TopicId topicId) { if (!checkNotificationPath(notificationPath)) { LOG.debug("Bad SchemaPath for notification try to register"); return false; @@ -119,11 +124,12 @@ class StreamNotificationTopicRegistration extends NotificationTopicRegistration activateNotificationSource(); if (!isActive()) { LOG.warn("Stream {} is not active, listener for notification {} is not registered.", getStreamName(), - notificationPath.toString()); + notificationPath.toString()); return false; } - ListenerRegistration registration = mountPoint.registerNotificationListener(netconfEventSource, notificationPath); + ListenerRegistration registration = + mountPoint.registerNotificationListener(netconfEventSource, notificationPath); notificationRegistrationMap.put(notificationPath, registration); Set topicIds = getTopicsForNotification(notificationPath); topicIds.add(topicId); @@ -132,7 +138,8 @@ class StreamNotificationTopicRegistration extends NotificationTopicRegistration return true; } - @Override synchronized void unRegisterNotificationTopic(TopicId topicId) { + @Override + synchronized void unRegisterNotificationTopic(TopicId topicId) { List notificationPathToRemove = new ArrayList<>(); for (SchemaPath notifKey : notificationTopicMap.keySet()) { Set topicList = notificationTopicMap.get(notifKey); @@ -152,7 +159,8 @@ class StreamNotificationTopicRegistration extends NotificationTopicRegistration } } - @Override public void close() throws Exception { + @Override + public void close() throws Exception { closeStream(); } diff --git a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistrationTest.java b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistrationTest.java index a19f13028e..5d3669aa05 100644 --- a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistrationTest.java +++ b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistrationTest.java @@ -71,12 +71,14 @@ public class ConnectionNotificationTopicRegistrationTest { final TopicId topic1 = registerTopic("topic1"); final TopicId topic2 = registerTopic("topic2"); final TopicId topic3 = registerTopic("topic3"); - final Set notificationTopicIds = registration.getTopicsForNotification(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH); + final Set notificationTopicIds = + registration.getTopicsForNotification(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH); Assert.assertNotNull(notificationTopicIds); Assert.assertThat(notificationTopicIds, hasItems(topic1, topic2, topic3)); registration.unRegisterNotificationTopic(topic3); - final Set afterUnregister = registration.getTopicsForNotification(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH); + final Set afterUnregister = + registration.getTopicsForNotification(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH); Assert.assertNotNull(afterUnregister); Assert.assertThat(afterUnregister, hasItems(topic1, topic2)); Assert.assertFalse(afterUnregister.contains(topic3)); @@ -91,15 +93,17 @@ public class ConnectionNotificationTopicRegistrationTest { /** * Checks status node of notification received by listener. + * * @param listener listener - * @param status expected value + * @param status expected value */ private static void checkStatus(DOMNotificationListener listener, EventSourceStatus status) { ArgumentCaptor notificationCaptor = ArgumentCaptor.forClass(DOMNotification.class); verify(listener).onNotification(notificationCaptor.capture()); final DOMNotification value = notificationCaptor.getValue(); Assert.assertEquals(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH, value.getType()); - final Collection> body = value.getBody().getValue(); + final Collection> body = value.getBody() + .getValue(); Assert.assertEquals(1, body.size()); final DOMSource source = (DOMSource) body.iterator().next().getValue(); final String statusNodeValue = source.getNode().getFirstChild().getFirstChild().getNodeValue(); diff --git a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManagerTest.java b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManagerTest.java index 13b855107d..6d9938cdc8 100644 --- a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManagerTest.java +++ b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManagerTest.java @@ -66,30 +66,36 @@ public class NetconfEventSourceManagerTest { @Before public void setUp() throws Exception { - DataBroker dataBrokerMock = mock(DataBroker.class); - DOMNotificationPublishService domNotificationPublishServiceMock = mock(DOMNotificationPublishService.class); + final DataBroker dataBrokerMock = mock(DataBroker.class); + final DOMNotificationPublishService domNotificationPublishServiceMock = + mock(DOMNotificationPublishService.class); domMountPointServiceMock = mock(DOMMountPointService.class); eventSourceTopologyMock = mock(EventSourceRegistry.class); rpcProviderRegistryMock = mock(RpcProviderRegistry.class); eventSourceRegistry = mock(EventSourceRegistry.class); listenerRegistrationMock = mock(ListenerRegistration.class); - doReturn(listenerRegistrationMock).when(dataBrokerMock).registerDataChangeListener(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class), any(NetconfEventSourceManager.class), eq( - AsyncDataBroker.DataChangeScope.SUBTREE)); + doReturn(listenerRegistrationMock).when(dataBrokerMock).registerDataChangeListener(eq(LogicalDatastoreType + .OPERATIONAL), any(InstanceIdentifier.class), any(NetconfEventSourceManager.class), eq( + AsyncDataBroker.DataChangeScope.SUBTREE)); DOMMountPoint domMountPointMock = mock(DOMMountPoint.class); Optional optionalDomMountServiceMock = Optional.of(domMountPointMock); - doReturn(optionalDomMountServiceMock).when(domMountPointServiceMock).getMountPoint((YangInstanceIdentifier)notNull()); + doReturn(optionalDomMountServiceMock).when(domMountPointServiceMock).getMountPoint((YangInstanceIdentifier) + notNull()); DOMDataBroker mpDataBroker = mock(DOMDataBroker.class); doReturn(Optional.of(mpDataBroker)).when(domMountPointMock).getService(DOMDataBroker.class); doReturn(Optional.of(mock(DOMRpcService.class))).when(domMountPointMock).getService(DOMRpcService.class); - doReturn(Optional.of(mock(DOMNotificationService.class))).when(domMountPointMock).getService(DOMNotificationService.class); + doReturn(Optional.of(mock(DOMNotificationService.class))).when(domMountPointMock) + .getService(DOMNotificationService.class); DOMDataReadOnlyTransaction rtx = mock(DOMDataReadOnlyTransaction.class); doReturn(rtx).when(mpDataBroker).newReadOnlyTransaction(); - CheckedFuture>, ReadFailedException> checkFeature = Futures.immediateCheckedFuture(Optional.of(NetconfTestUtils.getStreamsNode("stream-1"))); + CheckedFuture>, ReadFailedException> checkFeature = Futures + .immediateCheckedFuture(Optional.of(NetconfTestUtils.getStreamsNode("stream-1"))); - YangInstanceIdentifier pathStream = YangInstanceIdentifier.builder().node(Netconf.QNAME).node(Streams.QNAME).build(); + YangInstanceIdentifier pathStream = YangInstanceIdentifier.builder().node(Netconf.QNAME).node(Streams.QNAME) + .build(); doReturn(checkFeature).when(rtx).read(LogicalDatastoreType.OPERATIONAL, pathStream); netconfEventSourceManager = new NetconfEventSourceManager(dataBrokerMock, @@ -99,33 +105,34 @@ public class NetconfEventSourceManagerTest { @Test public void onDataChangedCreateEventSourceTestByCreateEntry() throws Exception { - onDataChangedTestHelper(true,false,true, NetconfTestUtils.notification_capability_prefix); + onDataChangedTestHelper(true, false, true, NetconfTestUtils.NOTIFICATION_CAPABILITY_PREFIX); netconfEventSourceManager.onDataChanged(asyncDataChangeEventMock); verify(eventSourceRegistry, times(1)).registerEventSource(any(EventSource.class)); } @Test public void onDataChangedCreateEventSourceTestByUpdateEntry() throws Exception { - onDataChangedTestHelper(false,true,true, NetconfTestUtils.notification_capability_prefix); + onDataChangedTestHelper(false, true, true, NetconfTestUtils.NOTIFICATION_CAPABILITY_PREFIX); netconfEventSourceManager.onDataChanged(asyncDataChangeEventMock); verify(eventSourceRegistry, times(1)).registerEventSource(any(EventSource.class)); } @Test public void onDataChangedCreateEventSourceTestNotNeconf() throws Exception { - onDataChangedTestHelper(false,true,false, NetconfTestUtils.notification_capability_prefix); + onDataChangedTestHelper(false, true, false, NetconfTestUtils.NOTIFICATION_CAPABILITY_PREFIX); netconfEventSourceManager.onDataChanged(asyncDataChangeEventMock); verify(eventSourceRegistry, times(0)).registerEventSource(any(EventSource.class)); } @Test public void onDataChangedCreateEventSourceTestNotNotificationCapability() throws Exception { - onDataChangedTestHelper(true,false,true,"bad-prefix"); + onDataChangedTestHelper(true, false, true, "bad-prefix"); netconfEventSourceManager.onDataChanged(asyncDataChangeEventMock); verify(eventSourceRegistry, times(0)).registerEventSource(any(EventSource.class)); } - private void onDataChangedTestHelper(boolean create, boolean update, boolean isNetconf, String notificationCapabilityPrefix) throws Exception{ + private void onDataChangedTestHelper(boolean create, boolean update, boolean isNetconf, String + notificationCapabilityPrefix) throws Exception { asyncDataChangeEventMock = mock(AsyncDataChangeEvent.class); Map mapCreate = new HashMap<>(); Map mapUpdate = new HashMap<>(); @@ -135,18 +142,19 @@ public class NetconfEventSourceManagerTest { doReturn(mapCreate).when(asyncDataChangeEventMock).getCreatedData(); doReturn(mapUpdate).when(asyncDataChangeEventMock).getUpdatedData(); - if(isNetconf){ + if (isNetconf) { node01 = NetconfTestUtils - .getNetconfNode(nodeId, "node01.test.local", ConnectionStatus.Connected, notificationCapabilityPrefix); + .getNetconfNode(nodeId, "node01.test.local", ConnectionStatus.Connected, + notificationCapabilityPrefix); } else { node01 = NetconfTestUtils.getNode(nodeId); } - if(create){ + if (create) { mapCreate.put(NetconfTestUtils.getInstanceIdentifier(node01), node01); } - if(update){ + if (update) { mapUpdate.put(NetconfTestUtils.getInstanceIdentifier(node01), node01); } diff --git a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceMountTest.java b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceMountTest.java index 369d6b4df8..d64e1a6415 100644 --- a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceMountTest.java +++ b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceMountTest.java @@ -66,11 +66,14 @@ public class NetconfEventSourceMountTest { MockitoAnnotations.initMocks(this); doReturn(Optional.of(dataBroker)).when(domMountPoint).getService(DOMDataBroker.class); doReturn(Optional.of(rpcService)).when(domMountPoint).getService(DOMRpcService.class); - doReturn(Optional.of(mock(DOMNotificationService.class))).when(domMountPoint).getService(DOMNotificationService.class); + doReturn(Optional.of(mock(DOMNotificationService.class))).when(domMountPoint) + .getService(DOMNotificationService.class); doReturn(tx).when(dataBroker).newReadOnlyTransaction(); - final YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(Netconf.QNAME).node(Streams.QNAME).build(); + final YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(Netconf.QNAME).node(Streams.QNAME) + .build(); final NormalizedNode streamsNode = NetconfTestUtils.getStreamsNode(STREAM_1, STREAM_2); - doReturn(Futures.immediateCheckedFuture(Optional.of(streamsNode))).when(tx).read(LogicalDatastoreType.OPERATIONAL, path); + doReturn(Futures.immediateCheckedFuture(Optional.of(streamsNode))).when(tx).read(LogicalDatastoreType + .OPERATIONAL, path); mount = new NetconfEventSourceMount(NetconfTestUtils.getNode("node-1"), domMountPoint); } @@ -80,7 +83,8 @@ public class NetconfEventSourceMountTest { .setName(new StreamNameType(STREAM_1)) .build(); mount.invokeCreateSubscription(stream, Optional.absent()); - final SchemaPath type = SchemaPath.create(true, QName.create(CreateSubscriptionInput.QNAME, "create-subscription")); + final SchemaPath type = SchemaPath.create(true, QName.create(CreateSubscriptionInput.QNAME, + "create-subscription")); ArgumentCaptor captor = ArgumentCaptor.forClass(ContainerNode.class); verify(rpcService).invokeRpc(eq(type), captor.capture()); Assert.assertEquals(STREAM_1, getStreamName(captor.getValue())); @@ -94,11 +98,13 @@ public class NetconfEventSourceMountTest { .build(); final Date date = new Date(); mount.invokeCreateSubscription(stream, Optional.of(date)); - final SchemaPath type = SchemaPath.create(true, QName.create(CreateSubscriptionInput.QNAME, "create-subscription")); + final SchemaPath type = SchemaPath.create(true, QName.create(CreateSubscriptionInput.QNAME, + "create-subscription")); ArgumentCaptor captor = ArgumentCaptor.forClass(ContainerNode.class); verify(rpcService).invokeRpc(eq(type), captor.capture()); Assert.assertEquals(STREAM_1, getStreamName(captor.getValue())); - final String expDate = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(date.toInstant().atZone(ZoneId.systemDefault())); + final String expDate = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(date.toInstant().atZone(ZoneId + .systemDefault())); final Optional actual = (Optional) getDate(captor.getValue()); Assert.assertTrue(actual.isPresent()); String actualDate = (String) actual.get().getValue(); @@ -112,7 +118,8 @@ public class NetconfEventSourceMountTest { .setReplaySupport(true) .build(); mount.invokeCreateSubscription(stream, Optional.absent()); - final SchemaPath type = SchemaPath.create(true, QName.create(CreateSubscriptionInput.QNAME, "create-subscription")); + final SchemaPath type = SchemaPath.create(true, QName.create(CreateSubscriptionInput.QNAME, + "create-subscription")); ArgumentCaptor captor = ArgumentCaptor.forClass(ContainerNode.class); verify(rpcService).invokeRpc(eq(type), captor.capture()); Assert.assertEquals(STREAM_1, getStreamName(captor.getValue())); @@ -137,12 +144,14 @@ public class NetconfEventSourceMountTest { } private String getStreamName(ContainerNode value) { - YangInstanceIdentifier.NodeIdentifier STREAM = new YangInstanceIdentifier.NodeIdentifier(QName.create(CreateSubscriptionInput.QNAME, "stream")); - return (String) value.getChild(STREAM).get().getValue(); + YangInstanceIdentifier.NodeIdentifier stream = + new YangInstanceIdentifier.NodeIdentifier(QName.create(CreateSubscriptionInput.QNAME, "stream")); + return (String) value.getChild(stream).get().getValue(); } private Optional getDate(ContainerNode value) { - YangInstanceIdentifier.NodeIdentifier START_TIME = new YangInstanceIdentifier.NodeIdentifier(QName.create(CreateSubscriptionInput.QNAME, "startTime")); - return value.getChild(START_TIME); + YangInstanceIdentifier.NodeIdentifier startTime = + new YangInstanceIdentifier.NodeIdentifier(QName.create(CreateSubscriptionInput.QNAME, "startTime")); + return value.getChild(startTime); } } \ No newline at end of file diff --git a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceTest.java b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceTest.java index 1a439b9ff6..56ce4ee61a 100644 --- a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceTest.java +++ b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceTest.java @@ -54,8 +54,10 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; public class NetconfEventSourceTest { - private static final SchemaPath notification1Path = SchemaPath.create(true, QName.create("ns1", "1970-01-15", "not1")); - private static final SchemaPath notification2Path = SchemaPath.create(true, QName.create("ns2", "1980-02-18", "not2")); + private static final SchemaPath NOTIFICATION_1_PATH = SchemaPath.create(true, QName.create("ns1", "1970-01-15", + "not1")); + private static final SchemaPath NOTIFICATION_2_PATH = SchemaPath.create(true, QName.create("ns2", "1980-02-18", + "not2")); NetconfEventSource netconfEventSource; @@ -72,14 +74,16 @@ public class NetconfEventSourceTest { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); //init notification mocks - doReturn(notification1Path).when(matchnigNotification).getType(); - doReturn(notification2Path).when(nonMachtingNotification).getType(); - DataContainerNodeAttrBuilder body = Builders.containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create("ns1", "1970-01-15", "not1data"))); + doReturn(NOTIFICATION_1_PATH).when(matchnigNotification).getType(); + doReturn(NOTIFICATION_2_PATH).when(nonMachtingNotification).getType(); + DataContainerNodeAttrBuilder body = Builders + .containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create("ns1", + "1970-01-15", "not1data"))); doReturn(body.build()).when(matchnigNotification).getBody(); //init schema context mock Set notifications = new HashSet<>(); - notifications.add(getNotificationDefinitionMock(notification1Path.getLastComponent())); - notifications.add(getNotificationDefinitionMock(notification2Path.getLastComponent())); + notifications.add(getNotificationDefinitionMock(NOTIFICATION_1_PATH.getLastComponent())); + notifications.add(getNotificationDefinitionMock(NOTIFICATION_2_PATH.getLastComponent())); SchemaContext schemaContext = mock(SchemaContext.class); doReturn(notifications).when(schemaContext).getNotifications(); //init mount point mock @@ -91,11 +95,12 @@ public class NetconfEventSourceTest { doReturn(Futures.immediateCheckedFuture(null)).when(mount).invokeCreateSubscription(any(), any()); doReturn(Futures.immediateCheckedFuture(null)).when(mount).invokeCreateSubscription(any()); doReturn(mock(ListenerRegistration.class)).when(mount).registerNotificationListener(any(), any()); - final Node nodeId1 = NetconfTestUtils.getNetconfNode("NodeId1", "node.test.local", ConnectionStatus.Connected, NetconfTestUtils.notification_capability_prefix); + final Node nodeId1 = NetconfTestUtils.getNetconfNode("NodeId1", "node.test.local", ConnectionStatus + .Connected, NetconfTestUtils.NOTIFICATION_CAPABILITY_PREFIX); doReturn(nodeId1).when(mount).getNode(); Map streamMap = new HashMap<>(); - streamMap.put(notification1Path.getLastComponent().getNamespace().toString(), "stream-1"); + streamMap.put(NOTIFICATION_1_PATH.getLastComponent().getNamespace().toString(), "stream-1"); netconfEventSource = new NetconfEventSource( streamMap, mount, @@ -121,7 +126,8 @@ public class NetconfEventSourceTest { final TopicDOMNotification value = (TopicDOMNotification) captor.getValue(); final QName qname = TopicNotification.QNAME; final YangInstanceIdentifier.NodeIdentifier topicIdNode = - new YangInstanceIdentifier.NodeIdentifier(QName.create(qname.getNamespace().toString(), qname.getFormattedRevision(), "topic-id")); + new YangInstanceIdentifier.NodeIdentifier(QName.create(qname.getNamespace().toString(), qname + .getFormattedRevision(), "topic-id")); final Object actualTopicId = value.getBody().getChild(topicIdNode).get().getValue(); Assert.assertEquals(topic1.getTopicId(), actualTopicId); } @@ -152,10 +158,10 @@ public class NetconfEventSourceTest { .build(); } - private NotificationDefinition getNotificationDefinitionMock(QName qName) { + private NotificationDefinition getNotificationDefinitionMock(QName qualifiedName) { NotificationDefinition notification = mock(NotificationDefinition.class); - doReturn(qName).when(notification).getQName(); - doReturn(SchemaPath.create(true, qName)).when(notification).getPath(); + doReturn(qualifiedName).when(notification).getQName(); + doReturn(SchemaPath.create(true, qualifiedName)).when(notification).getPath(); return notification; } diff --git a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfTestUtils.java b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfTestUtils.java index 3124d6b1f0..25c3a84756 100644 --- a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfTestUtils.java +++ b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfTestUtils.java @@ -46,22 +46,23 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNo public final class NetconfTestUtils { - public static final String notification_capability_prefix = "(urn:ietf:params:xml:ns:netconf:notification"; + public static final String NOTIFICATION_CAPABILITY_PREFIX = "(urn:ietf:params:xml:ns:netconf:notification"; private NetconfTestUtils() { } public static Node getNetconfNode(String nodeIdent, String hostName, ConnectionStatus cs, - String notificationCapabilityPrefix) { + String notificationCapabilityPrefix) { DomainName dn = new DomainName(hostName); Host host = new Host(dn); List avCapList = new ArrayList<>(); - avCapList.add(new AvailableCapabilityBuilder().setCapability(notificationCapabilityPrefix + "_availableCapabilityString1").build()); + avCapList.add(new AvailableCapabilityBuilder().setCapability(notificationCapabilityPrefix + + "_availableCapabilityString1").build()); AvailableCapabilities avCaps = new AvailableCapabilitiesBuilder().setAvailableCapability(avCapList).build(); NetconfNode nn = new NetconfNodeBuilder().setConnectionStatus(cs).setHost(host).setAvailableCapabilities(avCaps) - .build(); + .build(); NodeId nodeId = new NodeId(nodeIdent); NodeKey nk = new NodeKey(nodeId); @@ -81,14 +82,14 @@ public final class NetconfTestUtils { } public static InstanceIdentifier getInstanceIdentifier(Node node) { - TopologyKey NETCONF_TOPOLOGY_KEY = new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName())); + TopologyKey netconfTopologyKey = new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName())); InstanceIdentifier nodeII = InstanceIdentifier.create(NetworkTopology.class) - .child(Topology.class, NETCONF_TOPOLOGY_KEY).child(Node.class, node.getKey()); + .child(Topology.class, netconfTopologyKey).child(Node.class, node.getKey()); return nodeII; } - public static Optional getAvailableStream(String Name, boolean replaySupport) { - Stream stream = new StreamBuilder().setName(new StreamNameType(Name)).setReplaySupport(replaySupport).build(); + public static Optional getAvailableStream(String name, boolean replaySupport) { + Stream stream = new StreamBuilder().setName(new StreamNameType(name)).setReplaySupport(replaySupport).build(); List streamList = new ArrayList<>(); streamList.add(stream); Streams streams = new StreamsBuilder().setStream(streamList).build(); @@ -100,7 +101,8 @@ public final class NetconfTestUtils { Set streamSet = new HashSet<>(); for (String s : streamName) { MapEntryNode stream = Builders.mapEntryBuilder() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifierWithPredicates(Stream.QNAME, nameNode, s)) + .withNodeIdentifier(new YangInstanceIdentifier + .NodeIdentifierWithPredicates(Stream.QNAME, nameNode, s)) .withChild(Builders.leafBuilder() .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(nameNode)) .withValue(s) @@ -109,7 +111,8 @@ public final class NetconfTestUtils { streamSet.add(stream); } - CollectionNodeBuilder streams = Builders.mapBuilder().withNodeIdentifier(YangInstanceIdentifier.NodeIdentifier.create(Stream.QNAME)); + CollectionNodeBuilder streams = + Builders.mapBuilder().withNodeIdentifier(YangInstanceIdentifier.NodeIdentifier.create(Stream.QNAME)); for (MapEntryNode mapEntryNode : streamSet) { streams.withChild(mapEntryNode); } diff --git a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/StreamNotificationTopicRegistrationTest.java b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/StreamNotificationTopicRegistrationTest.java index 2bf354b2c9..e68caa6a7f 100644 --- a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/StreamNotificationTopicRegistrationTest.java +++ b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/StreamNotificationTopicRegistrationTest.java @@ -36,7 +36,8 @@ import org.opendaylight.yangtools.concepts.ListenerRegistration; public class StreamNotificationTopicRegistrationTest { private static final String STREAM_NAME = "stream-1"; - private static final String PREFIX = ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH.getLastComponent().getNamespace().toString(); + private static final String PREFIX = ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH + .getLastComponent().getNamespace().toString(); @Mock private NetconfEventSource source; @@ -56,13 +57,15 @@ public class StreamNotificationTopicRegistrationTest { Node node = new NodeBuilder().setNodeId(NodeId.getDefaultInstance("node-id")).build(); when(mount.getNode()).thenReturn(node); - when(mount.registerNotificationListener(source, ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH)) + when(mount.registerNotificationListener(source, ConnectionNotificationTopicRegistration + .EVENT_SOURCE_STATUS_PATH)) .thenReturn(listenerRegistration); when(mount.invokeCreateSubscription(any(), any())).thenReturn(Futures.immediateCheckedFuture(null)); when(mount.invokeCreateSubscription(any())).thenReturn(Futures.immediateCheckedFuture(null)); when(source.getMount()).thenReturn(mount); - stream = new StreamBuilder().setName(StreamNameType.getDefaultInstance(STREAM_NAME)).setReplaySupport(true).build(); + stream = new StreamBuilder().setName(StreamNameType.getDefaultInstance(STREAM_NAME)).setReplaySupport(true) + .build(); registration = new StreamNotificationTopicRegistration(stream, PREFIX, source); } @@ -107,12 +110,14 @@ public class StreamNotificationTopicRegistrationTest { final TopicId topic1 = registerTopic("topic1"); final TopicId topic2 = registerTopic("topic2"); final TopicId topic3 = registerTopic("topic3"); - final Set notificationTopicIds = registration.getTopicsForNotification(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH); + final Set notificationTopicIds = + registration.getTopicsForNotification(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH); Assert.assertNotNull(notificationTopicIds); Assert.assertThat(notificationTopicIds, hasItems(topic1, topic2, topic3)); registration.unRegisterNotificationTopic(topic3); - final Set afterUnregister = registration.getTopicsForNotification(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH); + final Set afterUnregister = + registration.getTopicsForNotification(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH); Assert.assertNotNull(afterUnregister); Assert.assertThat(afterUnregister, hasItems(topic1, topic2)); Assert.assertFalse(afterUnregister.contains(topic3)); -- 2.36.6