f90c0b52e883a63284b69118d3754a5634db41f7
[mdsal.git] / dom / mdsal-dom-broker / src / test / java / org / opendaylight / mdsal / dom / broker / RoutedDOMRpcRoutingTableEntryTest.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.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertThrows;
14 import static org.mockito.Mockito.doReturn;
15 import static org.mockito.Mockito.mock;
16 import static org.opendaylight.mdsal.dom.broker.TestUtils.TEST_CHILD;
17
18 import com.google.common.util.concurrent.ListenableFuture;
19 import java.util.HashMap;
20 import java.util.concurrent.ExecutionException;
21 import java.util.concurrent.TimeUnit;
22 import org.junit.Test;
23 import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
24 import org.opendaylight.mdsal.dom.broker.DOMRpcRouter.OperationInvocation;
25 import org.opendaylight.mdsal.dom.broker.util.TestModel;
26 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
27
28 public class RoutedDOMRpcRoutingTableEntryTest {
29     @Test
30     public void basicTest()  {
31         final RpcDefinition rpcDefinition = mock(RpcDefinition.class);
32         doReturn(TestModel.TEST2_QNAME).when(rpcDefinition).getQName();
33
34         final RoutedDOMRpcRoutingTableEntry routedDOMRpcRoutingTableEntry =
35                 new RoutedDOMRpcRoutingTableEntry(rpcDefinition, TestModel.TEST_PATH, new HashMap<>());
36         assertNotNull(routedDOMRpcRoutingTableEntry.newInstance(new HashMap<>()));
37
38         final ListenableFuture<?> future = OperationInvocation.invoke(routedDOMRpcRoutingTableEntry, TEST_CHILD);
39         final ExecutionException ex = assertThrows(ExecutionException.class, () -> future.get(5, TimeUnit.SECONDS));
40         assertThat(ex.getCause(), instanceOf(DOMRpcImplementationNotAvailableException.class));
41     }
42 }