Bug 7847: Implement YANG 1.1 XPath functions in YangFunctionContext
[yangtools.git] / yang / yang-parser-impl / 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.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
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.ContainerSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
22 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
23
24 public class Bug7879Test {
25     private static final String NS = "my-model-ns";
26     private static final String REV = "1970-01-01";
27
28     @Test
29     public void test() throws Exception {
30         final SchemaContext context = TestUtils.parseYangSources("/bugs/bug7879");
31         assertNotNull(context);
32
33         assertTrue(findNode(context, ImmutableList.of(qN("my-alarm"), qN("my-content"), qN("my-event-container"))) instanceof ContainerSchemaNode);
34         final SchemaNode myEventValueLeaf = findNode(context,
35                 ImmutableList.of(qN("my-alarm"), qN("my-content"), qN("my-event-value")));
36         assertTrue(myEventValueLeaf instanceof LeafSchemaNode);
37         assertEquals("new description", myEventValueLeaf.getDescription());
38     }
39
40     private static SchemaNode findNode(final SchemaContext context, final Iterable<QName> qNames) {
41         return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(qNames, true));
42     }
43
44     private static QName qN(final String localName) {
45         return QName.create(NS, REV, localName);
46     }
47 }