BUG-4688: Rework SchemaContext module lookups
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / stmt / rfc7950 / Bug9241Test.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
17 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.Module;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
22 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
23
24 public class Bug9241Test {
25
26     @Test
27     public void testImplicitInputAndOutputInAction() throws Exception {
28         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug9241/foo.yang");
29         assertNotNull(schemaContext);
30
31         final Module fooModule = schemaContext.findModule("foo", QName.parseRevision("2017-10-13")).get();
32
33         final ContainerSchemaNode actionCont = (ContainerSchemaNode) fooModule.getDataChildByName(QName.create(
34                 fooModule.getQNameModule(), "action-cont"));
35         assertNotNull(actionCont);
36
37         final ActionDefinition actionInCont = actionCont.getActions().iterator().next();
38
39         final ContainerSchemaNode input = actionInCont.getInput();
40         assertNotNull(input);
41         assertEquals(1, input.getChildNodes().size());
42         assertEquals(StatementSource.CONTEXT, ((EffectiveStatement<?, ?>) input).getDeclared().getStatementSource());
43
44         final ContainerSchemaNode output = actionInCont.getOutput();
45         assertNotNull(output);
46         assertEquals(1, output.getChildNodes().size());
47         assertEquals(StatementSource.CONTEXT, ((EffectiveStatement<?, ?>) output).getDeclared().getStatementSource());
48     }
49 }