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