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.controller.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.verify;
15 import java.net.InetSocketAddress;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.mockito.Mock;
19 import org.mockito.Mockito;
20 import org.mockito.MockitoAnnotations;
21 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
22 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException;
23 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizer;
24 import org.opendaylight.controller.sal.connect.netconf.util.NetconfBaseOps;
25 import org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil;
26 import org.opendaylight.controller.sal.connect.util.RemoteDeviceId;
27 import org.opendaylight.controller.sal.core.api.RpcImplementation;
28 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
29 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
30 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
32 public class ReadOnlyTxTest {
34 private static final YangInstanceIdentifier path = YangInstanceIdentifier.create();
37 private RpcImplementation rpc;
39 private DataNormalizer normalizer;
41 private CompositeNode mockedNode;
44 public void setUp() throws DataNormalizationException {
45 MockitoAnnotations.initMocks(this);
46 doReturn(path).when(normalizer).toLegacy(any(YangInstanceIdentifier.class));
47 doReturn(com.google.common.util.concurrent.Futures.immediateFuture(RpcResultBuilder.success(mockedNode).build())).when(rpc).invokeRpc(any(org.opendaylight.yangtools.yang.common.QName.class), any(CompositeNode.class));
48 doReturn("node").when(mockedNode).toString();
52 public void testRead() throws Exception {
53 final NetconfBaseOps netconfOps = new NetconfBaseOps(rpc);
55 final ReadOnlyTx readOnlyTx = new ReadOnlyTx(netconfOps, normalizer, new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)));
57 readOnlyTx.read(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.create());
58 verify(rpc).invokeRpc(Mockito.same(NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME), any(CompositeNode.class));
59 readOnlyTx.read(LogicalDatastoreType.OPERATIONAL, path);
60 verify(rpc).invokeRpc(Mockito.same(NetconfMessageTransformUtil.NETCONF_GET_QNAME), any(CompositeNode.class));