Execute the ShardedDOMDataTreeTransaction.submit() async.
[mdsal.git] / dom / mdsal-dom-inmemory-datastore / src / test / java / org / opendaylight / mdsal / dom / store / inmemory / ShardRootModificationContextTest.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.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14 import static org.mockito.Mockito.doNothing;
15 import static org.mockito.Mockito.doReturn;
16 import static org.mockito.Mockito.mock;
17 import static org.mockito.Mockito.verify;
18 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_IDENTIFIER;
19
20 import org.junit.Test;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeModification;
23 import org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeSnapshot;
24 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModificationCursor;
25
26 public class ShardRootModificationContextTest {
27
28     @Test
29     public void basicTest() throws Exception {
30         final CursorAwareDataTreeSnapshot cursorAwareDataTreeSnapshot = mock(CursorAwareDataTreeSnapshot.class);
31         final CursorAwareDataTreeModification cursorAwareDataTreeModification =
32                 mock(CursorAwareDataTreeModification.class);
33         final DataTreeModificationCursor dataTreeModificationCursor = mock(DataTreeModificationCursor.class);
34         doReturn(cursorAwareDataTreeModification).when(cursorAwareDataTreeSnapshot).newModification();
35         doNothing().when(cursorAwareDataTreeModification).ready();
36         doReturn(dataTreeModificationCursor)
37                 .when(cursorAwareDataTreeModification).createCursor(YangInstanceIdentifier.EMPTY);
38         doNothing().when(dataTreeModificationCursor).close();
39
40         final ShardRootModificationContext shardRootModificationContext =
41                 new ShardRootModificationContext(DOM_DATA_TREE_IDENTIFIER, cursorAwareDataTreeSnapshot);
42         assertEquals(DOM_DATA_TREE_IDENTIFIER, shardRootModificationContext.getIdentifier());
43         assertFalse(shardRootModificationContext.isModified());
44
45         final DataTreeModificationCursorAdaptor dataTreeModificationCursorAdaptor =
46                 shardRootModificationContext.cursor();
47         assertNotNull(dataTreeModificationCursorAdaptor);
48         assertTrue(shardRootModificationContext.isModified());
49         verify(cursorAwareDataTreeSnapshot).newModification();
50         verify(cursorAwareDataTreeModification).createCursor(YangInstanceIdentifier.EMPTY);
51
52         shardRootModificationContext.ready();
53         verify(cursorAwareDataTreeModification).ready();
54         verify(dataTreeModificationCursor).close();
55     }
56 }