5384856bd64415f5733e9c795c911c532fcc5474
[netconf.git] / netconf / netconf-topology-singleton / src / test / java / org / opendaylight / netconf / topology / singleton / impl / ProxyDOMDataBrokerTest.java
1 /*
2  * Copyright (c) 2018 Inocybe Technologies 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.topology.singleton.impl;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12
13 import akka.actor.ActorSystem;
14 import akka.actor.Status.Success;
15 import akka.testkit.TestProbe;
16 import akka.testkit.javadsl.TestKit;
17 import akka.util.Timeout;
18 import java.net.InetSocketAddress;
19 import java.util.concurrent.TimeUnit;
20 import org.junit.AfterClass;
21 import org.junit.Test;
22 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
23 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
24 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
25 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
26 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
27 import org.opendaylight.netconf.topology.singleton.messages.transactions.DeleteRequest;
28 import org.opendaylight.netconf.topology.singleton.messages.transactions.NewReadTransactionRequest;
29 import org.opendaylight.netconf.topology.singleton.messages.transactions.NewReadWriteTransactionRequest;
30 import org.opendaylight.netconf.topology.singleton.messages.transactions.NewWriteTransactionRequest;
31 import org.opendaylight.netconf.topology.singleton.messages.transactions.ReadRequest;
32 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
33
34 /**
35  * Unit tests for ProxyDOMDataBroker.
36  *
37  * @author Thomas Pantelis
38  */
39 public class ProxyDOMDataBrokerTest {
40     private static final RemoteDeviceId DEVICE_ID =
41             new RemoteDeviceId("dev1", InetSocketAddress.createUnresolved("localhost", 17830));
42
43     private static ActorSystem system = ActorSystem.apply();
44
45     private final TestProbe masterActor = new TestProbe(system);
46     private final ProxyDOMDataBroker proxy = new ProxyDOMDataBroker(DEVICE_ID, masterActor.ref(), system.dispatcher(),
47             Timeout.apply(5, TimeUnit.SECONDS));
48
49     @AfterClass
50     public static void staticTearDown() {
51         TestKit.shutdownActorSystem(system, true);
52     }
53
54     @Test
55     public void testNewReadOnlyTransaction() {
56         final DOMDataTreeReadTransaction tx = proxy.newReadOnlyTransaction();
57         masterActor.expectMsgClass(NewReadTransactionRequest.class);
58         masterActor.reply(new Success(masterActor.ref()));
59
60         assertEquals(DEVICE_ID, tx.getIdentifier());
61
62         tx.read(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
63         masterActor.expectMsgClass(ReadRequest.class);
64     }
65
66     @Test
67     public void testNewWriteOnlyTransaction() {
68         final DOMDataTreeWriteTransaction tx = proxy.newWriteOnlyTransaction();
69         masterActor.expectMsgClass(NewWriteTransactionRequest.class);
70         masterActor.reply(new Success(masterActor.ref()));
71
72         assertEquals(DEVICE_ID, tx.getIdentifier());
73
74         tx.delete(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
75         masterActor.expectMsgClass(DeleteRequest.class);
76     }
77
78     @Test
79     public void testNewReadWriteTransaction() {
80         final DOMDataTreeReadWriteTransaction tx = proxy.newReadWriteTransaction();
81         masterActor.expectMsgClass(NewReadWriteTransactionRequest.class);
82         masterActor.reply(new Success(masterActor.ref()));
83
84         assertEquals(DEVICE_ID, tx.getIdentifier());
85
86         tx.read(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
87         masterActor.expectMsgClass(ReadRequest.class);
88     }
89
90     @Test(expected = UnsupportedOperationException.class)
91     public void testCreateTransactionChain() {
92         proxy.createTransactionChain(null);
93     }
94
95     @Test
96     public void testGetSupportedExtensions() {
97         assertTrue(proxy.getExtensions().isEmpty());
98     }
99 }