152f484f3b016241edcd6c57c0980d4ca850d31d
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / BindingDOMDataTreeServiceAdapterTest.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.assertNotNull;
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.verify;
15 import static org.mockito.MockitoAnnotations.initMocks;
16
17 import com.google.common.collect.ImmutableSet;
18 import com.google.common.util.concurrent.MoreExecutors;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.mockito.Mock;
22 import org.opendaylight.mdsal.binding.api.DataTreeListener;
23 import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingBrokerTestFactory;
24 import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingTestContext;
25 import org.opendaylight.mdsal.dom.api.DOMDataTreeProducer;
26 import org.opendaylight.mdsal.dom.api.DOMDataTreeService;
27
28 public class BindingDOMDataTreeServiceAdapterTest {
29
30     private BindingDOMDataTreeServiceAdapter bindingDOMDataTreeServiceAdapter;
31     private BindingToNormalizedNodeCodec codec;
32
33     @Mock
34     private DOMDataTreeService delegate;
35
36     @Before
37     public void setUp() throws Exception {
38         initMocks(this);
39         final BindingBrokerTestFactory testFactory = new BindingBrokerTestFactory();
40         testFactory.setExecutor(MoreExecutors.newDirectExecutorService());
41         final BindingTestContext testContext = testFactory.getTestContext();
42         testContext.start();
43         codec = testContext.getCodec();
44         bindingDOMDataTreeServiceAdapter = BindingDOMDataTreeServiceAdapter.create(delegate, codec);
45     }
46
47     @Test
48     public void createProducerTest() throws Exception {
49         doReturn(mock(DOMDataTreeProducer.class)).when(delegate).createProducer(any());
50         assertNotNull(bindingDOMDataTreeServiceAdapter.createProducer(ImmutableSet.of()));
51         verify(delegate).createProducer(any());
52     }
53
54     @Test(expected = UnsupportedOperationException.class)
55     public void registerListenerTest() throws Exception {
56         bindingDOMDataTreeServiceAdapter.registerListener(mock(DataTreeListener.class), ImmutableSet.of(), false,
57                 ImmutableSet.of());
58     }
59 }