Adjust to yangtools-2.0.0 changes
[mdsal.git] / dom / mdsal-dom-spi / src / test / java / org / opendaylight / mdsal / dom / spi / RegistrationTreeNodeTest.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;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14 import static org.mockito.Mockito.doReturn;
15 import static org.mockito.Mockito.mock;
16
17 import java.util.Collections;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
23
24 public class RegistrationTreeNodeTest {
25
26     @Test
27     public void basicTest() throws Exception {
28         final PathArgument pathArgument = mock(PathArgument.class);
29         final RegistrationTreeNode<Object> registrationTreeNodeParent = new RegistrationTreeNode<>(null, pathArgument);
30         final RegistrationTreeNode<Object> registrationTreeNode =
31                 new RegistrationTreeNode<>(registrationTreeNodeParent, pathArgument);
32
33         assertEquals(pathArgument, registrationTreeNode.getIdentifier());
34
35         final Object registration = new Object();
36         assertFalse(registrationTreeNode.getRegistrations().contains(registration));
37         registrationTreeNode.addRegistration(registration);
38         assertTrue(registrationTreeNode.getRegistrations().contains(registration));
39         registrationTreeNode.removeRegistration(registration);
40         assertFalse(registrationTreeNode.getRegistrations().contains(registration));
41         registrationTreeNode.removeRegistration(registration);
42
43         assertNotNull(registrationTreeNode.ensureChild(pathArgument));
44         assertNotNull(registrationTreeNode.getExactChild(pathArgument));
45
46         final NodeWithValue<?> nodeWithValue = new NodeWithValue<>(QName.create("", "testNode"), new Object());
47         assertEquals(Collections.EMPTY_LIST, registrationTreeNode.getInexactChildren(nodeWithValue));
48         assertEquals(Collections.EMPTY_LIST, registrationTreeNode.getInexactChildren(pathArgument));
49
50         final NodeIdentifier nodeWithoutValue = new NodeIdentifier(QName.create("", "testNode"));
51         assertNotNull(registrationTreeNode.ensureChild(nodeWithoutValue));
52         assertFalse(registrationTreeNode.getInexactChildren(nodeWithValue).isEmpty());
53
54         doReturn("TestPathArgument").when(pathArgument).toString();
55         assertNotNull(registrationTreeNode.toString());
56         assertTrue(registrationTreeNode.toString().contains(pathArgument.toString()));
57     }
58 }