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.assertNull;
12 import static org.junit.Assert.assertTrue;
14 import com.google.common.collect.ImmutableList;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
21 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
22 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
24 public class Bug6876Test {
25 private static final String BAR_NS = "bar";
26 private static final String BAR_REV = "2017-01-11";
27 private static final String FOO_NS = "foo";
30 public void yang11Test() throws Exception {
31 final SchemaContext context = StmtTestUtils.parseYangSources("/rfc7950/bug6876/yang11");
32 assertNotNull(context);
34 assertTrue(findNode(context, ImmutableList.of(bar("augment-target"),
35 bar("my-leaf"))) instanceof LeafSchemaNode);
36 assertTrue(findNode(context, ImmutableList.of(bar("augment-target"),
37 foo("mandatory-leaf"))) instanceof LeafSchemaNode);
41 public void yang10Test() throws Exception {
42 final SchemaContext context = StmtTestUtils.parseYangSources("/rfc7950/bug6876/yang10");
43 assertNotNull(context);
45 assertTrue(findNode(context, ImmutableList.of(bar("augment-target"),
46 bar("my-leaf"))) instanceof LeafSchemaNode);
47 assertNull(findNode(context, ImmutableList.of(bar("augment-target"), foo("mandatory-leaf"))));
50 private static SchemaNode findNode(final SchemaContext context, final Iterable<QName> qnames) {
51 return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(qnames, true));
54 private static QName foo(final String localName) {
55 return QName.create(FOO_NS, localName);
58 private static QName bar(final String localName) {
59 return QName.create(BAR_NS, BAR_REV, localName);