Correct ActionService generics
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / RpcServiceAdapterTest.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;
9
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;
14
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.bi.ba.rpcservice.rev140701.RockTheHouseInputBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.OpendaylightTestRoutedRpcService;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInputBuilder;
26 import org.opendaylight.yangtools.yang.binding.RpcService;
27
28 public class RpcServiceAdapterTest {
29
30     @SuppressWarnings("checkstyle:IllegalThrows")
31     @Test
32     public void invoke() throws Throwable {
33         final BindingBrokerTestFactory bindingBrokerTestFactory = new BindingBrokerTestFactory();
34         bindingBrokerTestFactory.setExecutor(MoreExecutors.newDirectExecutorService());
35         final BindingTestContext bindingTestContext = bindingBrokerTestFactory.getTestContext();
36         bindingTestContext.start();
37
38         RpcServiceAdapter rpcServiceAdapter = new RpcServiceAdapter(OpendaylightTestRpcServiceService.class,
39                 bindingTestContext.getCodec(), bindingTestContext.getDomRpcInvoker());
40
41         Method method = TestRpcService.class.getMethod("equals", Object.class);
42         assertTrue((boolean) rpcServiceAdapter.invoke(rpcServiceAdapter.getProxy(), method,
43                 new Object[]{ rpcServiceAdapter.getProxy() }));
44         assertFalse((boolean) rpcServiceAdapter.invoke(rpcServiceAdapter.getProxy(), method,
45                 new Object[]{ new Object() }));
46
47         method = TestRpcService.class.getMethod("hashCode");
48         assertEquals(rpcServiceAdapter.getProxy().hashCode(), rpcServiceAdapter.invoke(rpcServiceAdapter.getProxy(),
49                 method, new Object[]{ }));
50
51         method = TestRpcService.class.getMethod("toString");
52         assertEquals(rpcServiceAdapter.getProxy().toString(), rpcServiceAdapter.invoke(rpcServiceAdapter.getProxy(),
53                 method, new Object[]{ }));
54
55         method = OpendaylightTestRpcServiceService.class.getMethod("rockTheHouse", RockTheHouseInput.class);
56         assertNotNull(rpcServiceAdapter.invoke(rpcServiceAdapter.getProxy(), method,
57             new Object[]{ new RockTheHouseInputBuilder().build() }));
58
59         rpcServiceAdapter = new RpcServiceAdapter(OpendaylightTestRoutedRpcService.class,
60                 bindingTestContext.getCodec(), bindingTestContext.getDomRpcInvoker());
61         method = OpendaylightTestRoutedRpcService.class.getMethod("routedSimpleRoute", RoutedSimpleRouteInput.class);
62         assertNotNull(rpcServiceAdapter.invoke(rpcServiceAdapter.getProxy(), method,
63                 new Object[]{ new RoutedSimpleRouteInputBuilder().build() }));
64     }
65
66     private interface TestRpcService extends RpcService {
67
68         @Override
69         String toString();
70
71         @Override
72         int hashCode();
73
74         @Override
75         boolean equals(Object object);
76     }
77 }