Populate xpath/ hierarchy
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / parser / stmt / rfc7950 / Bug6884Test.java
1 /*
2  * Copyright (c) 2017 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.parser.stmt.rfc7950;
9
10 import static org.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12
13 import org.junit.Test;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
16 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
18 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
19
20 public class Bug6884Test {
21     @Test
22     public void testYang11() throws Exception {
23         final EffectiveModelContext schemaContext = StmtTestUtils.parseYangSources("/rfc7950/bug6884/yang1-1");
24         final DataSchemaNode node = schemaContext.findDataTreeChild(foo("sub-root"), foo("sub-foo-2-con")).orElse(null);
25         assertThat(node, instanceOf(ContainerSchemaNode.class));
26     }
27
28     @Test
29     public void testCircularIncludesYang10() throws Exception {
30         final EffectiveModelContext schemaContext =
31             StmtTestUtils.parseYangSources("/rfc7950/bug6884/circular-includes");
32         DataSchemaNode node = schemaContext.findDataTreeChild(foo("sub-root"), foo("sub-foo-2-con")).orElse(null);
33         assertThat(node, instanceOf(ContainerSchemaNode.class));
34
35         node = schemaContext.findDataTreeChild(foo("sub-root-2"), foo("sub-foo-con")).orElse(null);
36         assertThat(node, instanceOf(ContainerSchemaNode.class));
37     }
38
39     private static QName foo(final String localName) {
40         return QName.create("foo", localName);
41     }
42 }