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;
14 import java.util.Date;
15 import java.util.List;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.common.QNameModule;
20 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
21 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.Module;
23 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
26 * 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 {
35 Set<Module> modules = null;
38 modules = TestUtils.loadModules(getClass().getResource("/bugs/bug1412").toURI());
41 final Module bug1412 = TestUtils.findModule(modules, "bug1412");
42 assertNotNull(bug1412);
44 final ContainerSchemaNode node = (ContainerSchemaNode) bug1412.getDataChildByName(QName.create(
45 bug1412.getQNameModule(), "node"));
46 List<UnknownSchemaNode> unknownNodes = node.getUnknownSchemaNodes();
47 assertEquals(1, unknownNodes.size());
48 final UnknownSchemaNode action = unknownNodes.get(0);
50 final Date revision = SimpleDateFormatUtil.getRevisionFormat().parse("2014-07-25");
51 final QNameModule qm = QNameModule.create(URI.create("urn:test:bug1412"), revision);
52 QName expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "action");
53 assertEquals(expectedNodeType, action.getNodeType());
54 assertEquals("hello", action.getNodeParameter());
55 final QName expectedQName = QName.create(qm, "hello");
56 assertEquals(expectedQName, action.getQName());
58 unknownNodes = action.getUnknownSchemaNodes();
59 assertEquals(4, unknownNodes.size());
60 UnknownSchemaNode info = null;
61 UnknownSchemaNode description = null;
62 UnknownSchemaNode actionPoint = null;
63 UnknownSchemaNode output = null;
64 for (final UnknownSchemaNode un : unknownNodes) {
65 final String name = un.getNodeType().getLocalName();
66 if ("info".equals(name)) {
68 } else if ("description".equals(name)) {
70 } else if ("actionpoint".equals(name)) {
72 } else if ("output".equals(name)) {
78 assertNotNull(description);
79 assertNotNull(actionPoint);
80 assertNotNull(output);
82 expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "info");
83 assertEquals(expectedNodeType, info.getNodeType());
84 assertEquals("greeting", info.getNodeParameter());
86 expectedNodeType = QName.create(qm, "description");
87 assertEquals(expectedNodeType, description.getNodeType());
88 assertEquals("say greeting", description.getNodeParameter());
90 expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "actionpoint");
91 assertEquals(expectedNodeType, actionPoint.getNodeType());
92 assertEquals("entry", actionPoint.getNodeParameter());
94 expectedNodeType = QName.create(qm, "output");
95 assertEquals(expectedNodeType, output.getNodeType());
96 assertEquals("", output.getNodeParameter());