2 * Copyright (c) 2016 Cisco Systems, Inc. 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
8 package org.opendaylight.mdsal.binding.dom.adapter;
10 import static org.junit.Assert.assertNotNull;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.doThrow;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.reset;
16 import static org.mockito.Mockito.verify;
18 import com.google.common.collect.ImmutableSet;
19 import com.google.common.util.concurrent.MoreExecutors;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23 import org.mockito.Mock;
24 import org.mockito.junit.MockitoJUnitRunner;
25 import org.opendaylight.mdsal.binding.api.DataTreeProducerException;
26 import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingBrokerTestFactory;
27 import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingTestContext;
28 import org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction;
29 import org.opendaylight.mdsal.dom.api.DOMDataTreeProducer;
30 import org.opendaylight.mdsal.dom.api.DOMDataTreeProducerBusyException;
31 import org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException;
33 @RunWith(MockitoJUnitRunner.StrictStubs.class)
34 public class BindingDOMDataTreeProducerAdapterTest {
35 private BindingDOMDataTreeProducerAdapter bindingDOMDataTreeProducerAdapter;
36 private AdapterContext codec;
39 private DOMDataTreeProducer delegate;
43 final BindingBrokerTestFactory testFactory = new BindingBrokerTestFactory();
44 testFactory.setExecutor(MoreExecutors.newDirectExecutorService());
45 final BindingTestContext testContext = testFactory.getTestContext();
47 codec = testContext.getCodec();
48 bindingDOMDataTreeProducerAdapter = new BindingDOMDataTreeProducerAdapter(codec, delegate);
52 public void createTransactionTest() {
53 doReturn(mock(DOMDataTreeCursorAwareTransaction.class)).when(delegate).createTransaction(true);
54 assertNotNull(bindingDOMDataTreeProducerAdapter.createTransaction(true));
55 verify(delegate).createTransaction(true);
59 public void createProducerTest() {
60 doReturn(mock(DOMDataTreeProducer.class)).when(delegate).createProducer(any());
61 assertNotNull(bindingDOMDataTreeProducerAdapter.createProducer(ImmutableSet.of()));
62 verify(delegate).createProducer(any());
66 public void closeTest() throws DataTreeProducerException, DOMDataTreeProducerException {
68 bindingDOMDataTreeProducerAdapter.close();
69 verify(delegate).close();
72 @Test(expected = DataTreeProducerException.class)
73 public void closeTestWithException1() throws DataTreeProducerException, DOMDataTreeProducerException {
74 doThrow(new DOMDataTreeProducerBusyException("test")).when(delegate).close();
75 bindingDOMDataTreeProducerAdapter.close();
78 @Test(expected = DataTreeProducerException.class)
79 public void closeTestWithException2() throws DataTreeProducerException, DOMDataTreeProducerException {
80 doThrow(new DOMDataTreeProducerException("test")).when(delegate).close();
81 bindingDOMDataTreeProducerAdapter.close();