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.yangtools.yang.data.api.YangInstanceIdentifier;
33 public class GlobalDOMRpcRoutingTableEntryTest {
35 public void basicTest() {
36 final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> rpcImplementations = new HashMap<>();
37 final List<DOMRpcImplementation> rpcImplementation = new ArrayList<>();
38 final YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.builder().build();
40 final GlobalDOMRpcRoutingTableEntry globalDOMRpcRoutingTableEntry = new GlobalDOMRpcRoutingTableEntry(
41 TestModel.TEST2_QNAME, new HashMap<>());
42 rpcImplementation.add(getTestRpcImplementation());
43 rpcImplementations.put(yangInstanceIdentifier, rpcImplementation);
45 assertEquals(TestModel.TEST2_QNAME, globalDOMRpcRoutingTableEntry.getType());
46 assertTrue(globalDOMRpcRoutingTableEntry.getImplementations().isEmpty());
47 assertFalse(globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations).getImplementations().isEmpty());
48 assertTrue(globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations).getImplementations().containsValue(
51 final ListenableFuture<?> future = OperationInvocation.invoke(
52 globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations), TEST_CONTAINER);
54 final var cause = assertThrows(ExecutionException.class, () -> Futures.getDone(future)).getCause();
55 assertThat(cause, instanceOf(DOMRpcImplementationNotAvailableException.class));
56 assertThat(cause.getMessage(), containsString(EXCEPTION_TEXT));