Remove inventory related code from netconf connector
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / sal / connect / netconf / sal / MountInstanceTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.sal.connect.netconf.sal;
9
10 import static org.mockito.Matchers.any;
11 import static org.mockito.Mockito.verify;
12 import static org.mockito.Mockito.when;
13
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;
32
33 public class MountInstanceTest {
34
35     private static SchemaContext SCHEMA_CONTEXT;
36
37     @Mock
38     private DOMMountPointService service;
39     @Mock
40     private DOMDataBroker broker;
41     @Mock
42     private DOMRpcService rpcService;
43     @Mock
44     private NetconfDeviceNotificationService notificationService;
45     @Mock
46     private DOMMountPointService.DOMMountPointBuilder mountPointBuilder;
47     @Mock
48     private ObjectRegistration<DOMMountPoint> registration;
49
50     private NetconfDeviceSalProvider.MountInstance mountInstance;
51
52     @BeforeClass
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();
58
59     }
60
61     @Before
62     public void setUp() throws Exception {
63         MockitoAnnotations.initMocks(this);
64         when(service.createMountPoint(any(YangInstanceIdentifier.class))).thenReturn(mountPointBuilder);
65
66         when(mountPointBuilder.register()).thenReturn(registration);
67         mountInstance = new NetconfDeviceSalProvider.MountInstance(service, new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830)));
68     }
69
70
71     @Test
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);
78     }
79
80     @Test
81     public void testOnTopologyDeviceDisconnected() throws Exception {
82         mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService);
83         mountInstance.onTopologyDeviceDisconnected();
84         verify(registration).close();
85         try {
86             mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService);
87         } catch (IllegalStateException e) {
88             e.printStackTrace();
89             Assert.fail("Topology registration still present after disconnect ");
90         }
91     }
92
93     @Test
94     public void testClose() throws Exception {
95         mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService);
96         mountInstance.close();
97         verify(registration).close();
98     }
99
100 }