9fd5c6c0d2cb919a69b958791bd9167b36eabb96
[mdsal.git] / dom / mdsal-dom-spi / src / test / java / org / opendaylight / mdsal / dom / spi / shard / WriteableNodeWithSubshardTest.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.spi.shard;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.mockito.Mockito.doNothing;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.verify;
15
16 import java.util.HashMap;
17 import java.util.Map;
18 import org.junit.After;
19 import org.junit.Assert;
20 import org.junit.Test;
21 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
23
24 public class WriteableNodeWithSubshardTest {
25
26     @Test
27     public void basicTest() throws Exception {
28         doReturn("test").when(TestUtils.WRITEABLE_MODIFICATION_NODE).toString();
29         doNothing().when(TestUtils.WRITEABLE_MODIFICATION_NODE).markDeleted();
30
31         final Map<PathArgument, WriteableModificationNode> children = new HashMap<>();
32         children.put(TestUtils.NODE_IDENTIFIER, TestUtils.WRITEABLE_MODIFICATION_NODE);
33
34         final WriteableNodeWithSubshard writeableNodeWithSubshard = new WriteableNodeWithSubshardImpl(children);
35
36         assertEquals(writeableNodeWithSubshard.getChildrenWithSubshards(), children);
37
38         final WriteableModificationNode TestWriteableModificationNode =
39                 writeableNodeWithSubshard.getChild(TestUtils.NODE_IDENTIFIER);
40         assertNotNull(TestWriteableModificationNode);
41         Assert.assertEquals(TestWriteableModificationNode, TestUtils.WRITEABLE_MODIFICATION_NODE);
42
43         writeableNodeWithSubshard.markDeleted();
44         verify(TestUtils.WRITEABLE_MODIFICATION_NODE).markDeleted();
45     }
46
47     @After
48     public void reset() {
49         TestUtils.resetMocks();
50     }
51
52     private static final class WriteableNodeWithSubshardImpl extends WriteableNodeWithSubshard {
53
54         WriteableNodeWithSubshardImpl(final Map<PathArgument, WriteableModificationNode> children) {
55             super(children);
56         }
57
58         @Override
59         public WriteCursorStrategy createOperation(final DOMDataTreeWriteCursor parentCursor) {
60             return null;
61         }
62
63         @Override
64         public PathArgument getIdentifier() {
65             throw new UnsupportedOperationException();
66         }
67     }
68 }