Fix checkstyle in yang-parser-impl and enable enforcement
[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 org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
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
23 public class Bug7879Test {
24     private static final String NS = "my-model-ns";
25
26     @Test
27     public void test() throws Exception {
28         final SchemaContext context = TestUtils.parseYangSources("/bugs/bug7879");
29         assertNotNull(context);
30
31         assertTrue(findNode(context, qN("my-alarm"), qN("my-content"), qN("my-event-container"))
32             instanceof ContainerSchemaNode);
33         final SchemaNode myEventValueLeaf = findNode(context, qN("my-alarm"), qN("my-content"), qN("my-event-value"));
34         assertTrue(myEventValueLeaf instanceof LeafSchemaNode);
35         assertEquals("new description", myEventValueLeaf.getDescription());
36     }
37
38     private static SchemaNode findNode(final SchemaContext context, final QName... qnames) {
39         return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, qnames));
40     }
41
42     private static QName qN(final String localName) {
43         return QName.create(NS, localName);
44     }
45 }