e2e891f5bb353c64ca903219c52bddd90811f03f
[mdsal.git] / binding2 / mdsal-binding2-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / javav2 / dom / adapter / impl / data / tree / BindingDOMDataTreeListenerAdapterTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.mdsal.binding.javav2.dom.adapter.impl.data.tree;
10
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Mockito.verify;
13 import static org.mockito.MockitoAnnotations.initMocks;
14
15 import com.google.common.collect.ImmutableMap;
16 import com.google.common.collect.ImmutableSet;
17 import com.google.common.util.concurrent.MoreExecutors;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.mockito.Mock;
21 import org.opendaylight.mdsal.binding.javav2.api.DataTreeListener;
22 import org.opendaylight.mdsal.binding.javav2.dom.adapter.test.BindingBrokerTestFactory;
23 import org.opendaylight.mdsal.binding.javav2.dom.adapter.test.BindingTestContext;
24 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
25 import org.opendaylight.mdsal.dom.api.DOMDataTreeListeningException;
26
27 public class BindingDOMDataTreeListenerAdapterTest {
28
29     private BindingDOMDataTreeListenerAdapter bindingDOMDataTreeListenerAdapter;
30
31     @Mock
32     private DataTreeListener delegate;
33
34     @Before
35     public void setUp() throws Exception {
36         initMocks(this);
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 }