2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.dom.spi;
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;
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;
29 public class RpcRoutingStrategyTest {
30 private static Collection<? extends RpcDefinition> RPCS;
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"));
39 RPCS = ctx.getModules().stream()
40 .filter(module -> module.getName().equals("foo"))
41 .findFirst().orElseThrow()
46 public static void afterClass() {
51 public void unroutedRpcStrategyTest() {
52 final RpcRoutingStrategy strategy = RpcRoutingStrategy.from(Iterables.get(RPCS, 1));
53 assertNotNull(strategy);
55 assertEquals(QName.create("foo", "unrouted"), strategy.getIdentifier());
56 assertFalse(strategy.isContextBasedRouted());
57 assertThrows(UnsupportedOperationException.class, () -> strategy.getLeaf());
58 assertThrows(UnsupportedOperationException.class, () -> strategy.getContext());
62 public void routedRpcStrategyTest() {
63 final RpcRoutingStrategy strategy = RpcRoutingStrategy.from(Iterables.get(RPCS, 0));
64 assertNotNull(strategy);
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());