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 junit.framework.Assert.assertEquals;
11 import static junit.framework.Assert.assertFalse;
12 import static junit.framework.Assert.assertNotNull;
13 import static junit.framework.Assert.assertTrue;
14 import static org.mockito.Mockito.doReturn;
15 import static org.mockito.Mockito.mock;
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;
24 public class RegistrationTreeNodeTest {
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);
33 assertEquals(pathArgument, registrationTreeNode.getIdentifier());
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);
43 assertNotNull(registrationTreeNode.ensureChild(pathArgument));
44 assertNotNull(registrationTreeNode.getExactChild(pathArgument));
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));
50 final NodeIdentifier nodeWithoutValue = new NodeIdentifier(QName.create("testNode"));
51 assertNotNull(registrationTreeNode.ensureChild(nodeWithoutValue));
52 assertFalse(registrationTreeNode.getInexactChildren(nodeWithValue).isEmpty());
54 doReturn("TestPathArgument").when(pathArgument).toString();
55 assertNotNull(registrationTreeNode.toString());
56 assertTrue(registrationTreeNode.toString().contains(pathArgument.toString()));