X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatabroker%2FClientBackedDataStoreTest.java;h=fa8b1ef99316c7a6ec7532bdb6cc211a246f6bd6;hb=514df5b3d350482fee8ee8f1f5b257c229f7e61a;hp=cf08d3311f36b9357f3bfdd454bcc76d9e30d731;hpb=f41c5e6e6f6e10b36b1e4b1992877e38e718c8fb;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 cf08d3311f..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 @@ -7,12 +7,16 @@ */ package org.opendaylight.controller.cluster.databroker; -import org.junit.Assert; +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 org.junit.Before; 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; @@ -24,31 +28,30 @@ 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( FrontendIdentifier.create(MemberName.forName("local"), FrontendType.forName("unknown")), 0); - private static FrontendIdentifier FRONTEND_IDENTIFIER = FrontendIdentifier.create( + private static final FrontendIdentifier FRONTEND_IDENTIFIER = FrontendIdentifier.create( MemberName.forName("member"), FrontendType.forName("frontend")); private static final ClientIdentifier CLIENT_IDENTIFIER = ClientIdentifier.create(FRONTEND_IDENTIFIER, 0); - private static LocalHistoryIdentifier HISTORY_ID = new LocalHistoryIdentifier(CLIENT_IDENTIFIER, 0); - private static final TransactionIdentifier TRANSACTION_IDENTIFIER = new TransactionIdentifier(HISTORY_ID, 0); + 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; @@ -60,59 +63,53 @@ public class ClientBackedDataStoreTest { private ClientSnapshot clientSnapshot; @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - - final SchemaContext schemaContext = TestModel.createTestContext(); - - Mockito.when(actorContext.getSchemaContext()).thenReturn(schemaContext); - Mockito.when(actorContext.getDatastoreContext()).thenReturn(DatastoreContext.newBuilder().build()); - Mockito.when(clientTransaction.getIdentifier()).thenReturn(TRANSACTION_IDENTIFIER); - Mockito.when(clientSnapshot.getIdentifier()).thenReturn(TRANSACTION_IDENTIFIER); - - Mockito.when(clientActor.getIdentifier()).thenReturn(CLIENT_IDENTIFIER); - Mockito.when(clientActor.createTransaction()).thenReturn(clientTransaction); - Mockito.when(clientActor.createLocalHistory()).thenReturn(clientLocalHistory); - Mockito.when(clientActor.createSnapshot()).thenReturn(clientSnapshot); + public void setUp() { + doReturn(DatastoreContext.newBuilder().build()).when(actorUtils).getDatastoreContext(); + doReturn(TRANSACTION_IDENTIFIER).when(clientTransaction).getIdentifier(); + doReturn(TRANSACTION_IDENTIFIER).when(clientSnapshot).getIdentifier(); + + doReturn(clientTransaction).when(clientActor).createTransaction(); + doReturn(clientLocalHistory).when(clientActor).createLocalHistory(); + doReturn(clientSnapshot).when(clientActor).createSnapshot(); } @Test - public void testCreateTransactionChain() throws Exception { + public void testCreateTransactionChain() { try (ClientBackedDataStore clientBackedDataStore = new ClientBackedDataStore( - actorContext, UNKNOWN_ID, clientActor)) { + actorUtils, UNKNOWN_ID, clientActor)) { final DOMStoreTransactionChain txChain = clientBackedDataStore.createTransactionChain(); - Assert.assertNotNull(txChain); - Mockito.verify(clientActor, Mockito.times(1)).createLocalHistory(); + assertNotNull(txChain); + verify(clientActor, times(1)).createLocalHistory(); } } @Test - public void testNewReadOnlyTransaction() throws Exception { + public void testNewReadOnlyTransaction() { try (ClientBackedDataStore clientBackedDataStore = new ClientBackedDataStore( - actorContext, UNKNOWN_ID, clientActor)) { + actorUtils, UNKNOWN_ID, clientActor)) { final DOMStoreReadTransaction tx = clientBackedDataStore.newReadOnlyTransaction(); - Assert.assertNotNull(tx); - Mockito.verify(clientActor, Mockito.times(1)).createSnapshot(); + assertNotNull(tx); + verify(clientActor, times(1)).createSnapshot(); } } @Test - public void testNewWriteOnlyTransaction() throws Exception { + public void testNewWriteOnlyTransaction() { try (ClientBackedDataStore clientBackedDataStore = new ClientBackedDataStore( - actorContext, UNKNOWN_ID, clientActor)) { + actorUtils, UNKNOWN_ID, clientActor)) { final DOMStoreWriteTransaction tx = clientBackedDataStore.newWriteOnlyTransaction(); - Assert.assertNotNull(tx); - Mockito.verify(clientActor, Mockito.times(1)).createTransaction(); + assertNotNull(tx); + verify(clientActor, times(1)).createTransaction(); } } @Test - public void testNewReadWriteTransaction() throws Exception { + public void testNewReadWriteTransaction() { try (ClientBackedDataStore clientBackedDataStore = new ClientBackedDataStore( - actorContext, UNKNOWN_ID, clientActor)) { + actorUtils, UNKNOWN_ID, clientActor)) { final DOMStoreReadWriteTransaction tx = clientBackedDataStore.newReadWriteTransaction(); - Assert.assertNotNull(tx); - Mockito.verify(clientActor, Mockito.times(1)).createTransaction(); + assertNotNull(tx); + verify(clientActor, times(1)).createTransaction(); } } }