Bug 4940 - correctly implement default-request-timeout-millis
[netconf.git] / opendaylight / netconf / netconf-topology / src / test / java / org / opendaylight / netconf / topology / pipeline / TopologyMountPointFacadeTest.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
9 package org.opendaylight.netconf.topology.pipeline;
10
11 import java.net.InetSocketAddress;
12 import java.util.Collections;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.mockito.Mock;
16 import org.mockito.Mockito;
17 import org.mockito.MockitoAnnotations;
18 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
19 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
20 import org.opendaylight.controller.sal.core.api.Broker;
21 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
22 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
23 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25
26 public class TopologyMountPointFacadeTest {
27
28     private static final RemoteDeviceId REMOTE_DEVICE_ID = new RemoteDeviceId("testing-device", new InetSocketAddress(9999));
29     private static final String TOPOLOGY_ID = "testing-topology";
30
31     @Mock
32     Broker domBroker;
33
34     @Mock
35     BindingAwareBroker bindingBroker;
36
37     @Mock
38     RemoteDeviceHandler<NetconfSessionPreferences> connectionStatusListener1;
39
40     @Mock
41     RemoteDeviceHandler<NetconfSessionPreferences> connectionStatusListener2;
42
43
44     private TopologyMountPointFacade mountPointFacade;
45
46     @Before
47     public void setUp() {
48
49         MockitoAnnotations.initMocks(this);
50
51         mountPointFacade = new TopologyMountPointFacade(TOPOLOGY_ID, REMOTE_DEVICE_ID, domBroker, bindingBroker);
52
53         mountPointFacade.registerConnectionStatusListener(connectionStatusListener1);
54         mountPointFacade.registerConnectionStatusListener(connectionStatusListener2);
55
56     }
57
58     @Test
59     public void testOnDeviceConnected() {
60         SchemaContext mockedContext = Mockito.mock(SchemaContext.class);
61         NetconfSessionPreferences mockedPreferences = NetconfSessionPreferences.fromStrings(Collections.<String>emptyList());
62         DOMRpcService mockedRpcService = Mockito.mock(DOMRpcService.class);
63         mountPointFacade.onDeviceConnected(mockedContext, mockedPreferences, mockedRpcService);
64
65         Mockito.verify(connectionStatusListener1).onDeviceConnected(mockedContext, mockedPreferences, mockedRpcService);
66         Mockito.verify(connectionStatusListener2).onDeviceConnected(mockedContext, mockedPreferences, mockedRpcService);
67     }
68
69     @Test
70     public void testOnDeviceDisconnected() {
71         mountPointFacade.onDeviceDisconnected();
72
73         Mockito.verify(connectionStatusListener1).onDeviceDisconnected();
74         Mockito.verify(connectionStatusListener2).onDeviceDisconnected();
75     }
76
77     @Test
78     public void testOnDeviceFailed() {
79         Throwable mockedException = Mockito.mock(Throwable.class);
80         mountPointFacade.onDeviceFailed(mockedException);
81
82         Mockito.verify(connectionStatusListener1).onDeviceFailed(mockedException);
83         Mockito.verify(connectionStatusListener2).onDeviceFailed(mockedException);
84     }
85
86 }