2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.stmt;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
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;
25 * Test ANTLR4 grammar capability to parse description statement in unknown node.
28 * Note: Everything under unknown node is unknown node.
30 public class Bug1412Test {
33 public void test() throws Exception {
34 final Module bug1412 = TestUtils.findModule(
35 TestUtils.loadModules(getClass().getResource("/bugs/bug1412").toURI()), "bug1412").get();
37 final ContainerSchemaNode node = (ContainerSchemaNode) bug1412.getDataChildByName(QName.create(
38 bug1412.getQNameModule(), "node"));
39 Collection<? extends UnrecognizedStatement> unknownNodes = node.asEffectiveStatement().getDeclared()
40 .declaredSubstatements(UnrecognizedStatement.class);
41 assertEquals(1, unknownNodes.size());
42 final UnrecognizedStatement action = unknownNodes.iterator().next();
44 final QNameModule qm = QNameModule.create(XMLNamespace.of("urn:test:bug1412"), Revision.of("2014-07-25"));
45 QName expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "action");
46 assertEquals(expectedNodeType, action.statementDefinition().getStatementName());
47 assertEquals("hello", action.argument());
49 unknownNodes = action.declaredSubstatements(UnrecognizedStatement.class);
50 assertEquals(4, unknownNodes.size());
51 UnrecognizedStatement info = null;
52 UnrecognizedStatement description = null;
53 UnrecognizedStatement actionPoint = null;
54 UnrecognizedStatement output = null;
55 for (final UnrecognizedStatement un : unknownNodes) {
56 final String name = un.statementDefinition().getStatementName().getLocalName();
57 if ("info".equals(name)) {
59 } else if ("description".equals(name)) {
61 } else if ("actionpoint".equals(name)) {
63 } else if ("output".equals(name)) {
69 assertNotNull(description);
70 assertNotNull(actionPoint);
71 assertNotNull(output);
73 expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "info");
74 assertEquals(expectedNodeType, info.statementDefinition().getStatementName());
75 assertEquals("greeting", info.argument());
77 expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "description");
78 assertEquals(expectedNodeType, description.statementDefinition().getStatementName());
79 assertEquals("say greeting", description.argument());
81 expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "actionpoint");
82 assertEquals(expectedNodeType, actionPoint.statementDefinition().getStatementName());
83 assertEquals("entry", actionPoint.argument());
85 expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "output");
86 assertEquals(expectedNodeType, output.statementDefinition().getStatementName());
87 assertEquals(Empty.getInstance(), output.argument());