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