Bug 8153: Enforce check-style rules for netconf - sal-netconf-connector
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / sal / connect / netconf / NetconfDeviceTest.java
1 /*
2  * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.netconf.sal.connect.netconf;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.Matchers.any;
13 import static org.mockito.Matchers.anyCollectionOf;
14 import static org.mockito.Matchers.eq;
15 import static org.mockito.Mockito.doAnswer;
16 import static org.mockito.Mockito.doNothing;
17 import static org.mockito.Mockito.doReturn;
18 import static org.mockito.Mockito.mock;
19 import static org.mockito.Mockito.timeout;
20 import static org.mockito.Mockito.times;
21 import static org.mockito.Mockito.verify;
22
23 import com.google.common.base.Optional;
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 java.io.IOException;
30 import java.io.InputStream;
31 import java.net.InetSocketAddress;
32 import java.util.ArrayList;
33 import java.util.Collection;
34 import java.util.Collections;
35 import java.util.HashMap;
36 import java.util.List;
37 import java.util.Map;
38 import java.util.concurrent.ExecutorService;
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.controller.config.util.xml.XmlUtil;
44 import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
45 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
46 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
47 import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
48 import org.opendaylight.netconf.api.NetconfMessage;
49 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
50 import org.opendaylight.netconf.sal.connect.api.MessageTransformer;
51 import org.opendaylight.netconf.sal.connect.api.NetconfDeviceSchemasResolver;
52 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
53 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities;
54 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator;
55 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
56 import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc;
57 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
58 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapability;
60 import org.opendaylight.yangtools.yang.common.QName;
61 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
62 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
63 import org.opendaylight.yangtools.yang.model.api.Module;
64 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
65 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
66 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
67 import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
68 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
69 import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
70 import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
71 import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
72 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
73 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
74 import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
75 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
76 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
77 import org.opendaylight.yangtools.yang.parser.util.ASTSchemaSource;
78 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
79 import org.xml.sax.SAXException;
80
81 @SuppressWarnings("checkstyle:IllegalCatch")
82 public class NetconfDeviceTest {
83
84     private static final NetconfMessage NOTIFICATION;
85
86     private static final ContainerNode COMPOSITE_NODE;
87
88     static {
89         try {
90             COMPOSITE_NODE = mockClass(ContainerNode.class);
91         } catch (final Exception e) {
92             throw new RuntimeException(e);
93         }
94         try {
95             NOTIFICATION = new NetconfMessage(XmlUtil
96                     .readXmlToDocument(NetconfDeviceTest.class.getResourceAsStream("/notification-payload.xml")));
97         } catch (SAXException | IOException e) {
98             throw new ExceptionInInitializerError(e);
99         }
100     }
101
102     private static final DOMRpcResult RPC_RESULT = new DefaultDOMRpcResult(COMPOSITE_NODE);
103
104     public static final String TEST_NAMESPACE = "test:namespace";
105     public static final String TEST_MODULE = "test-module";
106     public static final String TEST_REVISION = "2013-07-22";
107     public static final SourceIdentifier TEST_SID =
108             RevisionSourceIdentifier.create(TEST_MODULE, Optional.of(TEST_REVISION));
109     public static final String TEST_CAPABILITY =
110             TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION;
111
112     public static final SourceIdentifier TEST_SID2 =
113             RevisionSourceIdentifier.create(TEST_MODULE + "2", Optional.of(TEST_REVISION));
114     public static final String TEST_CAPABILITY2 =
115             TEST_NAMESPACE + "?module=" + TEST_MODULE + "2" + "&revision=" + TEST_REVISION;
116
117     private static final NetconfDeviceSchemasResolver STATE_SCHEMAS_RESOLVER =
118         (deviceRpc, remoteSessionCapabilities, id) -> NetconfStateSchemas.EMPTY;
119
120     @Test
121     public void testNetconfDeviceFlawedModelFailedResolution() throws Exception {
122         final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
123         final NetconfDeviceCommunicator listener = getListener();
124
125         final SchemaContextFactory schemaFactory = getSchemaFactory();
126         final SchemaContext schema = getSchema();
127         final SchemaRepository schemaRepository = getSchemaRepository();
128
129         final SchemaResolutionException schemaResolutionException =
130                 new SchemaResolutionException("fail first", TEST_SID, new Throwable("YangTools parser fail"));
131         doAnswer(invocation -> {
132             if (((Collection<?>) invocation.getArguments()[0]).size() == 2) {
133                 return Futures.immediateFailedCheckedFuture(schemaResolutionException);
134             } else {
135                 return Futures.immediateCheckedFuture(schema);
136             }
137         }).when(schemaFactory).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
138
139         final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id) -> {
140             final Module first = Iterables.getFirst(schema.getModules(), null);
141             final QName qName = QName.create(first.getQNameModule(), first.getName());
142             final NetconfStateSchemas.RemoteYangSchema source1 = new NetconfStateSchemas.RemoteYangSchema(qName);
143             final NetconfStateSchemas.RemoteYangSchema source2 =
144                     new NetconfStateSchemas.RemoteYangSchema(QName.create(first.getQNameModule(), "test-module2"));
145             return new NetconfStateSchemas(Sets.newHashSet(source1, source2));
146         };
147
148         final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice
149                 .SchemaResourcesDTO(getSchemaRegistry(), schemaRepository, schemaFactory, stateSchemasResolver);
150
151         final NetconfDevice device = new NetconfDeviceBuilder()
152                 .setReconnectOnSchemasChange(true)
153                 .setSchemaResourcesDTO(schemaResourcesDTO)
154                 .setGlobalProcessingExecutor(getExecutor())
155                 .setId(getId())
156                 .setSalFacade(facade)
157                 .build();
158         // Monitoring supported
159         final NetconfSessionPreferences sessionCaps =
160                 getSessionCaps(true, Lists.newArrayList(TEST_CAPABILITY, TEST_CAPABILITY2));
161         device.onRemoteSessionUp(sessionCaps, listener);
162
163         Mockito.verify(facade, Mockito.timeout(5000)).onDeviceConnected(
164                 any(SchemaContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class));
165         Mockito.verify(schemaFactory, times(2)).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
166     }
167
168     @Test
169     public void testNetconfDeviceFailFirstSchemaFailSecondEmpty() throws Exception {
170         final ArrayList<String> capList = Lists.newArrayList(TEST_CAPABILITY);
171
172         final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
173         final NetconfDeviceCommunicator listener = getListener();
174
175         final SchemaContextFactory schemaFactory = getSchemaFactory();
176         final SchemaRepository schemaRepository = getSchemaRepository();
177
178         // Make fallback attempt to fail due to empty resolved sources
179         final SchemaResolutionException schemaResolutionException
180                 = new SchemaResolutionException("fail first",
181                 Collections.<SourceIdentifier>emptyList(), HashMultimap.<SourceIdentifier, ModuleImport>create());
182         doReturn(Futures.immediateFailedCheckedFuture(
183                 schemaResolutionException))
184                 .when(schemaFactory).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
185
186         final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice
187                 .SchemaResourcesDTO(getSchemaRegistry(), schemaRepository, schemaFactory, STATE_SCHEMAS_RESOLVER);
188         final NetconfDevice device = new NetconfDeviceBuilder()
189                 .setReconnectOnSchemasChange(true)
190                 .setSchemaResourcesDTO(schemaResourcesDTO)
191                 .setGlobalProcessingExecutor(getExecutor())
192                 .setId(getId())
193                 .setSalFacade(facade)
194                 .build();
195
196         // Monitoring not supported
197         final NetconfSessionPreferences sessionCaps = getSessionCaps(false, capList);
198         device.onRemoteSessionUp(sessionCaps, listener);
199
200         Mockito.verify(facade, Mockito.timeout(5000)).onDeviceDisconnected();
201         Mockito.verify(listener, Mockito.timeout(5000)).close();
202         Mockito.verify(schemaFactory, times(1)).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
203     }
204
205     @Test
206     public void testNetconfDeviceMissingSource() throws Exception {
207         final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
208         final NetconfDeviceCommunicator listener = getListener();
209         final SchemaContext schema = getSchema();
210
211         final SchemaContextFactory schemaFactory = getSchemaFactory();
212         final SchemaRepository schemaRepository = getSchemaRepository();
213
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.immediateFailedCheckedFuture(schemaResolutionException))
218                 .when(schemaRepository).getSchemaSource(eq(TEST_SID), eq(ASTSchemaSource.class));
219         doAnswer(invocation -> {
220             if (((Collection<?>) invocation.getArguments()[0]).size() == 2) {
221                 return Futures.immediateFailedCheckedFuture(schemaResolutionException);
222             } else {
223                 return Futures.immediateCheckedFuture(schema);
224             }
225         }).when(schemaFactory).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
226
227         final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id) -> {
228             final Module first = Iterables.getFirst(schema.getModules(), null);
229             final QName qName = QName.create(first.getQNameModule(), first.getName());
230             final NetconfStateSchemas.RemoteYangSchema source1 = new NetconfStateSchemas.RemoteYangSchema(qName);
231             final NetconfStateSchemas.RemoteYangSchema source2 =
232                     new NetconfStateSchemas.RemoteYangSchema(QName.create(first.getQNameModule(), "test-module2"));
233             return new NetconfStateSchemas(Sets.newHashSet(source1, source2));
234         };
235
236         final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice
237                 .SchemaResourcesDTO(getSchemaRegistry(), schemaRepository, schemaFactory, stateSchemasResolver);
238
239         final NetconfDevice device = new NetconfDeviceBuilder()
240                 .setReconnectOnSchemasChange(true)
241                 .setSchemaResourcesDTO(schemaResourcesDTO)
242                 .setGlobalProcessingExecutor(getExecutor())
243                 .setId(getId())
244                 .setSalFacade(facade)
245                 .build();
246         // Monitoring supported
247         final NetconfSessionPreferences sessionCaps =
248                 getSessionCaps(true, Lists.newArrayList(TEST_CAPABILITY, TEST_CAPABILITY2));
249         device.onRemoteSessionUp(sessionCaps, listener);
250
251         Mockito.verify(facade, Mockito.timeout(5000)).onDeviceConnected(
252                 any(SchemaContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class));
253         Mockito.verify(schemaFactory, times(1)).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
254     }
255
256     private static SchemaSourceRegistry getSchemaRegistry() {
257         final SchemaSourceRegistry mock = mock(SchemaSourceRegistry.class);
258         final SchemaSourceRegistration<?> mockReg = mock(SchemaSourceRegistration.class);
259         doNothing().when(mockReg).close();
260         doReturn(mockReg).when(mock).registerSchemaSource(
261                 any(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider.class),
262                 any(PotentialSchemaSource.class));
263         return mock;
264     }
265
266     private static SchemaRepository getSchemaRepository() {
267         final SchemaRepository mock = mock(SchemaRepository.class);
268         final SchemaSourceRepresentation mockRep = mock(SchemaSourceRepresentation.class);
269         doReturn(Futures.immediateCheckedFuture(mockRep))
270                 .when(mock).getSchemaSource(any(SourceIdentifier.class), eq(ASTSchemaSource.class));
271         return mock;
272     }
273
274     @Test
275     public void testNotificationBeforeSchema() throws Exception {
276         final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
277         final NetconfDeviceCommunicator listener = getListener();
278
279         final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(
280                 getSchemaRegistry(), getSchemaRepository(), getSchemaFactory(), STATE_SCHEMAS_RESOLVER);
281         final NetconfDevice device = new NetconfDeviceBuilder()
282                 .setReconnectOnSchemasChange(true)
283                 .setSchemaResourcesDTO(schemaResourcesDTO)
284                 .setGlobalProcessingExecutor(getExecutor())
285                 .setId(getId())
286                 .setSalFacade(facade)
287                 .build();
288
289         device.onNotification(NOTIFICATION);
290         device.onNotification(NOTIFICATION);
291
292         verify(facade, times(0)).onNotification(any(DOMNotification.class));
293
294         final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
295                 Lists.newArrayList(TEST_CAPABILITY));
296
297         final DOMRpcService deviceRpc = mock(DOMRpcService.class);
298
299         device.handleSalInitializationSuccess(
300                 NetconfToNotificationTest.getNotificationSchemaContext(getClass(), false), sessionCaps, deviceRpc);
301
302         verify(facade, timeout(10000).times(2)).onNotification(any(DOMNotification.class));
303
304         device.onNotification(NOTIFICATION);
305         verify(facade, timeout(10000).times(3)).onNotification(any(DOMNotification.class));
306     }
307
308     @Test
309     public void testNetconfDeviceReconnect() throws Exception {
310         final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
311         final NetconfDeviceCommunicator listener = getListener();
312
313         final SchemaContextFactory schemaContextProviderFactory = getSchemaFactory();
314
315         final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(
316                 getSchemaRegistry(), getSchemaRepository(), schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
317         final NetconfDevice device = new NetconfDeviceBuilder()
318                 .setReconnectOnSchemasChange(true)
319                 .setSchemaResourcesDTO(schemaResourcesDTO)
320                 .setGlobalProcessingExecutor(getExecutor())
321                 .setId(getId())
322                 .setSalFacade(facade)
323                 .build();
324         final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
325                 Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&amp;revision=" + TEST_REVISION));
326         device.onRemoteSessionUp(sessionCaps, listener);
327
328         verify(schemaContextProviderFactory, timeout(5000)).createSchemaContext(any(Collection.class));
329         verify(facade, timeout(5000)).onDeviceConnected(
330                 any(SchemaContext.class), any(NetconfSessionPreferences.class), any(DOMRpcService.class));
331
332         device.onRemoteSessionDown();
333         verify(facade, timeout(5000)).onDeviceDisconnected();
334
335         device.onRemoteSessionUp(sessionCaps, listener);
336
337         verify(schemaContextProviderFactory, timeout(5000).times(2)).createSchemaContext(any(Collection.class));
338         verify(facade, timeout(5000).times(2)).onDeviceConnected(
339                 any(SchemaContext.class), any(NetconfSessionPreferences.class), any(DOMRpcService.class));
340     }
341
342     @Test
343     public void testNetconfDeviceAvailableCapabilitiesBuilding() throws Exception {
344         final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
345         final NetconfDeviceCommunicator listener = getListener();
346
347         final SchemaContextFactory schemaContextProviderFactory = getSchemaFactory();
348
349         final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(
350                 getSchemaRegistry(), getSchemaRepository(), schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
351         final NetconfDevice device = new NetconfDeviceBuilder()
352                 .setReconnectOnSchemasChange(true)
353                 .setSchemaResourcesDTO(schemaResourcesDTO)
354                 .setGlobalProcessingExecutor(getExecutor())
355                 .setId(getId())
356                 .setSalFacade(facade)
357                 .build();
358         NetconfDevice netconfSpy = Mockito.spy(device);
359
360         final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
361                 Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&amp;revision=" + TEST_REVISION));
362         Map<QName, AvailableCapability.CapabilityOrigin> moduleBasedCaps = new HashMap<>();
363         moduleBasedCaps.putAll(sessionCaps.getModuleBasedCapsOrigin());
364         moduleBasedCaps
365                 .put(QName.create("(test:qname:side:loading)test"), AvailableCapability.CapabilityOrigin.UserDefined);
366
367         netconfSpy.onRemoteSessionUp(sessionCaps.replaceModuleCaps(moduleBasedCaps), listener);
368
369         ArgumentCaptor argument = ArgumentCaptor.forClass(NetconfSessionPreferences.class);
370         verify(netconfSpy, timeout(5000)).handleSalInitializationSuccess(
371                 any(SchemaContext.class), (NetconfSessionPreferences) argument.capture(), any(DOMRpcService.class));
372         NetconfDeviceCapabilities netconfDeviceCaps =
373                 ((NetconfSessionPreferences) argument.getValue()).getNetconfDeviceCapabilities();
374
375         netconfDeviceCaps.getResolvedCapabilities()
376                 .forEach(entry -> assertEquals("Builded 'AvailableCapability' schemas should match input capabilities.",
377                         moduleBasedCaps.get(
378                                 QName.create(entry.getCapability())).getName(), entry.getCapabilityOrigin().getName()));
379     }
380
381     private static SchemaContextFactory getSchemaFactory() throws Exception {
382         final SchemaContextFactory schemaFactory = mockClass(SchemaContextFactory.class);
383         doReturn(Futures.immediateCheckedFuture(getSchema()))
384                 .when(schemaFactory).createSchemaContext(any(Collection.class));
385         return schemaFactory;
386     }
387
388     public static SchemaContext getSchema() throws Exception {
389         final List<InputStream> modelsToParse = Lists.newArrayList(
390                 NetconfDeviceTest.class.getResourceAsStream("/schemas/test-module.yang")
391         );
392         return YangParserTestUtils.parseYangStreams(modelsToParse);
393     }
394
395     private static RemoteDeviceHandler<NetconfSessionPreferences> getFacade() throws Exception {
396         final RemoteDeviceHandler<NetconfSessionPreferences> remoteDeviceHandler =
397                 mockCloseableClass(RemoteDeviceHandler.class);
398         doNothing().when(remoteDeviceHandler).onDeviceConnected(
399                 any(SchemaContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class));
400         doNothing().when(remoteDeviceHandler).onDeviceDisconnected();
401         doNothing().when(remoteDeviceHandler).onNotification(any(DOMNotification.class));
402         return remoteDeviceHandler;
403     }
404
405     private static <T extends AutoCloseable> T mockCloseableClass(final Class<T> remoteDeviceHandlerClass)
406             throws Exception {
407         final T mock = mockClass(remoteDeviceHandlerClass);
408         doNothing().when(mock).close();
409         return mock;
410     }
411
412     private static <T> T mockClass(final Class<T> remoteDeviceHandlerClass) {
413         final T mock = mock(remoteDeviceHandlerClass);
414         Mockito.doReturn(remoteDeviceHandlerClass.getSimpleName()).when(mock).toString();
415         return mock;
416     }
417
418     public RemoteDeviceId getId() {
419         return new RemoteDeviceId("test-D", InetSocketAddress.createUnresolved("localhost", 22));
420     }
421
422     public ExecutorService getExecutor() {
423         return Executors.newSingleThreadExecutor();
424     }
425
426     public MessageTransformer<NetconfMessage> getMessageTransformer() throws Exception {
427         final MessageTransformer<NetconfMessage> messageTransformer = mockClass(MessageTransformer.class);
428         doReturn(NOTIFICATION).when(messageTransformer).toRpcRequest(any(SchemaPath.class), any(NormalizedNode.class));
429         doReturn(RPC_RESULT).when(messageTransformer).toRpcResult(any(NetconfMessage.class), any(SchemaPath.class));
430         doReturn(COMPOSITE_NODE).when(messageTransformer).toNotification(any(NetconfMessage.class));
431         return messageTransformer;
432     }
433
434     public NetconfSessionPreferences getSessionCaps(final boolean addMonitor,
435                                                     final Collection<String> additionalCapabilities) {
436         final ArrayList<String> capabilities = Lists.newArrayList(
437                 XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_0,
438                 XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_1);
439
440         if (addMonitor) {
441             capabilities.add(NetconfMessageTransformUtil.IETF_NETCONF_MONITORING.getNamespace().toString());
442         }
443
444         capabilities.addAll(additionalCapabilities);
445
446         return NetconfSessionPreferences.fromStrings(
447                 capabilities);
448     }
449
450     public NetconfDeviceCommunicator getListener() throws Exception {
451         final NetconfDeviceCommunicator remoteDeviceCommunicator = mockCloseableClass(NetconfDeviceCommunicator.class);
452 //        doReturn(Futures.immediateFuture(rpcResult))
453 //                .when(remoteDeviceCommunicator).sendRequest(any(NetconfMessage.class), any(QName.class));
454         return remoteDeviceCommunicator;
455     }
456 }