2 * Copyright (c) 2015 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.Mockito.doReturn;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.verify;
16 import com.google.common.util.concurrent.Futures;
18 import java.net.InetSocketAddress;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.mockito.Mock;
23 import org.mockito.Mockito;
24 import org.mockito.MockitoAnnotations;
25 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
26 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException;
27 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
28 import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
29 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
30 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
31 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
32 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
33 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
34 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
35 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
37 public class ReadOnlyTxTest {
39 private static final YangInstanceIdentifier path = YangInstanceIdentifier.create();
42 private DOMRpcService rpc;
44 private NormalizedNode<?, ?> mockedNode;
47 public void setUp() throws DataNormalizationException {
48 MockitoAnnotations.initMocks(this);
49 doReturn(Futures.immediateCheckedFuture(new DefaultDOMRpcResult(mockedNode))).when(rpc)
50 .invokeRpc(any(SchemaPath.class), any(NormalizedNode.class));
51 doReturn("node").when(mockedNode).toString();
55 public void testRead() throws Exception {
56 final NetconfBaseOps netconfOps = new NetconfBaseOps(rpc, mock(SchemaContext.class));
58 final ReadOnlyTx readOnlyTx = new ReadOnlyTx(netconfOps, new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)));
60 readOnlyTx.read(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.create());
61 verify(rpc).invokeRpc(Mockito.eq(NetconfMessageTransformUtil.toPath(NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME)), any(NormalizedNode.class));
62 readOnlyTx.read(LogicalDatastoreType.OPERATIONAL, path);
63 verify(rpc).invokeRpc(Mockito.eq(NetconfMessageTransformUtil.toPath(NetconfMessageTransformUtil.NETCONF_GET_QNAME)), any(NormalizedNode.class));