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.spi.shard;
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertNull;
12 import static org.junit.Assert.assertSame;
13 import static org.mockito.Mockito.doNothing;
14 import static org.mockito.Mockito.doReturn;
15 import static org.mockito.Mockito.mock;
16 import static org.mockito.Mockito.times;
17 import static org.mockito.Mockito.verify;
19 import com.google.common.collect.ImmutableMap;
20 import org.junit.After;
21 import org.junit.Assert;
22 import org.junit.Test;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
25 public class WriteableSubshardBoundaryNodeTest {
27 private static final ForeignShardModificationContext FOREIGN_SHARD_MODIFICATION_CONTEXT =
28 new ForeignShardModificationContext(
29 TestUtils.DOM_DATA_TREE_IDENTIFIER, TestUtils.DOM_DATA_TREE_SHARD_PRODUCER);
32 public void createOperation() throws Exception {
33 final WriteableSubshardBoundaryNode writeableSubshardBoundaryNode =
34 WriteableSubshardBoundaryNode.from(FOREIGN_SHARD_MODIFICATION_CONTEXT);
36 doNothing().when(TestUtils.DOM_DATA_TREE_WRITE_CURSOR).exit();
37 doReturn(TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION)
38 .when(TestUtils.DOM_DATA_TREE_SHARD_PRODUCER).createTransaction();
39 doReturn(TestUtils.DOM_DATA_TREE_WRITE_CURSOR)
40 .when(TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).createCursor(TestUtils.DOM_DATA_TREE_IDENTIFIER);
41 doNothing().when(TestUtils.DOM_DATA_TREE_WRITE_CURSOR)
42 .enter(TestUtils.DOM_DATA_TREE_IDENTIFIER.getRootIdentifier().getLastPathArgument());
43 doNothing().when(TestUtils.DOM_DATA_TREE_WRITE_CURSOR).exit();
45 writeableSubshardBoundaryNode.createOperation(TestUtils.DOM_DATA_TREE_WRITE_CURSOR).exit();
46 verify(TestUtils.DOM_DATA_TREE_WRITE_CURSOR).exit();
48 WriteCursorStrategy writeCursorStrategy =
49 writeableSubshardBoundaryNode.createOperation(TestUtils.DOM_DATA_TREE_WRITE_CURSOR);
50 assertNotNull(writeCursorStrategy);
52 WriteCursorStrategy childWriteCursorStrategy =
53 writeCursorStrategy.enter(TestUtils.DOM_DATA_TREE_IDENTIFIER.getRootIdentifier().getLastPathArgument());
54 childWriteCursorStrategy.exit();
55 verify(TestUtils.DOM_DATA_TREE_WRITE_CURSOR, times(2)).exit();
59 public void getChildrenWithSubshards() throws Exception {
60 final WriteableSubshardBoundaryNode writeableSubshardBoundaryNode =
61 WriteableSubshardBoundaryNode.from(FOREIGN_SHARD_MODIFICATION_CONTEXT);
63 assertNotNull(writeableSubshardBoundaryNode.getChildrenWithSubshards());
64 assertSame(ImmutableMap.of(), writeableSubshardBoundaryNode.getChildrenWithSubshards());
65 Assert.assertEquals(TestUtils.DOM_DATA_TREE_IDENTIFIER.getRootIdentifier().getLastPathArgument(),
66 writeableSubshardBoundaryNode.getIdentifier());
67 assertNull(writeableSubshardBoundaryNode.getChild(mock(PathArgument.class)));
72 TestUtils.resetMocks();