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