Populate xpath/ hierarchy
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / yin / YinFileChoiceStmtTest.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.yin;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14
15 import java.util.Iterator;
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.CaseSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.Module;
23 import org.opendaylight.yangtools.yang.stmt.TestUtils;
24
25 public class YinFileChoiceStmtTest extends AbstractYinModulesTest {
26
27     @Test
28     public void testChoiceAndCases() {
29         final Module testModule = TestUtils.findModule(context, "config").get();
30         assertNotNull(testModule);
31
32         final ListSchemaNode list = (ListSchemaNode) testModule.findDataChildByName(
33             QName.create(testModule.getQNameModule(), "modules"),
34             QName.create(testModule.getQNameModule(), "module")).get();
35
36         ChoiceSchemaNode choice = (ChoiceSchemaNode) list.findDataChildByName(QName.create(testModule.getQNameModule(),
37                 "configuration")).get();
38
39         assertEquals("configuration", choice.getQName().getLocalName());
40         assertTrue(choice.isMandatory());
41         assertEquals(Optional.of(Boolean.TRUE), choice.effectiveConfig());
42         assertEquals(1, choice.getCases().size());
43
44         // this choice is augmented (see main-impl.yang.xml)
45         final Iterator<? extends CaseSchemaNode> casesIterator = choice.getCases().iterator();
46         final CaseSchemaNode caseNode = casesIterator.next();
47         assertEquals("main-impl", caseNode.getQName().getLocalName());
48         assertEquals(13, caseNode.getChildNodes().size());
49
50         assertTrue(caseNode.getWhenCondition().isPresent());
51
52         choice = (ChoiceSchemaNode) list.findDataChildByName(QName.create(testModule.getQNameModule(), "state")).get();
53
54         assertEquals("state", choice.getQName().getLocalName());
55         assertFalse(choice.isMandatory());
56         assertEquals(Optional.of(Boolean.FALSE), choice.effectiveConfig());
57         assertTrue(choice.getCases().isEmpty());
58     }
59 }