Merge "Fixup Augmentable and Identifiable methods changing"
[netconf.git] / netconf / netconf-topology-singleton / src / test / java / org / opendaylight / netconf / topology / singleton / impl / tx / WriteOnlyTransactionTest.java
index 3e86bd2572da3208bb965464d1dea8813a36637d..a13c9536254e6101c2b21f2bcf22fea53e1f2ae2 100644 (file)
@@ -11,7 +11,6 @@ package org.opendaylight.netconf.topology.singleton.impl.tx;
 import static junit.framework.TestCase.assertNull;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
@@ -28,11 +27,10 @@ import akka.testkit.JavaTestKit;
 import akka.testkit.TestActorRef;
 import akka.util.Timeout;
 import com.google.common.collect.Lists;
+import com.google.common.net.InetAddresses;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
-import java.net.InetAddress;
 import java.net.InetSocketAddress;
-import java.net.UnknownHostException;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 import org.junit.After;
@@ -46,6 +44,7 @@ import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFaile
 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.netconf.topology.singleton.impl.ProxyDOMDataBroker;
@@ -71,42 +70,56 @@ public class WriteOnlyTransactionTest {
     @Rule
     public final ExpectedException exception = ExpectedException.none();
 
-    private ActorRef masterRef;
-    private ProxyDOMDataBroker slaveDataBroker;
-    private List<SourceIdentifier> sourceIdentifiers;
     @Mock
     private DOMDataBroker deviceDataBroker;
     @Mock
     private DOMDataWriteTransaction writeTx;
     @Mock
     private DOMRpcService domRpcService;
+    @Mock
+    private DOMMountPointService mountPointService;
+    private ActorRef masterRef;
+    private ProxyDOMDataBroker slaveDataBroker;
+    private List<SourceIdentifier> sourceIdentifiers;
+    private NormalizedNode<?, ?> testNode;
+    private YangInstanceIdentifier instanceIdentifier;
+    private LogicalDatastoreType storeType;
 
     @Before
-    public void setup() throws UnknownHostException {
+    public void setup() throws Exception {
         initMocks(this);
 
         system = ActorSystem.create();
 
         final RemoteDeviceId remoteDeviceId = new RemoteDeviceId("netconf-topology",
-                new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 9999));
+                new InetSocketAddress(InetAddresses.forString("127.0.0.1"), 9999));
 
         final NetconfTopologySetup setup = mock(NetconfTopologySetup.class);
+        doReturn(Duration.apply(0, TimeUnit.SECONDS)).when(setup).getIdleTimeout();
         final Props props = NetconfNodeActor.props(setup, remoteDeviceId, DEFAULT_SCHEMA_REPOSITORY,
-                DEFAULT_SCHEMA_REPOSITORY, TIMEOUT);
+                DEFAULT_SCHEMA_REPOSITORY, TIMEOUT, mountPointService);
 
         masterRef = TestActorRef.create(system, props, "master_read");
 
         sourceIdentifiers = Lists.newArrayList();
 
-        writeTx = mock(DOMDataWriteTransaction.class);
         final DOMDataReadOnlyTransaction readTx = mock(DOMDataReadOnlyTransaction.class);
 
         doReturn(writeTx).when(deviceDataBroker).newWriteOnlyTransaction();
         doReturn(readTx).when(deviceDataBroker).newReadOnlyTransaction();
+        doNothing().when(writeTx).put(storeType, instanceIdentifier, testNode);
+        doNothing().when(writeTx).merge(storeType, instanceIdentifier, testNode);
+        doNothing().when(writeTx).delete(storeType, instanceIdentifier);
 
         // Create slave data broker for testing proxy
         slaveDataBroker =
                 new ProxyDOMDataBroker(system, remoteDeviceId, masterRef, Timeout.apply(5, TimeUnit.SECONDS));
