+ Mockito.verify(listener, Mockito.timeout(5000)).close();
+ Mockito.verify(schemaFactory, times(1)).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
+ }
+
+ @Test
+ public void testNetconfDeviceMissingSource() throws Exception {
+ final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
+ final NetconfDeviceCommunicator listener = getListener();
+
+ final SchemaContextFactory schemaFactory = getSchemaFactory();
+
+ // Make fallback attempt to fail due to empty resolved sources
+ final MissingSchemaSourceException schemaResolutionException = new MissingSchemaSourceException("fail first", TEST_SID);
+ doAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(final InvocationOnMock invocation) throws Throwable {
+ if(((Collection<?>) invocation.getArguments()[0]).size() == 2) {
+ return Futures.immediateFailedCheckedFuture(schemaResolutionException);
+ } else {
+ return Futures.immediateCheckedFuture(getSchema());
+ }
+ }
+ }).when(schemaFactory).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
+
+ final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO
+ = new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), schemaFactory, stateSchemasResolver);
+ final NetconfDevice device = new NetconfDevice(schemaResourcesDTO, getId(), facade, getExecutor(), true);
+ // 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));
+ Mockito.verify(schemaFactory, times(2)).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
+ }
+
+ private SchemaSourceRegistry getSchemaRegistry() {
+ final SchemaSourceRegistry mock = mock(SchemaSourceRegistry.class);
+ final SchemaSourceRegistration<?> mockReg = mock(SchemaSourceRegistration.class);
+ doNothing().when(mockReg).close();
+ doReturn(mockReg).when(mock).registerSchemaSource(any(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider.class), any(PotentialSchemaSource.class));
+ return mock;
+ }
+
+ @Test
+ public void testNotificationBeforeSchema() throws Exception {
+ final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
+ final NetconfDeviceCommunicator listener = getListener();
+
+ final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO
+ = new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), getSchemaFactory(), stateSchemasResolver);
+ final NetconfDevice device = new NetconfDevice(schemaResourcesDTO, getId(), facade, getExecutor(), true);
+
+ device.onNotification(notification);
+ device.onNotification(notification);
+
+ verify(facade, times(0)).onNotification(any(ContainerNode.class));
+
+ final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
+ Lists.newArrayList(TEST_CAPABILITY));
+
+ final DOMRpcService deviceRpc = mock(DOMRpcService.class);
+
+ device.handleSalInitializationSuccess(NetconfToNotificationTest.getNotificationSchemaContext(getClass()), sessionCaps, deviceRpc);
+
+ verify(facade, timeout(10000).times(2)).onNotification(any(ContainerNode.class));
+
+ device.onNotification(notification);
+ verify(facade, timeout(10000).times(3)).onNotification(any(ContainerNode.class));