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.dom.broker;
10 import static org.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertThrows;
14 import static org.mockito.Mockito.doReturn;
15 import static org.opendaylight.mdsal.dom.broker.TestUtils.TEST_CHILD;
17 import com.google.common.collect.ImmutableMap;
18 import com.google.common.util.concurrent.Futures;
19 import com.google.common.util.concurrent.ListenableFuture;
21 import java.util.concurrent.ExecutionException;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.mockito.Mock;
26 import org.mockito.junit.MockitoJUnitRunner;
27 import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
28 import org.opendaylight.mdsal.dom.broker.DOMRpcRouter.OperationInvocation;
29 import org.opendaylight.mdsal.dom.broker.util.TestModel;
30 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
32 @RunWith(MockitoJUnitRunner.StrictStubs.class)
33 public class RoutedDOMRpcRoutingTableEntryTest {
35 public RpcDefinition rpcDefinition;
37 private RoutedDOMRpcRoutingTableEntry entry;
40 public void before() {
41 doReturn(TestModel.TEST2_QNAME).when(rpcDefinition).getQName();
42 // Note: ImmutableMap.of() allows get(null), Map.of() does not
43 entry = new RoutedDOMRpcRoutingTableEntry(rpcDefinition, TestModel.TEST_PATH, ImmutableMap.of());
47 public void testNewInstance() {
48 final RoutedDOMRpcRoutingTableEntry instance = entry.newInstance(Map.of());
49 assertEquals(TestModel.TEST2_QNAME, entry.getType());
50 assertEquals(Map.of(), instance.getImplementations());
54 public void testUnregistered() {
55 final ListenableFuture<?> future = OperationInvocation.invoke(entry, TEST_CHILD);
56 final Throwable cause = assertThrows(ExecutionException.class, () -> Futures.getDone(future)).getCause();
57 assertThat(cause, instanceOf(DOMRpcImplementationNotAvailableException.class));
58 assertEquals("No implementation of RPC "
59 + "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test2 "