2 * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertTrue;
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;
23 public class Bug6884Test {
24 private static final String FOO_NS = "foo";
25 private static final String FOO_REV = "1970-01-01";
28 public void testYang11() throws Exception {
29 final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/rfc7950/bug6884/yang1-1");
30 assertNotNull(schemaContext);
32 assertTrue(findNode(schemaContext, ImmutableList.of(foo("sub-root"), foo("sub-foo-2-con")))
33 instanceof ContainerSchemaNode);
37 public void testCircularIncludesYang10() throws Exception {
38 final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/rfc7950/bug6884/circular-includes");
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);
47 private static SchemaNode findNode(final SchemaContext context, final Iterable<QName> qNames) {
48 return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(qNames, true));
51 private static QName foo(final String localName) {
52 return QName.create(FOO_NS, FOO_REV, localName);