43f475617c54d6b46a3aa4b38a8ea36aca0a6b4c
[yangtools.git] / yang / yang-parser-impl / 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.net.URI;
14 import java.util.Date;
15 import java.util.List;
16 import java.util.Set;
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;
24
25 /**
26  * Test ANTLR4 grammar capability to parse description statement in unknown node.
27  *
28  * Note: Everything under unknown node is unknown node.
29  */
30 public class Bug1412Test {
31
32     @Test
33     public void test() throws Exception {
34
35         Set<Module> modules = null;
36
37
38         modules = TestUtils.loadModules(getClass().getResource("/bugs/bug1412").toURI());
39
40
41         final Module bug1412 = TestUtils.findModule(modules, "bug1412");
42         assertNotNull(bug1412);
43
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);
49
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());
57
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)) {
67                 info = un;
68             } else if ("description".equals(name)) {
69                 description = un;
70             } else if ("actionpoint".equals(name)) {
71                 actionPoint = un;
72             } else if ("output".equals(name)) {
73                 output = un;
74             }
75         }
76
77         assertNotNull(info);
78         assertNotNull(description);
79         assertNotNull(actionPoint);
80         assertNotNull(output);
81
82         expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "info");
83         assertEquals(expectedNodeType, info.getNodeType());
84         assertEquals("greeting", info.getNodeParameter());
85
86         expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "description");
87         assertEquals(expectedNodeType, description.getNodeType());
88         assertEquals("say greeting", description.getNodeParameter());
89
90         expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "actionpoint");
91         assertEquals(expectedNodeType, actionPoint.getNodeType());
92         assertEquals("entry", actionPoint.getNodeParameter());
93
94         expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "output");
95         assertEquals(expectedNodeType, output.getNodeType());
96         assertEquals("", output.getNodeParameter());
97     }
98
99 }