checkStyleViolationSeverity=error implemented for mdsal-dom-broker
[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.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertTrue;
12 import static org.junit.Assert.fail;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.mock;
15
16 import java.util.ArrayList;
17 import java.util.HashMap;
18 import java.util.List;
19 import java.util.Map;
20 import org.junit.Test;
21 import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
22 import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
24 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
25 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
26
27 public class GlobalDOMRpcRoutingTableEntryTest extends TestUtils {
28
29     @Test
30     public void basicTest() throws Exception {
31         final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> rpcImplementations = new HashMap<>();
32         final List<DOMRpcImplementation> rpcImplementation = new ArrayList<>();
33         final RpcDefinition rpcDefinition = mock(RpcDefinition.class);
34         final YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.builder().build();
35
36         doReturn(SchemaPath.ROOT).when(rpcDefinition).getPath();
37         final GlobalDOMRpcRoutingTableEntry globalDOMRpcRoutingTableEntry = new GlobalDOMRpcRoutingTableEntry(
38                 rpcDefinition, new HashMap<>());
39         rpcImplementation.add(getTestRpcImplementation());
40         rpcImplementations.put(yangInstanceIdentifier, rpcImplementation);
41
42         assertTrue(globalDOMRpcRoutingTableEntry.getSchemaPath().equals(SchemaPath.ROOT));
43         assertTrue(globalDOMRpcRoutingTableEntry.getImplementations().isEmpty());
44         assertFalse(globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations).getImplementations().isEmpty());
45         assertTrue(globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations).getImplementations().containsValue(
46                 rpcImplementation));
47
48         try {
49             globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations)
50                     .invokeRpc(TEST_CONTAINER).checkedGet();
51             fail("Expected DOMRpcImplementationNotAvailableException");
52         } catch (DOMRpcImplementationNotAvailableException e) {
53             assertTrue(e.getMessage().contains(EXCEPTION_TEXT));
54         }
55     }
56 }