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";
28 private static final String FOO_REV = "1970-01-01";
31 public void yang11Test() throws Exception {
32 final SchemaContext context = StmtTestUtils.parseYangSources("/rfc7950/bug6876/yang11");
33 assertNotNull(context);
35 assertTrue(findNode(context, ImmutableList.of(bar("augment-target"),
36 bar("my-leaf"))) instanceof LeafSchemaNode);
37 assertTrue(findNode(context, ImmutableList.of(bar("augment-target"),
38 foo("mandatory-leaf"))) instanceof LeafSchemaNode);
42 public void yang10Test() throws Exception {
43 final SchemaContext context = StmtTestUtils.parseYangSources("/rfc7950/bug6876/yang10");
44 assertNotNull(context);
46 assertTrue(findNode(context, ImmutableList.of(bar("augment-target"),
47 bar("my-leaf"))) instanceof LeafSchemaNode);
48 assertNull(findNode(context, ImmutableList.of(bar("augment-target"), foo("mandatory-leaf"))));
51 private static SchemaNode findNode(final SchemaContext context, final Iterable<QName> qNames) {
52 return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(qNames, true));
55 private static QName foo(final String localName) {
56 return QName.create(FOO_NS, FOO_REV, localName);
59 private static QName bar(final String localName) {
60 return QName.create(BAR_NS, BAR_REV, localName);