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