Update sal-distributed-datastore tests a bit
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / databroker / ClientBackedDataStoreTest.java
index f423f614f85302ffd1f0baa583d79b23f6a99c9d..fa8b1ef99316c7a6ec7532bdb6cc211a246f6bd6 100644 (file)
@@ -8,16 +8,15 @@
 package org.opendaylight.controller.cluster.databroker;
 
 import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
 
-import org.junit.AfterClass;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
@@ -29,14 +28,13 @@ import org.opendaylight.controller.cluster.databroker.actors.dds.ClientSnapshot;
 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction;
 import org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient;
 import org.opendaylight.controller.cluster.datastore.DatastoreContext;
-import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
-import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
+import org.opendaylight.controller.cluster.datastore.utils.ActorUtils;
 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction;
 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction;
 import org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain;
 import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class ClientBackedDataStoreTest {
 
     private static final ClientIdentifier UNKNOWN_ID = ClientIdentifier.create(
@@ -46,16 +44,14 @@ public class ClientBackedDataStoreTest {
             MemberName.forName("member"), FrontendType.forName("frontend"));
     private static final ClientIdentifier CLIENT_IDENTIFIER = ClientIdentifier.create(FRONTEND_IDENTIFIER, 0);
 
-    private static final LocalHistoryIdentifier HISTORY_ID = new LocalHistoryIdentifier(CLIENT_IDENTIFIER, 0);
-    private static final TransactionIdentifier TRANSACTION_IDENTIFIER = new TransactionIdentifier(HISTORY_ID, 0);
-
-    private static SchemaContext SCHEMA_CONTEXT;
+    private static final TransactionIdentifier TRANSACTION_IDENTIFIER =
+        new TransactionIdentifier(new LocalHistoryIdentifier(CLIENT_IDENTIFIER, 0), 0);
 
     @Mock
     private DataStoreClient clientActor;
 
     @Mock
-    private ActorContext actorContext;
+    private ActorUtils actorUtils;
 
     @Mock
     private ClientLocalHistory clientLocalHistory;
@@ -66,68 +62,54 @@ public class ClientBackedDataStoreTest {
     @Mock
     private ClientSnapshot clientSnapshot;
 
-    @BeforeClass
-    public static void beforeClass() {
-        SCHEMA_CONTEXT = TestModel.createTestContext();
-    }
-
-    @AfterClass
-    public static void afterClass() {
-        SCHEMA_CONTEXT = null;
-    }
-
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-
-        when(actorContext.getSchemaContext()).thenReturn(SCHEMA_CONTEXT);
-        when(actorContext.getDatastoreContext()).thenReturn(DatastoreContext.newBuilder().build());
-        when(clientTransaction.getIdentifier()).thenReturn(TRANSACTION_IDENTIFIER);
-        when(clientSnapshot.getIdentifier()).thenReturn(TRANSACTION_IDENTIFIER);
+        doReturn(DatastoreContext.newBuilder().build()).when(actorUtils).getDatastoreContext();
+        doReturn(TRANSACTION_IDENTIFIER).when(clientTransaction).getIdentifier();
+        doReturn(TRANSACTION_IDENTIFIER).when(clientSnapshot).getIdentifier();
 
-        when(clientActor.getIdentifier()).thenReturn(CLIENT_IDENTIFIER);
-        when(clientActor.createTransaction()).thenReturn(clientTransaction);
-        when(clientActor.createLocalHistory()).thenReturn(clientLocalHistory);
-        when(clientActor.createSnapshot()).thenReturn(clientSnapshot);
+        doReturn(clientTransaction).when(clientActor).createTransaction();
+        doReturn(clientLocalHistory).when(clientActor).createLocalHistory();
+        doReturn(clientSnapshot).when(clientActor).createSnapshot();
     }
 
     @Test
     public void testCreateTransactionChain() {
         try (ClientBackedDataStore clientBackedDataStore = new ClientBackedDataStore(
-                actorContext, UNKNOWN_ID, clientActor)) {
+                actorUtils, UNKNOWN_ID, clientActor)) {
             final DOMStoreTransactionChain txChain = clientBackedDataStore.createTransactionChain();
             assertNotNull(txChain);
-            verify(clientActor, Mockito.times(1)).createLocalHistory();
+            verify(clientActor, times(1)).createLocalHistory();
         }
     }
 
     @Test
     public void testNewReadOnlyTransaction() {
         try (ClientBackedDataStore clientBackedDataStore = new ClientBackedDataStore(
-                actorContext, UNKNOWN_ID, clientActor)) {
+                actorUtils, UNKNOWN_ID, clientActor)) {
             final DOMStoreReadTransaction tx = clientBackedDataStore.newReadOnlyTransaction();
             assertNotNull(tx);
-            verify(clientActor, Mockito.times(1)).createSnapshot();
+            verify(clientActor, times(1)).createSnapshot();
         }
     }
 
     @Test
     public void testNewWriteOnlyTransaction() {
         try (ClientBackedDataStore clientBackedDataStore = new ClientBackedDataStore(
-                actorContext, UNKNOWN_ID, clientActor)) {
+                actorUtils, UNKNOWN_ID, clientActor)) {
             final DOMStoreWriteTransaction tx = clientBackedDataStore.newWriteOnlyTransaction();
             assertNotNull(tx);
-            verify(clientActor, Mockito.times(1)).createTransaction();
+            verify(clientActor, times(1)).createTransaction();
         }
     }
 
     @Test
     public void testNewReadWriteTransaction() {
         try (ClientBackedDataStore clientBackedDataStore = new ClientBackedDataStore(
-                actorContext, UNKNOWN_ID, clientActor)) {
+                actorUtils, UNKNOWN_ID, clientActor)) {
             final DOMStoreReadWriteTransaction tx = clientBackedDataStore.newReadWriteTransaction();
             assertNotNull(tx);
-            verify(clientActor, Mockito.times(1)).createTransaction();
+            verify(clientActor, times(1)).createTransaction();
         }
     }
 }