Further yang-parser-impl checkstyle fixes
[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     private static final String FOO_REV = "1970-01-01";
29
30     @Test
31     public void yang11Test() throws Exception {
32         final SchemaContext context = StmtTestUtils.parseYangSources("/rfc7950/bug6876/yang11");
33         assertNotNull(context);
34
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);
39     }
40
41     @Test
42     public void yang10Test() throws Exception {
43         final SchemaContext context = StmtTestUtils.parseYangSources("/rfc7950/bug6876/yang10");
44         assertNotNull(context);
45
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"))));
49     }
50
51     private static SchemaNode findNode(final SchemaContext context, final Iterable<QName> qnames) {
52         return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(qnames, true));
53     }
54
55     private static QName foo(final String localName) {
56         return QName.create(FOO_NS, FOO_REV, localName);
57     }
58
59     private static QName bar(final String localName) {
60         return QName.create(BAR_NS, BAR_REV, localName);
61     }
62 }