X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fsal-netconf-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fsal%2Fconnect%2Fnetconf%2Fsal%2FMountInstanceTest.java;h=d2f661a17cee46ebb2e5d91cfcd63d2d76f3fdba;hb=14bd5e7ef6421c109248f4e750be330cb0337287;hp=7e62990bc7288e619362040c2b04f78e31f11ac9;hpb=9173dd3c7d8283cc53edeef754250d0d6fbc91e4;p=netconf.git diff --git a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/MountInstanceTest.java b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/MountInstanceTest.java index 7e62990bc7..d2f661a17c 100644 --- a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/MountInstanceTest.java +++ b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/MountInstanceTest.java @@ -7,11 +7,10 @@ */ package org.opendaylight.netconf.sal.connect.netconf.sal; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import com.google.common.collect.Lists; import java.net.InetSocketAddress; import org.junit.Assert; import org.junit.Before; @@ -19,26 +18,34 @@ import org.junit.BeforeClass; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; -import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint; -import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; -import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; +import org.opendaylight.binding.runtime.spi.BindingRuntimeHelpers; +import org.opendaylight.mdsal.dom.api.DOMDataBroker; +import org.opendaylight.mdsal.dom.api.DOMMountPoint; +import org.opendaylight.mdsal.dom.api.DOMMountPointService; +import org.opendaylight.mdsal.dom.api.DOMNotification; +import org.opendaylight.mdsal.dom.api.DOMNotificationService; +import org.opendaylight.mdsal.dom.api.DOMRpcService; +import org.opendaylight.netconf.dom.api.NetconfDataTreeService; import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.IetfNetconfService; import org.opendaylight.yangtools.concepts.ObjectRegistration; -import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class MountInstanceTest { + private static final Logger LOG = LoggerFactory.getLogger(MountInstanceTest.class); - private static SchemaContext SCHEMA_CONTEXT; + private static EffectiveModelContext SCHEMA_CONTEXT; @Mock private DOMMountPointService service; @Mock private DOMDataBroker broker; @Mock + private NetconfDataTreeService netconfService; + @Mock private DOMRpcService rpcService; @Mock private NetconfDeviceNotificationService notificationService; @@ -46,16 +53,14 @@ public class MountInstanceTest { private DOMMountPointService.DOMMountPointBuilder mountPointBuilder; @Mock private ObjectRegistration registration; + @Mock + private DOMNotification notification; private NetconfDeviceSalProvider.MountInstance mountInstance; @BeforeClass - public static void suiteSetUp() throws Exception{ - final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create(); - moduleInfoBackedContext.addModuleInfos( - Lists.newArrayList(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.$YangModuleInfoImpl.getInstance())); - SCHEMA_CONTEXT = moduleInfoBackedContext.tryToCreateSchemaContext().get(); - + public static void suiteSetUp() throws Exception { + SCHEMA_CONTEXT = BindingRuntimeHelpers.createEffectiveModel(IetfNetconfService.class); } @Before @@ -64,12 +69,13 @@ public class MountInstanceTest { when(service.createMountPoint(any(YangInstanceIdentifier.class))).thenReturn(mountPointBuilder); when(mountPointBuilder.register()).thenReturn(registration); - mountInstance = new NetconfDeviceSalProvider.MountInstance(service, new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830))); + mountInstance = new NetconfDeviceSalProvider.MountInstance( + service, new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830))); } @Test - public void testOnTopologyDeviceConnected() throws Exception { + public void testOnTopologyDeviceConnected() { mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService); verify(mountPointBuilder).addInitialSchemaContext(SCHEMA_CONTEXT); verify(mountPointBuilder).addService(DOMDataBroker.class, broker); @@ -77,6 +83,16 @@ public class MountInstanceTest { verify(mountPointBuilder).addService(DOMNotificationService.class, notificationService); } + @Test + public void testOnTopologyDeviceConnectedWithNetconfService() { + mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, null, netconfService, rpcService, + notificationService, null); + verify(mountPointBuilder).addInitialSchemaContext(SCHEMA_CONTEXT); + verify(mountPointBuilder).addService(NetconfDataTreeService.class, netconfService); + verify(mountPointBuilder).addService(DOMRpcService.class, rpcService); + verify(mountPointBuilder).addService(DOMNotificationService.class, notificationService); + } + @Test public void testOnTopologyDeviceDisconnected() throws Exception { mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService); @@ -84,8 +100,8 @@ public class MountInstanceTest { verify(registration).close(); try { mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService); - } catch (IllegalStateException e) { - e.printStackTrace(); + } catch (final IllegalStateException e) { + LOG.warn("Operation failed.", e); Assert.fail("Topology registration still present after disconnect "); } } @@ -97,4 +113,14 @@ public class MountInstanceTest { verify(registration).close(); } -} \ No newline at end of file + @Test + public void testPublishNotification() throws Exception { + mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService); + verify(mountPointBuilder).addInitialSchemaContext(SCHEMA_CONTEXT); + verify(mountPointBuilder).addService(DOMNotificationService.class, notificationService); + mountInstance.publish(notification); + verify(notificationService).publishNotification(notification); + } + + +}