+        initializeDataTest();
+        testNode = ImmutableContainerNodeBuilder.create()
+                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create("", "TestQname")))
+                .withChild(ImmutableNodes.leafNode(QName.create("", "NodeQname"), "foo")).build();
+        instanceIdentifier = YangInstanceIdentifier.EMPTY;
+        storeType = LogicalDatastoreType.CONFIGURATION;
     }
 
     @After
@@ -117,85 +130,43 @@ public class WriteOnlyTransactionTest {
 
     @Test
     public void testPut() throws Exception {
-        /* Initialize data on master */
-
-        initializeDataTest();
-
-        final YangInstanceIdentifier instanceIdentifier = YangInstanceIdentifier.EMPTY;
-        final LogicalDatastoreType storeType = LogicalDatastoreType.CONFIGURATION;
-        final NormalizedNode<?, ?> testNode = ImmutableContainerNodeBuilder.create()
-                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create("TestQname")))
-                .withChild(ImmutableNodes.leafNode(QName.create("NodeQname"), "foo")).build();
-
         // Test of invoking put on master through slave proxy
-
-        doNothing().when(writeTx).put(storeType, instanceIdentifier, testNode);
-
         final DOMDataWriteTransaction wTx = slaveDataBroker.newWriteOnlyTransaction();
         wTx.put(storeType, instanceIdentifier, testNode);
 
         verify(writeTx, timeout(2000)).put(storeType, instanceIdentifier, testNode);
 
         wTx.cancel();
-
     }
 
     @Test
     public void testMerge() throws Exception {
-
-        /* Initialize data on master */
-
-        initializeDataTest();
-
-        final YangInstanceIdentifier instanceIdentifier = YangInstanceIdentifier.EMPTY;
-        final LogicalDatastoreType storeType = LogicalDatastoreType.CONFIGURATION;
-        final NormalizedNode<?, ?> testNode = ImmutableContainerNodeBuilder.create()
-                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create("TestQname")))
-                .withChild(ImmutableNodes.leafNode(QName.create("NodeQname"), "foo")).build();
         // Test of invoking merge on master through slave proxy
-
-        doNothing().when(writeTx).merge(storeType, instanceIdentifier, testNode);
         final DOMDataWriteTransaction wTx = slaveDataBroker.newWriteOnlyTransaction();
         wTx.merge(storeType, instanceIdentifier, testNode);
 
         verify(writeTx, timeout(2000)).merge(storeType, instanceIdentifier, testNode);
 
         wTx.cancel();
