Remove AbstractDOMRpcRoutingTableEntry.invokeRpc
[mdsal.git] / dom / mdsal-dom-broker / src / test / java / org / opendaylight / mdsal / dom / broker / GlobalDOMRpcRoutingTableEntryTest.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.dom.broker;
9
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertTrue;
12 import static org.junit.Assert.fail;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.mock;
15
16 import java.util.ArrayList;
17 import java.util.HashMap;
18 import java.util.List;
19 import java.util.Map;
20 import java.util.concurrent.ExecutionException;
21 import java.util.concurrent.TimeUnit;
22 import java.util.concurrent.TimeoutException;
23 import org.junit.Test;
24 import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
25 import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
26 import org.opendaylight.mdsal.dom.broker.DOMRpcRouter.RpcInvocation;
27 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
28 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
29 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
30
31 public class GlobalDOMRpcRoutingTableEntryTest extends TestUtils {
32
33     @Test
34     public void basicTest() throws InterruptedException, TimeoutException {
35         final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> rpcImplementations = new HashMap<>();
36         final List<DOMRpcImplementation> rpcImplementation = new ArrayList<>();
37         final RpcDefinition rpcDefinition = mock(RpcDefinition.class);
38         final YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.builder().build();
39
40         doReturn(SchemaPath.ROOT).when(rpcDefinition).getPath();
41         final GlobalDOMRpcRoutingTableEntry globalDOMRpcRoutingTableEntry = new GlobalDOMRpcRoutingTableEntry(
42                 rpcDefinition, new HashMap<>());
43         rpcImplementation.add(getTestRpcImplementation());
44         rpcImplementations.put(yangInstanceIdentifier, rpcImplementation);
45
46         assertTrue(globalDOMRpcRoutingTableEntry.getSchemaPath().equals(SchemaPath.ROOT));
47         assertTrue(globalDOMRpcRoutingTableEntry.getImplementations().isEmpty());
48         assertFalse(globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations).getImplementations().isEmpty());
49         assertTrue(globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations).getImplementations().containsValue(
50                 rpcImplementation));
51
52         try {
53             RpcInvocation.invoke(globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations),
54                     TEST_CONTAINER).get(5, TimeUnit.SECONDS);
55             fail("Expected DOMRpcImplementationNotAvailableException");
56         } catch (ExecutionException e) {
57             assertTrue(e.getCause() instanceof DOMRpcImplementationNotAvailableException);
58             assertTrue(e.getCause().getMessage().contains(EXCEPTION_TEXT));
59         }
60     }
61 }