Bump MRI upstreams
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / sal / connect / netconf / sal / tx / WriteCandidateTxTest.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.sal.connect.netconf.sal.tx;
9
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.ArgumentMatchers.eq;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.times;
14 import static org.mockito.Mockito.verify;
15
16 import java.net.InetSocketAddress;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.mockito.Mock;
21 import org.mockito.junit.MockitoJUnitRunner;
22 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
23 import org.opendaylight.mdsal.dom.api.DOMRpcService;
24 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
25 import org.opendaylight.netconf.sal.connect.netconf.AbstractTestModelTest;
26 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
27 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
28 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
29 import org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext;
30 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
31
32 @RunWith(MockitoJUnitRunner.StrictStubs.class)
33 public class WriteCandidateTxTest extends AbstractTestModelTest {
34     @Mock
35     private DOMRpcService rpc;
36     private NetconfBaseOps netconfOps;
37     private RemoteDeviceId id;
38
39     @Before
40     public void setUp() {
41         doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult())).when(rpc).invokeRpc(any(), any());
42         netconfOps = new NetconfBaseOps(rpc, new EmptyMountPointContext(SCHEMA_CONTEXT));
43         id = new RemoteDeviceId("device1", InetSocketAddress.createUnresolved("0.0.0.0", 17830));
44     }
45
46     @Test
47     public void testSubmit() throws Exception {
48         final WriteCandidateTx tx = new WriteCandidateTx(id, netconfOps, true);
49         //check, if lock is called
50         verify(rpc).invokeRpc(eq(NetconfMessageTransformUtil.NETCONF_LOCK_QNAME), any());
51
52         tx.put(LogicalDatastoreType.CONFIGURATION, TxTestUtils.getContainerId(), TxTestUtils.getContainerNode());
53         tx.merge(LogicalDatastoreType.CONFIGURATION, TxTestUtils.getLeafId(), TxTestUtils.getLeafNode());
54         //check, if both edits are called
55         verify(rpc, times(2)).invokeRpc(eq(NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME), any());
56         tx.commit().get();
57         //check, if unlock is called
58         verify(rpc).invokeRpc(NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME,
59                 NetconfMessageTransformUtil.COMMIT_RPC_CONTENT);
60         verify(rpc).invokeRpc(eq(NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME), any());
61     }
62 }