2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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
8 package org.opendaylight.mdsal.binding.javav2.spec.util;
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.mock;
16 import java.lang.reflect.Constructor;
17 import java.util.Collections;
18 import java.util.List;
19 import java.util.concurrent.Future;
20 import org.junit.Test;
21 import org.opendaylight.mdsal.binding.javav2.spec.base.BaseIdentity;
22 import org.opendaylight.mdsal.binding.javav2.spec.base.Input;
23 import org.opendaylight.mdsal.binding.javav2.spec.base.Rpc;
24 import org.opendaylight.mdsal.binding.javav2.spec.base.RpcCallback;
25 import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
26 import org.opendaylight.mdsal.binding.javav2.spec.structural.Augmentation;
27 import org.opendaylight.mdsal.binding.javav2.spec.structural.TreeChildNode;
28 import org.opendaylight.mdsal.binding.javav2.spec.util.test.mock.FooChild;
29 import org.opendaylight.mdsal.binding.javav2.spec.util.test.mock.GroupingFoo;
30 import org.opendaylight.yangtools.yang.common.QName;
32 public class BindingReflectionsTest {
35 public void testBindingWithDummyObject() throws Exception {
36 assertEquals("Package name should be equal to string", "org.opendaylight.mdsal.gen.javav2.test.rev990939",
37 BindingReflections.getModelRootPackageName("org.opendaylight.mdsal.gen.javav2.test.rev990939"));
38 assertEquals("ModuleInfoClassName should be equal to string", "test.$YangModuleInfoImpl",
39 BindingReflections.getModuleInfoClassName("test"));
40 assertEquals("Module info should be empty Set", Collections.EMPTY_SET, BindingReflections.loadModuleInfos());
41 assertFalse("Should not be RpcType", BindingReflections.isRpcOrActionType(TreeNode.class));
42 assertFalse("Should not be AugmentationChild", BindingReflections.isAugmentationChild(TreeNode.class));
43 assertTrue("Should be BindingClass", BindingReflections.isBindingClass(TreeNode.class));
44 assertFalse("Should not be Notification", BindingReflections.isNotification(TreeNode.class));
46 assertNull(mock(TreeChildNode.class).treeParent());
48 assertEquals(GroupingFoo.class, BindingReflections.findHierarchicalParent(FooChild.class));
50 assertTrue(BindingReflections.isRpcOrActionMethod(TestImplementation.class.getDeclaredMethod("rpcMethodTest")));
51 assertEquals(TestImplementation.class, BindingReflections.findAugmentationTarget(TestImplementation.class));
53 assertEquals(Object.class, BindingReflections
54 .resolveRpcOutputClass(TestImplementation.class.getDeclaredMethod("rpcMethodTest")).get());
55 assertFalse(BindingReflections
56 .resolveRpcOutputClass(TestImplementation.class.getDeclaredMethod("rpcMethodTest2")).isPresent());
58 assertTrue(BindingReflections.getQName(TestImplementation.class).toString().equals("test"));
61 @SuppressWarnings("rawtypes")
62 @Test(expected = UnsupportedOperationException.class)
63 public void testPrivateConstructor() throws Throwable {
64 assertFalse(BindingReflections.class.getDeclaredConstructor().isAccessible());
65 final Constructor constructor = BindingReflections.class.getDeclaredConstructor();
66 constructor.setAccessible(true);
68 constructor.newInstance();
69 } catch (final Exception e) {
74 @SuppressWarnings({ "rawtypes", "unused" })
75 private static final class TestImplementation extends BaseIdentity
76 implements Augmentation<TestImplementation>, Rpc {
78 public static final QName QNAME = QName.create("test");
80 Future<List<Object>> rpcMethodTest() {
84 Future rpcMethodTest2() {
89 public void invoke(final Input input, final RpcCallback callback) {