Bump upstreams for Silicon
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / sal / connect / netconf / NetconfDeviceTest.java
index 59f3ec6023f331577861c1ff65832e1e4508bd85..fca46b3943e328fb91f9d5269d749da4c532b478 100644 (file)
@@ -8,8 +8,10 @@
 package org.opendaylight.netconf.sal.connect.netconf;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyCollectionOf;
+import static org.mockito.ArgumentMatchers.anyCollection;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.ArgumentMatchers.isNull;
 import static org.mockito.Mockito.after;
@@ -17,6 +19,7 @@ import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
@@ -32,14 +35,16 @@ import com.google.common.util.concurrent.SettableFuture;
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.Executors;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
-import org.mockito.Mockito;
 import org.opendaylight.mdsal.dom.api.DOMActionService;
 import org.opendaylight.mdsal.dom.api.DOMNotification;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
@@ -58,16 +63,16 @@ import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc;
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapability;
+import org.opendaylight.yangtools.rfc8528.data.api.MountPointContext;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory;
 import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
@@ -78,19 +83,13 @@ import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
 import org.xml.sax.SAXException;
 
-@SuppressWarnings("checkstyle:IllegalCatch")
 public class NetconfDeviceTest extends AbstractTestModelTest {
 
     private static final NetconfMessage NOTIFICATION;
 
-    private static final ContainerNode COMPOSITE_NODE;
+    private static final ContainerNode COMPOSITE_NODE = mockClass(ContainerNode.class);
 
     static {
-        try {
-            COMPOSITE_NODE = mockClass(ContainerNode.class);
-        } catch (final Exception e) {
-            throw new RuntimeException(e);
-        }
         try {
             NOTIFICATION = new NetconfMessage(XmlUtil
                     .readXmlToDocument(NetconfDeviceTest.class.getResourceAsStream("/notification-payload.xml")));
@@ -123,7 +122,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
         final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
         final NetconfDeviceCommunicator listener = getListener();
 
-        final SchemaContextFactory schemaFactory = getSchemaFactory();
+        final EffectiveModelContextFactory schemaFactory = getSchemaFactory();
         final SchemaRepository schemaRepository = getSchemaRepository();
 
         final SchemaResolutionException schemaResolutionException =
@@ -134,7 +133,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
             } else {
                 return Futures.immediateFuture(SCHEMA_CONTEXT);
             }
-        }).when(schemaFactory).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
+        }).when(schemaFactory).createEffectiveModelContext(anyCollection());
 
         final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id,
                 schemaContext) -> {
@@ -155,15 +154,16 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 .setGlobalProcessingExecutor(getExecutor())
                 .setId(getId())
                 .setSalFacade(facade)
+                .setBaseSchemas(BASE_SCHEMAS)
                 .build();
         // Monitoring supported
         final NetconfSessionPreferences sessionCaps =
                 getSessionCaps(true, Lists.newArrayList(TEST_CAPABILITY, TEST_CAPABILITY2));
         device.onRemoteSessionUp(sessionCaps, listener);
 
-        Mockito.verify(facade, Mockito.timeout(5000)).onDeviceConnected(
-                any(SchemaContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class), isNull());
-        Mockito.verify(schemaFactory, times(2)).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
+        verify(facade, timeout(5000)).onDeviceConnected(any(MountPointContext.class),
+            any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class), isNull());
+        verify(schemaFactory, times(2)).createEffectiveModelContext(anyCollection());
     }
 
     @Test
@@ -173,7 +173,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
         final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
         final NetconfDeviceCommunicator listener = getListener();
 
-        final SchemaContextFactory schemaFactory = getSchemaFactory();
+        final EffectiveModelContextFactory schemaFactory = getSchemaFactory();
         final SchemaRepository schemaRepository = getSchemaRepository();
 
         // Make fallback attempt to fail due to empty resolved sources
@@ -181,7 +181,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 = new SchemaResolutionException("fail first",
                 Collections.emptyList(), HashMultimap.create());
         doReturn(Futures.immediateFailedFuture(schemaResolutionException))
-                .when(schemaFactory).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
+                .when(schemaFactory).createEffectiveModelContext(anyCollection());
 
         final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice
                 .SchemaResourcesDTO(getSchemaRegistry(), schemaRepository, schemaFactory, STATE_SCHEMAS_RESOLVER);
