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