99a78730dc10560ed56d8662933f977e9728b8e7
[yangtools.git] / yang / yang-parser-impl / 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.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertTrue;
12
13 import com.google.common.collect.ImmutableList;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
20 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
21 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
22
23 public class Bug6884Test {
24     private static final String FOO_NS = "foo";
25     private static final String FOO_REV = "1970-01-01";
26
27     @Test
28     public void testYang11() throws Exception {
29         final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/rfc7950/bug6884/yang1-1");
30         assertNotNull(schemaContext);
31
32         assertTrue(findNode(schemaContext, ImmutableList.of(foo("sub-root"), foo("sub-foo-2-con")))
33             instanceof ContainerSchemaNode);
34     }
35
36     @Test
37     public void testCircularIncludesYang10() throws Exception {
38         final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/rfc7950/bug6884/circular-includes");
39
40         assertNotNull(schemaContext);
41         assertTrue(findNode(schemaContext, ImmutableList.of(foo("sub-root"), foo("sub-foo-2-con")))
42             instanceof ContainerSchemaNode);
43         assertTrue(findNode(schemaContext, ImmutableList.of(foo("sub-root-2"), foo("sub-foo-con")))
44             instanceof ContainerSchemaNode);
45     }
46
47     private static SchemaNode findNode(final SchemaContext context, final Iterable<QName> qNames) {
48         return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(qNames, true));
49     }
50
51     private static QName foo(final String localName) {
52         return QName.create(FOO_NS, FOO_REV, localName);
53     }
54 }