Merge "Do not override managed versions"
[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 org.junit.Assert;
4 import org.junit.Test;
5 import org.mockito.Mock;
6 import org.mockito.MockitoAnnotations;
7 import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
8 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
9
10 import javax.management.*;
11
12 import static org.mockito.Matchers.any;
13 import static org.mockito.Mockito.*;
14
15 public class IdentityAttributeRefTest {
16
17     IdentityAttributeRef attr = new IdentityAttributeRef("attr");
18
19     @Test
20     public void testConstructor() throws Exception {
21         String param = new String("attr");
22         Assert.assertEquals(attr.getqNameOfIdentity(), param);
23     }
24
25     @Test(expected = NullPointerException.class)
26     public void testConstructor2() throws Exception {
27         IdentityAttributeRef attr = new IdentityAttributeRef(null);
28     }
29
30     @Test
31     public void testHashCode() throws Exception {
32         Assert.assertEquals(attr.hashCode(), new String("attr").hashCode());
33     }
34
35     @Test
36     public void testEqual() throws Exception {
37         Assert.assertEquals(attr, attr);
38     }
39
40     @Test
41     public void testEqual2() throws Exception {
42         Assert.assertEquals(attr, new IdentityAttributeRef("attr"));
43     }
44
45     @Test
46     public void testNotEqual() throws Exception {
47         Assert.assertNotEquals(attr, new IdentityAttributeRef("different"));
48     }
49
50     @Test
51     public void testResolveIdentity() throws Exception {
52         DependencyResolver res = mock(DependencyResolver.class);
53         IdentityAttributeRef a = new IdentityAttributeRef("abcd");
54         doReturn(SubIdentity.class).when(res).resolveIdentity(a, Identity.class);
55         a.resolveIdentity(res, Identity.class);
56         verify(res).resolveIdentity(a, Identity.class);
57     }
58
59     @Test
60     public void testValidateIdentity() throws Exception {
61         DependencyResolver res = mock(DependencyResolver.class);
62         JmxAttribute jmxAttr = new JmxAttribute("abc");
63         doNothing().when(res).validateIdentity(attr, Identity.class, jmxAttr);
64         attr.validateIdentity(res, Identity.class, jmxAttr);
65         verify(res).validateIdentity(attr, Identity.class, jmxAttr);
66     }
67
68     static class Identity extends BaseIdentity {}
69
70     static class SubIdentity extends Identity {}
71 }