93d97f1097f848138f6239606279e290f7da1dfd
[mdsal.git] / dom / mdsal-dom-spi / src / test / java / org / opendaylight / mdsal / dom / spi / ContentRoutedRpcContextTest.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.assertNotNull;
12 import static org.junit.Assert.assertNull;
13
14 import java.util.List;
15 import java.util.stream.Collectors;
16 import org.junit.AfterClass;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.yang.extension.yang.ext.rev130709.$YangModuleInfoImpl;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
23 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
24 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
25
26 public class ContentRoutedRpcContextTest {
27     private static List<RpcEffectiveStatement> RPCS;
28
29     @BeforeClass
30     public static void beforeClass() {
31         final var ctx = YangParserTestUtils.parseYangSources(YangParserConfiguration.DEFAULT, null,
32             YangTextSchemaSource.delegateForCharSource("yang-ext.yang",
33                 $YangModuleInfoImpl.getInstance().getYangTextCharSource()),
34             YangTextSchemaSource.forResource(ContentRoutedRpcContext.class, "/rpc-routing-strategy.yang"));
35
36         RPCS = ctx.findModuleStatements("foo").iterator().next()
37             .streamEffectiveSubstatements(RpcEffectiveStatement.class)
38             .collect(Collectors.toUnmodifiableList());
39     }
40
41     @AfterClass
42     public static void afterClass() {
43         RPCS = null;
44     }
45
46     @Test
47     public void unroutedRpcStrategyTest() {
48         assertNull(ContentRoutedRpcContext.forRpc(RPCS.get(1)));
49     }
50
51     @Test
52     public void routedRpcStrategyTest() {
53         final var context = ContentRoutedRpcContext.forRpc(RPCS.get(0));
54         assertNotNull(context);
55
56         assertEquals(QName.create("foo", "identity"), context.identity());
57         assertEquals(QName.create("foo", "ctx"), context.leaf());
58     }
59 }