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
9 package org.opendaylight.controller.netconf.notifications.impl.ops;
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.mock;
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.controller.netconf.api.NetconfSession;
22 import org.opendaylight.controller.netconf.notifications.NetconfNotificationListener;
23 import org.opendaylight.controller.netconf.notifications.NetconfNotificationRegistry;
24 import org.opendaylight.controller.netconf.notifications.NotificationListenerRegistration;
25 import org.opendaylight.controller.netconf.util.xml.XmlElement;
26 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType;
28 import org.w3c.dom.Element;
30 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\" xmlns:netconf=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
34 "<stream>TESTSTREAM</stream>" +
35 "</create-subscription>";
38 private NetconfNotificationRegistry notificationRegistry;
41 public void setUp() throws Exception {
42 MockitoAnnotations.initMocks(this);
43 doReturn(true).when(notificationRegistry).isStreamAvailable(any(StreamNameType.class));
44 doReturn(mock(NotificationListenerRegistration.class)).when(notificationRegistry).registerNotificationListener(any(StreamNameType.class), any(NetconfNotificationListener.class));
48 public void testHandleWithNoSubsequentOperations() throws Exception {
49 final CreateSubscription createSubscription = new CreateSubscription("id", notificationRegistry);
50 createSubscription.setSession(mock(NetconfSession.class));
52 final Element e = XmlUtil.readXmlToElement(CREATE_SUBSCRIPTION_XML);
54 final XmlElement operationElement = XmlElement.fromDomElement(e);
55 final Element element = createSubscription.handleWithNoSubsequentOperations(XmlUtil.newDocument(), operationElement);
57 Assert.assertThat(XmlUtil.toString(element), CoreMatchers.containsString("ok"));