2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.dom.store.inmemory;
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;
24 import java.util.Collections;
25 import org.junit.After;
26 import org.junit.Test;
28 public class WriteableSubshardBoundaryNodeTest {
30 private static final ForeignShardModificationContext FOREIGN_SHARD_MODIFICATION_CONTEXT =
31 new ForeignShardModificationContext(DOM_DATA_TREE_IDENTIFIER, DOM_DATA_TREE_SHARD_PRODUCER);
34 public void createOperation() throws Exception {
35 final WriteableSubshardBoundaryNode writeableSubshardBoundaryNode =
36 WriteableSubshardBoundaryNode.from(FOREIGN_SHARD_MODIFICATION_CONTEXT);
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();
46 writeableSubshardBoundaryNode.createOperation(DOM_DATA_TREE_WRITE_CURSOR).exit();
47 verify(DOM_DATA_TREE_WRITE_CURSOR).exit();
49 WriteCursorStrategy writeCursorStrategy =
50 writeableSubshardBoundaryNode.createOperation(DOM_DATA_TREE_WRITE_CURSOR);
51 assertNotNull(writeCursorStrategy);
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();
60 public void getChildrenWithSubshards() throws Exception {
61 final WriteableSubshardBoundaryNode writeableSubshardBoundaryNode =
62 WriteableSubshardBoundaryNode.from(FOREIGN_SHARD_MODIFICATION_CONTEXT);
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));