@@ -191,15 +191,16 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 .setGlobalProcessingExecutor(getExecutor())
                 .setId(getId())
                 .setSalFacade(facade)
+                .setBaseSchemas(BASE_SCHEMAS)
                 .build();
 
         // Monitoring not supported
         final NetconfSessionPreferences sessionCaps = getSessionCaps(false, capList);
         device.onRemoteSessionUp(sessionCaps, listener);
 
-        Mockito.verify(facade, Mockito.timeout(5000)).onDeviceDisconnected();
-        Mockito.verify(listener, Mockito.timeout(5000)).close();
-        Mockito.verify(schemaFactory, times(1)).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
+        verify(facade, timeout(5000)).onDeviceDisconnected();
+        verify(listener, timeout(5000)).close();
+        verify(schemaFactory, times(1)).createEffectiveModelContext(anyCollection());
     }
 
     @Test
@@ -207,7 +208,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
         final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
         final NetconfDeviceCommunicator listener = getListener();
 
-        final SchemaContextFactory schemaFactory = getSchemaFactory();
+        final EffectiveModelContextFactory schemaFactory = getSchemaFactory();
         final SchemaRepository schemaRepository = getSchemaRepository();
 
         // Make fallback attempt to fail due to empty resolved sources
@@ -221,7 +222,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
             } else {
                 return Futures.immediateFuture(SCHEMA_CONTEXT);
             }
