Further cleanup of tests
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug5481Test.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.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertTrue;
15
16 import java.util.Optional;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
22 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.Status;
24 import org.opendaylight.yangtools.yang.xpath.api.YangXPathExpression.QualifiedBound;
25
26 public class Bug5481Test extends AbstractYangTest {
27     @Test
28     public void test() throws Exception {
29         final var context = assertEffectiveModelDir("/bugs/bug5481");
30         ContainerSchemaNode topContainer = verifyTopContainer(context);
31         verifyExtendedLeaf(topContainer);
32     }
33
34     private static ContainerSchemaNode verifyTopContainer(final EffectiveModelContext context) {
35         QName top = QName.create("http://example.com/module1", "2016-03-09", "top");
36         DataSchemaNode dataChildByName = context.getDataChildByName(top);
37         assertThat(dataChildByName, instanceOf(ContainerSchemaNode.class));
38
39         ContainerSchemaNode topContainer = (ContainerSchemaNode) dataChildByName;
40
41         assertFalse(topContainer.getWhenCondition().isPresent());
42         assertEquals(Status.CURRENT, topContainer.getStatus());
43         assertFalse(topContainer.getDescription().isPresent());
44         assertFalse(topContainer.getReference().isPresent());
45         return topContainer;
46     }
47
48     private static void verifyExtendedLeaf(final ContainerSchemaNode topContainer) {
49         DataSchemaNode dataChildByName2 = topContainer.getDataChildByName(QName.create("http://example.com/module2",
50                 "2016-03-09", "extended-leaf"));
51         assertTrue(dataChildByName2 instanceof LeafSchemaNode);
52
53         LeafSchemaNode extendedLeaf = (LeafSchemaNode) dataChildByName2;
54         assertEquals(Status.DEPRECATED, extendedLeaf.getStatus());
55         assertEquals(Optional.of("text"), extendedLeaf.getDescription());
56         assertEquals(Optional.of("ref"), extendedLeaf.getReference());
57
58         QualifiedBound whenConditionExtendedLeaf = extendedLeaf.getWhenCondition().orElseThrow();
59         assertEquals("module1:top = 'extended'", whenConditionExtendedLeaf.toString());
60     }
61 }