2 * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.stmt;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
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;
24 public class Bug7879Test {
25 private static final String NS = "my-model-ns";
28 public void test() throws Exception {
29 final SchemaContext context = TestUtils.parseYangSources("/bugs/bug7879");
30 assertNotNull(context);
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());
39 private static SchemaNode findNode(final SchemaContext context, final QName... qnames) {
40 return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, qnames));
43 private static QName qN(final String localName) {
44 return QName.create(NS, localName);