-        }).when(schemaFactory).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
+        }).when(schemaFactory).createEffectiveModelContext(anyCollection());
 
         final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id,
             schemaContext) -> {
@@ -240,6 +241,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 .setReconnectOnSchemasChange(true)
                 .setSchemaResourcesDTO(schemaResourcesDTO)
                 .setGlobalProcessingExecutor(getExecutor())
+                .setBaseSchemas(BASE_SCHEMAS)
                 .setId(getId())
                 .setSalFacade(facade)
                 .build();
@@ -248,9 +250,9 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 getSessionCaps(true, Lists.newArrayList(TEST_CAPABILITY, TEST_CAPABILITY2));
         device.onRemoteSessionUp(sessionCaps, listener);
 
-        Mockito.verify(facade, Mockito.timeout(5000)).onDeviceConnected(
-                any(SchemaContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class), isNull());
-        Mockito.verify(schemaFactory, times(1)).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
+        verify(facade, timeout(5000)).onDeviceConnected(any(MountPointContext.class),
+            any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class), isNull());
+        verify(schemaFactory, times(1)).createEffectiveModelContext(anyCollection());
     }
 
     private static SchemaSourceRegistry getSchemaRegistry() {
@@ -275,9 +277,9 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
     public void testNotificationBeforeSchema() throws Exception {
         final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
         final NetconfDeviceCommunicator listener = getListener();
-        final SchemaContextFactory schemaContextProviderFactory = mock(SchemaContextFactory.class);
+        final EffectiveModelContextFactory schemaContextProviderFactory = mock(EffectiveModelContextFactory.class);
         final SettableFuture<SchemaContext> schemaFuture = SettableFuture.create();
-        doReturn(schemaFuture).when(schemaContextProviderFactory).createSchemaContext(any(Collection.class));
+        doReturn(schemaFuture).when(schemaContextProviderFactory).createEffectiveModelContext(any(Collection.class));
         final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO =
                 new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), getSchemaRepository(),
                         schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
@@ -287,6 +289,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 .setGlobalProcessingExecutor(getExecutor())
                 .setId(getId())
                 .setSalFacade(facade)
+                .setBaseSchemas(BASE_SCHEMAS)
                 .build();
 
         final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
@@ -310,7 +313,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
         final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
         final NetconfDeviceCommunicator listener = getListener();
 
-        final SchemaContextFactory schemaContextProviderFactory = getSchemaFactory();
+        final EffectiveModelContextFactory schemaContextProviderFactory = getSchemaFactory();
 
         final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(
                 getSchemaRegistry(), getSchemaRepository(), schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
@@ -320,14 +323,15 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 .setGlobalProcessingExecutor(getExecutor())
                 .setId(getId())
                 .setSalFacade(facade)
+                .setBaseSchemas(BASE_SCHEMAS)
                 .build();
         final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
                 Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&amp;revision=" + TEST_REVISION));
         device.onRemoteSessionUp(sessionCaps, listener);
 
-        verify(schemaContextProviderFactory, timeout(5000)).createSchemaContext(any(Collection.class));
+        verify(schemaContextProviderFactory, timeout(5000)).createEffectiveModelContext(any(Collection.class));
         verify(facade, timeout(5000)).onDeviceConnected(
-                any(SchemaContext.class), any(NetconfSessionPreferences.class), any(DOMRpcService.class),
+                any(MountPointContext.class), any(NetconfSessionPreferences.class), any(DOMRpcService.class),
                 isNull());
 
         device.onRemoteSessionDown();
@@ -335,9 +339,9 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
 
         device.onRemoteSessionUp(sessionCaps, listener);
 
-        verify(schemaContextProviderFactory, timeout(5000).times(2)).createSchemaContext(any(Collection.class));
+        verify(schemaContextProviderFactory, timeout(5000).times(2)).createEffectiveModelContext(any(Collection.class));
         verify(facade, timeout(5000).times(2)).onDeviceConnected(
-                any(SchemaContext.class), any(NetconfSessionPreferences.class), any(DOMRpcService.class),
+                any(MountPointContext.class), any(NetconfSessionPreferences.class), any(DOMRpcService.class),
                 isNull());
     }
 
@@ -345,9 +349,9 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
     public void testNetconfDeviceDisconnectListenerCallCancellation() throws Exception {
         final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
         final NetconfDeviceCommunicator listener = getListener();
-        final SchemaContextFactory schemaContextProviderFactory = mock(SchemaContextFactory.class);
+        final EffectiveModelContextFactory schemaContextProviderFactory = mock(EffectiveModelContextFactory.class);
         final SettableFuture<SchemaContext> schemaFuture = SettableFuture.create();
-        doReturn(schemaFuture).when(schemaContextProviderFactory).createSchemaContext(any(Collection.class));
+        doReturn(schemaFuture).when(schemaContextProviderFactory).createEffectiveModelContext(any(Collection.class));
         final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO
                 = new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), getSchemaRepository(),
                 schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
@@ -357,6 +361,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 .setGlobalProcessingExecutor(getExecutor())
                 .setId(getId())
                 .setSalFacade(facade)
+                .setBaseSchemas(BASE_SCHEMAS)
                 .build();
         final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
                 Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&amp;revision=" + TEST_REVISION));
@@ -376,7 +381,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
         final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
         final NetconfDeviceCommunicator listener = getListener();
 
-        final SchemaContextFactory schemaContextProviderFactory = getSchemaFactory();
+        final EffectiveModelContextFactory schemaContextProviderFactory = getSchemaFactory();
 
         final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(
                 getSchemaRegistry(), getSchemaRepository(), schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
@@ -386,8 +391,9 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 .setGlobalProcessingExecutor(getExecutor())
                 .setId(getId())
                 .setSalFacade(facade)
+                .setBaseSchemas(BASE_SCHEMAS)
                 .build();
-        final NetconfDevice netconfSpy = Mockito.spy(device);
+        final NetconfDevice netconfSpy = spy(device);
 
         final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
                 Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&amp;revision=" + TEST_REVISION));
@@ -400,8 +406,8 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
 
         final ArgumentCaptor<NetconfSessionPreferences> argument =
                 ArgumentCaptor.forClass(NetconfSessionPreferences.class);
-        verify(facade, timeout(5000))
-                .onDeviceConnected(any(SchemaContext.class), argument.capture(), any(DOMRpcService.class), isNull());
+        verify(facade, timeout(5000)).onDeviceConnected(any(MountPointContext.class), argument.capture(),
+            any(DOMRpcService.class), isNull());
         final NetconfDeviceCapabilities netconfDeviceCaps = argument.getValue().getNetconfDeviceCapabilities();
 
         netconfDeviceCaps.getResolvedCapabilities()
@@ -410,10 +416,137 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                                 QName.create(entry.getCapability())).getName(), entry.getCapabilityOrigin().getName()));
     }
 
