Split Restconf implementations (draft02 and RFC) - move
[netconf.git] / restconf / restconf-nb-bierman02 / src / test / java / org / opendaylight / restconf / RestConnectorProviderTest.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.restconf;
10
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.verify;
13
14 import org.junit.Before;
15 import org.junit.Rule;
16 import org.junit.Test;
17 import org.junit.rules.ExpectedException;
18 import org.mockito.Mock;
19 import org.mockito.Mockito;
20 import org.mockito.MockitoAnnotations;
21 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
22 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
23 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
24 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
25 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
26 import org.opendaylight.controller.sal.core.api.model.SchemaService;
27 import org.opendaylight.restconf.handlers.SchemaContextHandler;
28 import org.opendaylight.yangtools.concepts.ListenerRegistration;
29 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
30
31 /**
32  * Unit tests for {@link RestConnectorProvider}.
33  */
34 public class RestConnectorProviderTest {
35     // service under test
36     private RestConnectorProvider connectorProvider;
37
38     @Mock private SchemaService mockSchemaService;
39     @Mock private DOMMountPointService mockMountPointService;
40     @Mock private DOMDataBroker mockDataBroker;
41     @Mock private DOMRpcService mockRpcService;
42     @Mock private DOMNotificationService mockNotificationService;
43     @Mock DOMTransactionChain mockTransactionChain;
44     @Mock private ListenerRegistration<SchemaContextListener> mockRegistration;
45
46     @Rule
47     public ExpectedException thrown = ExpectedException.none();
48
49     @Before
50     public void init() {
51         MockitoAnnotations.initMocks(this);
52
53         doReturn(mockTransactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
54         doReturn(mockRegistration).when(mockSchemaService).registerSchemaContextListener(
55                 Mockito.any(SchemaContextHandler.class));
56
57         this.connectorProvider = new RestConnectorProvider(mockDataBroker, mockSchemaService, mockRpcService,
58                 mockNotificationService, mockMountPointService);
59     }
60
61     /**
62      * Test for successful start when all conditions are satisfied.
63      */
64     @Test
65     public void successfulStartTest() {
66         // test
67         this.connectorProvider.start();
68
69         // verify interactions
70         verify(mockDataBroker).createTransactionChain(Mockito.any());
71         verify(mockSchemaService).registerSchemaContextListener(Mockito.any(SchemaContextHandler.class));
72     }
73
74     /**
75      * Test of closing <code>null</code> registration.
76      */
77     @Test
78     public void closeNotOpenTest() throws Exception {
79         this.connectorProvider.close();
80     }
81
82     /**
83      * Test of creating and closing not <code>null</code> registration.
84      */
85     @Test
86     public void closeOpenTest() throws Exception {
87         // start
88         this.connectorProvider.start();
89
90         // close
91         this.connectorProvider.close();
92
93         // verify interaction
94         verify(this.mockRegistration).close();
95         verify(mockTransactionChain).close();
96     }
97 }