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.dom.api.NetconfDataTreeService;
31 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
32 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.IetfNetconfService;
34 import org.opendaylight.yangtools.concepts.ObjectRegistration;
35 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
36 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
40 @RunWith(MockitoJUnitRunner.StrictStubs.class)
41 public class MountInstanceTest {
42 private static final Logger LOG = LoggerFactory.getLogger(MountInstanceTest.class);
44 private static EffectiveModelContext SCHEMA_CONTEXT;
47 private DOMMountPointService service;
49 private DOMDataBroker broker;
51 private NetconfDataTreeService netconfService;
53 private DOMRpcService rpcService;
55 private NetconfDeviceNotificationService notificationService;
57 private DOMMountPointService.DOMMountPointBuilder mountPointBuilder;
59 private ObjectRegistration<DOMMountPoint> registration;
61 private DOMNotification notification;
63 private NetconfDeviceSalProvider.MountInstance mountInstance;
66 public static void suiteSetUp() throws Exception {
67 SCHEMA_CONTEXT = BindingRuntimeHelpers.createEffectiveModel(IetfNetconfService.class);
71 public void setUp() throws Exception {
72 when(service.createMountPoint(any(YangInstanceIdentifier.class))).thenReturn(mountPointBuilder);
74 when(mountPointBuilder.register()).thenReturn(registration);
75 mountInstance = new NetconfDeviceSalProvider.MountInstance(
76 service, new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830)));
81 public void testOnTopologyDeviceConnected() {
82 mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
83 notificationService, broker, null);
84 verify(mountPointBuilder).addService(eq(DOMSchemaService.class), any());
85 verify(mountPointBuilder).addService(DOMDataBroker.class, broker);
86 verify(mountPointBuilder).addService(DOMRpcService.class, rpcService);
87 verify(mountPointBuilder).addService(DOMNotificationService.class, notificationService);
91 public void testOnTopologyDeviceConnectedWithNetconfService() {
92 mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
93 notificationService, null, netconfService);
94 verify(mountPointBuilder).addService(eq(DOMSchemaService.class), any());
95 verify(mountPointBuilder).addService(NetconfDataTreeService.class, netconfService);
96 verify(mountPointBuilder).addService(DOMRpcService.class, rpcService);
97 verify(mountPointBuilder).addService(DOMNotificationService.class, notificationService);
101 public void testOnTopologyDeviceDisconnected() {
102 mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
103 notificationService, broker, null);
104 mountInstance.onTopologyDeviceDisconnected();
105 verify(registration).close();
106 mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
107 notificationService, broker, null);
111 public void testClose() {
112 mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
113 notificationService, broker, null);
114 mountInstance.close();
115 verify(registration).close();
119 public void testPublishNotification() {
120 mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
121 notificationService, broker, null);
122 verify(mountPointBuilder).addService(eq(DOMSchemaService.class), any());
123 verify(mountPointBuilder).addService(DOMNotificationService.class, notificationService);
124 mountInstance.publish(notification);
125 verify(notificationService).publishNotification(notification);