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=3a63e17a93fb7d777d10495b1d54d5e9056343f4;hb=798a05a2d099fd66040bf3b10635afaec9b3b7d4;hp=b2274d1ec73b12079dc679782ded2fe766a34807;hpb=476cc2164a06b77e7dd38859e0124d82cd2c8847;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 b2274d1ec7..3a63e17a93 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,43 +7,49 @@ */ package org.opendaylight.netconf.sal.connect.netconf.sal; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; 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; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; 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.DOMNotification; -import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; -import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext; +import org.mockito.junit.MockitoJUnitRunner; +import org.opendaylight.mdsal.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.mdsal.dom.api.DOMSchemaService; +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.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; +@RunWith(MockitoJUnitRunner.StrictStubs.class) 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; @@ -58,16 +64,11 @@ public class MountInstanceTest { @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(); - + SCHEMA_CONTEXT = BindingRuntimeHelpers.createEffectiveModel(IetfNetconfService.class); } @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); when(service.createMountPoint(any(YangInstanceIdentifier.class))).thenReturn(mountPointBuilder); when(mountPointBuilder.register()).thenReturn(registration); @@ -77,21 +78,34 @@ public class MountInstanceTest { @Test - public void testOnTopologyDeviceConnected() throws Exception { - mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService); - verify(mountPointBuilder).addInitialSchemaContext(SCHEMA_CONTEXT); + public void testOnTopologyDeviceConnected() { + mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, null, rpcService, + notificationService, null); + verify(mountPointBuilder).addService(eq(DOMSchemaService.class), any()); verify(mountPointBuilder).addService(DOMDataBroker.class, broker); 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); + public void testOnTopologyDeviceConnectedWithNetconfService() { + mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, null, netconfService, rpcService, + notificationService, null); + verify(mountPointBuilder).addService(eq(DOMSchemaService.class), any()); + verify(mountPointBuilder).addService(NetconfDataTreeService.class, netconfService); + verify(mountPointBuilder).addService(DOMRpcService.class, rpcService); + verify(mountPointBuilder).addService(DOMNotificationService.class, notificationService); + } + + @Test + public void testOnTopologyDeviceDisconnected() { + mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, null, rpcService, + notificationService, null); mountInstance.onTopologyDeviceDisconnected(); verify(registration).close(); try { - mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService); + mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, null, rpcService, + notificationService, null); } catch (final IllegalStateException e) { LOG.warn("Operation failed.", e); Assert.fail("Topology registration still present after disconnect "); @@ -99,20 +113,20 @@ public class MountInstanceTest { } @Test - public void testClose() throws Exception { - mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService); + public void testClose() { + mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, null, rpcService, + notificationService, null); mountInstance.close(); verify(registration).close(); } @Test - public void testPublishNotification() throws Exception { - mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService); - verify(mountPointBuilder).addInitialSchemaContext(SCHEMA_CONTEXT); + public void testPublishNotification() { + mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, null, rpcService, + notificationService, null); + verify(mountPointBuilder).addService(eq(DOMSchemaService.class), any()); verify(mountPointBuilder).addService(DOMNotificationService.class, notificationService); mountInstance.publish(notification); verify(notificationService).publishNotification(notification); } - - }