Bug 6669: Mandatory nodes cannot be added to node from another module via augment
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug6669Test.java
1 /*
2  * Copyright (c) 2016 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.assertNotNull;
11 import static org.junit.Assert.assertNull;
12 import static org.junit.Assert.assertTrue;
13
14 import java.io.FileNotFoundException;
15 import java.net.URISyntaxException;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
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 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
25 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
26
27 public class Bug6669Test {
28     private static final String REV = "2016-09-08";
29     private static final String FOO_NS = "foo";
30     private static final String BAR_NS = "bar";
31     private static final QName ROOT = QName.create(FOO_NS, REV, "root");
32     private static final QName BAR = QName.create(BAR_NS, REV, "bar");
33     private static final QName BAR_1 = QName.create(BAR_NS, REV, "bar1");
34     private static final QName BAR_2 = QName.create(BAR_NS, REV, "bar2");
35     private static final QName M = QName.create(BAR_NS, REV, "m");
36     private static final QName L = QName.create(BAR_NS, REV, "l");
37
38     @Test
39     public void testInvalidAugment() throws SourceException, ReactorException, FileNotFoundException,
40             URISyntaxException {
41         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test1");
42         assertNotNull(context);
43
44         final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
45                 SchemaPath.create(true, ROOT, BAR, BAR_1, M));
46         assertNull(findDataSchemaNode);
47     }
48
49     @Test
50     public void testInvalidAugment2() throws SourceException, ReactorException, FileNotFoundException,
51             URISyntaxException {
52         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test2");
53         assertNotNull(context);
54
55         final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
56                 SchemaPath.create(true, ROOT, BAR, BAR_1, BAR_2, M));
57         assertNull(findDataSchemaNode);
58     }
59
60     @Test
61     public void testInvalidAugment3() throws SourceException, ReactorException, FileNotFoundException,
62             URISyntaxException {
63         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test3");
64         assertNotNull(context);
65
66         final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
67                 SchemaPath.create(true, ROOT, BAR, BAR_1, BAR_2, L));
68         assertNull(findDataSchemaNode);
69     }
70
71     @Test
72     public void testValidAugment() throws SourceException, ReactorException, FileNotFoundException, URISyntaxException {
73         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/valid/test1");
74         assertNotNull(context);
75
76         final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
77                 SchemaPath.create(true, ROOT, BAR, BAR_1, M));
78         assertTrue(findDataSchemaNode instanceof LeafSchemaNode);
79     }
80
81     @Test
82     public void testValidAugment2() throws SourceException, ReactorException, FileNotFoundException, URISyntaxException {
83         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/valid/test2");
84         assertNotNull(context);
85
86         final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
87                 SchemaPath.create(true, ROOT, BAR, BAR_1, BAR_2, M));
88         assertTrue(findDataSchemaNode instanceof LeafSchemaNode);
89     }
90
91     @Test
92     public void testValidAugment3() throws SourceException, ReactorException, FileNotFoundException, URISyntaxException {
93         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/valid/test3");
94         assertNotNull(context);
95
96         final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
97                 SchemaPath.create(true, ROOT, BAR, BAR_1, BAR_2, L));
98         assertTrue(findDataSchemaNode instanceof ListSchemaNode);
99     }
100 }