c0e10f7fb236f1d7e4dcd4e7ad46f11b65132ece
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / BindingDOMDataTreeListenerAdapterTest.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.mockito.ArgumentMatchers.any;
11 import static org.mockito.Mockito.verify;
12
13 import com.google.common.collect.ImmutableMap;
14 import com.google.common.collect.ImmutableSet;
15 import com.google.common.util.concurrent.MoreExecutors;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Mock;
20 import org.mockito.junit.MockitoJUnitRunner;
21 import org.opendaylight.mdsal.binding.api.DataTreeListener;
22 import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingBrokerTestFactory;
23 import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingTestContext;
24 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
25 import org.opendaylight.mdsal.dom.api.DOMDataTreeListeningException;
26
27 @RunWith(MockitoJUnitRunner.StrictStubs.class)
28 public class BindingDOMDataTreeListenerAdapterTest {
29
30     private BindingDOMDataTreeListenerAdapter bindingDOMDataTreeListenerAdapter;
31
32     @Mock
33     private DataTreeListener delegate;
34
35     @Before
36     public void setUp() throws Exception {
37         final BindingBrokerTestFactory testFactory = new BindingBrokerTestFactory();
38         testFactory.setExecutor(MoreExecutors.newDirectExecutorService());
39         final BindingTestContext testContext = testFactory.getTestContext();
40         testContext.start();
41
42         bindingDOMDataTreeListenerAdapter =
43             new BindingDOMDataTreeListenerAdapter(delegate, testContext.getCodec(), LogicalDatastoreType.OPERATIONAL);
44     }
45
46     @Test
47     public void onDataTreeChanged() throws Exception {
48         bindingDOMDataTreeListenerAdapter.onDataTreeChanged(ImmutableSet.of(), ImmutableMap.of());
49         verify(delegate).onDataTreeChanged(any(), any());
50     }
51
52     @Test
53     public void onDataTreeFailedTest() throws Exception {
54         bindingDOMDataTreeListenerAdapter.onDataTreeFailed(ImmutableSet.of(new DOMDataTreeListeningException("test")));
55         verify(delegate).onDataTreeFailed(any());
56     }
57 }