Change DOM invokeRpc to FluentFuture
[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.yangtools.yang.data.api.YangInstanceIdentifier;
27 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
28 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
29
30 public class GlobalDOMRpcRoutingTableEntryTest extends TestUtils {
31
32     @Test
33     public void basicTest() throws InterruptedException, TimeoutException {
34         final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> rpcImplementations = new HashMap<>();
35         final List<DOMRpcImplementation> rpcImplementation = new ArrayList<>();
36         final RpcDefinition rpcDefinition = mock(RpcDefinition.class);
37         final YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.builder().build();
38
39         doReturn(SchemaPath.ROOT).when(rpcDefinition).getPath();
40         final GlobalDOMRpcRoutingTableEntry globalDOMRpcRoutingTableEntry = new GlobalDOMRpcRoutingTableEntry(
41                 rpcDefinition, new HashMap<>());
42         rpcImplementation.add(getTestRpcImplementation());
43         rpcImplementations.put(yangInstanceIdentifier, rpcImplementation);
44
45         assertTrue(globalDOMRpcRoutingTableEntry.getSchemaPath().equals(SchemaPath.ROOT));
46         assertTrue(globalDOMRpcRoutingTableEntry.getImplementations().isEmpty());
47         assertFalse(globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations).getImplementations().isEmpty());
48         assertTrue(globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations).getImplementations().containsValue(
49                 rpcImplementation));
50
51         try {
52             globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations)
53                     .invokeRpc(TEST_CONTAINER).get(5, TimeUnit.SECONDS);
54             fail("Expected DOMRpcImplementationNotAvailableException");
55         } catch (ExecutionException e) {
56             assertTrue(e.getCause() instanceof DOMRpcImplementationNotAvailableException);
57             assertTrue(e.getCause().getMessage().contains(EXCEPTION_TEXT));
58         }
59     }
60 }