From b2e863c042da2794ba2af751c8aef364ce0253df Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Wed, 7 Mar 2018 16:25:57 -0500 Subject: [PATCH] Fix checkstyle violations in messagebus Change-Id: I4af49c607bbbd607f8ea4fbcbe43ba4f078329d0 Signed-off-by: Tom Pantelis --- .../app/impl/EventSourceRegistrationImpl.java | 15 ++-- .../messagebus/app/impl/EventSourceTopic.java | 80 ++++++++++--------- .../app/impl/EventSourceTopology.java | 52 ++++++------ .../impl/EventSourceRegistrationImplTest.java | 22 +++-- .../app/impl/EventSourceTopicTest.java | 16 +++- .../app/impl/EventSourceTopologyTest.java | 64 +++++++++------ .../messagebus/spi/EventSource.java | 4 +- .../spi/EventSourceRegistration.java | 3 +- .../messagebus/spi/EventSourceRegistry.java | 4 +- .../controller/messagebus/app/util/Util.java | 19 ++--- .../app/util/TopicDOMNotificationTest.java | 12 +-- .../messagebus/app/util/UtilTest.java | 5 +- 12 files changed, 157 insertions(+), 139 deletions(-) diff --git a/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceRegistrationImpl.java b/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceRegistrationImpl.java index d939090323..dac4f8fee8 100644 --- a/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceRegistrationImpl.java +++ b/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceRegistrationImpl.java @@ -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 extends AbstractObjectRegistration implements EventSourceRegistration{ +class EventSourceRegistrationImpl extends AbstractObjectRegistration + implements EventSourceRegistration { 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 extends AbstractObject protected void removeRegistration() { this.eventSourceTopology.unRegister(getInstance()); } - } diff --git a/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopic.java b/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopic.java index ea04d99951..2a77807cd8 100644 --- a/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopic.java +++ b/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopic.java @@ -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, AutoCloseable { +public final class EventSourceTopic implements DataTreeChangeListener, 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, AutoClose private ListenerRegistration listenerRegistration; private final CopyOnWriteArraySet> 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, AutoClose public void notifyNode(final InstanceIdentifier nodeId) { LOG.debug("Notify node: {}", nodeId); try { - final RpcResult 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 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, ReadFailedException> future = + final ListenableFuture> future = tx.read(LogicalDatastoreType.OPERATIONAL, EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH); - Futures.addCallback(future, new FutureCallback>(){ - + Futures.addCallback(future, new FutureCallback>() { @Override public void onSuccess(final Optional data) { - if(data.isPresent()) { - final List nodes = data.get().getNode(); - if(nodes != null){ + if (data.isPresent()) { + final List 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, 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, 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 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 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(); } diff --git a/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopology.java b/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopology.java index b79d12b9d6..73819b263e 100644 --- a/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopology.java +++ b/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopology.java @@ -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 void putData(final LogicalDatastoreType store, final InstanceIdentifier path, - final T data){ + final T data) { final WriteTransaction tx = getDataBroker().newWriteOnlyTransaction(); tx.put(store, path, data, true); - Futures.addCallback( tx.submit(), new FutureCallback(){ - + Futures.addCallback(tx.submit(), new FutureCallback() { @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 void deleteData(final LogicalDatastoreType store, final InstanceIdentifier path){ + private void deleteData(final LogicalDatastoreType store, + final InstanceIdentifier path) { final WriteTransaction tx = getDataBroker().newWriteOnlyTransaction(); tx.delete(OPERATIONAL, path); - Futures.addCallback( tx.submit(), new FutureCallback(){ - + Futures.addCallback(tx.submit(), new FutureCallback() { @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 sourcePath) { final NodeKey nodeKey = sourcePath.getKey(); final InstanceIdentifier 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 sourcePath){ + private void remove(final KeyedInstanceIdentifier sourcePath) { final InstanceIdentifier augmentPath = sourcePath.augmentation(Node1.class); deleteData(OPERATIONAL, augmentPath); } @@ -170,7 +169,7 @@ public class EventSourceTopology implements EventAggregatorService, EventSourceR @Override public Future> 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 sourcePath = EVENT_SOURCE_TOPOLOGY_PATH.child(Node.class, nodeKey); - final RoutedRpcRegistration reg = rpcRegistry.addRoutedRpcImplementation(EventSourceService.class, eventSource); + final RoutedRpcRegistration 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 sourcePath = EVENT_SOURCE_TOPOLOGY_PATH.child(Node.class, nodeKey); final RoutedRpcRegistration removeRegistration = routedRpcRegistrations.remove(nodeKey); - if(removeRegistration != null){ + if (removeRegistration != null) { removeRegistration.close(); - remove(sourcePath); + remove(sourcePath); } } diff --git a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceRegistrationImplTest.java b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceRegistrationImplTest.java index 324b88f00a..6649aa82de 100644 --- a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceRegistrationImplTest.java +++ b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceRegistrationImplTest.java @@ -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 { + EventSourceRegistrationImplLocal(EventSource instance, EventSourceTopology eventSourceTopology) { super(instance, eventSourceTopology); } } diff --git a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopicTest.java b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopicTest.java index 8374d395a0..a2b2b7561a 100644 --- a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopicTest.java +++ b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopicTest.java @@ -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)); } } diff --git a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopologyTest.java b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopologyTest.java index 8776c996f9..56d67bff4d 100644 --- a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopologyTest.java +++ b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopologyTest.java @@ -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 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 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> localMap = getRoutedRpcRegistrations(); + Map> localMap = + getRoutedRpcRegistrations(); NodeKey nodeKeyMock = mock(NodeKey.class); doReturn(nodeKeyMock).when(eventSourceMock).getSourceNodeKey(); - BindingAwareBroker.RoutedRpcRegistration routedRpcRegistrationMock = mock(BindingAwareBroker.RoutedRpcRegistration.class); + BindingAwareBroker.RoutedRpcRegistration 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); diff --git a/opendaylight/md-sal/messagebus-spi/src/main/java/org/opendaylight/controller/messagebus/spi/EventSource.java b/opendaylight/md-sal/messagebus-spi/src/main/java/org/opendaylight/controller/messagebus/spi/EventSource.java index c367368d63..3221e1338d 100644 --- a/opendaylight/md-sal/messagebus-spi/src/main/java/org/opendaylight/controller/messagebus/spi/EventSource.java +++ b/opendaylight/md-sal/messagebus-spi/src/main/java/org/opendaylight/controller/messagebus/spi/EventSource.java @@ -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 getAvailableNotifications(); - } diff --git a/opendaylight/md-sal/messagebus-spi/src/main/java/org/opendaylight/controller/messagebus/spi/EventSourceRegistration.java b/opendaylight/md-sal/messagebus-spi/src/main/java/org/opendaylight/controller/messagebus/spi/EventSourceRegistration.java index 3f7f0c0391..dd6cc1a166 100644 --- a/opendaylight/md-sal/messagebus-spi/src/main/java/org/opendaylight/controller/messagebus/spi/EventSourceRegistration.java +++ b/opendaylight/md-sal/messagebus-spi/src/main/java/org/opendaylight/controller/messagebus/spi/EventSourceRegistration.java @@ -14,9 +14,8 @@ import org.opendaylight.yangtools.concepts.ObjectRegistration; * and it is used to unregister EventSource. * */ -public interface EventSourceRegistration extends ObjectRegistration{ +public interface EventSourceRegistration extends ObjectRegistration { @Override void close(); - } diff --git a/opendaylight/md-sal/messagebus-spi/src/main/java/org/opendaylight/controller/messagebus/spi/EventSourceRegistry.java b/opendaylight/md-sal/messagebus-spi/src/main/java/org/opendaylight/controller/messagebus/spi/EventSourceRegistry.java index 8f9b53074d..893ea16940 100644 --- a/opendaylight/md-sal/messagebus-spi/src/main/java/org/opendaylight/controller/messagebus/spi/EventSourceRegistry.java +++ b/opendaylight/md-sal/messagebus-spi/src/main/java/org/opendaylight/controller/messagebus/spi/EventSourceRegistry.java @@ -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()}. */ EventSourceRegistration registerEventSource(T eventSource); - } diff --git a/opendaylight/md-sal/messagebus-util/src/main/java/org/opendaylight/controller/messagebus/app/util/Util.java b/opendaylight/md-sal/messagebus-util/src/main/java/org/opendaylight/controller/messagebus/app/util/Util.java index 399cfb445c..a3f976da52 100644 --- a/opendaylight/md-sal/messagebus-util/src/main/java/org/opendaylight/controller/messagebus/app/util/Util.java +++ b/opendaylight/md-sal/messagebus-util/src/main/java/org/opendaylight/controller/messagebus/app/util/Util.java @@ -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 Future> resultRpcSuccessFor(final T output) { final RpcResult 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; diff --git a/opendaylight/md-sal/messagebus-util/src/test/java/org/opendaylight/controller/messagebus/app/util/TopicDOMNotificationTest.java b/opendaylight/md-sal/messagebus-util/src/test/java/org/opendaylight/controller/messagebus/app/util/TopicDOMNotificationTest.java index 22595a2cbb..eba02a81ca 100644 --- a/opendaylight/md-sal/messagebus-util/src/test/java/org/opendaylight/controller/messagebus/app/util/TopicDOMNotificationTest.java +++ b/opendaylight/md-sal/messagebus-util/src/test/java/org/opendaylight/controller/messagebus/app/util/TopicDOMNotificationTest.java @@ -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 +} diff --git a/opendaylight/md-sal/messagebus-util/src/test/java/org/opendaylight/controller/messagebus/app/util/UtilTest.java b/opendaylight/md-sal/messagebus-util/src/test/java/org/opendaylight/controller/messagebus/app/util/UtilTest.java index 05425f01ad..a06b793e48 100644 --- a/opendaylight/md-sal/messagebus-util/src/test/java/org/opendaylight/controller/messagebus/app/util/UtilTest.java +++ b/opendaylight/md-sal/messagebus-util/src/test/java/org/opendaylight/controller/messagebus/app/util/UtilTest.java @@ -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 { -- 2.36.6