2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.mdsal.binding.javav2.dom.adapter.impl.mountpoint;
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.Matchers.any;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.reset;
15 import static org.mockito.Mockito.verify;
16 import static org.mockito.Mockito.verifyZeroInteractions;
17 import static org.mockito.MockitoAnnotations.initMocks;
19 import com.google.common.util.concurrent.MoreExecutors;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.mockito.Mock;
23 import org.opendaylight.mdsal.binding.javav2.api.MountPointListener;
24 import org.opendaylight.mdsal.binding.javav2.dom.adapter.test.BindingBrokerTestFactory;
25 import org.opendaylight.mdsal.binding.javav2.dom.adapter.test.BindingTestContext;
26 import org.opendaylight.mdsal.binding.javav2.dom.codec.impl.BindingToNormalizedNodeCodec;
27 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
28 import org.opendaylight.yangtools.concepts.ListenerRegistration;
29 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
31 public class BindingDOMMountPointListenerAdapterTest {
33 private BindingDOMMountPointListenerAdapter bindingDOMMountPointListenerAdapter;
34 private BindingToNormalizedNodeCodec codec;
36 @Mock private MountPointListener listener;
37 @Mock private DOMMountPointService mountPointService;
38 @Mock private ListenerRegistration listenerRegistration;
41 public void setUp() throws Exception {
43 final BindingBrokerTestFactory testFactory = new BindingBrokerTestFactory();
44 testFactory.setExecutor(MoreExecutors.newDirectExecutorService());
45 final BindingTestContext testContext = testFactory.getTestContext();
47 codec = testContext.getCodec();
48 doReturn(listenerRegistration).when(mountPointService).registerProvisionListener(any());
49 bindingDOMMountPointListenerAdapter =
50 new BindingDOMMountPointListenerAdapter<>(listener, codec, mountPointService);
54 public void basicTest() throws Exception {
55 assertEquals(listener, bindingDOMMountPointListenerAdapter.getInstance());
56 bindingDOMMountPointListenerAdapter.close();
57 verify(listenerRegistration).close();
61 public void onMountPointCreatedWithExceptionTest() throws Exception {
63 bindingDOMMountPointListenerAdapter.onMountPointCreated(YangInstanceIdentifier.EMPTY);
64 verifyZeroInteractions(listener);
68 public void onMountPointRemovedWithExceptionTest() throws Exception {
70 bindingDOMMountPointListenerAdapter.onMountPointRemoved(YangInstanceIdentifier.EMPTY);
71 verifyZeroInteractions(listener);