2 * Copyright (c) 2017 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.parser.stmt.rfc7950;
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.assertThrows;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
21 import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
22 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
24 public class Bug6876Test extends AbstractYangTest {
26 public void yang11Test() {
27 final var context = assertEffectiveModelDir("/rfc7950/bug6876/yang11");
28 DataSchemaNode node = context.findDataTreeChild(bar("augment-target"), bar("my-leaf")).orElse(null);
29 assertThat(node, instanceOf(LeafSchemaNode.class));
30 node = context.findDataTreeChild(bar("augment-target"), foo("mandatory-leaf")).orElse(null);
31 assertThat(node, instanceOf(LeafSchemaNode.class));
35 public void yang10Test() {
36 final ReactorException ex = assertThrows(ReactorException.class,
37 () -> StmtTestUtils.parseYangSources("/rfc7950/bug6876/yang10"));
38 final Throwable cause = ex.getCause();
39 assertThat(cause, instanceOf(InferenceException.class));
40 assertThat(cause.getMessage(), startsWith(
41 "An augment cannot add node 'mandatory-leaf' because it is mandatory and in module different than target"));
44 private static QName foo(final String localName) {
45 return QName.create("foo", localName);
48 private static QName bar(final String localName) {
49 return QName.create("bar", "2017-01-11", localName);