-
     }
 
     @Test
     public void testDelete() throws Exception {
-
-        /* Initialize data on master */
-
-        initializeDataTest();
-
-        final YangInstanceIdentifier instanceIdentifier = YangInstanceIdentifier.EMPTY;
-        final LogicalDatastoreType storeType = LogicalDatastoreType.CONFIGURATION;
         // Test of invoking delete on master through slave proxy
-
-        doNothing().when(writeTx).delete(storeType, instanceIdentifier);
         final DOMDataWriteTransaction wTx = slaveDataBroker.newWriteOnlyTransaction();
-        wTx.delete(storeType, instanceIdentifier);
+        wTx.delete(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
         wTx.cancel();
 
-        verify(writeTx, timeout(2000)).delete(storeType, instanceIdentifier);
-
+        verify(writeTx, timeout(2000)).delete(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
     }
 
     @Test
     public void testSubmit() throws Exception {
-
-        /* Initialize data on master */
-
-        initializeDataTest();
+        final CheckedFuture<Void, TransactionCommitFailedException> resultSubmit = Futures.immediateCheckedFuture(null);
+        doReturn(resultSubmit).when(writeTx).submit();
 
         // Without Tx
-
         final DOMDataWriteTransaction wTx = slaveDataBroker.newWriteOnlyTransaction();
-        final CheckedFuture<Void, TransactionCommitFailedException> resultSubmit = Futures.immediateCheckedFuture(null);
-        doReturn(resultSubmit).when(writeTx).submit();
 
         final CheckedFuture<Void, TransactionCommitFailedException> resultSubmitResponse = wTx.submit();
 
@@ -206,19 +177,14 @@ public class WriteOnlyTransactionTest {
 
     @Test
     public void testSubmitWithOperation() throws Exception {
-
-        /* Initialize data on master */
-
-        initializeDataTest();
+        final CheckedFuture<Void, TransactionCommitFailedException> resultSubmitTx =
+                Futures.immediateCheckedFuture(null);
+        doReturn(resultSubmitTx).when(writeTx).submit();
         // With Tx
         final DOMDataWriteTransaction wTx = slaveDataBroker.newWriteOnlyTransaction();
-        doNothing().when(writeTx).delete(any(), any());
         wTx.delete(LogicalDatastoreType.CONFIGURATION,
                 YangInstanceIdentifier.EMPTY);
 
-        final CheckedFuture<Void, TransactionCommitFailedException> resultSubmitTx = Futures.immediateCheckedFuture(null);
-        doReturn(resultSubmitTx).when(writeTx).submit();
-
         final CheckedFuture<Void, TransactionCommitFailedException> resultSubmitTxResponse = wTx.submit();
 
         final Object resultTx = resultSubmitTxResponse.checkedGet(TIMEOUT_SEC, TimeUnit.SECONDS);
@@ -228,36 +194,25 @@ public class WriteOnlyTransactionTest {
 
     @Test
     public void testSubmitFail() throws Exception {
-
-        /* Initialize data on master */
-
-        initializeDataTest();
-        final DOMDataWriteTransaction wTx = slaveDataBroker.newWriteOnlyTransaction();
-        wTx.delete(LogicalDatastoreType.CONFIGURATION,
-                YangInstanceIdentifier.EMPTY);
-
         final TransactionCommitFailedException throwable = new TransactionCommitFailedException("Fail", null);
-        final CheckedFuture<Void,TransactionCommitFailedException> resultThrowable =
+        final CheckedFuture<Void, TransactionCommitFailedException> resultThrowable =
                 Futures.immediateFailedCheckedFuture(throwable);
-
         doReturn(resultThrowable).when(writeTx).submit();
 
+        final DOMDataWriteTransaction wTx = slaveDataBroker.newWriteOnlyTransaction();
+        wTx.delete(LogicalDatastoreType.CONFIGURATION,
+                YangInstanceIdentifier.EMPTY);
         final CheckedFuture<Void, TransactionCommitFailedException> resultThrowableResponse =
                 wTx.submit();
-
         exception.expect(TransactionCommitFailedException.class);
         resultThrowableResponse.checkedGet(TIMEOUT_SEC, TimeUnit.SECONDS);
     }
 
     @Test
     public void testCancel() throws Exception {
-
-        /* Initialize data on master */
-
-        initializeDataTest();
+        doReturn(true).when(writeTx).cancel();
 
         // Without Tx
-        doReturn(true).when(writeTx).cancel();
         final DOMDataWriteTransaction wTx = slaveDataBroker.newWriteOnlyTransaction();
         final Boolean resultFalseNoTx = wTx.cancel();
         assertEquals(true, resultFalseNoTx);
@@ -265,25 +220,18 @@ public class WriteOnlyTransactionTest {
 
     @Test
     public void testCancelWithOperation() throws Exception {
-
-        /* Initialize data on master */
-
-        initializeDataTest();
+        doReturn(true).when(writeTx).cancel();
 
         // With Tx, readWriteTx test
-
         final DOMDataWriteTransaction wTx = slaveDataBroker.newWriteOnlyTransaction();
-        doNothing().when(writeTx).delete(any(), any());
         wTx.delete(LogicalDatastoreType.CONFIGURATION,
                 YangInstanceIdentifier.EMPTY);
 
-        doReturn(true).when(writeTx).cancel();
         final Boolean resultTrue = wTx.cancel();
         assertEquals(true, resultTrue);
 
         final Boolean resultFalse = wTx.cancel();
         assertEquals(false, resultFalse);
-
     }
 
     private void initializeDataTest() throws Exception {