Make ServicesWrapperImpl as argument in provider
[netconf.git] / restconf / restconf-nb-rfc8040 / src / test / java / org / opendaylight / restconf / nb / rfc8040 / 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.nb.rfc8040;
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.nb.rfc8040.handlers.SchemaContextHandler;
28 import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl;
29 import org.opendaylight.yangtools.concepts.ListenerRegistration;
30 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
31
32 /**
33  * Unit tests for {@link RestConnectorProvider}.
34  */
35 public class RestConnectorProviderTest {
36     // service under test
37     private RestConnectorProvider connectorProvider;
38
39     @Mock private SchemaService mockSchemaService;
40     @Mock private DOMMountPointService mockMountPointService;
41     @Mock private DOMDataBroker mockDataBroker;
42     @Mock private DOMRpcService mockRpcService;
43     @Mock private DOMNotificationService mockNotificationService;
44     @Mock DOMTransactionChain mockTransactionChain;
45     @Mock private ListenerRegistration<SchemaContextListener> mockRegistration;
46
47     @Rule
48     public ExpectedException thrown = ExpectedException.none();
49
50     @Before
51     public void init() {
52         MockitoAnnotations.initMocks(this);
53
54         doReturn(mockTransactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
55         doReturn(mockRegistration).when(mockSchemaService).registerSchemaContextListener(
56                 Mockito.any(SchemaContextHandler.class));
57
58         this.connectorProvider = new RestConnectorProvider(mockDataBroker, mockSchemaService, mockRpcService,
59                 mockNotificationService, mockMountPointService, ServicesWrapperImpl.getInstance());
60     }
61
62     /**
63      * Test for successful start when all conditions are satisfied.
64      */
65     @Test
66     public void successfulStartTest() {
67         // test
68         this.connectorProvider.start();
69
70         // verify interactions
71         verify(mockDataBroker).createTransactionChain(Mockito.any());
72         verify(mockSchemaService).registerSchemaContextListener(Mockito.any(SchemaContextHandler.class));
73     }
74
75     /**
76      * Test of closing <code>null</code> registration.
77      */
78     @Test
79     public void closeNotOpenTest() throws Exception {
80         this.connectorProvider.close();
81     }
82
83     /**
84      * Test of creating and closing not <code>null</code> registration.
85      */
86     @Test
87     public void closeOpenTest() throws Exception {
88         // start
89         this.connectorProvider.start();
90
91         // close
92         this.connectorProvider.close();
93
94         // verify interaction
95         verify(this.mockRegistration).close();
96         verify(mockTransactionChain).close();
97     }
98 }