Bug 9241: Action definition should implicitly define input/output
[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 java.util.Date;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
18 import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
19 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.Module;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
24 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
25
26 public class Bug9241Test {
27
28     @Test
29     public void testImplicitInputAndOutputInAction() throws Exception {
30         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug9241/foo.yang");
31         assertNotNull(schemaContext);
32
33         final Date revision = SimpleDateFormatUtil.getRevisionFormat().parse("2017-10-13");
34
35         final Module fooModule = schemaContext.findModuleByName("foo", revision);
36         assertNotNull(fooModule);
37
38         final ContainerSchemaNode actionCont = (ContainerSchemaNode) fooModule.getDataChildByName(QName.create(
39                 fooModule.getQNameModule(), "action-cont"));
40         assertNotNull(actionCont);
41
42         final ActionDefinition actionInCont = actionCont.getActions().iterator().next();
43
44         final ContainerSchemaNode input = actionInCont.getInput();
45         assertNotNull(input);
46         assertEquals(1, input.getChildNodes().size());
47         assertEquals(StatementSource.CONTEXT, ((EffectiveStatement<?, ?>) input).getDeclared().getStatementSource());
48
49         final ContainerSchemaNode output = actionInCont.getOutput();
50         assertNotNull(output);
51         assertEquals(1, output.getChildNodes().size());
52         assertEquals(StatementSource.CONTEXT, ((EffectiveStatement<?, ?>) output).getDeclared().getStatementSource());
53     }
54 }