2 * Copyright (c) 2018 Inocybe Technologies 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
8 package org.opendaylight.netconf.topology.singleton.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
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;
35 * Unit tests for ProxyDOMDataBroker.
37 * @author Thomas Pantelis
39 public class ProxyDOMDataBrokerTest {
40 private static final RemoteDeviceId DEVICE_ID =
41 new RemoteDeviceId("dev1", InetSocketAddress.createUnresolved("localhost", 17830));
43 private static ActorSystem system = ActorSystem.apply();
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));
50 public static void staticTearDown() {
51 TestKit.shutdownActorSystem(system, true);
55 public void testNewReadOnlyTransaction() {
56 final DOMDataTreeReadTransaction tx = proxy.newReadOnlyTransaction();
57 masterActor.expectMsgClass(NewReadTransactionRequest.class);
58 masterActor.reply(new Success(masterActor.ref()));
60 assertEquals(DEVICE_ID, tx.getIdentifier());
62 tx.read(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
63 masterActor.expectMsgClass(ReadRequest.class);
67 public void testNewWriteOnlyTransaction() {
68 final DOMDataTreeWriteTransaction tx = proxy.newWriteOnlyTransaction();
69 masterActor.expectMsgClass(NewWriteTransactionRequest.class);
70 masterActor.reply(new Success(masterActor.ref()));
72 assertEquals(DEVICE_ID, tx.getIdentifier());
74 tx.delete(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
75 masterActor.expectMsgClass(DeleteRequest.class);
79 public void testNewReadWriteTransaction() {
80 final DOMDataTreeReadWriteTransaction tx = proxy.newReadWriteTransaction();
81 masterActor.expectMsgClass(NewReadWriteTransactionRequest.class);
82 masterActor.reply(new Success(masterActor.ref()));
84 assertEquals(DEVICE_ID, tx.getIdentifier());
86 tx.read(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
87 masterActor.expectMsgClass(ReadRequest.class);
90 @Test(expected = UnsupportedOperationException.class)
91 public void testCreateTransactionChain() {
92 proxy.createTransactionChain(null);
96 public void testGetSupportedExtensions() {
97 assertTrue(proxy.getExtensions().isEmpty());