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