066a293bece066cfa1094f53957179a2859df3e0
[mdsal.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.assertTrue;
13
14 import com.google.common.util.concurrent.ListenableFuture;
15 import java.util.List;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.binding.Augmentation;
18 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
19 import org.opendaylight.yangtools.yang.binding.DataObject;
20 import org.opendaylight.yangtools.yang.binding.RpcService;
21 import org.opendaylight.yangtools.yang.common.QName;
22
23 public class BindingReflectionsTest {
24
25     @Test
26     public void testBindingWithDummyObject() throws Exception {
27         assertFalse("Should not be RpcType", BindingReflections.isRpcType(DataObject.class));
28         assertTrue("Should be BindingClass", BindingReflections.isBindingClass(DataObject.class));
29         assertFalse("Should not be Notification", BindingReflections.isNotification(DataObject.class));
30
31         assertTrue(BindingReflections.isRpcMethod(TestImplementation.class.getDeclaredMethod("rpcMethodTest")));
32
33         assertEquals(QName.create("test", "test"), BindingReflections.getQName(TestIdentity.VALUE));
34     }
35
36     interface TestIdentity extends BaseIdentity {
37         QName QNAME = QName.create("test", "test");
38         TestIdentity VALUE = () -> TestIdentity.class;
39
40         @Override
41         Class<? extends TestIdentity> implementedInterface();
42     }
43
44     static final class TestImplementation implements Augmentation<TestImplementation>, RpcService {
45         public static final QName QNAME = QName.create("test", "test");
46
47         @SuppressWarnings("static-method")
48         ListenableFuture<List<Object>> rpcMethodTest() {
49             return null;
50         }
51
52         @Override
53         public Class<TestImplementation> implementedInterface() {
54             return TestImplementation.class;
55         }
56     }
57 }