2 * Copyright (c) 2013 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.parser.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
14 import java.text.SimpleDateFormat;
15 import java.util.Date;
16 import java.util.List;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.common.QNameModule;
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 antlr grammar capability to parse description statement in unknown node.
28 * Not that everything under unknown node is unknown node.
30 public class Bug1412Test {
33 public void test() throws Exception {
34 Set<Module> modules = TestUtils.loadModules(getClass().getResource("/bugs/bug1412").toURI());
35 Module bug1412 = TestUtils.findModule(modules, "bug1412");
36 assertNotNull(bug1412);
38 ContainerSchemaNode node = (ContainerSchemaNode) bug1412.getDataChildByName("node");
39 List<UnknownSchemaNode> unknownNodes = node.getUnknownSchemaNodes();
40 assertEquals(1, unknownNodes.size());
41 UnknownSchemaNode action = unknownNodes.get(0);
43 Date revision = new SimpleDateFormat("yyyy-MM-dd").parse("2014-07-25");
44 QNameModule qm = QNameModule.create(URI.create("urn:test:bug1412"), revision);
45 QName expectedNodeType = new QName(null, null, null, "action");
46 assertEquals(QName.create(null, (Date) null, "action"), action.getNodeType());
47 assertEquals("hello", action.getNodeParameter());
48 QName expectedQName = QName.create(qm, "hello");
49 assertEquals(expectedQName, action.getQName());
51 unknownNodes = action.getUnknownSchemaNodes();
52 assertEquals(4, unknownNodes.size());
53 UnknownSchemaNode info = null;
54 UnknownSchemaNode description = null;
55 UnknownSchemaNode actionPoint = null;
56 UnknownSchemaNode output = null;
57 for (UnknownSchemaNode un : unknownNodes) {
58 if ("info".equals(un.getNodeType().getLocalName())) {
60 } else if ("description".equals(un.getNodeType().getLocalName())) {
62 } else if ("actionpoint".equals(un.getNodeType().getLocalName())) {
64 } else if ("output".equals(un.getNodeType().getLocalName())) {
69 assertNotNull(description);
70 assertNotNull(actionPoint);
71 assertNotNull(output);
73 expectedNodeType = new QName(null, null, null, "info");
74 assertEquals(expectedNodeType, info.getNodeType());
75 assertEquals("greeting", info.getNodeParameter());
77 expectedNodeType = QName.create(qm, "description");
78 assertEquals(expectedNodeType, description.getNodeType());
79 assertEquals("say greeting", description.getNodeParameter());
81 expectedNodeType = new QName(null, null, null, "actionpoint");
82 assertEquals(expectedNodeType, actionPoint.getNodeType());
83 assertEquals("entry", actionPoint.getNodeParameter());
85 expectedNodeType = QName.create(qm, "output");
86 assertEquals(expectedNodeType, output.getNodeType());
87 assertEquals("", output.getNodeParameter());