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