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.opendaylight.mdsal.dom.broker.TestUtils.EXCEPTION_TEXT;
18 import static org.opendaylight.mdsal.dom.broker.TestUtils.TEST_CONTAINER;
19 import static org.opendaylight.mdsal.dom.broker.TestUtils.getTestRpcImplementation;
21 import com.google.common.util.concurrent.Futures;
22 import com.google.common.util.concurrent.ListenableFuture;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
27 import java.util.concurrent.ExecutionException;
28 import org.junit.Test;
29 import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
30 import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
31 import org.opendaylight.mdsal.dom.broker.DOMRpcRouter.OperationInvocation;
32 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
34 public class GlobalDOMRpcRoutingTableEntryTest {
36 public void basicTest() {
37 final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> rpcImplementations = new HashMap<>();
38 final List<DOMRpcImplementation> rpcImplementation = new ArrayList<>();
39 final YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.builder().build();
41 final GlobalDOMRpcRoutingTableEntry globalDOMRpcRoutingTableEntry = new GlobalDOMRpcRoutingTableEntry(
42 TestModel.TEST2_QNAME, new HashMap<>());
43 rpcImplementation.add(getTestRpcImplementation());
44 rpcImplementations.put(yangInstanceIdentifier, rpcImplementation);
46 assertEquals(TestModel.TEST2_QNAME, globalDOMRpcRoutingTableEntry.getType());
47 assertTrue(globalDOMRpcRoutingTableEntry.getImplementations().isEmpty());
48 assertFalse(globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations).getImplementations().isEmpty());
49 assertTrue(globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations).getImplementations().containsValue(
52 final ListenableFuture<?> future = OperationInvocation.invoke(
53 globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations), TEST_CONTAINER);
55 final var cause = assertThrows(ExecutionException.class, () -> Futures.getDone(future)).getCause();
56 assertThat(cause, instanceOf(DOMRpcImplementationNotAvailableException.class));
57 assertThat(cause.getMessage(), containsString(EXCEPTION_TEXT));