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 / Bug6876Test.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.assertNull;
12 import static org.junit.Assert.assertTrue;
13
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;
23
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
29     @Test
30     public void yang11Test() throws Exception {
31         final SchemaContext context = StmtTestUtils.parseYangSources("/rfc7950/bug6876/yang11");
32         assertNotNull(context);
33
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);
38     }
39
40     @Test
41     public void yang10Test() throws Exception {
42         final SchemaContext context = StmtTestUtils.parseYangSources("/rfc7950/bug6876/yang10");
43         assertNotNull(context);
44
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"))));
48     }
49
50     private static SchemaNode findNode(final SchemaContext context, final Iterable<QName> qnames) {
51         return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(qnames, true));
52     }
53
54     private static QName foo(final String localName) {
55         return QName.create(FOO_NS, localName);
56     }
57
58     private static QName bar(final String localName) {
59         return QName.create(BAR_NS, BAR_REV, localName);
60     }
61 }