Fix lead transaction cancellation
[mdsal.git] / dom / mdsal-dom-spi / src / test / java / org / opendaylight / mdsal / dom / spi / RpcRoutingStrategyTest.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.spi;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertThrows;
14 import static org.junit.Assert.assertTrue;
15
16 import com.google.common.collect.Iterables;
17 import java.util.Collection;
18 import org.junit.AfterClass;
19 import org.junit.BeforeClass;
20 import org.junit.Test;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.yang.extension.yang.ext.rev130709.$YangModuleInfoImpl;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
24 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
25 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
26 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
27 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
28
29 public class RpcRoutingStrategyTest {
30     private static Collection<? extends RpcDefinition> RPCS;
31
32     @BeforeClass
33     public static void beforeClass() {
34         final EffectiveModelContext ctx = YangParserTestUtils.parseYangSources(YangParserConfiguration.DEFAULT, null,
35             YangTextSchemaSource.delegateForByteSource("yang-ext.yang",
36                 $YangModuleInfoImpl.getInstance().getYangTextByteSource()),
37             YangTextSchemaSource.forResource(RpcRoutingStrategy.class, "/rpc-routing-strategy.yang"));
38
39         RPCS = ctx.getModules().stream()
40             .filter(module -> module.getName().equals("foo"))
41             .findFirst().orElseThrow()
42             .getRpcs();
43     }
44
45     @AfterClass
46     public static void afterClass() {
47         RPCS = null;
48     }
49
50     @Test
51     public void unroutedRpcStrategyTest() {
52         final RpcRoutingStrategy strategy = RpcRoutingStrategy.from(Iterables.get(RPCS, 1));
53         assertNotNull(strategy);
54
55         assertEquals(QName.create("foo", "unrouted"), strategy.getIdentifier());
56         assertFalse(strategy.isContextBasedRouted());
57         assertThrows(UnsupportedOperationException.class, () -> strategy.getLeaf());
58         assertThrows(UnsupportedOperationException.class, () -> strategy.getContext());
59     }
60
61     @Test
62     public void routedRpcStrategyTest() {
63         final RpcRoutingStrategy strategy = RpcRoutingStrategy.from(Iterables.get(RPCS, 0));
64         assertNotNull(strategy);
65
66         assertEquals(QName.create("foo", "routed"), strategy.getIdentifier());
67         assertTrue(strategy.isContextBasedRouted());
68         assertEquals(QName.create("foo", "identity"), strategy.getContext());
69         assertEquals(QName.create("foo", "ctx"), strategy.getLeaf());
70     }
71 }