6e0d10c8588e9644b0f88dc3e190b7dbb6d94a65
[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
15 import java.util.List;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
20
21 public class RegistrationTreeNodeTest {
22     @Test
23     public void basicTest() throws Exception {
24         final NodeIdentifier pathArgument = new NodeIdentifier(QName.create("", "pathArgument"));
25         final RegistrationTreeNode<Object> registrationTreeNodeParent = new RegistrationTreeNode<>(null, pathArgument);
26         final RegistrationTreeNode<Object> registrationTreeNode =
27                 new RegistrationTreeNode<>(registrationTreeNodeParent, pathArgument);
28
29         assertEquals(pathArgument, registrationTreeNode.getIdentifier());
30
31         final Object registration = new Object();
32         assertFalse(registrationTreeNode.getRegistrations().contains(registration));
33         registrationTreeNode.addRegistration(registration);
34         assertTrue(registrationTreeNode.getRegistrations().contains(registration));
35         registrationTreeNode.removeRegistration(registration);
36         assertFalse(registrationTreeNode.getRegistrations().contains(registration));
37         registrationTreeNode.removeRegistration(registration);
38
39         assertNotNull(registrationTreeNode.ensureChild(pathArgument));
40         assertNotNull(registrationTreeNode.getExactChild(pathArgument));
41
42         final NodeWithValue<?> nodeWithValue = new NodeWithValue<>(QName.create("", "testNode"), new Object());
43         assertEquals(List.of(), registrationTreeNode.getInexactChildren(nodeWithValue));
44         assertEquals(List.of(), registrationTreeNode.getInexactChildren(pathArgument));
45
46         final NodeIdentifier nodeWithoutValue = new NodeIdentifier(QName.create("", "testNode"));
47         assertNotNull(registrationTreeNode.ensureChild(nodeWithoutValue));
48         assertFalse(registrationTreeNode.getInexactChildren(nodeWithValue).isEmpty());
49
50         assertNotNull(registrationTreeNode.toString());
51         assertTrue(registrationTreeNode.toString().contains(pathArgument.toString()));
52     }
53 }