9cb64c5cc8987d85584f8ada4640edfe2406ad21
[controller.git] / opendaylight / config / config-api / src / test / java / org / opendaylight / controller / config / api / IdentityAttributeRefTest.java
1 package org.opendaylight.controller.config.api;
2
3 import static org.mockito.Mockito.doNothing;
4 import static org.mockito.Mockito.doReturn;
5 import static org.mockito.Mockito.mock;
6 import static org.mockito.Mockito.verify;
7
8 import org.junit.Assert;
9 import org.junit.Test;
10 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
11
12 public class IdentityAttributeRefTest {
13
14     IdentityAttributeRef attr = new IdentityAttributeRef("attr");
15
16     @Test
17     public void testConstructor() throws Exception {
18         String param = new String("attr");
19         Assert.assertEquals(attr.getqNameOfIdentity(), param);
20     }
21
22     @Test(expected = NullPointerException.class)
23     public void testConstructor2() throws Exception {
24         IdentityAttributeRef attr = new IdentityAttributeRef(null);
25     }
26
27     @Test
28     public void testHashCode() throws Exception {
29         Assert.assertEquals(attr.hashCode(), new String("attr").hashCode());
30     }
31
32     @Test
33     public void testEqual() throws Exception {
34         Assert.assertEquals(attr, attr);
35     }
36
37     @Test
38     public void testEqual2() throws Exception {
39         Assert.assertEquals(attr, new IdentityAttributeRef("attr"));
40     }
41
42     @Test
43     public void testNotEqual() throws Exception {
44         Assert.assertNotEquals(attr, new IdentityAttributeRef("different"));
45     }
46
47     @Test
48     public void testResolveIdentity() throws Exception {
49         DependencyResolver res = mock(DependencyResolver.class);
50         IdentityAttributeRef a = new IdentityAttributeRef("abcd");
51         doReturn(SubIdentity.class).when(res).resolveIdentity(a, Identity.class);
52         a.resolveIdentity(res, Identity.class);
53         verify(res).resolveIdentity(a, Identity.class);
54     }
55
56     @Test
57     public void testValidateIdentity() throws Exception {
58         DependencyResolver res = mock(DependencyResolver.class);
59         JmxAttribute jmxAttr = new JmxAttribute("abc");
60         doNothing().when(res).validateIdentity(attr, Identity.class, jmxAttr);
61         attr.validateIdentity(res, Identity.class, jmxAttr);
62         verify(res).validateIdentity(attr, Identity.class, jmxAttr);
63     }
64
65     static class Identity extends BaseIdentity {}
66
67     static class SubIdentity extends Identity {}
68 }