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