Remove RpcMethodInvoker specializations
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / invoke / RpcMethodInvokerTest.java
1 /*
2  * Copyright (c) 2016 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.dom.adapter.invoke;
9
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertThrows;
12
13 import com.google.common.util.concurrent.Futures;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import java.lang.invoke.MethodHandle;
16 import java.lang.invoke.MethodHandles;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.opendaylight.yangtools.yang.binding.RpcService;
20
21 public class RpcMethodInvokerTest {
22     private static final TestImplClassWithInput TEST_IMPL_CLASS = new TestImplClassWithInput();
23
24     @Test
25     public void invokeOnTest() throws Exception {
26         final MethodHandle methodHandle = MethodHandles.lookup().unreflect(
27                 TestImplClassWithInput.class.getDeclaredMethod("testMethod", RpcService.class, DataObject.class));
28         final RpcMethodInvoker rpcMethodInvokerWithInput = new RpcMethodInvoker(methodHandle);
29         assertNotNull(rpcMethodInvokerWithInput.invokeOn(TEST_IMPL_CLASS, null));
30     }
31
32     @Test
33     public void invokeOnWithException() throws Exception {
34         final MethodHandle methodHandle = MethodHandles.lookup().unreflect(TestImplClassWithInput.class
35                 .getDeclaredMethod("testMethodWithException", RpcService.class, DataObject.class));
36         final RpcMethodInvoker rpcMethodInvokerWithInput = new RpcMethodInvoker(methodHandle);
37
38         assertThrows(InternalError.class, () -> rpcMethodInvokerWithInput.invokeOn(TEST_IMPL_CLASS, null));
39     }
40
41     static final class TestImplClassWithInput implements RpcService {
42
43         static ListenableFuture<?> testMethod(final RpcService testArg, final DataObject data) {
44             return Futures.immediateFuture(null);
45         }
46
47         static ListenableFuture<?> testMethodWithException(final RpcService testArg, final DataObject data) {
48             throw new InternalError();
49         }
50     }
51 }