Deprecate DOMDataTreeProducer-related classes
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / sharding / DistributedShardFrontendTest.java
index 6a346202fb0469b4f0ad76441978ed1e1acebcb6..aba233fe6f074ea6613f90b30433a8607e9b9e73 100644 (file)
@@ -5,12 +5,13 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.controller.cluster.sharding;
 
+import static org.hamcrest.CoreMatchers.hasItems;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
@@ -20,6 +21,7 @@ import static org.mockito.Mockito.verify;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Collections;
+import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
@@ -29,7 +31,7 @@ import org.opendaylight.controller.cluster.databroker.actors.dds.ClientLocalHist
 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction;
 import org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient;
 import org.opendaylight.controller.cluster.datastore.DistributedDataStore;
-import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
+import org.opendaylight.controller.cluster.datastore.utils.ActorUtils;
 import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper;
 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
@@ -42,18 +44,19 @@ import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
 
+@Deprecated(forRemoval = true)
 public class DistributedShardFrontendTest {
 
     private static final DOMDataTreeIdentifier ROOT =
-            new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
+            new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty());
     private static final ListenableFuture<Object> SUCCESS_FUTURE = Futures.immediateFuture(null);
 
     private ShardedDOMDataTree shardedDOMDataTree;
@@ -64,19 +67,19 @@ public class DistributedShardFrontendTest {
     private DOMDataTreeWriteCursor cursor;
 
     private static final YangInstanceIdentifier OUTER_LIST_YID = TestModel.OUTER_LIST_PATH.node(
-            new NodeIdentifierWithPredicates(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1));
+            NodeIdentifierWithPredicates.of(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1));
     private static final DOMDataTreeIdentifier OUTER_LIST_ID =
             new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, OUTER_LIST_YID);
 
     @Captor
-    private ArgumentCaptor<YangInstanceIdentifier.PathArgument> pathArgumentCaptor;
+    private ArgumentCaptor<PathArgument> pathArgumentCaptor;
     @Captor
     private ArgumentCaptor<NormalizedNode<?, ?>> nodeCaptor;
 
     private DOMStoreThreePhaseCommitCohort commitCohort;
 
     @Before
-    public void setUp() throws Exception {
+    public void setUp() {
         MockitoAnnotations.initMocks(this);
         shardedDOMDataTree = new ShardedDOMDataTree();
         client = mock(DataStoreClient.class);
@@ -108,10 +111,9 @@ public class DistributedShardFrontendTest {
 
     @Test
     public void testClientTransaction() throws Exception {
-
         final DistributedDataStore distributedDataStore = mock(DistributedDataStore.class);
-        final ActorContext context = mock(ActorContext.class);
-        doReturn(context).when(distributedDataStore).getActorContext();
+        final ActorUtils context = mock(ActorUtils.class);
+        doReturn(context).when(distributedDataStore).getActorUtils();
         doReturn(SchemaContextHelper.full()).when(context).getSchemaContext();
 
         final DistributedShardFrontend rootShard = new DistributedShardFrontend(distributedDataStore, client, ROOT);
@@ -157,22 +159,18 @@ public class DistributedShardFrontendTest {
         //check the lower shard got the correct modification
         verify(outerListCursor, times(2)).write(pathArgumentCaptor.capture(), nodeCaptor.capture());
 
-        final YangInstanceIdentifier.PathArgument expectedYid = new NodeIdentifier(TestModel.ID_QNAME);
-        final YangInstanceIdentifier.PathArgument actualIdYid = pathArgumentCaptor.getAllValues().get(0);
-        assertEquals(expectedYid, actualIdYid);
-
-        final YangInstanceIdentifier.PathArgument expectedInnerYid = new NodeIdentifier(TestModel.INNER_LIST_QNAME);
-        final YangInstanceIdentifier.PathArgument actualInnerListYid = pathArgumentCaptor.getAllValues().get(1);
-        assertEquals(expectedInnerYid, actualInnerListYid);
-
-        final LeafNode<Integer> actualIdNode = (LeafNode<Integer>) nodeCaptor.getAllValues().get(0);
-        assertEquals(ImmutableNodes.leafNode(TestModel.ID_QNAME, 1), actualIdNode);
+        final List<PathArgument> capturedArgs = pathArgumentCaptor.getAllValues();
+        assertEquals(2, capturedArgs.size());
+        assertThat(capturedArgs,
+            hasItems(new NodeIdentifier(TestModel.ID_QNAME), new NodeIdentifier(TestModel.INNER_LIST_QNAME)));
 
-        final MapNode actualInnerListNode = (MapNode) nodeCaptor.getAllValues().get(1);
-        assertEquals(createInnerMapNode(1), actualInnerListNode);
+        final List<NormalizedNode<?, ?>> capturedValues = nodeCaptor.getAllValues();
+        assertEquals(2, capturedValues.size());
+        assertThat(capturedValues,
+            hasItems(ImmutableNodes.leafNode(TestModel.ID_QNAME, 1), createInnerMapNode(1)));
 
         txCursor.close();
-        tx.submit().checkedGet();
+        tx.commit().get();
 
         verify(commitCohort, times(2)).canCommit();
         verify(commitCohort, times(2)).preCommit();