Derive RpcRoutingStrategy from RpcEffectiveStatement
[mdsal.git] / dom / mdsal-dom-broker / src / test / java / org / opendaylight / mdsal / dom / broker / GlobalDOMRpcRoutingTableEntryTest.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.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;
20
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;
26 import java.util.Map;
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;
33
34 public class GlobalDOMRpcRoutingTableEntryTest {
35     @Test
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();
40
41         final GlobalDOMRpcRoutingTableEntry globalDOMRpcRoutingTableEntry = new GlobalDOMRpcRoutingTableEntry(
42             TestModel.TEST2_QNAME, new HashMap<>());
43         rpcImplementation.add(getTestRpcImplementation());
44         rpcImplementations.put(yangInstanceIdentifier, rpcImplementation);
45
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(
50                 rpcImplementation));
51
52         final ListenableFuture<?> future = OperationInvocation.invoke(
53             globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations), TEST_CONTAINER);
54
55         final var cause = assertThrows(ExecutionException.class, () -> Futures.getDone(future)).getCause();
56         assertThat(cause, instanceOf(DOMRpcImplementationNotAvailableException.class));
57         assertThat(cause.getMessage(), containsString(EXCEPTION_TEXT));
58     }
59 }