X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatabroker%2Factors%2Fdds%2FAbstractClientHistoryTest.java;h=8b376f2dd0172cc2a45590c80eae012cc8d159b2;hp=48ac3484f7c622030ab66514d74e815f7039a295;hb=refs%2Fchanges%2F61%2F96761%2F2;hpb=1808c7ff4e755fb475253f5b6c3b5ef627a1bdc0 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractClientHistoryTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractClientHistoryTest.java index 48ac3484f7..8b376f2dd0 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractClientHistoryTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractClientHistoryTest.java @@ -7,22 +7,22 @@ */ package org.opendaylight.controller.cluster.databroker.actors.dds; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.CLIENT_ID; -import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.TRANSACTION_ID; import akka.actor.ActorRef; import akka.actor.ActorSelection; import akka.actor.ActorSystem; import com.google.common.primitives.UnsignedLong; import java.util.Optional; -import org.junit.Assert; import org.junit.Test; import org.mockito.Mock; -import org.mockito.Mockito; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.client.AccessClientUtil; import org.opendaylight.controller.cluster.access.client.ClientActorContext; @@ -38,7 +38,7 @@ import scala.concurrent.impl.Promise.DefaultPromise; public abstract class AbstractClientHistoryTest { protected static final String SHARD_NAME = "default"; protected static final String PERSISTENCE_ID = "per-1"; - protected static final LocalHistoryIdentifier HISTORY_ID = new LocalHistoryIdentifier(CLIENT_ID, 1L); + protected static final LocalHistoryIdentifier HISTORY_ID = new LocalHistoryIdentifier(TestUtils.CLIENT_ID, 1L); @Mock private DataTree tree; @@ -70,62 +70,63 @@ public abstract class AbstractClientHistoryTest @Test public void testCreateSnapshotProxy() { - final AbstractProxyTransaction snapshotProxy = object().createSnapshotProxy(TRANSACTION_ID, 0L); - Assert.assertNotNull(snapshotProxy); - Assert.assertNotEquals(TRANSACTION_ID, snapshotProxy.getIdentifier()); + final AbstractProxyTransaction snapshotProxy = object().createSnapshotProxy(TestUtils.TRANSACTION_ID, 0L); + assertNotNull(snapshotProxy); + assertNotEquals(TestUtils.TRANSACTION_ID, snapshotProxy.getIdentifier()); } @Test public void testCreateTransactionProxy() { - AbstractProxyTransaction transactionProxy = object().createTransactionProxy(TRANSACTION_ID, 0L); - Assert.assertNotNull(transactionProxy); - Assert.assertNotEquals(TRANSACTION_ID, transactionProxy.getIdentifier()); + AbstractProxyTransaction transactionProxy = object().createTransactionProxy(TestUtils.TRANSACTION_ID, 0L); + assertNotNull(transactionProxy); + assertNotEquals(TestUtils.TRANSACTION_ID, transactionProxy.getIdentifier()); } @Test public void testState() { - Assert.assertEquals(AbstractClientHistory.State.IDLE, object().state()); + assertEquals(AbstractClientHistory.State.IDLE, object().state()); } @Test public void testUpdateState() { object().updateState(AbstractClientHistory.State.IDLE, AbstractClientHistory.State.CLOSED); - Assert.assertEquals(AbstractClientHistory.State.CLOSED, object().state()); + assertEquals(AbstractClientHistory.State.CLOSED, object().state()); } @Test public void testDoClose() { - object().createTransactionProxy(TRANSACTION_ID, 0L); + object().createTransactionProxy(TestUtils.TRANSACTION_ID, 0L); object().doClose(); - Assert.assertEquals(AbstractClientHistory.State.CLOSED, object().state()); + assertEquals(AbstractClientHistory.State.CLOSED, object().state()); } @Test public void testGetIdentifier() { - Assert.assertEquals(HISTORY_ID, object().getIdentifier()); + assertEquals(HISTORY_ID, object().getIdentifier()); } @Test public void testNextTx() { - Assert.assertTrue(object().nextTx() + 1 == object().nextTx()); + assertEquals(object().nextTx() + 1, object().nextTx()); } @Test public void testResolveShardForPath() { final Long shardForPath = object().resolveShardForPath(YangInstanceIdentifier.empty()); - Assert.assertEquals(0L, shardForPath.longValue()); + assertNotNull(shardForPath); + assertEquals(0L, (long) shardForPath); } @Test public void testLocalAbort() { object().localAbort(new Throwable()); - Assert.assertEquals(AbstractClientHistory.State.CLOSED, object().state()); + assertEquals(AbstractClientHistory.State.CLOSED, object().state()); } @Test public void testOnProxyDestroyed() { - final ProxyHistory proxyHistory = Mockito.mock(ProxyHistory.class); - when(proxyHistory.getIdentifier()).thenReturn(HISTORY_ID); + final ProxyHistory proxyHistory = mock(ProxyHistory.class); + doReturn(HISTORY_ID).when(proxyHistory).getIdentifier(); object().onProxyDestroyed(proxyHistory); verify(proxyHistory).getIdentifier(); @@ -134,13 +135,13 @@ public abstract class AbstractClientHistoryTest @Test public void testCreateTransaction() { final ClientTransaction transaction = object().createTransaction(); - Assert.assertNotNull(transaction); + assertNotNull(transaction); } @Test public void testTakeSnapshot() { final ClientSnapshot clientSnapshot = object().takeSnapshot(); - Assert.assertEquals(object().getIdentifier(), clientSnapshot.getIdentifier().getHistoryId()); + assertEquals(object().getIdentifier(), clientSnapshot.getIdentifier().getHistoryId()); } @Test @@ -153,10 +154,10 @@ public abstract class AbstractClientHistoryTest SHARD_NAME, UnsignedLong.ZERO, Optional.of(tree), 10); final ConnectedClientConnection newConn = AccessClientUtil.createConnectedConnection( clientActorContext(), cookie, info); - object().createSnapshotProxy(TRANSACTION_ID, shard); + object().createSnapshotProxy(TestUtils.TRANSACTION_ID, shard); final HistoryReconnectCohort reconnectCohort = object().startReconnect(newConn); - Assert.assertNotNull(reconnectCohort); + assertNotNull(reconnectCohort); } @Test @@ -169,10 +170,10 @@ public abstract class AbstractClientHistoryTest SHARD_NAME, UnsignedLong.ZERO, Optional.of(tree), 10); final ConnectedClientConnection newConn = AccessClientUtil.createConnectedConnection( clientActorContext(), cookie, info); - object().createSnapshotProxy(TRANSACTION_ID, shard); + object().createSnapshotProxy(TestUtils.TRANSACTION_ID, shard); final HistoryReconnectCohort reconnectCohort = object().startReconnect(newConn); - Assert.assertNull(reconnectCohort); + assertNull(reconnectCohort); } protected static ActorUtils createActorUtilsMock(final ActorSystem system, final ActorRef actor) { @@ -181,7 +182,7 @@ public abstract class AbstractClientHistoryTest final ActorSelection selection = system.actorSelection(actor.path()); final PrimaryShardInfo shardInfo = new PrimaryShardInfo(selection, (short) 0); promise.success(shardInfo); - when(mock.findPrimaryShardAsync(any())).thenReturn(promise.future()); + doReturn(promise.future()).when(mock).findPrimaryShardAsync(any()); return mock; } } \ No newline at end of file