+
+ /**
+ * Create notification stream for toaster module.
+ */
+ @Test
+ public void createNotificationStreamTest() {
+ final NormalizedNodeContext payload = mock(NormalizedNodeContext.class);
+ final InstanceIdentifierContext iiCtx = mock(InstanceIdentifierContext.class);
+ doReturn(iiCtx).when(payload).getInstanceIdentifierContext();
+
+ final SchemaNode schemaNode = mock(SchemaNode.class,
+ Mockito.withSettings().extraInterfaces(RpcDefinition.class));
+ doReturn(schemaNode).when(iiCtx).getSchemaNode();
+ doReturn(mock(SchemaPath.class)).when(schemaNode).getPath();
+
+ doReturn(QName.create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:remote",
+ "2014-01-14", "create-notification-stream")).when(schemaNode).getQName();
+ doReturn(null).when(iiCtx).getMountPoint();
+
+ final Set<DataContainerChild<?, ?>> children = Sets.newHashSet();
+ final DataContainerChild<?, ?> child = mock(DataContainerChild.class,
+ Mockito.withSettings().extraInterfaces(LeafSetNode.class));
+
+ final LeafSetEntryNode entryNode = mock(LeafSetEntryNode.class);
+ when(entryNode.getValue()).thenReturn("(http://netconfcentral.org/ns/toaster?revision=2009-11-20)toastDone");
+ when(((LeafSetNode) child).getValue()).thenReturn(Sets.newHashSet(entryNode));
+ children.add(child);
+
+ final NormalizedNode<?, ?> normalizedNode = mock(NormalizedNode.class,
+ Mockito.withSettings().extraInterfaces(ContainerNode.class));
+ doReturn(normalizedNode).when(payload).getData();
+ doReturn(children).when(normalizedNode).getValue();
+
+ // register notification
+ final NormalizedNodeContext context = this.restconfImpl
+ .invokeRpc("sal-remote:create-notification-stream", payload, null);
+ assertNotNull(context);
+ }
+
+ /**
+ * Subscribe for notification stream of toaster module.
+ */
+ @Test
+ public void subscribeToNotificationStreamTest() throws Exception {
+ final String identifier = "create-notification-stream/toaster:toastDone";
+
+ // register test notification stream
+ final SchemaPath path = SchemaPath.create(
+ true, QName.create("http://netconfcentral.org/ns/toaster", "2009-11-20", "toastDone"));
+ Notificator.createNotificationListener(Lists.newArrayList(path), identifier, "XML");
+
+ final UriInfo uriInfo = mock(UriInfo.class);
+ final UriBuilder uriBuilder = mock(UriBuilder.class);
+ when(uriBuilder.port(8181)).thenReturn(uriBuilder);
+ when(uriBuilder.replacePath(identifier)).thenReturn(uriBuilder);
+ when(uriBuilder.build()).thenReturn(new URI(""));
+ when(uriBuilder.scheme("ws")).thenReturn(uriBuilder);
+ when(uriInfo.getAbsolutePathBuilder()).thenReturn(uriBuilder);
+ final MultivaluedMap<String, String> map = mock(MultivaluedMap.class);
+ final Set<Entry<String, List<String>>> set = new HashSet<>();
+ when(map.entrySet()).thenReturn(set);
+ when(uriInfo.getQueryParameters()).thenReturn(map);
+
+ final BrokerFacade brokerFacade = mock(BrokerFacade.class);
+ this.restconfImpl.setBroker(brokerFacade);
+
+ // subscribe to stream and verify response
+ final NormalizedNodeContext response = this.restconfImpl.subscribeToStream(identifier, uriInfo);
+
+ // remove test notification stream
+ Notificator.removeAllListeners();
+ }