2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.server.events.mdsal;
10 import static org.hamcrest.CoreMatchers.containsString;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.mockito.ArgumentMatchers.any;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.mock;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Mock;
20 import org.mockito.junit.MockitoJUnitRunner;
21 import org.opendaylight.netconf.api.NetconfSession;
22 import org.opendaylight.netconf.api.xml.XmlElement;
23 import org.opendaylight.netconf.api.xml.XmlUtil;
24 import org.opendaylight.netconf.notifications.NetconfNotificationListener;
25 import org.opendaylight.netconf.notifications.NetconfNotificationRegistry;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType;
27 import org.opendaylight.yangtools.concepts.Registration;
28 import org.w3c.dom.Element;
30 @RunWith(MockitoJUnitRunner.StrictStubs.class)
31 public class CreateSubscriptionTest {
32 private static final String CREATE_SUBSCRIPTION_XML = "<create-subscription\n"
33 + "xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\" "
34 + "xmlns:netconf=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
35 + "<stream>TESTSTREAM</stream>"
36 + "</create-subscription>";
39 private NetconfNotificationRegistry notificationRegistry;
43 doReturn(true).when(notificationRegistry).isStreamAvailable(any(StreamNameType.class));
44 doReturn(mock(Registration.class)).when(notificationRegistry)
45 .registerNotificationListener(any(StreamNameType.class), any(NetconfNotificationListener.class));
49 public void testHandleWithNoSubsequentOperations() throws Exception {
50 final CreateSubscription createSubscription = new CreateSubscription("id", notificationRegistry);
51 createSubscription.setSession(mock(NetconfSession.class));
53 final Element e = XmlUtil.readXmlToElement(CREATE_SUBSCRIPTION_XML);
55 final XmlElement operationElement = XmlElement.fromDomElement(e);
56 final Element element =
57 createSubscription.handleWithNoSubsequentOperations(XmlUtil.newDocument(), operationElement);
59 assertThat(XmlUtil.toString(element), containsString("ok"));