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