X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fnetconf%2Fnetconf-notifications-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fnotifications%2Fimpl%2Fops%2FCreateSubscriptionTest.java;fp=opendaylight%2Fnetconf%2Fnetconf-notifications-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fnotifications%2Fimpl%2Fops%2FCreateSubscriptionTest.java;h=aca8f2de91764e491fd32799bb1d995235f8637d;hb=65cde02cd20da08f68934329711d5c28b12f6e56;hp=0000000000000000000000000000000000000000;hpb=c1f5a28943e916b6d61cbe707894b4d5af325af8;p=controller.git diff --git a/opendaylight/netconf/netconf-notifications-impl/src/test/java/org/opendaylight/controller/netconf/notifications/impl/ops/CreateSubscriptionTest.java b/opendaylight/netconf/netconf-notifications-impl/src/test/java/org/opendaylight/controller/netconf/notifications/impl/ops/CreateSubscriptionTest.java new file mode 100644 index 0000000000..aca8f2de91 --- /dev/null +++ b/opendaylight/netconf/netconf-notifications-impl/src/test/java/org/opendaylight/controller/netconf/notifications/impl/ops/CreateSubscriptionTest.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.controller.netconf.notifications.impl.ops; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + +import org.hamcrest.CoreMatchers; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.netconf.api.NetconfSession; +import org.opendaylight.controller.netconf.notifications.NetconfNotificationListener; +import org.opendaylight.controller.netconf.notifications.NetconfNotificationRegistry; +import org.opendaylight.controller.netconf.notifications.NotificationListenerRegistration; +import org.opendaylight.controller.netconf.util.xml.XmlElement; +import org.opendaylight.controller.netconf.util.xml.XmlUtil; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType; +import org.w3c.dom.Element; + +public class CreateSubscriptionTest { + + private static final String CREATE_SUBSCRIPTION_XML = "\n" + + "TESTSTREAM" + + ""; + + @Mock + private NetconfNotificationRegistry notificationRegistry; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + doReturn(true).when(notificationRegistry).isStreamAvailable(any(StreamNameType.class)); + doReturn(mock(NotificationListenerRegistration.class)).when(notificationRegistry).registerNotificationListener(any(StreamNameType.class), any(NetconfNotificationListener.class)); + } + + @Test + public void testHandleWithNoSubsequentOperations() throws Exception { + final CreateSubscription createSubscription = new CreateSubscription("id", notificationRegistry); + createSubscription.setSession(mock(NetconfSession.class)); + + final Element e = XmlUtil.readXmlToElement(CREATE_SUBSCRIPTION_XML); + + final XmlElement operationElement = XmlElement.fromDomElement(e); + final Element element = createSubscription.handleWithNoSubsequentOperations(XmlUtil.newDocument(), operationElement); + + Assert.assertThat(XmlUtil.toString(element), CoreMatchers.containsString("ok")); + } +} \ No newline at end of file