Fix checkstyle violations in messagebus 35/69235/3
authorTom Pantelis <tompantelis@gmail.com>
Wed, 7 Mar 2018 21:25:57 +0000 (16:25 -0500)
committerMichael Vorburger <vorburger@redhat.com>
Fri, 9 Mar 2018 15:30:56 +0000 (15:30 +0000)
Change-Id: I4af49c607bbbd607f8ea4fbcbe43ba4f078329d0
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
12 files changed:
opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceRegistrationImpl.java
opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopic.java
opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopology.java
opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceRegistrationImplTest.java
opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopicTest.java
opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopologyTest.java
opendaylight/md-sal/messagebus-spi/src/main/java/org/opendaylight/controller/messagebus/spi/EventSource.java
opendaylight/md-sal/messagebus-spi/src/main/java/org/opendaylight/controller/messagebus/spi/EventSourceRegistration.java
opendaylight/md-sal/messagebus-spi/src/main/java/org/opendaylight/controller/messagebus/spi/EventSourceRegistry.java
opendaylight/md-sal/messagebus-util/src/main/java/org/opendaylight/controller/messagebus/app/util/Util.java
opendaylight/md-sal/messagebus-util/src/test/java/org/opendaylight/controller/messagebus/app/util/TopicDOMNotificationTest.java
opendaylight/md-sal/messagebus-util/src/test/java/org/opendaylight/controller/messagebus/app/util/UtilTest.java

index d9390903232fcda81292a24a96768adb6436a5de..dac4f8fee8025afe31778c6908dbdb160047024e 100644 (file)
@@ -7,21 +7,23 @@
  */
 package org.opendaylight.controller.messagebus.app.impl;
 
+import com.google.common.base.Preconditions;
 import org.opendaylight.controller.messagebus.spi.EventSource;
 import org.opendaylight.controller.messagebus.spi.EventSourceRegistration;
 import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
 
