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.Matchers.any;
11 import static org.mockito.Mockito.verify;
12 import static org.mockito.Mockito.when;
14 import com.google.common.collect.Lists;
15 import java.net.InetSocketAddress;
16 import org.junit.Assert;
17 import org.junit.Before;
18 import org.junit.BeforeClass;
19 import org.junit.Test;
20 import org.mockito.Mock;
21 import org.mockito.MockitoAnnotations;
22 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
23 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
24 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
25 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
26 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
27 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
28 import org.opendaylight.yangtools.concepts.ObjectRegistration;
29 import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
30 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
31 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
33 public class MountInstanceTest {
35 private static SchemaContext SCHEMA_CONTEXT;
38 private DOMMountPointService service;
40 private DOMDataBroker broker;
42 private DOMRpcService rpcService;
44 private NetconfDeviceNotificationService notificationService;
46 private DOMMountPointService.DOMMountPointBuilder mountPointBuilder;
48 private ObjectRegistration<DOMMountPoint> registration;
50 private NetconfDeviceSalProvider.MountInstance mountInstance;
53 public static void suiteSetUp() throws Exception{
54 final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();
55 moduleInfoBackedContext.addModuleInfos(
56 Lists.newArrayList(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.$YangModuleInfoImpl.getInstance()));
57 SCHEMA_CONTEXT = moduleInfoBackedContext.tryToCreateSchemaContext().get();
62 public void setUp() throws Exception {
63 MockitoAnnotations.initMocks(this);
64 when(service.createMountPoint(any(YangInstanceIdentifier.class))).thenReturn(mountPointBuilder);
66 when(mountPointBuilder.register()).thenReturn(registration);
67 mountInstance = new NetconfDeviceSalProvider.MountInstance(service, new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830)));
72 public void testOnTopologyDeviceConnected() throws Exception {
73 mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService);
74 verify(mountPointBuilder).addInitialSchemaContext(SCHEMA_CONTEXT);
75 verify(mountPointBuilder).addService(DOMDataBroker.class, broker);
76 verify(mountPointBuilder).addService(DOMRpcService.class, rpcService);
77 verify(mountPointBuilder).addService(DOMNotificationService.class, notificationService);
81 public void testOnTopologyDeviceDisconnected() throws Exception {
82 mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService);
83 mountInstance.onTopologyDeviceDisconnected();
84 verify(registration).close();
86 mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService);
87 } catch (IllegalStateException e) {
89 Assert.fail("Topology registration still present after disconnect ");
94 public void testClose() throws Exception {
95 mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService);
96 mountInstance.close();
97 verify(registration).close();