Populate parser/ hierarchy
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug7879Test.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.stmt;
9
10 import static org.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
13
14 import java.util.Optional;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.common.XMLNamespace;
18 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
22
23 public class Bug7879Test {
24     private static final XMLNamespace NS = XMLNamespace.of("my-model-ns");
25
26     @Test
27     public void test() throws Exception {
28         final ModuleEffectiveStatement module = TestUtils.parseYangSources("/bugs/bug7879")
29             .getModuleStatement(QName.create(NS, "my-model"));
30
31         final SchemaTreeEffectiveStatement<?> container = module.findSchemaTreeNode(
32             qN("my-alarm"), qN("my-content"), qN("my-event-container")).orElse(null);
33         assertThat(container, instanceOf(ContainerSchemaNode.class));
34
35         final SchemaTreeEffectiveStatement<?> leaf = module.findSchemaTreeNode(
36             qN("my-alarm"), qN("my-content"), qN("my-event-value")).orElse(null);
37         assertThat(leaf, instanceOf(LeafSchemaNode.class));
38         assertEquals(Optional.of("new description"), ((LeafSchemaNode) leaf).getDescription());
39     }
40
41     private static QName qN(final String localName) {
42         return QName.create(NS, localName);
43     }
44 }