2 * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.sal.connect.netconf;
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.ArgumentMatchers.anyCollectionOf;
13 import static org.mockito.ArgumentMatchers.eq;
14 import static org.mockito.ArgumentMatchers.isNull;
15 import static org.mockito.Mockito.after;
16 import static org.mockito.Mockito.doAnswer;
17 import static org.mockito.Mockito.doNothing;
18 import static org.mockito.Mockito.doReturn;
19 import static org.mockito.Mockito.mock;
20 import static org.mockito.Mockito.timeout;
21 import static org.mockito.Mockito.times;
22 import static org.mockito.Mockito.verify;
24 import com.google.common.collect.HashMultimap;
25 import com.google.common.collect.Iterables;
26 import com.google.common.collect.Lists;
27 import com.google.common.collect.Sets;
28 import com.google.common.util.concurrent.Futures;
29 import com.google.common.util.concurrent.ListeningExecutorService;
30 import com.google.common.util.concurrent.MoreExecutors;
31 import com.google.common.util.concurrent.SettableFuture;
32 import java.io.IOException;
33 import java.net.InetSocketAddress;
34 import java.util.ArrayList;
35 import java.util.Collection;
36 import java.util.Collections;
37 import java.util.HashMap;
39 import java.util.concurrent.Executors;
40 import org.junit.Test;
41 import org.mockito.ArgumentCaptor;
42 import org.mockito.Mockito;
43 import org.opendaylight.mdsal.dom.api.DOMActionService;
44 import org.opendaylight.mdsal.dom.api.DOMNotification;
45 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
46 import org.opendaylight.mdsal.dom.api.DOMRpcService;
47 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
48 import org.opendaylight.netconf.api.NetconfMessage;
49 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
50 import org.opendaylight.netconf.api.xml.XmlUtil;
51 import org.opendaylight.netconf.sal.connect.api.MessageTransformer;
52 import org.opendaylight.netconf.sal.connect.api.NetconfDeviceSchemasResolver;
53 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
54 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities;
55 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator;
56 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
57 import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc;
58 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
59 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapability;
61 import org.opendaylight.yangtools.rfc8528.data.api.MountPointContext;
62 import org.opendaylight.yangtools.yang.common.QName;
63 import org.opendaylight.yangtools.yang.common.Revision;
64 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
65 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
66 import org.opendaylight.yangtools.yang.model.api.Module;
67 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
68 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
69 import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
70 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
71 import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
72 import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
73 import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
74 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
75 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
76 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
77 import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
78 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
79 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
80 import org.xml.sax.SAXException;
82 @SuppressWarnings("checkstyle:IllegalCatch")
83 public class NetconfDeviceTest extends AbstractTestModelTest {
85 private static final NetconfMessage NOTIFICATION;
87 private static final ContainerNode COMPOSITE_NODE;
91 COMPOSITE_NODE = mockClass(ContainerNode.class);
92 } catch (final Exception e) {
93 throw new RuntimeException(e);
96 NOTIFICATION = new NetconfMessage(XmlUtil
97 .readXmlToDocument(NetconfDeviceTest.class.getResourceAsStream("/notification-payload.xml")));
98 } catch (SAXException | IOException e) {
99 throw new ExceptionInInitializerError(e);
103 private static final DOMRpcResult RPC_RESULT = new DefaultDOMRpcResult(COMPOSITE_NODE);
105 public static final String TEST_NAMESPACE = "test:namespace";
106 public static final String TEST_MODULE = "test-module";
107 public static final String TEST_REVISION = "2013-07-22";
108 public static final SourceIdentifier TEST_SID =
109 RevisionSourceIdentifier.create(TEST_MODULE, Revision.of(TEST_REVISION));
110 public static final String TEST_CAPABILITY =
111 TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION;
113 public static final SourceIdentifier TEST_SID2 =
114 RevisionSourceIdentifier.create(TEST_MODULE + "2", Revision.of(TEST_REVISION));
115 public static final String TEST_CAPABILITY2 =
116 TEST_NAMESPACE + "?module=" + TEST_MODULE + "2" + "&revision=" + TEST_REVISION;
118 private static final NetconfDeviceSchemasResolver STATE_SCHEMAS_RESOLVER =
119 (deviceRpc, remoteSessionCapabilities, id, schemaContext) -> NetconfStateSchemas.EMPTY;
123 public void testNetconfDeviceFlawedModelFailedResolution() throws Exception {
124 final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
125 final NetconfDeviceCommunicator listener = getListener();
127 final SchemaContextFactory schemaFactory = getSchemaFactory();
128 final SchemaRepository schemaRepository = getSchemaRepository();
130 final SchemaResolutionException schemaResolutionException =
131 new SchemaResolutionException("fail first", TEST_SID, new Throwable("YangTools parser fail"));
132 doAnswer(invocation -> {
133 if (((Collection<?>) invocation.getArguments()[0]).size() == 2) {
134 return Futures.immediateFailedFuture(schemaResolutionException);
136 return Futures.immediateFuture(SCHEMA_CONTEXT);
138 }).when(schemaFactory).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
140 final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id,
142 final Module first = Iterables.getFirst(SCHEMA_CONTEXT.getModules(), null);
143 final QName qName = QName.create(first.getQNameModule(), first.getName());
144 final NetconfStateSchemas.RemoteYangSchema source1 = new NetconfStateSchemas.RemoteYangSchema(qName);
145 final NetconfStateSchemas.RemoteYangSchema source2 =
146 new NetconfStateSchemas.RemoteYangSchema(QName.create(first.getQNameModule(), "test-module2"));
147 return new NetconfStateSchemas(Sets.newHashSet(source1, source2));
150 final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice
151 .SchemaResourcesDTO(getSchemaRegistry(), schemaRepository, schemaFactory, stateSchemasResolver);
153 final NetconfDevice device = new NetconfDeviceBuilder()
154 .setReconnectOnSchemasChange(true)
155 .setSchemaResourcesDTO(schemaResourcesDTO)
156 .setGlobalProcessingExecutor(getExecutor())
158 .setSalFacade(facade)
160 // Monitoring supported
161 final NetconfSessionPreferences sessionCaps =
162 getSessionCaps(true, Lists.newArrayList(TEST_CAPABILITY, TEST_CAPABILITY2));
163 device.onRemoteSessionUp(sessionCaps, listener);
165 Mockito.verify(facade, Mockito.timeout(5000)).onDeviceConnected(any(MountPointContext.class),
166 any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class), isNull());
167 Mockito.verify(schemaFactory, times(2)).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
171 public void testNetconfDeviceFailFirstSchemaFailSecondEmpty() throws Exception {
172 final ArrayList<String> capList = Lists.newArrayList(TEST_CAPABILITY);
174 final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
175 final NetconfDeviceCommunicator listener = getListener();
177 final SchemaContextFactory schemaFactory = getSchemaFactory();
178 final SchemaRepository schemaRepository = getSchemaRepository();
180 // Make fallback attempt to fail due to empty resolved sources
181 final SchemaResolutionException schemaResolutionException
182 = new SchemaResolutionException("fail first",
183 Collections.emptyList(), HashMultimap.create());
184 doReturn(Futures.immediateFailedFuture(schemaResolutionException))
185 .when(schemaFactory).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
187 final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice
188 .SchemaResourcesDTO(getSchemaRegistry(), schemaRepository, schemaFactory, STATE_SCHEMAS_RESOLVER);
189 final NetconfDevice device = new NetconfDeviceBuilder()
190 .setReconnectOnSchemasChange(true)
191 .setSchemaResourcesDTO(schemaResourcesDTO)
192 .setGlobalProcessingExecutor(getExecutor())
194 .setSalFacade(facade)
197 // Monitoring not supported
198 final NetconfSessionPreferences sessionCaps = getSessionCaps(false, capList);
199 device.onRemoteSessionUp(sessionCaps, listener);
201 Mockito.verify(facade, Mockito.timeout(5000)).onDeviceDisconnected();
202 Mockito.verify(listener, Mockito.timeout(5000)).close();
203 Mockito.verify(schemaFactory, times(1)).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
207 public void testNetconfDeviceMissingSource() throws Exception {
208 final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
209 final NetconfDeviceCommunicator listener = getListener();
211 final SchemaContextFactory schemaFactory = getSchemaFactory();
212 final SchemaRepository schemaRepository = getSchemaRepository();
214 // Make fallback attempt to fail due to empty resolved sources
215 final MissingSchemaSourceException schemaResolutionException =
216 new MissingSchemaSourceException("fail first", TEST_SID);
217 doReturn(Futures.immediateFailedFuture(schemaResolutionException))
218 .when(schemaRepository).getSchemaSource(eq(TEST_SID), eq(YangTextSchemaSource.class));
219 doAnswer(invocation -> {
220 if (((Collection<?>) invocation.getArguments()[0]).size() == 2) {
221 return Futures.immediateFailedFuture(schemaResolutionException);
223 return Futures.immediateFuture(SCHEMA_CONTEXT);
225 }).when(schemaFactory).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
227 final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id,
229 final Module first = Iterables.getFirst(SCHEMA_CONTEXT.getModules(), null);
230 final QName qName = QName.create(first.getQNameModule(), first.getName());
231 final NetconfStateSchemas.RemoteYangSchema source1 = new NetconfStateSchemas.RemoteYangSchema(qName);
232 final NetconfStateSchemas.RemoteYangSchema source2 =
233 new NetconfStateSchemas.RemoteYangSchema(QName.create(first.getQNameModule(), "test-module2"));
234 return new NetconfStateSchemas(Sets.newHashSet(source1, source2));
237 final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice
238 .SchemaResourcesDTO(getSchemaRegistry(), schemaRepository, schemaFactory, stateSchemasResolver);
240 final NetconfDevice device = new NetconfDeviceBuilder()
241 .setReconnectOnSchemasChange(true)
242 .setSchemaResourcesDTO(schemaResourcesDTO)
243 .setGlobalProcessingExecutor(getExecutor())
245 .setSalFacade(facade)
247 // Monitoring supported
248 final NetconfSessionPreferences sessionCaps =
249 getSessionCaps(true, Lists.newArrayList(TEST_CAPABILITY, TEST_CAPABILITY2));
250 device.onRemoteSessionUp(sessionCaps, listener);
252 Mockito.verify(facade, Mockito.timeout(5000)).onDeviceConnected(any(MountPointContext.class),
253 any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class), isNull());
254 Mockito.verify(schemaFactory, times(1)).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
257 private static SchemaSourceRegistry getSchemaRegistry() {
258 final SchemaSourceRegistry mock = mock(SchemaSourceRegistry.class);
259 final SchemaSourceRegistration<?> mockReg = mock(SchemaSourceRegistration.class);
260 doNothing().when(mockReg).close();
261 doReturn(mockReg).when(mock).registerSchemaSource(
262 any(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider.class),
263 any(PotentialSchemaSource.class));
267 private static SchemaRepository getSchemaRepository() {
268 final SchemaRepository mock = mock(SchemaRepository.class);
269 final SchemaSourceRepresentation mockRep = mock(SchemaSourceRepresentation.class);
270 doReturn(Futures.immediateFuture(mockRep))
271 .when(mock).getSchemaSource(any(SourceIdentifier.class), eq(YangTextSchemaSource.class));
276 public void testNotificationBeforeSchema() throws Exception {
277 final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
278 final NetconfDeviceCommunicator listener = getListener();
279 final SchemaContextFactory schemaContextProviderFactory = mock(SchemaContextFactory.class);
280 final SettableFuture<SchemaContext> schemaFuture = SettableFuture.create();
281 doReturn(schemaFuture).when(schemaContextProviderFactory).createSchemaContext(any(Collection.class));
282 final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO =
283 new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), getSchemaRepository(),
284 schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
285 final NetconfDevice device = new NetconfDeviceBuilder()
286 .setReconnectOnSchemasChange(true)
287 .setSchemaResourcesDTO(schemaResourcesDTO)
288 .setGlobalProcessingExecutor(getExecutor())
290 .setSalFacade(facade)
293 final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
294 Lists.newArrayList(TEST_CAPABILITY));
295 device.onRemoteSessionUp(sessionCaps, listener);
297 device.onNotification(NOTIFICATION);
298 device.onNotification(NOTIFICATION);
299 verify(facade, times(0)).onNotification(any(DOMNotification.class));
301 verify(facade, times(0)).onNotification(any(DOMNotification.class));
302 schemaFuture.set(NetconfToNotificationTest.getNotificationSchemaContext(getClass(), false));
303 verify(facade, timeout(10000).times(2)).onNotification(any(DOMNotification.class));
305 device.onNotification(NOTIFICATION);
306 verify(facade, timeout(10000).times(3)).onNotification(any(DOMNotification.class));
310 public void testNetconfDeviceReconnect() throws Exception {
311 final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
312 final NetconfDeviceCommunicator listener = getListener();
314 final SchemaContextFactory schemaContextProviderFactory = getSchemaFactory();
316 final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(
317 getSchemaRegistry(), getSchemaRepository(), schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
318 final NetconfDevice device = new NetconfDeviceBuilder()
319 .setReconnectOnSchemasChange(true)
320 .setSchemaResourcesDTO(schemaResourcesDTO)
321 .setGlobalProcessingExecutor(getExecutor())
323 .setSalFacade(facade)
325 final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
326 Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION));
327 device.onRemoteSessionUp(sessionCaps, listener);
329 verify(schemaContextProviderFactory, timeout(5000)).createSchemaContext(any(Collection.class));
330 verify(facade, timeout(5000)).onDeviceConnected(
331 any(MountPointContext.class), any(NetconfSessionPreferences.class), any(DOMRpcService.class),
334 device.onRemoteSessionDown();
335 verify(facade, timeout(5000)).onDeviceDisconnected();
337 device.onRemoteSessionUp(sessionCaps, listener);
339 verify(schemaContextProviderFactory, timeout(5000).times(2)).createSchemaContext(any(Collection.class));
340 verify(facade, timeout(5000).times(2)).onDeviceConnected(
341 any(MountPointContext.class), any(NetconfSessionPreferences.class), any(DOMRpcService.class),
346 public void testNetconfDeviceDisconnectListenerCallCancellation() throws Exception {
347 final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
348 final NetconfDeviceCommunicator listener = getListener();
349 final SchemaContextFactory schemaContextProviderFactory = mock(SchemaContextFactory.class);
350 final SettableFuture<SchemaContext> schemaFuture = SettableFuture.create();
351 doReturn(schemaFuture).when(schemaContextProviderFactory).createSchemaContext(any(Collection.class));
352 final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO
353 = new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), getSchemaRepository(),
354 schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
355 final NetconfDevice device = new NetconfDeviceBuilder()
356 .setReconnectOnSchemasChange(true)
357 .setSchemaResourcesDTO(schemaResourcesDTO)
358 .setGlobalProcessingExecutor(getExecutor())
360 .setSalFacade(facade)
362 final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
363 Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION));
364 //session up, start schema resolution
365 device.onRemoteSessionUp(sessionCaps, listener);
367 device.onRemoteSessionDown();
368 verify(facade, timeout(5000)).onDeviceDisconnected();
369 //complete schema setup
370 schemaFuture.set(SCHEMA_CONTEXT);
371 //facade.onDeviceDisconnected() was called, so facade.onDeviceConnected() shouldn't be called anymore
372 verify(facade, after(1000).never()).onDeviceConnected(any(), any(), any(), any(DOMActionService.class));
376 public void testNetconfDeviceAvailableCapabilitiesBuilding() throws Exception {
377 final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
378 final NetconfDeviceCommunicator listener = getListener();
380 final SchemaContextFactory schemaContextProviderFactory = getSchemaFactory();
382 final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(
383 getSchemaRegistry(), getSchemaRepository(), schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
384 final NetconfDevice device = new NetconfDeviceBuilder()
385 .setReconnectOnSchemasChange(true)
386 .setSchemaResourcesDTO(schemaResourcesDTO)
387 .setGlobalProcessingExecutor(getExecutor())
389 .setSalFacade(facade)
391 final NetconfDevice netconfSpy = Mockito.spy(device);
393 final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
394 Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION));
395 final Map<QName, AvailableCapability.CapabilityOrigin> moduleBasedCaps = new HashMap<>();
396 moduleBasedCaps.putAll(sessionCaps.getModuleBasedCapsOrigin());
398 .put(QName.create("(test:qname:side:loading)test"), AvailableCapability.CapabilityOrigin.UserDefined);
400 netconfSpy.onRemoteSessionUp(sessionCaps.replaceModuleCaps(moduleBasedCaps), listener);
402 final ArgumentCaptor<NetconfSessionPreferences> argument =
403 ArgumentCaptor.forClass(NetconfSessionPreferences.class);
404 verify(facade, timeout(5000)).onDeviceConnected(any(MountPointContext.class), argument.capture(),
405 any(DOMRpcService.class), isNull());
406 final NetconfDeviceCapabilities netconfDeviceCaps = argument.getValue().getNetconfDeviceCapabilities();
408 netconfDeviceCaps.getResolvedCapabilities()
409 .forEach(entry -> assertEquals("Builded 'AvailableCapability' schemas should match input capabilities.",
411 QName.create(entry.getCapability())).getName(), entry.getCapabilityOrigin().getName()));
414 private static SchemaContextFactory getSchemaFactory() throws Exception {
415 final SchemaContextFactory schemaFactory = mockClass(SchemaContextFactory.class);
416 doReturn(Futures.immediateFuture(SCHEMA_CONTEXT))
417 .when(schemaFactory).createSchemaContext(any(Collection.class));
418 return schemaFactory;
421 private static RemoteDeviceHandler<NetconfSessionPreferences> getFacade() throws Exception {
422 final RemoteDeviceHandler<NetconfSessionPreferences> remoteDeviceHandler =
423 mockCloseableClass(RemoteDeviceHandler.class);
424 doNothing().when(remoteDeviceHandler).onDeviceConnected(
425 any(MountPointContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class),
426 any(DOMActionService.class));
427 doNothing().when(remoteDeviceHandler).onDeviceDisconnected();
428 doNothing().when(remoteDeviceHandler).onNotification(any(DOMNotification.class));
429 return remoteDeviceHandler;
432 private static <T extends AutoCloseable> T mockCloseableClass(final Class<T> remoteDeviceHandlerClass)
434 final T mock = mockClass(remoteDeviceHandlerClass);
435 doNothing().when(mock).close();
439 private static <T> T mockClass(final Class<T> remoteDeviceHandlerClass) {
440 final T mock = mock(remoteDeviceHandlerClass);
441 Mockito.doReturn(remoteDeviceHandlerClass.getSimpleName()).when(mock).toString();
445 public RemoteDeviceId getId() {
446 return new RemoteDeviceId("test-D", InetSocketAddress.createUnresolved("localhost", 22));
449 public ListeningExecutorService getExecutor() {
450 return MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
453 public MessageTransformer<NetconfMessage> getMessageTransformer() throws Exception {
454 final MessageTransformer<NetconfMessage> messageTransformer = mockClass(MessageTransformer.class);
455 doReturn(NOTIFICATION).when(messageTransformer).toRpcRequest(any(SchemaPath.class), any(NormalizedNode.class));
456 doReturn(RPC_RESULT).when(messageTransformer).toRpcResult(any(NetconfMessage.class), any(SchemaPath.class));
457 doReturn(COMPOSITE_NODE).when(messageTransformer).toNotification(any(NetconfMessage.class));
458 return messageTransformer;
461 public NetconfSessionPreferences getSessionCaps(final boolean addMonitor,
462 final Collection<String> additionalCapabilities) {
463 final ArrayList<String> capabilities = Lists.newArrayList(
464 XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_0,
465 XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_1);
468 capabilities.add(NetconfMessageTransformUtil.IETF_NETCONF_MONITORING.getNamespace().toString());
471 capabilities.addAll(additionalCapabilities);
473 return NetconfSessionPreferences.fromStrings(
477 public NetconfDeviceCommunicator getListener() throws Exception {
478 final NetconfDeviceCommunicator remoteDeviceCommunicator = mockCloseableClass(NetconfDeviceCommunicator.class);
479 // doReturn(Futures.immediateFuture(rpcResult))
480 // .when(remoteDeviceCommunicator).sendRequest(any(NetconfMessage.class), any(QName.class));
481 return remoteDeviceCommunicator;