Add AbstractTransactionCommitCohort unit tests
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / databroker / actors / dds / EmptyTransactionCommitCohortTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.databroker.actors.dds;
9
10 import static org.mockito.Mockito.verify;
11 import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.TRANSACTION_ID;
12 import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.getWithTimeout;
13
14 import com.google.common.util.concurrent.ListenableFuture;
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.mockito.Mock;
19 import org.mockito.MockitoAnnotations;
20
21 public class EmptyTransactionCommitCohortTest {
22
23     @Mock
24     private AbstractClientHistory history;
25
26     private EmptyTransactionCommitCohort cohort;
27
28     @Before
29     public void setUp() throws Exception {
30         MockitoAnnotations.initMocks(this);
31         cohort = new EmptyTransactionCommitCohort(history, TRANSACTION_ID);
32     }
33
34     @Test
35     public void testCanCommit() throws Exception {
36         final ListenableFuture<Boolean> canCommit = cohort.canCommit();
37         Assert.assertTrue(getWithTimeout(canCommit));
38     }
39
40     @Test
41     public void testPreCommit() throws Exception {
42         final ListenableFuture<Void> preCommit = cohort.preCommit();
43         Assert.assertNull(getWithTimeout(preCommit));
44     }
45
46     @Test
47     public void testAbort() throws Exception {
48         final ListenableFuture<Void> abort = cohort.abort();
49         verify(history).onTransactionComplete(TRANSACTION_ID);
50         Assert.assertNull(getWithTimeout(abort));
51     }
52
53     @Test
54     public void testCommit() throws Exception {
55         final ListenableFuture<Void> commit = cohort.commit();
56         verify(history).onTransactionComplete(TRANSACTION_ID);
57         Assert.assertNull(getWithTimeout(commit));
58     }
59
60 }