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
9 package org.opendaylight.netconf.sal.connect.netconf;
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.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.base.Optional;
25 import com.google.common.collect.HashMultimap;
26 import com.google.common.collect.Iterables;
27 import com.google.common.collect.Lists;
28 import com.google.common.collect.Sets;
29 import com.google.common.util.concurrent.Futures;
30 import com.google.common.util.concurrent.SettableFuture;
31 import java.io.IOException;
32 import java.io.InputStream;
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;
38 import java.util.List;
40 import java.util.concurrent.ExecutorService;
41 import java.util.concurrent.Executors;
42 import org.junit.Test;
43 import org.mockito.ArgumentCaptor;
44 import org.mockito.Mockito;
45 import org.opendaylight.controller.config.util.xml.XmlUtil;
46 import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
47 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
48 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
49 import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
50 import org.opendaylight.netconf.api.NetconfMessage;
51 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
52 import org.opendaylight.netconf.sal.connect.api.MessageTransformer;
53 import org.opendaylight.netconf.sal.connect.api.NetconfDeviceSchemasResolver;
54 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
55 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities;
56 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator;
57 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
58 import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc;
59 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
60 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapability;
62 import org.opendaylight.yangtools.yang.common.QName;
63 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
64 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
65 import org.opendaylight.yangtools.yang.model.api.Module;
66 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
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.spi.PotentialSchemaSource;
77 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
78 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
79 import org.opendaylight.yangtools.yang.parser.util.ASTSchemaSource;
80 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
81 import org.xml.sax.SAXException;
83 @SuppressWarnings("checkstyle:IllegalCatch")
84 public class NetconfDeviceTest {
86 private static final NetconfMessage NOTIFICATION;
88 private static final ContainerNode COMPOSITE_NODE;
92 COMPOSITE_NODE = mockClass(ContainerNode.class);
93 } catch (final Exception e) {
94 throw new RuntimeException(e);
97 NOTIFICATION = new NetconfMessage(XmlUtil
98 .readXmlToDocument(NetconfDeviceTest.class.getResourceAsStream("/notification-payload.xml")));
99 } catch (SAXException | IOException e) {
100 throw new ExceptionInInitializerError(e);
104 private static final DOMRpcResult RPC_RESULT = new DefaultDOMRpcResult(COMPOSITE_NODE);
106 public static final String TEST_NAMESPACE = "test:namespace";
107 public static final String TEST_MODULE = "test-module";
108 public static final String TEST_REVISION = "2013-07-22";
109 public static final SourceIdentifier TEST_SID =
110 RevisionSourceIdentifier.create(TEST_MODULE, Optional.of(TEST_REVISION));
111 public static final String TEST_CAPABILITY =
112 TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION;
114 public static final SourceIdentifier TEST_SID2 =
115 RevisionSourceIdentifier.create(TEST_MODULE + "2", Optional.of(TEST_REVISION));
116 public static final String TEST_CAPABILITY2 =
117 TEST_NAMESPACE + "?module=" + TEST_MODULE + "2" + "&revision=" + TEST_REVISION;
119 private static final NetconfDeviceSchemasResolver STATE_SCHEMAS_RESOLVER =
120 (deviceRpc, remoteSessionCapabilities, id) -> 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 SchemaContext schema = getSchema();
129 final SchemaRepository schemaRepository = getSchemaRepository();
131 final SchemaResolutionException schemaResolutionException =
132 new SchemaResolutionException("fail first", TEST_SID, new Throwable("YangTools parser fail"));
133 doAnswer(invocation -> {
134 if (((Collection<?>) invocation.getArguments()[0]).size() == 2) {
135 return Futures.immediateFailedCheckedFuture(schemaResolutionException);
137 return Futures.immediateCheckedFuture(schema);
139 }).when(schemaFactory).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
141 final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id) -> {
142 final Module first = Iterables.getFirst(schema.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(
166 any(SchemaContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class));
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.<SourceIdentifier>emptyList(), HashMultimap.<SourceIdentifier, ModuleImport>create());
184 doReturn(Futures.immediateFailedCheckedFuture(
185 schemaResolutionException))
186 .when(schemaFactory).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
188 final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice
189 .SchemaResourcesDTO(getSchemaRegistry(), schemaRepository, schemaFactory, STATE_SCHEMAS_RESOLVER);
190 final NetconfDevice device = new NetconfDeviceBuilder()
191 .setReconnectOnSchemasChange(true)
192 .setSchemaResourcesDTO(schemaResourcesDTO)
193 .setGlobalProcessingExecutor(getExecutor())
195 .setSalFacade(facade)
198 // Monitoring not supported
199 final NetconfSessionPreferences sessionCaps = getSessionCaps(false, capList);
200 device.onRemoteSessionUp(sessionCaps, listener);
202 Mockito.verify(facade, Mockito.timeout(5000)).onDeviceDisconnected();
203 Mockito.verify(listener, Mockito.timeout(5000)).close();
204 Mockito.verify(schemaFactory, times(1)).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
208 public void testNetconfDeviceMissingSource() throws Exception {
209 final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
210 final NetconfDeviceCommunicator listener = getListener();
211 final SchemaContext schema = getSchema();
213 final SchemaContextFactory schemaFactory = getSchemaFactory();
214 final SchemaRepository schemaRepository = getSchemaRepository();
216 // Make fallback attempt to fail due to empty resolved sources
217 final MissingSchemaSourceException schemaResolutionException =
218 new MissingSchemaSourceException("fail first", TEST_SID);
219 doReturn(Futures.immediateFailedCheckedFuture(schemaResolutionException))
220 .when(schemaRepository).getSchemaSource(eq(TEST_SID), eq(ASTSchemaSource.class));
221 doAnswer(invocation -> {
222 if (((Collection<?>) invocation.getArguments()[0]).size() == 2) {
223 return Futures.immediateFailedCheckedFuture(schemaResolutionException);
225 return Futures.immediateCheckedFuture(schema);
227 }).when(schemaFactory).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
229 final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id) -> {
230 final Module first = Iterables.getFirst(schema.getModules(), null);
231 final QName qName = QName.create(first.getQNameModule(), first.getName());
232 final NetconfStateSchemas.RemoteYangSchema source1 = new NetconfStateSchemas.RemoteYangSchema(qName);
233 final NetconfStateSchemas.RemoteYangSchema source2 =
234 new NetconfStateSchemas.RemoteYangSchema(QName.create(first.getQNameModule(), "test-module2"));
235 return new NetconfStateSchemas(Sets.newHashSet(source1, source2));
238 final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice
239 .SchemaResourcesDTO(getSchemaRegistry(), schemaRepository, schemaFactory, stateSchemasResolver);
241 final NetconfDevice device = new NetconfDeviceBuilder()
242 .setReconnectOnSchemasChange(true)
243 .setSchemaResourcesDTO(schemaResourcesDTO)
244 .setGlobalProcessingExecutor(getExecutor())
246 .setSalFacade(facade)
248 // Monitoring supported
249 final NetconfSessionPreferences sessionCaps =
250 getSessionCaps(true, Lists.newArrayList(TEST_CAPABILITY, TEST_CAPABILITY2));
251 device.onRemoteSessionUp(sessionCaps, listener);
253 Mockito.verify(facade, Mockito.timeout(5000)).onDeviceConnected(
254 any(SchemaContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class));
255 Mockito.verify(schemaFactory, times(1)).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
258 private static SchemaSourceRegistry getSchemaRegistry() {
259 final SchemaSourceRegistry mock = mock(SchemaSourceRegistry.class);
260 final SchemaSourceRegistration<?> mockReg = mock(SchemaSourceRegistration.class);
261 doNothing().when(mockReg).close();
262 doReturn(mockReg).when(mock).registerSchemaSource(
263 any(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider.class),
264 any(PotentialSchemaSource.class));
268 private static SchemaRepository getSchemaRepository() {
269 final SchemaRepository mock = mock(SchemaRepository.class);
270 final SchemaSourceRepresentation mockRep = mock(SchemaSourceRepresentation.class);
271 doReturn(Futures.immediateCheckedFuture(mockRep))
272 .when(mock).getSchemaSource(any(SourceIdentifier.class), eq(ASTSchemaSource.class));
277 public void testNotificationBeforeSchema() throws Exception {
278 final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
279 final NetconfDeviceCommunicator listener = getListener();
280 final SchemaContextFactory schemaContextProviderFactory = mock(SchemaContextFactory.class);
281 final SettableFuture<SchemaContext> schemaFuture = SettableFuture.create();
282 doReturn(Futures.makeChecked(schemaFuture, e -> new SchemaResolutionException("fail")))
283 .when(schemaContextProviderFactory).createSchemaContext(any(Collection.class));
284 final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO =
285 new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), getSchemaRepository(),
286 schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
287 final NetconfDevice device = new NetconfDeviceBuilder()
288 .setReconnectOnSchemasChange(true)
289 .setSchemaResourcesDTO(schemaResourcesDTO)
290 .setGlobalProcessingExecutor(getExecutor())
292 .setSalFacade(facade)
295 final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
296 Lists.newArrayList(TEST_CAPABILITY));
297 device.onRemoteSessionUp(sessionCaps, listener);
299 device.onNotification(NOTIFICATION);
300 device.onNotification(NOTIFICATION);
301 verify(facade, times(0)).onNotification(any(DOMNotification.class));
303 verify(facade, times(0)).onNotification(any(DOMNotification.class));
304 schemaFuture.set(NetconfToNotificationTest.getNotificationSchemaContext(getClass(), false));
305 verify(facade, timeout(10000).times(2)).onNotification(any(DOMNotification.class));
307 device.onNotification(NOTIFICATION);
308 verify(facade, timeout(10000).times(3)).onNotification(any(DOMNotification.class));
312 public void testNetconfDeviceReconnect() throws Exception {
313 final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
314 final NetconfDeviceCommunicator listener = getListener();
316 final SchemaContextFactory schemaContextProviderFactory = getSchemaFactory();
318 final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(
319 getSchemaRegistry(), getSchemaRepository(), schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
320 final NetconfDevice device = new NetconfDeviceBuilder()
321 .setReconnectOnSchemasChange(true)
322 .setSchemaResourcesDTO(schemaResourcesDTO)
323 .setGlobalProcessingExecutor(getExecutor())
325 .setSalFacade(facade)
327 final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
328 Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION));
329 device.onRemoteSessionUp(sessionCaps, listener);
331 verify(schemaContextProviderFactory, timeout(5000)).createSchemaContext(any(Collection.class));
332 verify(facade, timeout(5000)).onDeviceConnected(
333 any(SchemaContext.class), any(NetconfSessionPreferences.class), any(DOMRpcService.class));
335 device.onRemoteSessionDown();
336 verify(facade, timeout(5000)).onDeviceDisconnected();
338 device.onRemoteSessionUp(sessionCaps, listener);
340 verify(schemaContextProviderFactory, timeout(5000).times(2)).createSchemaContext(any(Collection.class));
341 verify(facade, timeout(5000).times(2)).onDeviceConnected(
342 any(SchemaContext.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(Futures.makeChecked(schemaFuture, e -> new SchemaResolutionException("fail")))
352 .when(schemaContextProviderFactory).createSchemaContext(any(Collection.class));
353 final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO
354 = new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), getSchemaRepository(),
355 schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
356 final NetconfDevice device = new NetconfDeviceBuilder()
357 .setReconnectOnSchemasChange(true)
358 .setSchemaResourcesDTO(schemaResourcesDTO)
359 .setGlobalProcessingExecutor(getExecutor())
361 .setSalFacade(facade)
363 final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
364 Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION));
365 //session up, start schema resolution
366 device.onRemoteSessionUp(sessionCaps, listener);
368 device.onRemoteSessionDown();
369 verify(facade, timeout(5000)).onDeviceDisconnected();
370 //complete schema setup
371 schemaFuture.set(getSchema());
372 //facade.onDeviceDisconnected() was called, so facade.onDeviceConnected() shouldn't be called anymore
373 verify(facade, after(1000).never()).onDeviceConnected(any(), any(), any());
377 public void testNetconfDeviceAvailableCapabilitiesBuilding() throws Exception {
378 final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
379 final NetconfDeviceCommunicator listener = getListener();
381 final SchemaContextFactory schemaContextProviderFactory = getSchemaFactory();
383 final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(
384 getSchemaRegistry(), getSchemaRepository(), schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
385 final NetconfDevice device = new NetconfDeviceBuilder()
386 .setReconnectOnSchemasChange(true)
387 .setSchemaResourcesDTO(schemaResourcesDTO)
388 .setGlobalProcessingExecutor(getExecutor())
390 .setSalFacade(facade)
392 final NetconfDevice netconfSpy = Mockito.spy(device);
394 final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
395 Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION));
396 final Map<QName, AvailableCapability.CapabilityOrigin> moduleBasedCaps = new HashMap<>();
397 moduleBasedCaps.putAll(sessionCaps.getModuleBasedCapsOrigin());
399 .put(QName.create("(test:qname:side:loading)test"), AvailableCapability.CapabilityOrigin.UserDefined);
401 netconfSpy.onRemoteSessionUp(sessionCaps.replaceModuleCaps(moduleBasedCaps), listener);
403 final ArgumentCaptor<NetconfSessionPreferences> argument =
404 ArgumentCaptor.forClass(NetconfSessionPreferences.class);
405 verify(facade, timeout(5000))
406 .onDeviceConnected(any(SchemaContext.class), argument.capture(), any(DOMRpcService.class));
407 final NetconfDeviceCapabilities netconfDeviceCaps = argument.getValue().getNetconfDeviceCapabilities();
409 netconfDeviceCaps.getResolvedCapabilities()
410 .forEach(entry -> assertEquals("Builded 'AvailableCapability' schemas should match input capabilities.",
412 QName.create(entry.getCapability())).getName(), entry.getCapabilityOrigin().getName()));
415 private static SchemaContextFactory getSchemaFactory() throws Exception {
416 final SchemaContextFactory schemaFactory = mockClass(SchemaContextFactory.class);
417 doReturn(Futures.immediateCheckedFuture(getSchema()))
418 .when(schemaFactory).createSchemaContext(any(Collection.class));
419 return schemaFactory;
422 public static SchemaContext getSchema() throws Exception {
423 final List<InputStream> modelsToParse = Lists.newArrayList(
424 NetconfDeviceTest.class.getResourceAsStream("/schemas/test-module.yang")
426 return YangParserTestUtils.parseYangStreams(modelsToParse);
429 private static RemoteDeviceHandler<NetconfSessionPreferences> getFacade() throws Exception {
430 final RemoteDeviceHandler<NetconfSessionPreferences> remoteDeviceHandler =
431 mockCloseableClass(RemoteDeviceHandler.class);
432 doNothing().when(remoteDeviceHandler).onDeviceConnected(
433 any(SchemaContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class));
434 doNothing().when(remoteDeviceHandler).onDeviceDisconnected();
435 doNothing().when(remoteDeviceHandler).onNotification(any(DOMNotification.class));
436 return remoteDeviceHandler;
439 private static <T extends AutoCloseable> T mockCloseableClass(final Class<T> remoteDeviceHandlerClass)
441 final T mock = mockClass(remoteDeviceHandlerClass);
442 doNothing().when(mock).close();
446 private static <T> T mockClass(final Class<T> remoteDeviceHandlerClass) {
447 final T mock = mock(remoteDeviceHandlerClass);
448 Mockito.doReturn(remoteDeviceHandlerClass.getSimpleName()).when(mock).toString();
452 public RemoteDeviceId getId() {
453 return new RemoteDeviceId("test-D", InetSocketAddress.createUnresolved("localhost", 22));
456 public ExecutorService getExecutor() {
457 return Executors.newSingleThreadExecutor();
460 public MessageTransformer<NetconfMessage> getMessageTransformer() throws Exception {
461 final MessageTransformer<NetconfMessage> messageTransformer = mockClass(MessageTransformer.class);
462 doReturn(NOTIFICATION).when(messageTransformer).toRpcRequest(any(SchemaPath.class), any(NormalizedNode.class));
463 doReturn(RPC_RESULT).when(messageTransformer).toRpcResult(any(NetconfMessage.class), any(SchemaPath.class));
464 doReturn(COMPOSITE_NODE).when(messageTransformer).toNotification(any(NetconfMessage.class));
465 return messageTransformer;
468 public NetconfSessionPreferences getSessionCaps(final boolean addMonitor,
469 final Collection<String> additionalCapabilities) {
470 final ArrayList<String> capabilities = Lists.newArrayList(
471 XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_0,
472 XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_1);
475 capabilities.add(NetconfMessageTransformUtil.IETF_NETCONF_MONITORING.getNamespace().toString());
478 capabilities.addAll(additionalCapabilities);
480 return NetconfSessionPreferences.fromStrings(
484 public NetconfDeviceCommunicator getListener() throws Exception {
485 final NetconfDeviceCommunicator remoteDeviceCommunicator = mockCloseableClass(NetconfDeviceCommunicator.class);
486 // doReturn(Futures.immediateFuture(rpcResult))
487 // .when(remoteDeviceCommunicator).sendRequest(any(NetconfMessage.class), any(QName.class));
488 return remoteDeviceCommunicator;