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
9 package org.opendaylight.restconf.nb.rfc8040;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.verify;
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;
33 * Unit tests for {@link RestConnectorProvider}.
35 public class RestConnectorProviderTest {
37 private RestConnectorProvider connectorProvider;
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;
48 public ExpectedException thrown = ExpectedException.none();
52 MockitoAnnotations.initMocks(this);
54 doReturn(mockTransactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
55 doReturn(mockRegistration).when(mockSchemaService).registerSchemaContextListener(
56 Mockito.any(SchemaContextHandler.class));
58 this.connectorProvider = new RestConnectorProvider(mockDataBroker, mockSchemaService, mockRpcService,
59 mockNotificationService, mockMountPointService, ServicesWrapperImpl.getInstance());
63 * Test for successful start when all conditions are satisfied.
66 public void successfulStartTest() {
68 this.connectorProvider.start();
70 // verify interactions
71 verify(mockDataBroker).createTransactionChain(Mockito.any());
72 verify(mockSchemaService).registerSchemaContextListener(Mockito.any(SchemaContextHandler.class));
76 * Test of closing <code>null</code> registration.
79 public void closeNotOpenTest() throws Exception {
80 this.connectorProvider.close();
84 * Test of creating and closing not <code>null</code> registration.
87 public void closeOpenTest() throws Exception {
89 this.connectorProvider.start();
92 this.connectorProvider.close();
95 verify(this.mockRegistration).close();
96 verify(mockTransactionChain).close();