Update MRI projects for Aluminium
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / 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 package org.opendaylight.netconf.sal.connect.netconf.sal.tx;
9
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.mock;
13 import static org.mockito.Mockito.verify;
14
15 import java.net.InetSocketAddress;
16 import org.junit.Assert;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.mockito.Mock;
20 import org.mockito.Mockito;
21 import org.mockito.MockitoAnnotations;
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.util.NetconfBaseOps;
26 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
27 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
28 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
29 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
30 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
31 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
32 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
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() {
46         MockitoAnnotations.initMocks(this);
47         doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(mockedNode))).when(rpc)
48                 .invokeRpc(any(SchemaPath.class), any(ContainerNode.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(EffectiveModelContext.class));
55
56         final ReadOnlyTx readOnlyTx =
57                 new ReadOnlyTx(netconfOps, new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)));
58
59         readOnlyTx.read(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.create());
60         verify(rpc).invokeRpc(Mockito.eq(NetconfMessageTransformUtil.toPath(
61                 NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME)), any(ContainerNode.class));
62         readOnlyTx.read(LogicalDatastoreType.OPERATIONAL, PATH);
63         verify(rpc).invokeRpc(Mockito.eq(NetconfMessageTransformUtil.toPath(
64                 NetconfMessageTransformUtil.NETCONF_GET_QNAME)), any(ContainerNode.class));
65     }
66
67     @Test
68     public void testExists() throws Exception {
69         final NetconfBaseOps netconfOps = new NetconfBaseOps(rpc, mock(EffectiveModelContext.class));
70
71         final ReadOnlyTx readOnlyTx =
72                 new ReadOnlyTx(netconfOps, new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)));
73
74         readOnlyTx.exists(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.create());
75         verify(rpc).invokeRpc(Mockito.eq(NetconfMessageTransformUtil.toPath(
76                 NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME)), any(ContainerNode.class));
77         readOnlyTx.exists(LogicalDatastoreType.OPERATIONAL, PATH);
78         verify(rpc).invokeRpc(Mockito.eq(NetconfMessageTransformUtil.toPath(
79                 NetconfMessageTransformUtil.NETCONF_GET_QNAME)), any(ContainerNode.class));
80     }
81
82     @Test
83     public void testIdentifier() throws Exception {
84         final NetconfBaseOps netconfOps = new NetconfBaseOps(rpc, mock(EffectiveModelContext.class));
85         final ReadOnlyTx tx1 =
86                 new ReadOnlyTx(netconfOps, new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)));
87         final ReadOnlyTx tx2 =
88                 new ReadOnlyTx(netconfOps, new RemoteDeviceId("a", new InetSocketAddress("localhost", 196)));
89         Assert.assertNotEquals(tx1.getIdentifier(), tx2.getIdentifier());
90     }
91 }