Clean up TreeNode API
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug8126Test.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.hamcrest.CoreMatchers.startsWith;
11 import static org.junit.jupiter.api.Assertions.assertEquals;
12 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
13
14 import java.util.Optional;
15 import org.junit.jupiter.api.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.common.QNameModule;
18 import org.opendaylight.yangtools.yang.common.XMLNamespace;
19 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
20
21 class Bug8126Test extends AbstractYangTest {
22     private static final XMLNamespace FOO_NS = XMLNamespace.of("foo");
23     private static final XMLNamespace BAR_NS = XMLNamespace.of("bar");
24
25     @Test
26     void testValidAugments() {
27         final var fooModule = assertEffectiveModelDir("/bugs/bug8126/valid").getModuleStatement(QNameModule.of(FOO_NS));
28         assertInstanceOf(LeafSchemaNode.class, fooModule.findSchemaTreeNode(
29             foo("root"), bar("my-container"), bar("my-choice"), bar("one"), bar("one"), bar("mandatory-leaf"))
30             .orElseThrow());
31         assertInstanceOf(LeafSchemaNode.class, fooModule.findSchemaTreeNode(
32             foo("root"), bar("my-list"), bar("two"), bar("mandatory-leaf-2"))
33             .orElseThrow());
34         assertEquals(Optional.empty(), fooModule.findSchemaTreeNode(foo("root"), bar("mandatory-list")));
35         assertEquals(Optional.empty(), fooModule.findSchemaTreeNode(
36             foo("root"), bar("mandatory-container"), bar("mandatory-choice")));
37         assertEquals(Optional.empty(), fooModule.findSchemaTreeNode(
38             foo("root"), bar("mandatory-container-2"), bar("one"), bar("mandatory-leaf-3")));
39     }
40
41     @Test
42     void testAugmentMandatoryChoice() {
43         assertInferenceExceptionDir("/bugs/bug8126/inv-choice", startsWith(
44             "An augment cannot add node 'mandatory-choice' because it is mandatory and in module different than "));
45     }
46
47     @Test
48     void testAugmentMandatoryList() {
49         assertInferenceExceptionDir("/bugs/bug8126/inv-list", startsWith(
50             "An augment cannot add node 'mandatory-list' because it is mandatory and in module different than "));
51     }
52
53     @Test
54     void testAugmentMandatoryContainer() {
55         assertInferenceExceptionDir("/bugs/bug8126/inv-cont", startsWith(
56             "An augment cannot add node 'mandatory-leaf-3' because it is mandatory and in module different than "));
57     }
58
59     private static QName foo(final String localName) {
60         return QName.create(FOO_NS, localName);
61     }
62
63     private static QName bar(final String localName) {
64         return QName.create(BAR_NS, localName);
65     }
66 }