Remove BindingReflections.isAugmentationChild()
[yangtools.git] / binding / mdsal-binding-spec-util / src / test / java / org / opendaylight / mdsal / binding / spec / reflect / BindingReflectionsTest.java
1 /*
2  * Copyright (c) 2014 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.binding.spec.reflect;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertTrue;
14 import static org.mockito.Mockito.doReturn;
15 import static org.mockito.Mockito.mock;
16 import static org.opendaylight.mdsal.binding.spec.reflect.BindingReflections.findHierarchicalParent;
17
18 import com.google.common.util.concurrent.ListenableFuture;
19 import java.util.Collections;
20 import java.util.List;
21 import org.junit.Test;
22 import org.opendaylight.mdsal.binding.spec.util.FooChild;
23 import org.opendaylight.mdsal.binding.spec.util.GroupingFoo;
24 import org.opendaylight.yangtools.yang.binding.Augmentation;
25 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
26 import org.opendaylight.yangtools.yang.binding.ChildOf;
27 import org.opendaylight.yangtools.yang.binding.DataObject;
28 import org.opendaylight.yangtools.yang.binding.RpcService;
29 import org.opendaylight.yangtools.yang.common.QName;
30
31 public class BindingReflectionsTest {
32
33     @Test
34     public void testBindingWithDummyObject() throws Exception {
35         assertEquals("Package name should be equal to string", "org.opendaylight.yang.gen.v1.test.rev990939",
36                 BindingReflections.getModelRootPackageName("org.opendaylight.yang.gen.v1.test.rev990939"));
37         assertEquals("ModuleInfoClassName should be equal to string", "test.$YangModuleInfoImpl",
38                 BindingReflections.getModuleInfoClassName("test"));
39         assertEquals("Module info should be empty Set", Collections.emptySet(),
40                 BindingReflections.loadModuleInfos());
41         assertFalse("Should not be RpcType", BindingReflections.isRpcType(DataObject.class));
42         assertTrue("Should be BindingClass", BindingReflections.isBindingClass(DataObject.class));
43         assertFalse("Should not be Notification", BindingReflections.isNotification(DataObject.class));
44
45         assertNull(findHierarchicalParent(mock(DataObject.class)));
46         assertEquals(GroupingFoo.class, BindingReflections.findHierarchicalParent(FooChild.class));
47         final ChildOf<?> childOf = mock(FooChild.class);
48         doReturn(FooChild.class).when(childOf).implementedInterface();
49         assertEquals(GroupingFoo.class, BindingReflections.findHierarchicalParent(childOf));
50         assertTrue(BindingReflections.isRpcMethod(TestImplementation.class.getDeclaredMethod("rpcMethodTest")));
51         assertEquals(TestImplementation.class, BindingReflections.findAugmentationTarget(TestImplementation.class));
52
53         assertEquals(Object.class, BindingReflections.resolveRpcOutputClass(
54                 TestImplementation.class.getDeclaredMethod("rpcMethodTest")).get());
55         assertFalse(BindingReflections.resolveRpcOutputClass(
56                 TestImplementation.class.getDeclaredMethod("rpcMethodTest2")).isPresent());
57
58         assertEquals(QName.create("test", "test"), BindingReflections.getQName(TestIdentity.VALUE));
59     }
60
61     interface TestIdentity extends BaseIdentity {
62         QName QNAME = QName.create("test", "test");
63         TestIdentity VALUE = () -> TestIdentity.class;
64
65         @Override
66         Class<? extends TestIdentity> implementedInterface();
67     }
68
69     static final class TestImplementation implements Augmentation<TestImplementation>, RpcService {
70         public static final QName QNAME = QName.create("test", "test");
71
72         @SuppressWarnings("static-method")
73         ListenableFuture<List<Object>> rpcMethodTest() {
74             return null;
75         }
76
77         @SuppressWarnings("static-method")
78         ListenableFuture<?> rpcMethodTest2() {
79             return null;
80         }
81
82         @Override
83         public Class<TestImplementation> implementedInterface() {
84             return TestImplementation.class;
85         }
86     }
87 }