Bump upstreams for Silicon
[netconf.git] / netconf / messagebus-netconf / src / test / java / org / opendaylight / netconf / messagebus / eventsources / netconf / ConnectionNotificationTopicRegistrationTest.java
index b23e0f59f61c7214f791a8a0cf980ddba75ddaf0..c9d0f3ebdc7850531a2ba0ea773452c19b572c3f 100644 (file)
@@ -5,28 +5,32 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.messagebus.eventsources.netconf;
 
 import static org.hamcrest.CoreMatchers.hasItems;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.mockito.Mockito.verify;
 
-import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Set;
 import javax.xml.transform.dom.DOMSource;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.mdsal.dom.api.DOMNotification;
+import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
 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.EventSourceStatus;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class ConnectionNotificationTopicRegistrationTest {
 
     private ConnectionNotificationTopicRegistration registration;
@@ -35,8 +39,7 @@ public class ConnectionNotificationTopicRegistrationTest {
     private DOMNotificationListener listener;
 
     @Before
-    public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
+    public void setUp() {
         registration = new ConnectionNotificationTopicRegistration("candidate", listener);
     }
 
@@ -44,7 +47,7 @@ public class ConnectionNotificationTopicRegistrationTest {
     public void testClose() throws Exception {
         registration.setActive(true);
         registration.close();
-        Assert.assertFalse(registration.isActive());
+        assertFalse(registration.isActive());
         checkStatus(listener, EventSourceStatus.Deactive);
     }
 
@@ -71,38 +74,43 @@ public class ConnectionNotificationTopicRegistrationTest {
         final TopicId topic1 = registerTopic("topic1");
         final TopicId topic2 = registerTopic("topic2");
         final TopicId topic3 = registerTopic("topic3");
-        final ArrayList<TopicId> notificationTopicIds = registration.getNotificationTopicIds(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH);
-        Assert.assertNotNull(notificationTopicIds);
-        Assert.assertThat(notificationTopicIds, hasItems(topic1, topic2, topic3));
+        final Set<TopicId> notificationTopicIds = registration.getTopicsForNotification(
+            ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH.asSchemaPath());
+        assertNotNull(notificationTopicIds);
+        assertThat(notificationTopicIds, hasItems(topic1, topic2, topic3));
 
         registration.unRegisterNotificationTopic(topic3);
-        final ArrayList<TopicId> afterUnregister = registration.getNotificationTopicIds(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH);
-        Assert.assertNotNull(afterUnregister);
-        Assert.assertThat(afterUnregister, hasItems(topic1, topic2));
-        Assert.assertFalse(afterUnregister.contains(topic3));
+        final Set<TopicId> afterUnregister = registration.getTopicsForNotification(
+            ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH.asSchemaPath());
+        assertNotNull(afterUnregister);
+        assertThat(afterUnregister, hasItems(topic1, topic2));
+        assertFalse(afterUnregister.contains(topic3));
     }
 
-    private TopicId registerTopic(String value) {
+    private TopicId registerTopic(final String value) {
         final TopicId topic = TopicId.getDefaultInstance(value);
-        registration.registerNotificationTopic(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH, topic);
+        registration.registerNotificationTopic(
+            ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH.asSchemaPath(), topic);
         return topic;
     }
 
 
     /**
      * 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) {
+    private static void checkStatus(final DOMNotificationListener listener, final EventSourceStatus status) {
         ArgumentCaptor<DOMNotification> 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<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> body = value.getBody().getValue();
-        Assert.assertEquals(1, body.size());
+        assertEquals(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH, value.getType());
+        final Collection<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> body =
+            value.getBody().getValue();
+        assertEquals(1, body.size());
         final DOMSource source = (DOMSource) body.iterator().next().getValue();
         final String statusNodeValue = source.getNode().getFirstChild().getFirstChild().getNodeValue();
-        Assert.assertEquals(status.toString(), statusNodeValue);
+        assertEquals(status.toString(), statusNodeValue);
     }
 }
\ No newline at end of file