Adjust test suite parser update to conform with API changes
[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
26     @Test
27     public void testYang11() throws Exception {
28         final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/rfc7950/bug6884/yang1-1");
29         assertNotNull(schemaContext);
30
31         assertTrue(findNode(schemaContext, ImmutableList.of(foo("sub-root"), foo("sub-foo-2-con")))
32             instanceof ContainerSchemaNode);
33     }
34
35     @Test
36     public void testCircularIncludesYang10() throws Exception {
37         final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/rfc7950/bug6884/circular-includes");
38
39         assertNotNull(schemaContext);
40         assertTrue(findNode(schemaContext, ImmutableList.of(foo("sub-root"), foo("sub-foo-2-con")))
41             instanceof ContainerSchemaNode);
42         assertTrue(findNode(schemaContext, ImmutableList.of(foo("sub-root-2"), foo("sub-foo-con")))
43             instanceof ContainerSchemaNode);
44     }
45
46     private static SchemaNode findNode(final SchemaContext context, final Iterable<QName> qnames) {
47         return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(qnames, true));
48     }
49
50     private static QName foo(final String localName) {
51         return QName.create(FOO_NS, localName);
52     }
53 }