checkStyleViolationSeverity=error implemented for mdsal-dom-inmemory-datastore
[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.doReturn;
12 import static org.mockito.Mockito.verify;
13 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_IDENTIFIER;
14 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_SHARD_PRODUCER;
15 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION;
16 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_WRITE_CURSOR;
17 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.resetMocks;
18
19 import org.junit.After;
20 import org.junit.Test;
21
22 public class ForeignShardThreePhaseCommitCohortTest {
23
24     @Test
25     public void basicTest() throws Exception {
26         final ForeignShardModificationContext foreignShardModificationContext =
27                 new ForeignShardModificationContext(DOM_DATA_TREE_IDENTIFIER, DOM_DATA_TREE_SHARD_PRODUCER);
28         doReturn(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).when(DOM_DATA_TREE_SHARD_PRODUCER).createTransaction();
29         doReturn(DOM_DATA_TREE_WRITE_CURSOR)
30                 .when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).createCursor(DOM_DATA_TREE_IDENTIFIER);
31         foreignShardModificationContext.getCursor();
32
33         final ForeignShardThreePhaseCommitCohort foreignShardThreePhaseCommitCohort =
34                 new ForeignShardThreePhaseCommitCohort(DOM_DATA_TREE_IDENTIFIER, foreignShardModificationContext);
35
36         doReturn(null).when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).prepare();
37         foreignShardThreePhaseCommitCohort.preCommit();
38         verify(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).prepare();
39
40         doReturn(null).when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).validate();
41         foreignShardThreePhaseCommitCohort.canCommit();
42         verify(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).validate();
43
44         doReturn(null).when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).commit();
45         foreignShardThreePhaseCommitCohort.commit();
46         verify(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).commit();
47
48         assertEquals(null, foreignShardThreePhaseCommitCohort.abort().get());
49     }
50
51     @After
52     public void reset() {
53         resetMocks();
54     }
55 }