443a972d9c6d28a9279b783ef0a4a70e64afe2f8
[mdsal.git] / dom / mdsal-dom-inmemory-datastore / src / test / java / org / opendaylight / mdsal / dom / store / inmemory / WriteableSubshardBoundaryNodeTest.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.assertNotNull;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertSame;
14 import static org.mockito.Mockito.doNothing;
15 import static org.mockito.Mockito.doReturn;
16 import static org.mockito.Mockito.times;
17 import static org.mockito.Mockito.verify;
18 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_IDENTIFIER;
19 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_SHARD_PRODUCER;
20 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION;
21 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_WRITE_CURSOR;
22 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.resetMocks;
23
24 import java.util.Collections;
25 import org.junit.After;
26 import org.junit.Test;
27
28 public class WriteableSubshardBoundaryNodeTest {
29
30     private static final ForeignShardModificationContext FOREIGN_SHARD_MODIFICATION_CONTEXT =
31             new ForeignShardModificationContext(DOM_DATA_TREE_IDENTIFIER, DOM_DATA_TREE_SHARD_PRODUCER);
32
33     @Test
34     public void createOperation() throws Exception {
35         final WriteableSubshardBoundaryNode writeableSubshardBoundaryNode =
36                 WriteableSubshardBoundaryNode.from(FOREIGN_SHARD_MODIFICATION_CONTEXT);
37
38         doNothing().when(DOM_DATA_TREE_WRITE_CURSOR).exit();
39         doReturn(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).when(DOM_DATA_TREE_SHARD_PRODUCER).createTransaction();
40         doReturn(DOM_DATA_TREE_WRITE_CURSOR)
41                 .when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).createCursor(DOM_DATA_TREE_IDENTIFIER);
42         doNothing().when(DOM_DATA_TREE_WRITE_CURSOR)
43                 .enter(DOM_DATA_TREE_IDENTIFIER.getRootIdentifier().getLastPathArgument());
44         doNothing().when(DOM_DATA_TREE_WRITE_CURSOR).exit();
45
46         writeableSubshardBoundaryNode.createOperation(DOM_DATA_TREE_WRITE_CURSOR).exit();
47         verify(DOM_DATA_TREE_WRITE_CURSOR).exit();
48
49         WriteCursorStrategy writeCursorStrategy =
50                 writeableSubshardBoundaryNode.createOperation(DOM_DATA_TREE_WRITE_CURSOR);
51         assertNotNull(writeCursorStrategy);
52
53         WriteCursorStrategy childWriteCursorStrategy =
54                 writeCursorStrategy.enter(DOM_DATA_TREE_IDENTIFIER.getRootIdentifier().getLastPathArgument());
55         childWriteCursorStrategy.exit();
56         verify(DOM_DATA_TREE_WRITE_CURSOR, times(2)).exit();
57     }
58
59     @Test
60     public void getChildrenWithSubshards() throws Exception {
61         final WriteableSubshardBoundaryNode writeableSubshardBoundaryNode =
62                 WriteableSubshardBoundaryNode.from(FOREIGN_SHARD_MODIFICATION_CONTEXT);
63
64         assertNotNull(writeableSubshardBoundaryNode.getChildrenWithSubshards());
65         assertSame(Collections.emptyMap(),writeableSubshardBoundaryNode.getChildrenWithSubshards());
66         assertEquals(DOM_DATA_TREE_IDENTIFIER.getRootIdentifier().getLastPathArgument(),
67                 writeableSubshardBoundaryNode.getIdentifier());
68         assertNull(writeableSubshardBoundaryNode.getChild(null));
69     }
70
71     @After
72     public void reset() {
73         resetMocks();
74     }
75 }