YANGTOOLS-706: Split out yang-parser-rfc7950
[yangtools.git] / yang / 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.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertTrue;
14
15 import com.google.common.collect.ImmutableSet;
16 import java.util.Optional;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
23 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
24
25 public class Bug8922Test {
26     private static final String NS = "foo";
27
28     @Test
29     public void testAllFeaturesSupported() throws Exception {
30         final SchemaContext context = StmtTestUtils.parseYangSource("/bugs/bug8922/foo.yang");
31         assertNotNull(context);
32         final SchemaNode findNode = findNode(context, qN("target"), qN("my-con"));
33         assertTrue(findNode instanceof ContainerSchemaNode);
34         assertEquals(Optional.of("New description"), ((ContainerSchemaNode) findNode).getDescription());
35     }
36
37     @Test
38     public void testNoFeatureSupported() throws Exception {
39         final SchemaContext context = StmtTestUtils.parseYangSource("/bugs/bug8922/foo.yang", ImmutableSet.of());
40         assertNotNull(context);
41         final SchemaNode findNode = findNode(context, qN("target"), qN("my-con"));
42         assertNull(findNode);
43         assertTrue(context.getAvailableAugmentations().isEmpty());
44     }
45
46     private static SchemaNode findNode(final SchemaContext context, final QName... qnames) {
47         return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, qnames));
48     }
49
50     private static QName qN(final String localName) {
51         return QName.create(NS, localName);
52     }
53 }