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;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
15 import com.google.common.util.concurrent.MoreExecutors;
16 import java.lang.reflect.Method;
17 import org.junit.Test;
18 import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingBrokerTestFactory;
19 import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingTestContext;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.OpendaylightTestRpcServiceService;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.OpendaylightTestRoutedRpcService;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInputBuilder;
25 import org.opendaylight.yangtools.yang.binding.RpcService;
27 public class RpcServiceAdapterTest {
29 @SuppressWarnings("checkstyle:IllegalThrows")
31 public void invoke() throws Throwable {
32 final BindingBrokerTestFactory bindingBrokerTestFactory = new BindingBrokerTestFactory();
33 bindingBrokerTestFactory.setExecutor(MoreExecutors.newDirectExecutorService());
34 final BindingTestContext bindingTestContext = bindingBrokerTestFactory.getTestContext();
35 bindingTestContext.start();
37 RpcServiceAdapter rpcServiceAdapter = new RpcServiceAdapter(OpendaylightTestRpcServiceService.class,
38 bindingTestContext.getCodec(), bindingTestContext.getDomRpcInvoker());
40 Method method = TestRpcService.class.getMethod("equals", Object.class);
41 assertTrue((boolean) rpcServiceAdapter.invoke(rpcServiceAdapter.getProxy(), method,
42 new Object[]{ rpcServiceAdapter.getProxy() }));
43 assertFalse((boolean) rpcServiceAdapter.invoke(rpcServiceAdapter.getProxy(), method,
44 new Object[]{ new Object() }));
46 method = TestRpcService.class.getMethod("hashCode");
47 assertEquals(rpcServiceAdapter.getProxy().hashCode(), rpcServiceAdapter.invoke(rpcServiceAdapter.getProxy(),
48 method, new Object[]{ }));
50 method = TestRpcService.class.getMethod("toString");
51 assertEquals(rpcServiceAdapter.getProxy().toString(), rpcServiceAdapter.invoke(rpcServiceAdapter.getProxy(),
52 method, new Object[]{ }));
54 method = OpendaylightTestRpcServiceService.class.getMethod("rockTheHouse", RockTheHouseInput.class);
55 assertNotNull(rpcServiceAdapter.invoke(rpcServiceAdapter.getProxy(), method, new Object[]{ null }));
57 rpcServiceAdapter = new RpcServiceAdapter(OpendaylightTestRoutedRpcService.class,
58 bindingTestContext.getCodec(), bindingTestContext.getDomRpcInvoker());
59 method = OpendaylightTestRoutedRpcService.class.getMethod("routedSimpleRoute", RoutedSimpleRouteInput.class);
60 assertNotNull(rpcServiceAdapter.invoke(rpcServiceAdapter.getProxy(), method,
61 new Object[]{ new RoutedSimpleRouteInputBuilder().build() }));
64 private interface TestRpcService extends RpcService {
70 boolean equals(Object object);