Clean up binding-util tests
[mdsal.git] / dom / mdsal-dom-inmemory-datastore / src / test / java / org / opendaylight / mdsal / dom / store / inmemory / ForeignShardThreePhaseCommitCohortTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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.mdsal.dom.store.inmemory;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.doNothing;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.verify;
14 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_IDENTIFIER;
15 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_SHARD_PRODUCER;
16 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION;
17 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_WRITE_CURSOR;
18 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.resetMocks;
19
20 import org.junit.After;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.opendaylight.mdsal.dom.spi.shard.ForeignShardModificationContext;
24
25 public class ForeignShardThreePhaseCommitCohortTest {
26
27     @Before
28     public void setUp() throws Exception {
29         doNothing().when(DOM_DATA_TREE_WRITE_CURSOR).close();
30     }
31
32     @Test
33     public void basicTest() throws Exception {
34         final ForeignShardModificationContext foreignShardModificationContext =
35                 new ForeignShardModificationContext(DOM_DATA_TREE_IDENTIFIER, DOM_DATA_TREE_SHARD_PRODUCER);
36         doReturn(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).when(DOM_DATA_TREE_SHARD_PRODUCER).createTransaction();
37         doReturn(DOM_DATA_TREE_WRITE_CURSOR)
38                 .when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).createCursor(DOM_DATA_TREE_IDENTIFIER);
39         doNothing().when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).ready();
40
41         foreignShardModificationContext.getCursor();
42         foreignShardModificationContext.ready();
43         final ForeignShardThreePhaseCommitCohort foreignShardThreePhaseCommitCohort =
44                 new ForeignShardThreePhaseCommitCohort(DOM_DATA_TREE_IDENTIFIER, foreignShardModificationContext);
45
46         doReturn(null).when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).prepare();
47         foreignShardThreePhaseCommitCohort.preCommit();
48         verify(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).prepare();
49
50         doReturn(null).when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).validate();
51         foreignShardThreePhaseCommitCohort.canCommit();
52         verify(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).validate();
53
54         doReturn(null).when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).commit();
55         foreignShardThreePhaseCommitCohort.commit();
56         verify(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).commit();
57
58         assertEquals(null, foreignShardThreePhaseCommitCohort.abort().get());
59     }
60
61     @After
62     public void reset() {
63         resetMocks();
64     }
65 }