02824349d08bc6b83ce8f3a4c3ace68e8ef378da
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / BindingDOMDataTreeCommitCohortRegistryAdapterTest.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.doNothing;
12 import static org.mockito.Mockito.doReturn;
13
14 import com.google.common.util.concurrent.MoreExecutors;
15 import org.junit.jupiter.api.Test;
16 import org.junit.jupiter.api.extension.ExtendWith;
17 import org.mockito.Mock;
18 import org.mockito.junit.jupiter.MockitoExtension;
19 import org.opendaylight.mdsal.binding.api.DataTreeCommitCohort;
20 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
21 import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingBrokerTestFactory;
22 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
23 import org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohortRegistry;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
25 import org.opendaylight.yangtools.concepts.Registration;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27
28 @ExtendWith(MockitoExtension.class)
29 public class BindingDOMDataTreeCommitCohortRegistryAdapterTest {
30     @Mock
31     private DOMDataTreeCommitCohortRegistry cohortRegistry;
32     @Mock
33     private Registration cohortRegistration;
34     @Mock
35     private DataTreeCommitCohort<Top> dataTreeCommitCohort;
36
37     @Test
38     void basicTest() {
39         final var bindingBrokerTestFactory = new BindingBrokerTestFactory();
40         bindingBrokerTestFactory.setExecutor(MoreExecutors.newDirectExecutorService());
41         final var bindingTestContext = bindingBrokerTestFactory.getTestContext();
42         bindingTestContext.start();
43
44         doReturn(cohortRegistration).when(cohortRegistry).registerCommitCohort(any(), any());
45         doNothing().when(cohortRegistration).close();
46         final var registryAdapter = new BindingDOMDataTreeCommitCohortRegistryAdapter(bindingTestContext.getCodec(),
47             cohortRegistry);
48
49         final var dataTreeIdentifier = DataTreeIdentifier.of(LogicalDatastoreType.CONFIGURATION,
50                 InstanceIdentifier.create(Top.class));
51         try (var reg = registryAdapter.registerCommitCohort(dataTreeIdentifier, dataTreeCommitCohort)) {
52             // Nothing else
53         }
54     }
55 }