Port yang-parser-rfc7950 to JUnit 5
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / parser / stmt / rfc7950 / Bug6876Test.java
1 /*
2  * Copyright (c) 2017 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.parser.stmt.rfc7950;
9
10 import static org.hamcrest.CoreMatchers.startsWith;
11 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
12
13 import org.junit.jupiter.api.Test;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
16 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
17 import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
18
19 class Bug6876Test extends AbstractYangTest {
20     @Test
21     void yang11Test() {
22         final var context = assertEffectiveModelDir("/rfc7950/bug6876/yang11");
23         DataSchemaNode node = context.findDataTreeChild(bar("augment-target"), bar("my-leaf")).orElse(null);
24         assertInstanceOf(LeafSchemaNode.class, node);
25         node = context.findDataTreeChild(bar("augment-target"), foo("mandatory-leaf")).orElse(null);
26         assertInstanceOf(LeafSchemaNode.class, node);
27     }
28
29     @Test
30     void yang10Test() {
31         assertInferenceExceptionDir("/rfc7950/bug6876/yang10", startsWith(
32             "An augment cannot add node 'mandatory-leaf' because it is mandatory and in module different than target"));
33     }
34
35     private static QName foo(final String localName) {
36         return QName.create("foo", localName);
37     }
38
39     private static QName bar(final String localName) {
40         return QName.create("bar", "2017-01-11", localName);
41     }
42 }