Clean up AbstractRegistrationTree
[mdsal.git] / dom / mdsal-dom-spi / src / test / java / org / opendaylight / mdsal / dom / spi / AbstractRegistrationTreeTest.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.assertFalse;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertThrows;
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
20 public class AbstractRegistrationTreeTest extends AbstractRegistrationTree<Object> {
21     @Test
22     public void basicTest() throws Exception {
23         final NodeIdentifier pathArgument = new NodeIdentifier(QName.create("", "pathArgument"));
24         final Node<Object> registrationTreeNodeParent = new Node<>(null, pathArgument);
25         final Node<Object> registrationTreeNode =
26                 new Node<>(registrationTreeNodeParent, pathArgument);
27
28         final Object registration = new Object();
29         takeLock();
30         addRegistration(registrationTreeNode, registration);
31         assertTrue(registrationTreeNode.getRegistrations().contains(registration));
32         releaseLock();
33
34         removeRegistration(registrationTreeNode, registration);
35         assertFalse(registrationTreeNode.getRegistrations().contains(registration));
36
37         assertNotNull(findNodeFor(List.of(pathArgument)));
38         assertNotNull(takeSnapshot());
39     }
40
41     @Test
42     public void unlockTest() throws Exception {
43         assertThrows(IllegalMonitorStateException.class, this::releaseLock);
44     }
45 }