Further cleanup of tests
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug6669Test.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
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
19
20 public class Bug6669Test extends AbstractYangTest {
21     private static final String REV = "2016-09-08";
22     private static final String FOO_NS = "foo";
23     private static final String BAR_NS = "bar";
24     private static final QName ROOT = QName.create(FOO_NS, REV, "root");
25     private static final QName BAR = QName.create(BAR_NS, REV, "bar");
26     private static final QName BAR_1 = QName.create(BAR_NS, REV, "bar1");
27     private static final QName BAR_2 = QName.create(BAR_NS, REV, "bar2");
28     private static final QName M = QName.create(BAR_NS, REV, "m");
29
30     @Test
31     public void testInvalidAugment() {
32         assertInferenceExceptionDir("/bugs/bug6669/invalid/test1", startsWith(
33             "An augment cannot add node 'm' because it is mandatory and in module different than target"));
34     }
35
36     @Test
37     public void testInvalidAugment2() {
38         assertInferenceExceptionDir("/bugs/bug6669/invalid/test2", startsWith(
39             "An augment cannot add node 'm' because it is mandatory and in module different than target"));
40     }
41
42     @Test
43     public void testInvalidAugment3() {
44         assertInferenceExceptionDir("/bugs/bug6669/invalid/test3", startsWith(
45             "An augment cannot add node 'l' because it is mandatory and in module different than target"));
46     }
47
48     @Test
49     public void testValidAugment() {
50         final var context = assertEffectiveModelDir("/bugs/bug6669/valid/test1");
51         final SchemaNode findDataSchemaNode = context.findDataTreeChild(ROOT, BAR, BAR_1, M).get();
52         assertThat(findDataSchemaNode, instanceOf(LeafSchemaNode.class));
53     }
54
55     @Test
56     public void testValidAugment2() {
57         final var context = assertEffectiveModelDir("/bugs/bug6669/valid/test2");
58         final SchemaNode findDataSchemaNode = context.findDataTreeChild(ROOT, BAR, BAR_1, BAR_2, M).get();
59         assertThat(findDataSchemaNode, instanceOf(LeafSchemaNode.class));
60     }
61
62     @Test
63     public void testValidAugment3() throws Exception {
64         final var context = assertEffectiveModelDir("/bugs/bug6669/valid/test3");
65         final SchemaNode findDataSchemaNode = context.findDataTreeChild(ROOT, BAR, BAR_1, BAR_2,
66                 QName.create(BAR_NS, REV, "l")).get();
67         assertThat(findDataSchemaNode, instanceOf(ListSchemaNode.class));
68     }
69 }