Bump upstreams
[netconf.git] / plugins / netconf-client-mdsal / src / test / java / org / opendaylight / netconf / client / mdsal / spi / ReadWriteTxTest.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.netconf.client.mdsal.spi;
9
10 import static org.junit.Assert.assertNotEquals;
11 import static org.junit.Assert.assertTrue;
12 import static org.mockito.Mockito.verify;
13 import static org.mockito.Mockito.when;
14
15 import com.google.common.util.concurrent.FluentFuture;
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.common.api.LogicalDatastoreType;
22 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
23 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
24 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
26 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
27 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
28
29 @RunWith(MockitoJUnitRunner.StrictStubs.class)
30 public class ReadWriteTxTest {
31     @Mock
32     private DOMDataTreeReadTransaction delegateReadTx;
33     @Mock
34     private DOMDataTreeWriteTransaction delegateWriteTx;
35     private ReadWriteTx<?> tx;
36
37     @Before
38     public void setUp() throws Exception {
39         tx = new ReadWriteTx<>(delegateReadTx, delegateWriteTx);
40     }
41
42     @Test
43     public void submit() throws Exception {
44         final YangInstanceIdentifier id1 = TxTestUtils.getContainerId();
45         final ContainerNode containerNode = TxTestUtils.getContainerNode();
46         tx.put(LogicalDatastoreType.CONFIGURATION, id1, containerNode);
47         verify(delegateWriteTx).put(LogicalDatastoreType.CONFIGURATION, id1, containerNode);
48         final YangInstanceIdentifier id2 = TxTestUtils.getLeafId();
49         final LeafNode<String> leafNode = TxTestUtils.getLeafNode();
50         tx.merge(LogicalDatastoreType.CONFIGURATION, id2, leafNode);
51         verify(delegateWriteTx).merge(LogicalDatastoreType.CONFIGURATION, id2, leafNode);
52         tx.delete(LogicalDatastoreType.CONFIGURATION, id2);
53         verify(delegateWriteTx).delete(LogicalDatastoreType.CONFIGURATION, id2);
54         tx.commit();
55         verify(delegateWriteTx).commit();
56     }
57
58     @Test
59     public void cancel() throws Exception {
60         tx.cancel();
61         verify(delegateWriteTx).cancel();
62     }
63
64     @Test
65     public void read() throws Exception {
66         tx.read(LogicalDatastoreType.CONFIGURATION, TxTestUtils.getContainerId());
67         verify(delegateReadTx).read(LogicalDatastoreType.CONFIGURATION, TxTestUtils.getContainerId());
68     }
69
70     @Test
71     public void exists() throws Exception {
72         final YangInstanceIdentifier id = TxTestUtils.getContainerId();
73         when(delegateReadTx.exists(LogicalDatastoreType.CONFIGURATION, id)).thenReturn(
74             FluentFutures.immediateTrueFluentFuture());
75         final FluentFuture<Boolean> exists = tx.exists(LogicalDatastoreType.CONFIGURATION, id);
76         assertTrue(exists.get());
77     }
78
79     @Test
80     public void getIdentifier() throws Exception {
81         final ReadWriteTx<?> tx2 = new ReadWriteTx<>(delegateReadTx, delegateWriteTx);
82         assertNotEquals(tx.getIdentifier(), tx2.getIdentifier());
83     }
84 }