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.mdsal.dom.api.DOMSchemaService;
28 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
29 import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl;
30 import org.opendaylight.yangtools.concepts.ListenerRegistration;
31 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
34 * Unit tests for {@link RestConnectorProvider}.
36 public class RestConnectorProviderTest {
38 private RestConnectorProvider connectorProvider;
40 @Mock private SchemaService mockSchemaService;
41 @Mock private DOMMountPointService mockMountPointService;
42 @Mock private DOMDataBroker mockDataBroker;
43 @Mock private DOMRpcService mockRpcService;
44 @Mock private DOMNotificationService mockNotificationService;
45 @Mock DOMTransactionChain mockTransactionChain;
46 @Mock private ListenerRegistration<SchemaContextListener> mockRegistration;
48 private DOMSchemaService domSchemaService;
51 public ExpectedException thrown = ExpectedException.none();
55 MockitoAnnotations.initMocks(this);
57 doReturn(mockTransactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
58 doReturn(mockRegistration).when(mockSchemaService).registerSchemaContextListener(
59 Mockito.any(SchemaContextHandler.class));
61 this.connectorProvider = new RestConnectorProvider(mockDataBroker, mockSchemaService, mockRpcService,
62 mockNotificationService, mockMountPointService, domSchemaService, ServicesWrapperImpl.getInstance());
66 * Test for successful start when all conditions are satisfied.
69 public void successfulStartTest() {
71 this.connectorProvider.start();
73 // verify interactions
74 verify(mockDataBroker).createTransactionChain(Mockito.any());
75 verify(mockSchemaService).registerSchemaContextListener(Mockito.any(SchemaContextHandler.class));
79 * Test of closing <code>null</code> registration.
82 public void closeNotOpenTest() throws Exception {
83 this.connectorProvider.close();
87 * Test of creating and closing not <code>null</code> registration.
90 public void closeOpenTest() throws Exception {
92 this.connectorProvider.start();
95 this.connectorProvider.close();
98 verify(this.mockRegistration).close();
99 verify(mockTransactionChain).close();