Adopt odlparent-10.0.0/yangtools-8.0.0-SNAPSHOT
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / BindingDOMMountPointListenerAdapterTest.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 package org.opendaylight.mdsal.binding.dom.adapter;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.reset;
14 import static org.mockito.Mockito.verify;
15 import static org.mockito.Mockito.verifyNoInteractions;
16
17 import com.google.common.util.concurrent.MoreExecutors;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.mockito.Mock;
22 import org.mockito.junit.MockitoJUnitRunner;
23 import org.opendaylight.mdsal.binding.api.MountPointService.MountPointListener;
24 import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingBrokerTestFactory;
25 import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingTestContext;
26 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
27 import org.opendaylight.yangtools.concepts.ListenerRegistration;
28 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
29
30 @RunWith(MockitoJUnitRunner.StrictStubs.class)
31 public class BindingDOMMountPointListenerAdapterTest {
32
33     private BindingDOMMountPointListenerAdapter<?> bindingDOMMountPointListenerAdapter;
34     private AdapterContext codec;
35
36     @Mock private MountPointListener listener;
37     @Mock private DOMMountPointService mountPointService;
38     @Mock private ListenerRegistration<?> listenerRegistration;
39
40     @Before
41     public void setUp() throws Exception {
42         final BindingBrokerTestFactory testFactory = new BindingBrokerTestFactory();
43         testFactory.setExecutor(MoreExecutors.newDirectExecutorService());
44         final BindingTestContext testContext = testFactory.getTestContext();
45         testContext.start();
46         codec = testContext.getCodec();
47         doReturn(listenerRegistration).when(mountPointService).registerProvisionListener(any());
48         bindingDOMMountPointListenerAdapter =
49                 new BindingDOMMountPointListenerAdapter<>(listener, codec, mountPointService);
50     }
51
52     @Test
53     public void basicTest() throws Exception {
54         assertEquals(listener, bindingDOMMountPointListenerAdapter.getInstance());
55         bindingDOMMountPointListenerAdapter.close();
56         verify(listenerRegistration).close();
57     }
58
59     @Test
60     public void onMountPointCreatedWithExceptionTest() throws Exception {
61         reset(listener);
62         bindingDOMMountPointListenerAdapter.onMountPointCreated(YangInstanceIdentifier.empty());
63         verifyNoInteractions(listener);
64     }
65
66     @Test
67     public void onMountPointRemovedWithExceptionTest() throws Exception {
68         reset(listener);
69         bindingDOMMountPointListenerAdapter.onMountPointRemoved(YangInstanceIdentifier.empty());
70         verifyNoInteractions(listener);
71     }
72 }