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.containsString;
11 import static org.hamcrest.CoreMatchers.instanceOf;
12 import static org.hamcrest.MatcherAssert.assertThat;
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertFalse;
15 import static org.junit.Assert.assertThrows;
16 import static org.junit.Assert.assertTrue;
17 import static org.mockito.Mockito.doReturn;
18 import static org.mockito.Mockito.mock;
19 import static org.opendaylight.mdsal.dom.broker.TestUtils.EXCEPTION_TEXT;
20 import static org.opendaylight.mdsal.dom.broker.TestUtils.TEST_CONTAINER;
21 import static org.opendaylight.mdsal.dom.broker.TestUtils.getTestRpcImplementation;
23 import com.google.common.util.concurrent.ListenableFuture;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
28 import java.util.concurrent.ExecutionException;
29 import java.util.concurrent.TimeUnit;
30 import org.junit.Test;
31 import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
32 import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
33 import org.opendaylight.mdsal.dom.broker.DOMRpcRouter.OperationInvocation;
34 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
35 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
37 public class GlobalDOMRpcRoutingTableEntryTest {
39 public void basicTest() {
40 final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> rpcImplementations = new HashMap<>();
41 final List<DOMRpcImplementation> rpcImplementation = new ArrayList<>();
42 final RpcDefinition rpcDefinition = mock(RpcDefinition.class);
43 final YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.builder().build();
45 doReturn(TestModel.TEST2_QNAME).when(rpcDefinition).getQName();
46 final GlobalDOMRpcRoutingTableEntry globalDOMRpcRoutingTableEntry = new GlobalDOMRpcRoutingTableEntry(
47 rpcDefinition, new HashMap<>());
48 rpcImplementation.add(getTestRpcImplementation());
49 rpcImplementations.put(yangInstanceIdentifier, rpcImplementation);
51 assertEquals(TestModel.TEST2_QNAME, globalDOMRpcRoutingTableEntry.getType());
52 assertTrue(globalDOMRpcRoutingTableEntry.getImplementations().isEmpty());
53 assertFalse(globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations).getImplementations().isEmpty());
54 assertTrue(globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations).getImplementations().containsValue(
57 final ListenableFuture<?> future = OperationInvocation.invoke(
58 globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations), TEST_CONTAINER);
60 final ExecutionException ex = assertThrows(ExecutionException.class, () -> future.get(5, TimeUnit.SECONDS));
61 final Throwable cause = ex.getCause();
62 assertThat(cause, instanceOf(DOMRpcImplementationNotAvailableException.class));
63 assertThat(cause.getMessage(), containsString(EXCEPTION_TEXT));