2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.dom.spi;
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;
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;
21 public class RegistrationTreeNodeTest {
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);
29 assertEquals(pathArgument, registrationTreeNode.getIdentifier());
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);
39 assertNotNull(registrationTreeNode.ensureChild(pathArgument));
40 assertNotNull(registrationTreeNode.getExactChild(pathArgument));
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));
46 final NodeIdentifier nodeWithoutValue = new NodeIdentifier(QName.create("", "testNode"));
47 assertNotNull(registrationTreeNode.ensureChild(nodeWithoutValue));
48 assertFalse(registrationTreeNode.getInexactChildren(nodeWithValue).isEmpty());
50 assertNotNull(registrationTreeNode.toString());
51 assertTrue(registrationTreeNode.toString().contains(pathArgument.toString()));