X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatabroker%2FClientBackedDataStoreTest.java;h=fa8b1ef99316c7a6ec7532bdb6cc211a246f6bd6;hb=514df5b3d350482fee8ee8f1f5b257c229f7e61a;hp=f423f614f85302ffd1f0baa583d79b23f6a99c9d;hpb=7c7bfd6155f65f58343d3ef1a18378c263a5deed;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedDataStoreTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedDataStoreTest.java index f423f614f8..fa8b1ef993 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedDataStoreTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ClientBackedDataStoreTest.java @@ -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(); } } }