Adjust test suite parser update to conform with API changes
[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 java.util.Optional;
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
27     @Test
28     public void test() throws Exception {
29         final SchemaContext context = TestUtils.parseYangSources("/bugs/bug7879");
30         assertNotNull(context);
31
32         assertTrue(findNode(context, qN("my-alarm"), qN("my-content"), qN("my-event-container"))
33             instanceof ContainerSchemaNode);
34         final SchemaNode myEventValueLeaf = findNode(context, qN("my-alarm"), qN("my-content"), qN("my-event-value"));
35         assertTrue(myEventValueLeaf instanceof LeafSchemaNode);
36         assertEquals(Optional.of("new description"), myEventValueLeaf.getDescription());
37     }
38
39     private static SchemaNode findNode(final SchemaContext context, final QName... qnames) {
40         return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, qnames));
41     }
42
43     private static QName qN(final String localName) {
44         return QName.create(NS, localName);
45     }
46 }