Switch to using StampedLock
[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 junit.framework.Assert.assertTrue;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.mockito.Mockito.mock;
14
15 import com.google.common.collect.ImmutableList;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
18
19 public class AbstractRegistrationTreeTest extends AbstractRegistrationTree<Object> {
20
21     @Test
22     public void basicTest() throws Exception {
23         final PathArgument pathArgument = mock(PathArgument.class);
24         final RegistrationTreeNode<Object> registrationTreeNodeParent = new RegistrationTreeNode<>(null, pathArgument);
25         final RegistrationTreeNode<Object> registrationTreeNode =
26                 new RegistrationTreeNode<>(registrationTreeNodeParent, pathArgument);
27
28         final Object registration = new Object();
29         this.takeLock();
30         this.addRegistration(registrationTreeNode, registration);
31         assertTrue(registrationTreeNode.getRegistrations().contains(registration));
32         this.releaseLock();
33
34         this.removeRegistration(registrationTreeNode, registration);
35         assertFalse(registrationTreeNode.getRegistrations().contains(registration));
36
37         assertNotNull(this.findNodeFor(ImmutableList.of(pathArgument)));
38         assertNotNull(this.takeSnapshot());
39     }
40
41     @Test(expected = IllegalMonitorStateException.class)
42     public void unlockTest() throws Exception {
43         this.releaseLock();
44     }
45 }