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.EffectiveModelContextFactory;
70 import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
71 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
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 EffectiveModelContextFactory 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).createEffectiveModelContext(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)
159 .setBaseSchemas(BASE_SCHEMAS)
161 // Monitoring supported
162 final NetconfSessionPreferences sessionCaps =
163 getSessionCaps(true, Lists.newArrayList(TEST_CAPABILITY, TEST_CAPABILITY2));
164 device.onRemoteSessionUp(sessionCaps, listener);
166 Mockito.verify(facade, Mockito.timeout(5000)).onDeviceConnected(any(MountPointContext.class),
167 any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class), isNull());
168 Mockito.verify(schemaFactory, times(2)).createEffectiveModelContext(anyCollectionOf(SourceIdentifier.class));
172 public void testNetconfDeviceFailFirstSchemaFailSecondEmpty() throws Exception {
173 final ArrayList<String> capList = Lists.newArrayList(TEST_CAPABILITY);
175 final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
176 final NetconfDeviceCommunicator listener = getListener();
178 final EffectiveModelContextFactory schemaFactory = getSchemaFactory();
179 final SchemaRepository schemaRepository = getSchemaRepository();
181 // Make fallback attempt to fail due to empty resolved sources
182 final SchemaResolutionException schemaResolutionException
183 = new SchemaResolutionException("fail first",
184 Collections.emptyList(), HashMultimap.create());
185 doReturn(Futures.immediateFailedFuture(schemaResolutionException))
186 .when(schemaFactory).createEffectiveModelContext(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)
196 .setBaseSchemas(BASE_SCHEMAS)
199 // Monitoring not supported
200 final NetconfSessionPreferences sessionCaps = getSessionCaps(false, capList);
201 device.onRemoteSessionUp(sessionCaps, listener);
203 Mockito.verify(facade, Mockito.timeout(5000)).onDeviceDisconnected();
204 Mockito.verify(listener, Mockito.timeout(5000)).close();
205 Mockito.verify(schemaFactory, times(1)).createEffectiveModelContext(anyCollectionOf(SourceIdentifier.class));
209 public void testNetconfDeviceMissingSource() throws Exception {
210 final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
211 final NetconfDeviceCommunicator listener = getListener();
213 final EffectiveModelContextFactory 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.immediateFailedFuture(schemaResolutionException))
220 .when(schemaRepository).getSchemaSource(eq(TEST_SID), eq(YangTextSchemaSource.class));
221 doAnswer(invocation -> {
222 if (((Collection<?>) invocation.getArguments()[0]).size() == 2) {
223 return Futures.immediateFailedFuture(schemaResolutionException);
225 return Futures.immediateFuture(SCHEMA_CONTEXT);
227 }).when(schemaFactory).createEffectiveModelContext(anyCollectionOf(SourceIdentifier.class));
229 final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id,
231 final Module first = Iterables.getFirst(SCHEMA_CONTEXT.getModules(), null);
232 final QName qName = QName.create(first.getQNameModule(), first.getName());
233 final NetconfStateSchemas.RemoteYangSchema source1 = new NetconfStateSchemas.RemoteYangSchema(qName);
234 final NetconfStateSchemas.RemoteYangSchema source2 =
235 new NetconfStateSchemas.RemoteYangSchema(QName.create(first.getQNameModule(), "test-module2"));
236 return new NetconfStateSchemas(Sets.newHashSet(source1, source2));
239 final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice
240 .SchemaResourcesDTO(getSchemaRegistry(), schemaRepository, schemaFactory, stateSchemasResolver);
242 final NetconfDevice device = new NetconfDeviceBuilder()
243 .setReconnectOnSchemasChange(true)
244 .setSchemaResourcesDTO(schemaResourcesDTO)
245 .setGlobalProcessingExecutor(getExecutor())
246 .setBaseSchemas(BASE_SCHEMAS)
248 .setSalFacade(facade)
250 // Monitoring supported
251 final NetconfSessionPreferences sessionCaps =
252 getSessionCaps(true, Lists.newArrayList(TEST_CAPABILITY, TEST_CAPABILITY2));
253 device.onRemoteSessionUp(sessionCaps, listener);
255 Mockito.verify(facade, Mockito.timeout(5000)).onDeviceConnected(any(MountPointContext.class),
256 any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class), isNull());
257 Mockito.verify(schemaFactory, times(1)).createEffectiveModelContext(anyCollectionOf(SourceIdentifier.class));
260 private static SchemaSourceRegistry getSchemaRegistry() {
261 final SchemaSourceRegistry mock = mock(SchemaSourceRegistry.class);
262 final SchemaSourceRegistration<?> mockReg = mock(SchemaSourceRegistration.class);
263 doNothing().when(mockReg).close();
264 doReturn(mockReg).when(mock).registerSchemaSource(
265 any(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider.class),
266 any(PotentialSchemaSource.class));
270 private static SchemaRepository getSchemaRepository() {
271 final SchemaRepository mock = mock(SchemaRepository.class);
272 final SchemaSourceRepresentation mockRep = mock(SchemaSourceRepresentation.class);
273 doReturn(Futures.immediateFuture(mockRep))
274 .when(mock).getSchemaSource(any(SourceIdentifier.class), eq(YangTextSchemaSource.class));
279 public void testNotificationBeforeSchema() throws Exception {
280 final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
281 final NetconfDeviceCommunicator listener = getListener();
282 final EffectiveModelContextFactory schemaContextProviderFactory = mock(EffectiveModelContextFactory.class);
283 final SettableFuture<SchemaContext> schemaFuture = SettableFuture.create();
284 doReturn(schemaFuture).when(schemaContextProviderFactory).createEffectiveModelContext(any(Collection.class));
285 final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO =
286 new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), getSchemaRepository(),
287 schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
288 final NetconfDevice device = new NetconfDeviceBuilder()
289 .setReconnectOnSchemasChange(true)
290 .setSchemaResourcesDTO(schemaResourcesDTO)
291 .setGlobalProcessingExecutor(getExecutor())
293 .setSalFacade(facade)
294 .setBaseSchemas(BASE_SCHEMAS)
297 final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
298 Lists.newArrayList(TEST_CAPABILITY));
299 device.onRemoteSessionUp(sessionCaps, listener);
301 device.onNotification(NOTIFICATION);
302 device.onNotification(NOTIFICATION);
303 verify(facade, times(0)).onNotification(any(DOMNotification.class));
305 verify(facade, times(0)).onNotification(any(DOMNotification.class));
306 schemaFuture.set(NetconfToNotificationTest.getNotificationSchemaContext(getClass(), false));
307 verify(facade, timeout(10000).times(2)).onNotification(any(DOMNotification.class));
309 device.onNotification(NOTIFICATION);
310 verify(facade, timeout(10000).times(3)).onNotification(any(DOMNotification.class));
314 public void testNetconfDeviceReconnect() throws Exception {
315 final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
316 final NetconfDeviceCommunicator listener = getListener();
318 final EffectiveModelContextFactory schemaContextProviderFactory = getSchemaFactory();
320 final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(
321 getSchemaRegistry(), getSchemaRepository(), schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
322 final NetconfDevice device = new NetconfDeviceBuilder()
323 .setReconnectOnSchemasChange(true)
324 .setSchemaResourcesDTO(schemaResourcesDTO)
325 .setGlobalProcessingExecutor(getExecutor())
327 .setSalFacade(facade)
328 .setBaseSchemas(BASE_SCHEMAS)
330 final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
331 Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION));
332 device.onRemoteSessionUp(sessionCaps, listener);
334 verify(schemaContextProviderFactory, timeout(5000)).createEffectiveModelContext(any(Collection.class));
335 verify(facade, timeout(5000)).onDeviceConnected(
336 any(MountPointContext.class), any(NetconfSessionPreferences.class), any(DOMRpcService.class),
339 device.onRemoteSessionDown();
340 verify(facade, timeout(5000)).onDeviceDisconnected();
342 device.onRemoteSessionUp(sessionCaps, listener);
344 verify(schemaContextProviderFactory, timeout(5000).times(2)).createEffectiveModelContext(any(Collection.class));
345 verify(facade, timeout(5000).times(2)).onDeviceConnected(
346 any(MountPointContext.class), any(NetconfSessionPreferences.class), any(DOMRpcService.class),
351 public void testNetconfDeviceDisconnectListenerCallCancellation() throws Exception {
352 final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
353 final NetconfDeviceCommunicator listener = getListener();
354 final EffectiveModelContextFactory schemaContextProviderFactory = mock(EffectiveModelContextFactory.class);
355 final SettableFuture<SchemaContext> schemaFuture = SettableFuture.create();
356 doReturn(schemaFuture).when(schemaContextProviderFactory).createEffectiveModelContext(any(Collection.class));
357 final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO
358 = new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), getSchemaRepository(),
359 schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
360 final NetconfDevice device = new NetconfDeviceBuilder()
361 .setReconnectOnSchemasChange(true)
362 .setSchemaResourcesDTO(schemaResourcesDTO)
363 .setGlobalProcessingExecutor(getExecutor())
365 .setSalFacade(facade)
366 .setBaseSchemas(BASE_SCHEMAS)
368 final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
369 Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION));
370 //session up, start schema resolution
371 device.onRemoteSessionUp(sessionCaps, listener);
373 device.onRemoteSessionDown();
374 verify(facade, timeout(5000)).onDeviceDisconnected();
375 //complete schema setup
376 schemaFuture.set(SCHEMA_CONTEXT);
377 //facade.onDeviceDisconnected() was called, so facade.onDeviceConnected() shouldn't be called anymore
378 verify(facade, after(1000).never()).onDeviceConnected(any(), any(), any(), any(DOMActionService.class));
382 public void testNetconfDeviceAvailableCapabilitiesBuilding() throws Exception {
383 final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
384 final NetconfDeviceCommunicator listener = getListener();
386 final EffectiveModelContextFactory schemaContextProviderFactory = getSchemaFactory();
388 final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(
389 getSchemaRegistry(), getSchemaRepository(), schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
390 final NetconfDevice device = new NetconfDeviceBuilder()
391 .setReconnectOnSchemasChange(true)
392 .setSchemaResourcesDTO(schemaResourcesDTO)
393 .setGlobalProcessingExecutor(getExecutor())
395 .setSalFacade(facade)
396 .setBaseSchemas(BASE_SCHEMAS)
398 final NetconfDevice netconfSpy = Mockito.spy(device);
400 final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
401 Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION));
402 final Map<QName, AvailableCapability.CapabilityOrigin> moduleBasedCaps = new HashMap<>();
403 moduleBasedCaps.putAll(sessionCaps.getModuleBasedCapsOrigin());
405 .put(QName.create("(test:qname:side:loading)test"), AvailableCapability.CapabilityOrigin.UserDefined);
407 netconfSpy.onRemoteSessionUp(sessionCaps.replaceModuleCaps(moduleBasedCaps), listener);
409 final ArgumentCaptor<NetconfSessionPreferences> argument =
410 ArgumentCaptor.forClass(NetconfSessionPreferences.class);
411 verify(facade, timeout(5000)).onDeviceConnected(any(MountPointContext.class), argument.capture(),
412 any(DOMRpcService.class), isNull());
413 final NetconfDeviceCapabilities netconfDeviceCaps = argument.getValue().getNetconfDeviceCapabilities();
415 netconfDeviceCaps.getResolvedCapabilities()
416 .forEach(entry -> assertEquals("Builded 'AvailableCapability' schemas should match input capabilities.",
418 QName.create(entry.getCapability())).getName(), entry.getCapabilityOrigin().getName()));
421 private static EffectiveModelContextFactory getSchemaFactory() throws Exception {
422 final EffectiveModelContextFactory schemaFactory = mockClass(EffectiveModelContextFactory.class);
423 doReturn(Futures.immediateFuture(SCHEMA_CONTEXT))
424 .when(schemaFactory).createEffectiveModelContext(any(Collection.class));
425 return schemaFactory;
428 private static RemoteDeviceHandler<NetconfSessionPreferences> getFacade() throws Exception {
429 final RemoteDeviceHandler<NetconfSessionPreferences> remoteDeviceHandler =
430 mockCloseableClass(RemoteDeviceHandler.class);
431 doNothing().when(remoteDeviceHandler).onDeviceConnected(
432 any(MountPointContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class),
433 any(DOMActionService.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 ListeningExecutorService getExecutor() {
457 return MoreExecutors.listeningDecorator(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;