-    private static SchemaContextFactory getSchemaFactory() throws Exception {
-        final SchemaContextFactory schemaFactory = mockClass(SchemaContextFactory.class);
+    @Test
+    public void testNetconfDeviceNotificationsModelNotPresentWithCapability() throws Exception {
+        final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
+        final NetconfDeviceCommunicator listener = getListener();
+        final EffectiveModelContextFactory schemaContextProviderFactory = getSchemaFactory();
+
+        final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(
+                getSchemaRegistry(), getSchemaRepository(), schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
+        final NetconfDevice device = new NetconfDeviceBuilder()
+                .setSchemaResourcesDTO(schemaResourcesDTO)
+                .setGlobalProcessingExecutor(getExecutor())
+                .setId(getId())
+                .setSalFacade(facade)
+                .setBaseSchemas(BASE_SCHEMAS)
+                .build();
+        final NetconfDevice netconfSpy = spy(device);
+
+        final NetconfSessionPreferences sessionCaps = getSessionCaps(false,
+                Lists.newArrayList(XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_CAPABILITY_NOTIFICATION_1_0));
+
+        netconfSpy.onRemoteSessionUp(sessionCaps, listener);
+
+        final ArgumentCaptor<NetconfSessionPreferences> argument =
+                ArgumentCaptor.forClass(NetconfSessionPreferences.class);
+        verify(facade, timeout(5000)).onDeviceConnected(any(MountPointContext.class), argument.capture(),
+                any(DOMRpcService.class), isNull());
+
+        List<String> notificationModulesName = Arrays.asList(
+                org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714
+                        .$YangModuleInfoImpl.getInstance().getName().toString(),
+                org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715
+                        .$YangModuleInfoImpl.getInstance().getName().toString());
+
+        final Set<AvailableCapability> resolvedCapabilities = argument.getValue().getNetconfDeviceCapabilities()
+                .getResolvedCapabilities();
+
+        assertEquals(2, resolvedCapabilities.size());
+        assertTrue(resolvedCapabilities.stream().anyMatch(entry -> notificationModulesName
+                .contains(entry.getCapability())));
+    }
+
+    @Test
+    public void testNetconfDeviceNotificationsCapabilityIsNotPresent() throws Exception {
+        final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
+        final NetconfDeviceCommunicator listener = getListener();
+        final EffectiveModelContextFactory schemaContextProviderFactory = getSchemaFactory();
+
+        final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(
+                getSchemaRegistry(), getSchemaRepository(), schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
+        final NetconfDevice device = new NetconfDeviceBuilder()
+                .setSchemaResourcesDTO(schemaResourcesDTO)
+                .setGlobalProcessingExecutor(getExecutor())
+                .setId(getId())
+                .setSalFacade(facade)
+                .setBaseSchemas(BASE_SCHEMAS)
+                .build();
+        final NetconfDevice netconfSpy = spy(device);
+
+        final NetconfSessionPreferences sessionCaps = getSessionCaps(false,
+                Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&amp;revision=" + TEST_REVISION));
+
+        netconfSpy.onRemoteSessionUp(sessionCaps, listener);
+
+        final ArgumentCaptor<NetconfSessionPreferences> argument =
+                ArgumentCaptor.forClass(NetconfSessionPreferences.class);
+        verify(facade, timeout(5000)).onDeviceConnected(any(MountPointContext.class), argument.capture(),
+                any(DOMRpcService.class), isNull());
+        final NetconfDeviceCapabilities netconfDeviceCaps = argument.getValue().getNetconfDeviceCapabilities();
+
+        List<String> notificationModulesName = Arrays.asList(
+                org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714
+                        .$YangModuleInfoImpl.getInstance().getName().toString(),
+                org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715
+                        .$YangModuleInfoImpl.getInstance().getName().toString());
+
+        assertFalse(netconfDeviceCaps.getResolvedCapabilities().stream().anyMatch(entry -> notificationModulesName
+                .contains(entry.getCapability())));
+    }
+
+    @Test
+    public void testNetconfDeviceNotificationsModelIsPresent() throws Exception {
+        final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
+        final NetconfDeviceCommunicator listener = getListener();
+        final EffectiveModelContextFactory schemaContextProviderFactory = getSchemaFactory();
+
+        final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(
+                getSchemaRegistry(), getSchemaRepository(), schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
+        final NetconfDevice device = new NetconfDeviceBuilder()
+                .setSchemaResourcesDTO(schemaResourcesDTO)
+                .setGlobalProcessingExecutor(getExecutor())
+                .setId(getId())
+                .setSalFacade(facade)
+                .setBaseSchemas(BASE_SCHEMAS)
+                .build();
+        final NetconfDevice netconfSpy = spy(device);
+
+        final NetconfSessionPreferences sessionCaps = getSessionCaps(false, Collections.emptyList());
+
+        final Map<QName, AvailableCapability.CapabilityOrigin> moduleBasedCaps = new HashMap<>();
+        moduleBasedCaps.put(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714
+                        .$YangModuleInfoImpl.getInstance().getName(),
+                AvailableCapability.CapabilityOrigin.DeviceAdvertised);
+        moduleBasedCaps.put(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715
+                        .$YangModuleInfoImpl.getInstance().getName(),
+                AvailableCapability.CapabilityOrigin.DeviceAdvertised);
+
+
+        netconfSpy.onRemoteSessionUp(sessionCaps.replaceModuleCaps(moduleBasedCaps), listener);
+
+        final ArgumentCaptor<NetconfSessionPreferences> argument =
+                ArgumentCaptor.forClass(NetconfSessionPreferences.class);
+        verify(facade, timeout(5000)).onDeviceConnected(any(MountPointContext.class), argument.capture(),
+                any(DOMRpcService.class), isNull());
+        final Set<AvailableCapability> resolvedCapabilities = argument.getValue().getNetconfDeviceCapabilities()
+                .getResolvedCapabilities();
+
+        List<String> notificationModulesName = Arrays.asList(
+                org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714
+                        .$YangModuleInfoImpl.getInstance().getName().toString(),
+                org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715
+                        .$YangModuleInfoImpl.getInstance().getName().toString());
+
+        assertEquals(2, resolvedCapabilities.size());
+        assertTrue(resolvedCapabilities.stream().anyMatch(entry -> notificationModulesName
+                .contains(entry.getCapability())));
+    }
+
+    private static EffectiveModelContextFactory getSchemaFactory() throws Exception {
+        final EffectiveModelContextFactory schemaFactory = mockClass(EffectiveModelContextFactory.class);
         doReturn(Futures.immediateFuture(SCHEMA_CONTEXT))
-                .when(schemaFactory).createSchemaContext(any(Collection.class));
+                .when(schemaFactory).createEffectiveModelContext(any(Collection.class));
         return schemaFactory;
     }
 
@@ -421,7 +554,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
         final RemoteDeviceHandler<NetconfSessionPreferences> remoteDeviceHandler =
                 mockCloseableClass(RemoteDeviceHandler.class);
         doNothing().when(remoteDeviceHandler).onDeviceConnected(
-                any(SchemaContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class),
+                any(MountPointContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class),
                 any(DOMActionService.class));
         doNothing().when(remoteDeviceHandler).onDeviceDisconnected();
         doNothing().when(remoteDeviceHandler).onNotification(any(DOMNotification.class));
@@ -437,7 +570,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
 
     private static <T> T mockClass(final Class<T> remoteDeviceHandlerClass) {
         final T mock = mock(remoteDeviceHandlerClass);
-        Mockito.doReturn(remoteDeviceHandlerClass.getSimpleName()).when(mock).toString();
+        doReturn(remoteDeviceHandlerClass.getSimpleName()).when(mock).toString();
         return mock;
     }
 
@@ -451,8 +584,8 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
 
     public MessageTransformer<NetconfMessage> getMessageTransformer() throws Exception {
         final MessageTransformer<NetconfMessage> messageTransformer = mockClass(MessageTransformer.class);
-        doReturn(NOTIFICATION).when(messageTransformer).toRpcRequest(any(SchemaPath.class), any(NormalizedNode.class));
-        doReturn(RPC_RESULT).when(messageTransformer).toRpcResult(any(NetconfMessage.class), any(SchemaPath.class));
+        doReturn(NOTIFICATION).when(messageTransformer).toRpcRequest(any(QName.class), any(NormalizedNode.class));
+        doReturn(RPC_RESULT).when(messageTransformer).toRpcResult(any(NetconfMessage.class), any(QName.class));
         doReturn(COMPOSITE_NODE).when(messageTransformer).toNotification(any(NetconfMessage.class));
         return messageTransformer;
     }