2 * Copyright (c) 2016 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.sal;
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.ArgumentMatchers.eq;
12 import static org.mockito.Mockito.verify;
13 import static org.mockito.Mockito.when;
15 import java.net.InetSocketAddress;
16 import org.junit.Before;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.mockito.Mock;
21 import org.mockito.junit.MockitoJUnitRunner;
22 import org.opendaylight.mdsal.binding.runtime.spi.BindingRuntimeHelpers;
23 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
24 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
25 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
26 import org.opendaylight.mdsal.dom.api.DOMNotification;
27 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
28 import org.opendaylight.mdsal.dom.api.DOMRpcService;
29 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
30 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceId;
31 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceServices;
32 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceServices.Rpcs;
33 import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.IetfNetconfService;
35 import org.opendaylight.yangtools.concepts.ObjectRegistration;
36 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
37 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
39 @RunWith(MockitoJUnitRunner.StrictStubs.class)
40 public class MountInstanceTest {
41 private static EffectiveModelContext SCHEMA_CONTEXT;
44 private DOMMountPointService service;
46 private DOMDataBroker broker;
48 private NetconfDataTreeService netconfService;
50 private Rpcs.Normalized rpcService;
52 private NetconfDeviceNotificationService notificationService;
54 private DOMMountPointService.DOMMountPointBuilder mountPointBuilder;
56 private ObjectRegistration<DOMMountPoint> registration;
58 private DOMNotification notification;
60 private NetconfDeviceMount mountInstance;
63 public static void suiteSetUp() throws Exception {
64 SCHEMA_CONTEXT = BindingRuntimeHelpers.createEffectiveModel(IetfNetconfService.class);
68 public void setUp() throws Exception {
69 when(service.createMountPoint(any(YangInstanceIdentifier.class))).thenReturn(mountPointBuilder);
70 when(mountPointBuilder.register()).thenReturn(registration);
72 mountInstance = new NetconfDeviceMount(
73 new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830)),
74 service, YangInstanceIdentifier.empty());
78 public void testOnTopologyDeviceConnected() {
79 mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
80 notificationService, broker, null);
81 verify(mountPointBuilder).addService(eq(DOMSchemaService.class), any());
82 verify(mountPointBuilder).addService(DOMDataBroker.class, broker);
83 verify(mountPointBuilder).addService(DOMRpcService.class, rpcService);
84 verify(mountPointBuilder).addService(DOMNotificationService.class, notificationService);
88 public void testOnTopologyDeviceConnectedWithNetconfService() {
89 mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
90 notificationService, null, netconfService);
91 verify(mountPointBuilder).addService(eq(DOMSchemaService.class), any());
92 verify(mountPointBuilder).addService(NetconfDataTreeService.class, netconfService);
93 verify(mountPointBuilder).addService(DOMRpcService.class, rpcService);
94 verify(mountPointBuilder).addService(DOMNotificationService.class, notificationService);
98 public void testOnTopologyDeviceDisconnected() {
99 mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
100 notificationService, broker, null);
101 mountInstance.onDeviceDisconnected();
102 verify(registration).close();
103 mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
104 notificationService, broker, null);
108 public void testClose() {
109 mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
110 notificationService, broker, null);
111 mountInstance.close();
112 verify(registration).close();
116 public void testPublishNotification() {
117 mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
118 notificationService, broker, null);
119 verify(mountPointBuilder).addService(eq(DOMSchemaService.class), any());
120 verify(mountPointBuilder).addService(DOMNotificationService.class, notificationService);
121 mountInstance.publish(notification);
122 verify(notificationService).publishNotification(notification);