Remove unneeded throws
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug1412Test.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.yangtools.yang.stmt;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12
13 import java.util.Collection;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.Empty;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.common.QNameModule;
18 import org.opendaylight.yangtools.yang.common.Revision;
19 import org.opendaylight.yangtools.yang.common.XMLNamespace;
20 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
23
24 /**
25  * Test ANTLR4 grammar capability to parse description statement in unknown node.
26  *
27  * <p>
28  * Note: Everything under unknown node is unknown node.
29  */
30 public class Bug1412Test extends AbstractYangTest {
31     @Test
32     public void test() throws Exception {
33         final Module bug1412 = assertEffectiveModelDir("/bugs/bug1412").findModules("bug1412").iterator().next();
34
35         final ContainerSchemaNode node = (ContainerSchemaNode) bug1412.getDataChildByName(QName.create(
36                 bug1412.getQNameModule(), "node"));
37         Collection<? extends UnrecognizedStatement> unknownNodes = node.asEffectiveStatement().getDeclared()
38             .declaredSubstatements(UnrecognizedStatement.class);
39         assertEquals(1, unknownNodes.size());
40         final UnrecognizedStatement action = unknownNodes.iterator().next();
41
42         final QNameModule qm = QNameModule.create(XMLNamespace.of("urn:test:bug1412"), Revision.of("2014-07-25"));
43         assertEquals(QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "action"),
44             action.statementDefinition().getStatementName());
45         assertEquals("hello", action.argument());
46
47         unknownNodes = action.declaredSubstatements(UnrecognizedStatement.class);
48         assertEquals(4, unknownNodes.size());
49         UnrecognizedStatement info = null;
50         UnrecognizedStatement description = null;
51         UnrecognizedStatement actionPoint = null;
52         UnrecognizedStatement output = null;
53         for (final UnrecognizedStatement un : unknownNodes) {
54             final String name = un.statementDefinition().getStatementName().getLocalName();
55             if ("info".equals(name)) {
56                 info = un;
57             } else if ("description".equals(name)) {
58                 description = un;
59             } else if ("actionpoint".equals(name)) {
60                 actionPoint = un;
61             } else if ("output".equals(name)) {
62                 output = un;
63             }
64         }
65
66         assertNotNull(info);
67         assertEquals(QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "info"),
68             info.statementDefinition().getStatementName());
69         assertEquals("greeting", info.argument());
70
71         assertNotNull(description);
72         assertEquals(QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "description"),
73             description.statementDefinition().getStatementName());
74         assertEquals("say greeting", description.argument());
75
76         assertNotNull(actionPoint);
77         assertEquals(QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "actionpoint"),
78             actionPoint.statementDefinition().getStatementName());
79         assertEquals("entry", actionPoint.argument());
80
81         assertNotNull(output);
82         assertEquals(QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "output"),
83             output.statementDefinition().getStatementName());
84         assertEquals(Empty.value(), output.argument());
85     }
86 }