-import com.google.common.base.Preconditions;
-
-
-class EventSourceRegistrationImpl <T extends EventSource> extends AbstractObjectRegistration<T> implements EventSourceRegistration<T>{
+class EventSourceRegistrationImpl<T extends EventSource> extends AbstractObjectRegistration<T>
+        implements EventSourceRegistration<T> {
 
     private final EventSourceTopology eventSourceTopology;
 
     /**
-     * @param instance of EventSource that has been registered by {@link EventSourceRegistryImpl#registerEventSource(Node, EventSource)}
+     * Constructor.
+     *
+     * @param instance of EventSource that has been registered by
+     *     {@link EventSourceRegistryImpl#registerEventSource(Node, EventSource)}
      */
-    public EventSourceRegistrationImpl(T instance, EventSourceTopology eventSourceTopology) {
+    EventSourceRegistrationImpl(T instance, EventSourceTopology eventSourceTopology) {
         super(instance);
         this.eventSourceTopology = Preconditions.checkNotNull(eventSourceTopology);
     }
@@ -30,5 +32,4 @@ class EventSourceRegistrationImpl <T extends EventSource> extends AbstractObject
     protected void removeRegistration() {
         this.eventSourceTopology.unRegister(getInstance());
     }
-
 }
index ea04d9995109c8be4fd567612151e33c706102ec..2a77807cd8b06241cb1947208a9bf7bec05dfa64 100644 (file)
@@ -10,9 +10,10 @@ package org.opendaylight.controller.messagebus.app.impl;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
 import java.util.Collection;
 import java.util.List;
 import java.util.UUID;
@@ -25,7 +26,6 @@ import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.DisJoinTopicInput;
@@ -43,7 +43,7 @@ import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.LoggerFactory;
 
-public class EventSourceTopic implements DataTreeChangeListener<Node>, AutoCloseable {
+public final class EventSourceTopic implements DataTreeChangeListener<Node>, AutoCloseable {
     private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(EventSourceTopic.class);
     private final NotificationPattern notificationPattern;
     private final EventSourceService sourceService;
@@ -52,14 +52,17 @@ public class EventSourceTopic implements DataTreeChangeListener<Node>, AutoClose
     private ListenerRegistration<?> listenerRegistration;
     private final CopyOnWriteArraySet<InstanceIdentifier<?>> joinedEventSources = new CopyOnWriteArraySet<>();
 
-    public static EventSourceTopic create(final NotificationPattern notificationPattern, final String nodeIdRegexPattern, final EventSourceTopology eventSourceTopology){
-        final EventSourceTopic est = new EventSourceTopic(notificationPattern, nodeIdRegexPattern, eventSourceTopology.getEventSourceService());
+    public static EventSourceTopic create(final NotificationPattern notificationPattern,
+            final String nodeIdRegexPattern, final EventSourceTopology eventSourceTopology) {
+        final EventSourceTopic est = new EventSourceTopic(notificationPattern, nodeIdRegexPattern,
+                eventSourceTopology.getEventSourceService());
         est.registerListner(eventSourceTopology);
         est.notifyExistingNodes(eventSourceTopology);
         return est;
     }
 
-    private EventSourceTopic(final NotificationPattern notificationPattern, final String nodeIdRegexPattern, final EventSourceService sourceService) {
+    private EventSourceTopic(final NotificationPattern notificationPattern, final String nodeIdRegexPattern,
+            final EventSourceService sourceService) {
         this.notificationPattern = Preconditions.checkNotNull(notificationPattern);
         this.sourceService = Preconditions.checkNotNull(sourceService);
         this.nodeIdPattern = Pattern.compile(nodeIdRegexPattern);
@@ -93,52 +96,52 @@ public class EventSourceTopic implements DataTreeChangeListener<Node>, AutoClose
     public void notifyNode(final InstanceIdentifier<?> nodeId) {
         LOG.debug("Notify node: {}", nodeId);
         try {
-            final RpcResult<JoinTopicOutput> rpcResultJoinTopic = sourceService.joinTopic(getJoinTopicInputArgument(nodeId)).get();
-            if(rpcResultJoinTopic.isSuccessful() == false){
-                for(final RpcError err : rpcResultJoinTopic.getErrors()){
-                    LOG.error("Can not join topic: [{}] on node: [{}]. Error: {}",getTopicId().getValue(),nodeId.toString(),err.toString());
+            final RpcResult<JoinTopicOutput> rpcResultJoinTopic =
+                    sourceService.joinTopic(getJoinTopicInputArgument(nodeId)).get();
+            if (!rpcResultJoinTopic.isSuccessful()) {
+                for (final RpcError err : rpcResultJoinTopic.getErrors()) {
+                    LOG.error("Can not join topic: [{}] on node: [{}]. Error: {}", getTopicId().getValue(),
+                            nodeId.toString(), err.toString());
                 }
             } else {
                 joinedEventSources.add(nodeId);
             }
-        } catch (final Exception e) {
+        } catch (InterruptedException | ExecutionException e) {
             LOG.error("Could not invoke join topic for node {}", nodeId);
         }
     }
 
-    private void notifyExistingNodes(final EventSourceTopology eventSourceTopology){
+    private void notifyExistingNodes(final EventSourceTopology eventSourceTopology) {
         LOG.debug("Notify existing nodes");
         final Pattern nodeRegex = this.nodeIdPattern;
 
         final ReadOnlyTransaction tx = eventSourceTopology.getDataBroker().newReadOnlyTransaction();
-        final CheckedFuture<Optional<Topology>, ReadFailedException> future =
+        final ListenableFuture<Optional<Topology>> future =
                 tx.read(LogicalDatastoreType.OPERATIONAL, EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH);
 
-        Futures.addCallback(future, new FutureCallback<Optional<Topology>>(){
-
+        Futures.addCallback(future, new FutureCallback<Optional<Topology>>() {
             @Override
             public void onSuccess(final Optional<Topology> data) {
-                if(data.isPresent()) {
-                     final List<Node> nodes = data.get().getNode();
-                     if(nodes != null){
+                if (data.isPresent()) {
+                    final List<Node> nodes = data.get().getNode();
+                    if (nodes != null) {
                         for (final Node node : nodes) {
-                             if (nodeRegex.matcher(node.getNodeId().getValue()).matches()) {
-                                 notifyNode(EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH.child(Node.class, node.getKey()));
-                             }
-                         }
-                     }
+                            if (nodeRegex.matcher(node.getNodeId().getValue()).matches()) {
+                                notifyNode(EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH.child(Node.class,
+                                        node.getKey()));
+                            }
+                        }
+                    }
                 }
                 tx.close();
             }
 
             @Override
-            public void onFailure(final Throwable t) {
-                LOG.error("Can not notify existing nodes", t);
+            public void onFailure(final Throwable ex) {
+                LOG.error("Can not notify existing nodes", ex);
                 tx.close();
             }
-
-        });
-
+        }, MoreExecutors.directExecutor());
     }
 
     private JoinTopicInput getJoinTopicInputArgument(final InstanceIdentifier<?> path) {
@@ -156,7 +159,7 @@ public class EventSourceTopic implements DataTreeChangeListener<Node>, AutoClose
         return nodeIdPattern;
     }
 
-    private DisJoinTopicInput getDisJoinTopicInputArgument(final InstanceIdentifier<?> eventSourceNodeId){
+    private DisJoinTopicInput getDisJoinTopicInputArgument(final InstanceIdentifier<?> eventSourceNodeId) {
         final NodeRef nodeRef = new NodeRef(eventSourceNodeId);
         final DisJoinTopicInput dji = new DisJoinTopicInputBuilder()
                 .setNode(nodeRef.getValue())
@@ -175,25 +178,28 @@ public class EventSourceTopic implements DataTreeChangeListener<Node>, AutoClose
 
     @Override
     public void close() {
-        if(this.listenerRegistration != null){
+        if (this.listenerRegistration != null) {
             this.listenerRegistration.close();
         }
-        for(final InstanceIdentifier<?> eventSourceNodeId : joinedEventSources){
+        for (final InstanceIdentifier<?> eventSourceNodeId : joinedEventSources) {
             try {
-                final RpcResult<Void> result = sourceService.disJoinTopic(getDisJoinTopicInputArgument(eventSourceNodeId)).get();
-                if(result.isSuccessful() == false){
-                    for(final RpcError err : result.getErrors()){
-                        LOG.error("Can not destroy topic: [{}] on node: [{}]. Error: {}",getTopicId().getValue(),eventSourceNodeId,err.toString());
+                final RpcResult<Void> result = sourceService
+                        .disJoinTopic(getDisJoinTopicInputArgument(eventSourceNodeId)).get();
+                if (result.isSuccessful() == false) {
+                    for (final RpcError err : result.getErrors()) {
+                        LOG.error("Can not destroy topic: [{}] on node: [{}]. Error: {}", getTopicId().getValue(),
+                                eventSourceNodeId, err.toString());
                     }
                 }
             } catch (InterruptedException | ExecutionException ex) {
-                LOG.error("Can not close event source topic / destroy topic {} on node {}.", this.topicId.getValue(), eventSourceNodeId, ex);
+                LOG.error("Can not close event source topic / destroy topic {} on node {}.", this.topicId.getValue(),
+                        eventSourceNodeId, ex);
             }
         }
         joinedEventSources.clear();
     }
 
-    private static String getUUIDIdent(){
+    private static String getUUIDIdent() {
         final UUID uuid = UUID.randomUUID();
         return uuid.toString();
     }
index b79d12b9d66569493a4e6d8cfbec33ea5415da4a..73819b263e804646b19f0c20f138262e0ae1e881 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.controller.messagebus.app.impl;
 
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.Future;
@@ -53,7 +54,6 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 public class EventSourceTopology implements EventAggregatorService, EventSourceRegistry {
     private static final Logger LOG = LoggerFactory.getLogger(EventSourceTopology.class);
 
@@ -87,58 +87,57 @@ public class EventSourceTopology implements EventAggregatorService, EventSourceR
         eventSourceService = rpcRegistry.getRpcService(EventSourceService.class);
 
         final TopologyEventSource topologySource = new TopologyEventSourceBuilder().build();
-        final TopologyTypes1 topologyTypeAugment = new TopologyTypes1Builder().setTopologyEventSource(topologySource).build();
+        final TopologyTypes1 topologyTypeAugment =
+                new TopologyTypes1Builder().setTopologyEventSource(topologySource).build();
         putData(OPERATIONAL, TOPOLOGY_TYPE_PATH, topologyTypeAugment);
         LOG.info("EventSourceRegistry has been initialized");
     }
 
     private <T extends DataObject>  void putData(final LogicalDatastoreType store,
                                                  final InstanceIdentifier<T> path,
-                                                 final T data){
+                                                 final T data) {
 
         final WriteTransaction tx = getDataBroker().newWriteOnlyTransaction();
         tx.put(store, path, data, true);
-        Futures.addCallback( tx.submit(), new FutureCallback<Void>(){
-
+        Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
             @Override
             public void onSuccess(final Void result) {
                 LOG.trace("Data has put into datastore {} {}", store, path);
             }
 
             @Override
-            public void onFailure(final Throwable t) {
-                LOG.error("Can not put data into datastore [store: {}] [path: {}] [exception: {}]",store,path, t);
+            public void onFailure(final Throwable ex) {
+                LOG.error("Can not put data into datastore [store: {}] [path: {}] [exception: {}]",store,path, ex);
             }
-        });
-
+        }, MoreExecutors.directExecutor());
     }
 
-    private <T extends DataObject>  void deleteData(final LogicalDatastoreType store, final InstanceIdentifier<T> path){
+    private <T extends DataObject>  void deleteData(final LogicalDatastoreType store,
+            final InstanceIdentifier<T> path) {
         final WriteTransaction tx = getDataBroker().newWriteOnlyTransaction();
         tx.delete(OPERATIONAL, path);
-        Futures.addCallback( tx.submit(), new FutureCallback<Void>(){
-
+        Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
             @Override
             public void onSuccess(final Void result) {
                 LOG.trace("Data has deleted from datastore {} {}", store, path);
             }
 
             @Override
-            public void onFailure(final Throwable t) {
-                LOG.error("Can not delete data from datastore [store: {}] [path: {}] [exception: {}]",store,path, t);
+            public void onFailure(final Throwable ex) {
+                LOG.error("Can not delete data from datastore [store: {}] [path: {}] [exception: {}]",store,path, ex);
             }
-
-        });
+        }, MoreExecutors.directExecutor());
     }
 
     private void insert(final KeyedInstanceIdentifier<Node, NodeKey> sourcePath) {
         final NodeKey nodeKey = sourcePath.getKey();
         final InstanceIdentifier<Node1> augmentPath = sourcePath.augmentation(Node1.class);
-        final Node1 nodeAgument = new Node1Builder().setEventSourceNode(new NodeId(nodeKey.getNodeId().getValue())).build();
+        final Node1 nodeAgument = new Node1Builder().setEventSourceNode(
+                new NodeId(nodeKey.getNodeId().getValue())).build();
         putData(OPERATIONAL, augmentPath, nodeAgument);
     }
 
-    private void remove(final KeyedInstanceIdentifier<Node, NodeKey> sourcePath){
+    private void remove(final KeyedInstanceIdentifier<Node, NodeKey> sourcePath) {
         final InstanceIdentifier<Node1> augmentPath = sourcePath.augmentation(Node1.class);
         deleteData(OPERATIONAL, augmentPath);
     }
@@ -170,7 +169,7 @@ public class EventSourceTopology implements EventAggregatorService, EventSourceR
     @Override
     public Future<RpcResult<Void>> destroyTopic(final DestroyTopicInput input) {
         final EventSourceTopic topicToDestroy = eventSourceTopicMap.remove(input.getTopicId());
-        if(topicToDestroy != null){
+        if (topicToDestroy != null) {
             topicToDestroy.close();
         }
         return Util.resultRpcSuccessFor((Void) null);
@@ -179,29 +178,28 @@ public class EventSourceTopology implements EventAggregatorService, EventSourceR
     @Override
     public void close() {
         aggregatorRpcReg.close();
-        for(final EventSourceTopic est : eventSourceTopicMap.values()){
-            est.close();
-        }
+        eventSourceTopicMap.values().forEach(EventSourceTopic::close);
     }
 
-    public void register(final EventSource eventSource){
+    public void register(final EventSource eventSource) {
 
         final NodeKey nodeKey = eventSource.getSourceNodeKey();
         final KeyedInstanceIdentifier<Node, NodeKey> sourcePath = EVENT_SOURCE_TOPOLOGY_PATH.child(Node.class, nodeKey);
-        final RoutedRpcRegistration<EventSourceService> reg = rpcRegistry.addRoutedRpcImplementation(EventSourceService.class, eventSource);
+        final RoutedRpcRegistration<EventSourceService> reg = rpcRegistry.addRoutedRpcImplementation(
+                EventSourceService.class, eventSource);
         reg.registerPath(NodeContext.class, sourcePath);
         routedRpcRegistrations.put(nodeKey,reg);
         insert(sourcePath);
 
     }
 
-    public void unRegister(final EventSource eventSource){
+    public void unRegister(final EventSource eventSource) {
         final NodeKey nodeKey = eventSource.getSourceNodeKey();
         final KeyedInstanceIdentifier<Node, NodeKey> sourcePath = EVENT_SOURCE_TOPOLOGY_PATH.child(Node.class, nodeKey);
         final RoutedRpcRegistration<EventSourceService> removeRegistration = routedRpcRegistrations.remove(nodeKey);
-        if(removeRegistration != null){
+        if (removeRegistration != null) {
             removeRegistration.close();
-        remove(sourcePath);
+            remove(sourcePath);
         }
     }
 
index 324b88f00a014b881a9ceba89a8a184028cb72bc..6649aa82de7d08948cab9e9a60d990bb3d58a693 100644 (file)
@@ -7,16 +7,16 @@
  */
 package org.opendaylight.controller.messagebus.app.impl;
 
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.opendaylight.controller.messagebus.spi.EventSource;
-
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.controller.messagebus.spi.EventSource;
+
 public class EventSourceRegistrationImplTest {
 
     EventSourceRegistrationImplLocal eventSourceRegistrationImplLocal;
@@ -30,7 +30,8 @@ public class EventSourceRegistrationImplTest {
     public void setUp() throws Exception {
         EventSource eventSourceMock = mock(EventSource.class);
         eventSourceTopologyMock = mock(EventSourceTopology.class);
-        eventSourceRegistrationImplLocal = new EventSourceRegistrationImplLocal(eventSourceMock, eventSourceTopologyMock);
+        eventSourceRegistrationImplLocal = new EventSourceRegistrationImplLocal(eventSourceMock,
+                eventSourceTopologyMock);
     }
 
     @Test
@@ -40,13 +41,8 @@ public class EventSourceRegistrationImplTest {
     }
 
 
-    private class EventSourceRegistrationImplLocal extends EventSourceRegistrationImpl{
-
-        /**
-         * @param instance of EventSource that has been registered by {@link EventSourceRegistryImpl#registerEventSource(Node, org.opendaylight.controller.messagebus.spi.EventSource)}
-         * @param eventSourceTopology
-         */
-        public EventSourceRegistrationImplLocal(EventSource instance, EventSourceTopology eventSourceTopology) {
+    private class EventSourceRegistrationImplLocal extends EventSourceRegistrationImpl<EventSource> {
+        EventSourceRegistrationImplLocal(EventSource instance, EventSourceTopology eventSourceTopology) {
             super(instance, eventSourceTopology);
         }
     }
index 8374d395a0febace1b2af0f7283b79d86c93ac61..a2b2b7561ac5ef904311a8293dc5bcd65499ffe6 100644 (file)
@@ -31,11 +31,14 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.EventSourceService;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicInput;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicStatus;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 
 public class EventSourceTopicTest {
 
@@ -50,8 +53,11 @@ public class EventSourceTopicTest {
 
     @Before
     public void setUp() throws Exception {
-        NotificationPattern notificationPattern = new NotificationPattern("value1");
+        final NotificationPattern notificationPattern = new NotificationPattern("value1");
         eventSourceServiceMock = mock(EventSourceService.class);
+        doReturn(RpcResultBuilder.success(new JoinTopicOutputBuilder().setStatus(JoinTopicStatus.Up).build())
+                .buildFuture()).when(eventSourceServiceMock).joinTopic(any(JoinTopicInput.class));
+
         eventSourceTopologyMock = mock(EventSourceTopology.class);
         dataBrokerMock = mock(DataBroker.class);
         doReturn(eventSourceServiceMock).when(eventSourceTopologyMock).getEventSourceService();
@@ -59,14 +65,16 @@ public class EventSourceTopicTest {
 
         WriteTransaction writeTransactionMock = mock(WriteTransaction.class);
         doReturn(writeTransactionMock).when(dataBrokerMock).newWriteOnlyTransaction();
-        doNothing().when(writeTransactionMock).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(DataObject.class),eq(true));
+        doNothing().when(writeTransactionMock).put(any(LogicalDatastoreType.class),
+                any(InstanceIdentifier.class), any(DataObject.class),eq(true));
         CheckedFuture checkedFutureWriteMock = mock(CheckedFuture.class);
         doReturn(checkedFutureWriteMock).when(writeTransactionMock).submit();
 
         ReadOnlyTransaction readOnlyTransactionMock = mock(ReadOnlyTransaction.class);
         doReturn(readOnlyTransactionMock).when(dataBrokerMock).newReadOnlyTransaction();
         CheckedFuture checkedFutureReadMock = mock(CheckedFuture.class);
-        doReturn(checkedFutureReadMock).when(readOnlyTransactionMock).read(LogicalDatastoreType.OPERATIONAL, EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH);
+        doReturn(checkedFutureReadMock).when(readOnlyTransactionMock).read(LogicalDatastoreType.OPERATIONAL,
+                EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH);
         eventSourceTopic = EventSourceTopic.create(notificationPattern, "nodeIdPattern1", eventSourceTopologyMock);
     }
 
@@ -111,7 +119,7 @@ public class EventSourceTopicTest {
         verify(eventSourceServiceMock, times(1)).joinTopic(any(JoinTopicInput.class));
     }
 
-    public NodeKey getNodeKey(String nodeId){
+    public NodeKey getNodeKey(String nodeId) {
         return new NodeKey(new NodeId(nodeId));
     }
 }
index 8776c996f981278963b8f94d64c587797b0524a2..56d67bff4dc8bb690d558ba873b0d00bbf7a9067 100644 (file)
@@ -74,37 +74,40 @@ public class EventSourceTopologyTest {
         assertNotNull("Instance has not been created correctly.", eventSourceTopology);
     }
 
-    private void constructorTestHelper(){
+    private void constructorTestHelper() {
         aggregatorRpcReg = mock(RpcRegistration.class);
         EventSourceService eventSourceService = mock(EventSourceService.class);
-        doReturn(aggregatorRpcReg).when(rpcProviderRegistryMock).addRpcImplementation(eq(EventAggregatorService.class), any(EventSourceTopology.class));
+        doReturn(aggregatorRpcReg).when(rpcProviderRegistryMock).addRpcImplementation(eq(EventAggregatorService.class),
+                any(EventSourceTopology.class));
         doReturn(eventSourceService).when(rpcProviderRegistryMock).getRpcService(EventSourceService.class);
         WriteTransaction writeTransactionMock = mock(WriteTransaction.class);
         doReturn(writeTransactionMock).when(dataBrokerMock).newWriteOnlyTransaction();
-        doNothing().when(writeTransactionMock).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(DataObject.class),eq(true));
+        doNothing().when(writeTransactionMock).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
+                any(DataObject.class),eq(true));
         CheckedFuture checkedFutureMock = mock(CheckedFuture.class);
         doReturn(checkedFutureMock).when(writeTransactionMock).submit();
     }
 
     @Test
-    public void createTopicTest() throws Exception{
+    public void createTopicTest() throws Exception {
         topicTestHelper();
         assertNotNull("Topic has not been created correctly.", eventSourceTopology.createTopic(createTopicInputMock));
     }
 
     @Test
-    public void destroyTopicTest() throws Exception{
+    public void destroyTopicTest() throws Exception {
         topicTestHelper();
         TopicId topicId = new TopicId("topic-id-007");
         Map<TopicId,EventSourceTopic> localMap = getEventSourceTopicMap();
-        EventSourceTopic eventSourceTopicMock = mock(EventSourceTopic.class);
-        localMap.put(topicId, eventSourceTopicMock);
+        EventSourceTopic eventSourceTopic = EventSourceTopic.create(new NotificationPattern("foo"),
+                "pattern", eventSourceTopology);
+        localMap.put(topicId, eventSourceTopic);
         DestroyTopicInput input = new DestroyTopicInputBuilder().setTopicId(topicId).build();
         eventSourceTopology.destroyTopic(input);
-        verify(eventSourceTopicMock, times(1)).close();
+        verify(listenerRegistrationMock, times(1)).close();
     }
 
-    private void topicTestHelper() throws Exception{
+    private void topicTestHelper() throws Exception {
         constructorTestHelper();
         createTopicInputMock = mock(CreateTopicInput.class);
         eventSourceTopology = new EventSourceTopology(dataBrokerMock, rpcProviderRegistryMock);
@@ -140,16 +143,17 @@ public class EventSourceTopologyTest {
     }
 
     @Test
-    public void closeTest() throws Exception{
+    public void closeTest() throws Exception {
         constructorTestHelper();
         topicTestHelper();
         Map<TopicId,EventSourceTopic> localMap = getEventSourceTopicMap();
         TopicId topicIdMock = mock(TopicId.class);
-        EventSourceTopic eventSourceTopicMock = mock(EventSourceTopic.class);
-        localMap.put(topicIdMock, eventSourceTopicMock);
+        EventSourceTopic eventSourceTopic = EventSourceTopic.create(new NotificationPattern("foo"),
+                "pattern", eventSourceTopology);
+        localMap.put(topicIdMock, eventSourceTopic);
         eventSourceTopology.close();
         verify(aggregatorRpcReg, times(1)).close();
-        verify(eventSourceTopicMock, times(1)).close();
+        verify(listenerRegistrationMock, times(1)).close();
     }
 
     @Test
@@ -161,11 +165,15 @@ public class EventSourceTopologyTest {
         nodeKey = new NodeKey(nodeId);
         doReturn(nodeKey).when(nodeMock).getKey();
         doReturn(nodeKey).when(eventSourceMock).getSourceNodeKey();
-        BindingAwareBroker.RoutedRpcRegistration routedRpcRegistrationMock = mock(BindingAwareBroker.RoutedRpcRegistration.class);
-        doReturn(routedRpcRegistrationMock).when(rpcProviderRegistryMock).addRoutedRpcImplementation(EventSourceService.class, eventSourceMock);
-        doNothing().when(routedRpcRegistrationMock).registerPath(eq(NodeContext.class), any(KeyedInstanceIdentifier.class));
+        BindingAwareBroker.RoutedRpcRegistration routedRpcRegistrationMock = mock(
+                BindingAwareBroker.RoutedRpcRegistration.class);
+        doReturn(routedRpcRegistrationMock).when(rpcProviderRegistryMock)
+                .addRoutedRpcImplementation(EventSourceService.class, eventSourceMock);
+        doNothing().when(routedRpcRegistrationMock).registerPath(eq(NodeContext.class),
+                any(KeyedInstanceIdentifier.class));
         eventSourceTopology.register(eventSourceMock);
-        verify(routedRpcRegistrationMock, times(1)).registerPath(eq(NodeContext.class), any(KeyedInstanceIdentifier.class));
+        verify(routedRpcRegistrationMock, times(1)).registerPath(eq(NodeContext.class),
+                any(KeyedInstanceIdentifier.class));
     }
 
     @Test
@@ -174,10 +182,12 @@ public class EventSourceTopologyTest {
         EventSource eventSourceMock = mock(EventSource.class);
         NodeId nodeId = new NodeId("nodeIdValue1");
         nodeKey = new NodeKey(nodeId);
-        Map<NodeKey, BindingAwareBroker.RoutedRpcRegistration<EventSourceService>> localMap = getRoutedRpcRegistrations();
+        Map<NodeKey, BindingAwareBroker.RoutedRpcRegistration<EventSourceService>> localMap =
+                getRoutedRpcRegistrations();
         NodeKey nodeKeyMock = mock(NodeKey.class);
         doReturn(nodeKeyMock).when(eventSourceMock).getSourceNodeKey();
-        BindingAwareBroker.RoutedRpcRegistration<EventSourceService> routedRpcRegistrationMock = mock(BindingAwareBroker.RoutedRpcRegistration.class);
+        BindingAwareBroker.RoutedRpcRegistration<EventSourceService> routedRpcRegistrationMock =
+                mock(BindingAwareBroker.RoutedRpcRegistration.class);
         localMap.put(nodeKeyMock, routedRpcRegistrationMock);
         eventSourceTopology.unRegister(eventSourceMock);
         verify(routedRpcRegistrationMock, times(1)).close();
@@ -192,19 +202,23 @@ public class EventSourceTopologyTest {
         nodeKey = new NodeKey(nodeId);
         doReturn(nodeKey).when(nodeMock).getKey();
         doReturn(nodeKey).when(eventSourceMock).getSourceNodeKey();
-        BindingAwareBroker.RoutedRpcRegistration routedRpcRegistrationMock = mock(BindingAwareBroker.RoutedRpcRegistration.class);
-        doReturn(routedRpcRegistrationMock).when(rpcProviderRegistryMock).addRoutedRpcImplementation(EventSourceService.class, eventSourceMock);
-        doNothing().when(routedRpcRegistrationMock).registerPath(eq(NodeContext.class), any(KeyedInstanceIdentifier.class));
-        assertNotNull("Return value has not been created correctly.", eventSourceTopology.registerEventSource(eventSourceMock));
+        BindingAwareBroker.RoutedRpcRegistration routedRpcRegistrationMock = mock(
+                BindingAwareBroker.RoutedRpcRegistration.class);
+        doReturn(routedRpcRegistrationMock).when(rpcProviderRegistryMock)
+                .addRoutedRpcImplementation(EventSourceService.class, eventSourceMock);
+        doNothing().when(routedRpcRegistrationMock).registerPath(eq(NodeContext.class),
+                any(KeyedInstanceIdentifier.class));
+        assertNotNull("Return value has not been created correctly.",
+                eventSourceTopology.registerEventSource(eventSourceMock));
     }
 
-    private Map getEventSourceTopicMap() throws Exception{
+    private Map getEventSourceTopicMap() throws Exception {
         Field nesField = EventSourceTopology.class.getDeclaredField("eventSourceTopicMap");
         nesField.setAccessible(true);
         return (Map) nesField.get(eventSourceTopology);
     }
 
-    private Map getRoutedRpcRegistrations() throws Exception{
+    private Map getRoutedRpcRegistrations() throws Exception {
         Field nesField = EventSourceTopology.class.getDeclaredField("routedRpcRegistrations");
         nesField.setAccessible(true);
         return (Map) nesField.get(eventSourceTopology);
index c367368d6306b635bf39efc18990d1b4884712c0..3221e1338d52ffcbdf908887056407bac7a4e8b6 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.controller.messagebus.spi;
 
 import java.util.List;
-
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.EventSourceService;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
@@ -25,7 +24,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 public interface EventSource extends EventSourceService, AutoCloseable {
 
     /**
-     * Identifier of node associated with event source
+     * Identifier of node associated with event source.
      *
      * @return instance of NodeKey
      */
@@ -37,5 +36,4 @@ public interface EventSource extends EventSourceService, AutoCloseable {
      * @return list of available notification
      */
     List<SchemaPath> getAvailableNotifications();
-
 }
index 3f7f0c0391205eca94a51f5eecea23d6b1b491b2..dd6cc1a166d6ee514816176e609ebcbb022e274b 100644 (file)
@@ -14,9 +14,8 @@ import org.opendaylight.yangtools.concepts.ObjectRegistration;
  * and it is used to unregister EventSource.
  *
  */
-public interface EventSourceRegistration <T extends EventSource> extends ObjectRegistration<T>{
+public interface EventSourceRegistration<T extends EventSource> extends ObjectRegistration<T> {
 
     @Override
     void close();
-
 }
index 8f9b53074dd70d4dfd7119b3945869be055b4d62..893ea16940370a55dce46e0ed5947040bea25876 100644 (file)
@@ -17,8 +17,8 @@ public interface EventSourceRegistry extends AutoCloseable {
      * associated with the node identified via {@link EventSource#getSourceNodeKey}.
      *
      * @param eventSource the EventSource instance to register
-     * @return an EventSourceRegistration instance that is used to unregister the EventSource via {@link EventSourceRegistration#close()}.
+     * @return an EventSourceRegistration instance that is used to unregister the EventSource
+     * via {@link EventSourceRegistration#close()}.
      */
     <T extends EventSource> EventSourceRegistration<T> registerEventSource(T eventSource);
-
 }
index 399cfb445c99a06b5288d3316ce59e52775e9f56..a3f976da52182521259a7334ac147cff5ff5cae9 100644 (file)
@@ -8,19 +8,18 @@
 
 package org.opendaylight.controller.messagebus.app.util;
 
+import com.google.common.util.concurrent.Futures;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.Future;
 import java.util.regex.Pattern;
-
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 
-import com.google.common.util.concurrent.Futures;
-
-
 public final class Util {
+    private Util() {
+    }
 
     public static <T> Future<RpcResult<T>> resultRpcSuccessFor(final T output) {
         final RpcResult<T> result = RpcResultBuilder.success(output).build();
@@ -28,9 +27,9 @@ public final class Util {
     }
 
     /**
-     * Method filters qnames based on wildcard strings
+     * Method filters qnames based on wildcard strings.
      *
-     * @param list
+     * @param list list of SchemaPaths
      * @param pattern matching pattern
      * @return list of filtered qnames
      */
@@ -47,15 +46,13 @@ public final class Util {
     }
 
     /**
-     * CREDIT to http://www.rgagnon.com/javadetails/java-0515.html
-     * @param wildcard
-     * @return
+     * CREDIT to http://www.rgagnon.com/javadetails/java-0515.html.
      */
-    public static String wildcardToRegex(final String wildcard){
+    public static String wildcardToRegex(final String wildcard) {
         final StringBuilder s = new StringBuilder(wildcard.length());
         s.append('^');
         for (final char c : wildcard.toCharArray()) {
-            switch(c) {
+            switch (c) {
                 case '*':
                     s.append(".*");
                     break;
index 22595a2cbb5f2874a9f9c0ef2844d09b19cf9721..eba02a81cab985ff559f58bf9be92f8b41b8b5f0 100644 (file)
@@ -21,7 +21,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 
 public class TopicDOMNotificationTest {
 
-    private static final String containerNodeBodyMockToString = "containerNodeBodyMock";
+    private static final String CONTAINER_NODE_BODY_MOCK_TO_STRING = "containerNodeBodyMock";
     ContainerNode containerNodeBodyMock;
     TopicDOMNotification topicDOMNotification;
 
@@ -32,7 +32,7 @@ public class TopicDOMNotificationTest {
     @Before
     public void setUp() throws Exception {
         containerNodeBodyMock = mock(ContainerNode.class);
-        doReturn(containerNodeBodyMockToString).when(containerNodeBodyMock).toString();
+        doReturn(CONTAINER_NODE_BODY_MOCK_TO_STRING).when(containerNodeBodyMock).toString();
         topicDOMNotification = new TopicDOMNotification(containerNodeBodyMock);
     }
 
@@ -43,8 +43,8 @@ public class TopicDOMNotificationTest {
 
     @Test
     public void getTypeTest() {
-        SchemaPath TOPIC_NOTIFICATION_ID = SchemaPath.create(true, TopicNotification.QNAME);
-        assertEquals("Type has not been created correctly.", TOPIC_NOTIFICATION_ID, topicDOMNotification.getType());
+        SchemaPath topicNotificationId = SchemaPath.create(true, TopicNotification.QNAME);
+        assertEquals("Type has not been created correctly.", topicNotificationId, topicDOMNotification.getType());
     }
 
     @Test
@@ -54,7 +54,7 @@ public class TopicDOMNotificationTest {
 
     @Test
     public void getToStringTest() {
-        String bodyString = "TopicDOMNotification [body=" + containerNodeBodyMockToString + "]";
+        String bodyString = "TopicDOMNotification [body=" + CONTAINER_NODE_BODY_MOCK_TO_STRING + "]";
         assertEquals("String has not been created correctly.", bodyString, topicDOMNotification.toString());
     }
-}
\ No newline at end of file
+}
index 05425f01ad3d30f8e01a26cbe823f6245cfcdc9c..a06b793e48c8ad5df96bc78b9e6a9142a2eac1a4 100644 (file)
@@ -14,14 +14,15 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.regex.Pattern;
-
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+
 /**
- * @author ppalmar
+ * Unit tests for Util.
  *
+ * @author ppalmar
  */
 public class UtilTest {