Further cleanup of tests
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug5335Test.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.DataSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
18 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
19
20 public class Bug5335Test extends AbstractYangTest {
21     private static final String FOO = "foo";
22     private static final String BAR = "bar";
23     private static final String REV = "2016-03-04";
24
25     private static final QName ROOT = QName.create(FOO, REV, "root");
26     private static final QName NON_PRESENCE_CONTAINER_F = QName.create(FOO, REV, "non-presence-container");
27     private static final QName MANDATORY_LEAF_F = QName.create(FOO, REV, "mandatory-leaf");
28     private static final QName PRESENCE_CONTAINER_B = QName.create(BAR, REV, "presence-container");
29     private static final QName NON_PRESENCE_CONTAINER_B = QName.create(BAR, REV, "non-presence-container");
30     private static final QName MANDATORY_LEAF_B = QName.create(BAR, REV, "mandatory-leaf");
31
32     @Test
33     public void incorrectTest1() {
34         assertInferenceExceptionDir("/bugs/bug5335/incorrect/case-1", startsWith(
35             "An augment cannot add node 'mandatory-leaf' because it is mandatory and in module different than target"));
36     }
37
38     @Test
39     public void incorrectTest2() {
40         assertInferenceExceptionDir("/bugs/bug5335/incorrect/case-2", startsWith(
41             "An augment cannot add node 'mandatory-leaf' because it is mandatory and in module different than target"));
42     }
43
44     @Test
45     public void incorrectTest3() {
46         assertInferenceExceptionDir("/bugs/bug5335/incorrect/case-3", startsWith(
47             "An augment cannot add node 'mandatory-leaf' because it is mandatory and in module different than target"));
48     }
49
50     @Test
51     public void correctTest1() {
52         final EffectiveModelContext context = assertEffectiveModelDir("/bugs/bug5335/correct/case-1");
53         final DataSchemaNode mandatoryLeaf = context.findDataTreeChild(ROOT, PRESENCE_CONTAINER_B, MANDATORY_LEAF_B)
54             .orElse(null);
55         assertThat(mandatoryLeaf, instanceOf(LeafSchemaNode.class));
56     }
57
58     @Test
59     public void correctTest2() {
60         final EffectiveModelContext context = assertEffectiveModelDir("/bugs/bug5335/correct/case-2");
61         final DataSchemaNode mandatoryLeaf = context.findDataTreeChild(ROOT, PRESENCE_CONTAINER_B,
62             NON_PRESENCE_CONTAINER_B, MANDATORY_LEAF_B).orElse(null);
63         assertThat(mandatoryLeaf, instanceOf(LeafSchemaNode.class));
64     }
65
66     @Test
67     public void correctTest3() {
68         final EffectiveModelContext context = assertEffectiveModelDir("/bugs/bug5335/correct/case-3");
69         final DataSchemaNode mandatoryLeaf = context.findDataTreeChild(ROOT, PRESENCE_CONTAINER_B,
70             NON_PRESENCE_CONTAINER_B, MANDATORY_LEAF_B).orElse(null);
71         assertThat(mandatoryLeaf, instanceOf(LeafSchemaNode.class));
72     }
73
74     @Test
75     public void correctTest4() {
76         final EffectiveModelContext context = assertEffectiveModelDir("/bugs/bug5335/correct/case-4");
77         final DataSchemaNode mandatoryLeaf = context.findDataTreeChild(ROOT, NON_PRESENCE_CONTAINER_F, MANDATORY_LEAF_F)
78             .orElse(null);
79         assertThat(mandatoryLeaf, instanceOf(LeafSchemaNode.class));
80     }
81 }