Populate xpath/ hierarchy
[yangtools.git] / yang / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug394Test.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 import static org.junit.Assert.assertTrue;
13
14 import java.util.Collection;
15 import java.util.Iterator;
16 import java.util.stream.Collectors;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
24
25 /**
26  * Test antlr grammar capability to parse nested unknown nodes.
27  */
28 public class Bug394Test {
29     @Test
30     public void testParseList() throws Exception {
31         final SchemaContext context = TestUtils.loadModules(getClass().getResource("/bugs/bug394-retest").toURI());
32         final Module bug394 = TestUtils.findModule(context, "bug394").get();
33         final Module bug394_ext = TestUtils.findModule(context, "bug394-ext").get();
34
35         final ContainerSchemaNode logrecords = (ContainerSchemaNode) bug394.getDataChildByName(QName.create(
36                 bug394.getQNameModule(), "logrecords"));
37         assertNotNull(logrecords);
38
39         final Collection<? extends UnrecognizedStatement> nodes = logrecords.asEffectiveStatement().getDeclared()
40             .declaredSubstatements(UnrecognizedStatement.class);
41         assertEquals(2, nodes.size());
42
43         final Collection<QName> extensions = bug394_ext.getExtensionSchemaNodes()
44             .stream().map(ExtensionDefinition::getQName).collect(Collectors.toUnmodifiableList());
45         assertEquals(3, extensions.size());
46
47         final Iterator<? extends UnrecognizedStatement> it = nodes.iterator();
48         assertTrue(extensions.contains(it.next().statementDefinition().getStatementName()));
49         assertTrue(extensions.contains(it.next().statementDefinition().getStatementName()));
50     }
51 }