2 * Copyright (c) 2016 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
8 package org.opendaylight.mdsal.binding.dom.adapter.invoke;
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertThrows;
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;
21 @Deprecated(since = "11.0.0", forRemoval = true)
22 public class RpcMethodInvokerTest {
23 private static final TestImplClassWithInput TEST_IMPL_CLASS = new TestImplClassWithInput();
26 public void invokeOnTest() throws Exception {
27 final MethodHandle methodHandle = MethodHandles.lookup().unreflect(
28 TestImplClassWithInput.class.getDeclaredMethod("testMethod", RpcService.class, DataObject.class));
29 final RpcMethodInvoker rpcMethodInvokerWithInput = new RpcMethodInvoker(methodHandle);
30 assertNotNull(rpcMethodInvokerWithInput.invokeOn(TEST_IMPL_CLASS, null));
34 public void invokeOnWithException() throws Exception {
35 final MethodHandle methodHandle = MethodHandles.lookup().unreflect(TestImplClassWithInput.class
36 .getDeclaredMethod("testMethodWithException", RpcService.class, DataObject.class));
37 final RpcMethodInvoker rpcMethodInvokerWithInput = new RpcMethodInvoker(methodHandle);
39 assertThrows(InternalError.class, () -> rpcMethodInvokerWithInput.invokeOn(TEST_IMPL_CLASS, null));
42 static final class TestImplClassWithInput implements RpcService {
44 static ListenableFuture<?> testMethod(final RpcService testArg, final DataObject data) {
45 return Futures.immediateFuture(null);
48 static ListenableFuture<?> testMethodWithException(final RpcService testArg, final DataObject data) {
49 throw new InternalError();