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.Mockito.verify;
12 import static org.mockito.Mockito.when;
14 import java.net.InetSocketAddress;
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19 import org.mockito.Mock;
20 import org.mockito.MockitoAnnotations;
21 import org.opendaylight.binding.runtime.spi.BindingRuntimeHelpers;
22 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
23 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
24 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
25 import org.opendaylight.mdsal.dom.api.DOMNotification;
26 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
27 import org.opendaylight.mdsal.dom.api.DOMRpcService;
28 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.IetfNetconfService;
30 import org.opendaylight.yangtools.concepts.ObjectRegistration;
31 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
32 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 public class MountInstanceTest {
37 private static final Logger LOG = LoggerFactory.getLogger(MountInstanceTest.class);
39 private static EffectiveModelContext SCHEMA_CONTEXT;
42 private DOMMountPointService service;
44 private DOMDataBroker broker;
46 private DOMRpcService rpcService;
48 private NetconfDeviceNotificationService notificationService;
50 private DOMMountPointService.DOMMountPointBuilder mountPointBuilder;
52 private ObjectRegistration<DOMMountPoint> registration;
54 private DOMNotification notification;
56 private NetconfDeviceSalProvider.MountInstance mountInstance;
59 public static void suiteSetUp() throws Exception {
60 SCHEMA_CONTEXT = BindingRuntimeHelpers.createEffectiveModel(IetfNetconfService.class);
64 public void setUp() throws Exception {
65 MockitoAnnotations.initMocks(this);
66 when(service.createMountPoint(any(YangInstanceIdentifier.class))).thenReturn(mountPointBuilder);
68 when(mountPointBuilder.register()).thenReturn(registration);
69 mountInstance = new NetconfDeviceSalProvider.MountInstance(
70 service, new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830)));
75 public void testOnTopologyDeviceConnected() throws Exception {
76 mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService);
77 verify(mountPointBuilder).addInitialSchemaContext(SCHEMA_CONTEXT);
78 verify(mountPointBuilder).addService(DOMDataBroker.class, broker);
79 verify(mountPointBuilder).addService(DOMRpcService.class, rpcService);
80 verify(mountPointBuilder).addService(DOMNotificationService.class, notificationService);
84 public void testOnTopologyDeviceDisconnected() throws Exception {
85 mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService);
86 mountInstance.onTopologyDeviceDisconnected();
87 verify(registration).close();
89 mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService);
90 } catch (final IllegalStateException e) {
91 LOG.warn("Operation failed.", e);
92 Assert.fail("Topology registration still present after disconnect ");
97 public void testClose() throws Exception {
98 mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService);
99 mountInstance.close();
100 verify(registration).close();
104 public void testPublishNotification() throws Exception {
105 mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService);
106 verify(mountPointBuilder).addInitialSchemaContext(SCHEMA_CONTEXT);
107 verify(mountPointBuilder).addService(DOMNotificationService.class, notificationService);
108 mountInstance.publish(notification);
109 verify(notificationService).publishNotification(notification);