2 * Copyright (c) 2014, 2017 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
9 package org.opendaylight.controller.config.api;
11 import static org.mockito.Mockito.doNothing;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.verify;
16 import org.junit.Assert;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
20 public class IdentityAttributeRefTest {
22 IdentityAttributeRef attr = new IdentityAttributeRef("attr");
25 public void testConstructor() throws Exception {
26 String param = new String("attr");
27 Assert.assertEquals(attr.getqNameOfIdentity(), param);
30 @Test(expected = NullPointerException.class)
31 public void testConstructor2() throws Exception {
32 new IdentityAttributeRef(null);
36 public void testHashCode() throws Exception {
37 Assert.assertEquals(attr.hashCode(), new String("attr").hashCode());
41 public void testEqual() throws Exception {
42 Assert.assertEquals(attr, attr);
46 public void testEqual2() throws Exception {
47 Assert.assertEquals(attr, new IdentityAttributeRef("attr"));
51 public void testNotEqual() throws Exception {
52 Assert.assertNotEquals(attr, new IdentityAttributeRef("different"));
56 public void testResolveIdentity() throws Exception {
57 DependencyResolver res = mock(DependencyResolver.class);
58 IdentityAttributeRef identityAttributeRef = new IdentityAttributeRef("abcd");
59 doReturn(SubIdentity.class).when(res).resolveIdentity(identityAttributeRef, Identity.class);
60 identityAttributeRef.resolveIdentity(res, Identity.class);
61 verify(res).resolveIdentity(identityAttributeRef, Identity.class);
65 public void testValidateIdentity() throws Exception {
66 DependencyResolver res = mock(DependencyResolver.class);
67 JmxAttribute jmxAttr = new JmxAttribute("abc");
68 doNothing().when(res).validateIdentity(attr, Identity.class, jmxAttr);
69 attr.validateIdentity(res, Identity.class, jmxAttr);
70 verify(res).validateIdentity(attr, Identity.class, jmxAttr);
73 interface Identity extends BaseIdentity {}
75 interface SubIdentity extends Identity {}