db532a90d430c65a43fadbc5d687bc463e56638e
[netconf.git] / netconf / netconf-notifications-impl / src / test / java / org / opendaylight / netconf / notifications / impl / ops / CreateSubscriptionTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.netconf.notifications.impl.ops;
10
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.mock;
14
15 import org.hamcrest.CoreMatchers;
16 import org.junit.Assert;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.mockito.Mock;
20 import org.mockito.MockitoAnnotations;
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.netconf.notifications.NotificationListenerRegistration;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType;
28 import org.w3c.dom.Element;
29
30 public class CreateSubscriptionTest {
31
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>";
37
38     @Mock
39     private NetconfNotificationRegistry notificationRegistry;
40
41     @Before
42     public void setUp() throws Exception {
43         MockitoAnnotations.initMocks(this);
44         doReturn(true).when(notificationRegistry).isStreamAvailable(any(StreamNameType.class));
45         doReturn(mock(NotificationListenerRegistration.class)).when(notificationRegistry)
46                 .registerNotificationListener(any(StreamNameType.class), any(NetconfNotificationListener.class));
47     }
48
49     @Test
50     public void testHandleWithNoSubsequentOperations() throws Exception {
51         final CreateSubscription createSubscription = new CreateSubscription("id", notificationRegistry);
52         createSubscription.setSession(mock(NetconfSession.class));
53
54         final Element e = XmlUtil.readXmlToElement(CREATE_SUBSCRIPTION_XML);
55
56         final XmlElement operationElement = XmlElement.fromDomElement(e);
57         final Element element =
58                 createSubscription.handleWithNoSubsequentOperations(XmlUtil.newDocument(), operationElement);
59
60         Assert.assertThat(XmlUtil.toString(element), CoreMatchers.containsString("ok"));
61     }
62 }