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