2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.stmt;
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;
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;
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");
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"))
31 assertInstanceOf(LeafSchemaNode.class, fooModule.findSchemaTreeNode(
32 foo("root"), bar("my-list"), bar("two"), bar("mandatory-leaf-2"))
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")));
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 "));
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 "));
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 "));
59 private static QName foo(final String localName) {
60 return QName.create(FOO_NS, localName);
63 private static QName bar(final String localName) {
64 return QName.create(BAR_NS, localName);