Populate parser/ hierarchy
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug8922Test.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 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertTrue;
15
16 import com.google.common.collect.ImmutableSet;
17 import java.util.Optional;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
23
24 public class Bug8922Test {
25     private static final String NS = "foo";
26
27     @Test
28     public void testAllFeaturesSupported() throws Exception {
29         final SchemaContext context = StmtTestUtils.parseYangSource("/bugs/bug8922/foo.yang");
30         assertNotNull(context);
31         final SchemaNode findNode = context.findDataTreeChild(qN("target"), qN("my-con")).get();
32         assertThat(findNode, instanceOf(ContainerSchemaNode.class));
33         assertEquals(Optional.of("New description"), findNode.getDescription());
34     }
35
36     @Test
37     public void testNoFeatureSupported() throws Exception {
38         final SchemaContext context = StmtTestUtils.parseYangSource("/bugs/bug8922/foo.yang", ImmutableSet.of());
39         assertNotNull(context);
40         assertEquals(Optional.empty(), context.findDataTreeChild(qN("target"), qN("my-con")));
41         assertTrue(context.getAvailableAugmentations().isEmpty());
42     }
43
44     private static QName qN(final String localName) {
45         return QName.create(NS, localName);
46     }
47 }