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
9 package org.opendaylight.netconf.sal.connect.netconf.sal.tx;
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Matchers.eq;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.never;
15 import static org.mockito.Mockito.times;
16 import static org.mockito.Mockito.verify;
18 import com.google.common.util.concurrent.Futures;
19 import java.net.InetSocketAddress;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.mockito.Mock;
23 import org.mockito.MockitoAnnotations;
24 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
25 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
26 import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
27 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
28 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
29 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
30 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
31 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
32 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
34 public class WriteRunningTxTest {
37 private DOMRpcService rpc;
38 private NetconfBaseOps netconfOps;
39 private RemoteDeviceId id;
42 public void setUp() throws Exception {
43 MockitoAnnotations.initMocks(this);
44 final SchemaContext schemaContext =
45 YangParserTestUtils.parseYangResource("/schemas/test-module.yang");
46 doReturn(Futures.immediateCheckedFuture(new DefaultDOMRpcResult())).when(rpc).invokeRpc(any(), any());
47 netconfOps = new NetconfBaseOps(rpc, schemaContext);
48 id = new RemoteDeviceId("device1", InetSocketAddress.createUnresolved("0.0.0.0", 17830));
52 public void testSubmit() throws Exception {
53 final WriteRunningTx tx = new WriteRunningTx(id, netconfOps, true);
54 //check, if lock is called
55 verify(rpc).invokeRpc(eq(SchemaPath.create(true, NetconfMessageTransformUtil.NETCONF_LOCK_QNAME)), any());
56 tx.put(LogicalDatastoreType.CONFIGURATION, TxTestUtils.getContainerId(), TxTestUtils.getContainerNode());
57 tx.merge(LogicalDatastoreType.CONFIGURATION, TxTestUtils.getLeafId(), TxTestUtils.getLeafNode());
58 //check, if no edit-config is called before submit
60 .invokeRpc(eq(SchemaPath.create(true, NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME)), any());
62 //check, if both edits are called
64 .invokeRpc(eq(SchemaPath.create(true, NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME)), any());
65 //check, if unlock is called
66 verify(rpc).invokeRpc(eq(SchemaPath.create(true, NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME)), any());