Update DOMStoreThreePhaseCommitCohort design
[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 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;
22
23 import com.google.common.util.concurrent.ListenableFuture;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
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;
36
37 public class GlobalDOMRpcRoutingTableEntryTest {
38     @Test
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();
44
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);
50
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(
55                 rpcImplementation));
56
57         final ListenableFuture<?> future = OperationInvocation.invoke(
58             globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations), TEST_CONTAINER);
59
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));
64     }
65 }