Merge branch 'master' of ../controller
[yangtools.git] / yang / 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 org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.stmt.TestUtils;
23
24 public class YinFileChoiceStmtTest extends AbstractYinModulesTest {
25
26     @Test
27     public void testChoiceAndCases() {
28         final Module testModule = TestUtils.findModule(context, "config").get();
29         assertNotNull(testModule);
30
31         final ListSchemaNode list = (ListSchemaNode) testModule.findDataChildByName(
32             QName.create(testModule.getQNameModule(), "modules"),
33             QName.create(testModule.getQNameModule(), "module")).get();
34
35         ChoiceSchemaNode choice = (ChoiceSchemaNode) list.findDataChildByName(QName.create(testModule.getQNameModule(),
36                 "configuration")).get();
37
38         assertEquals("configuration", choice.getQName().getLocalName());
39         assertTrue(choice.isMandatory());
40         assertTrue(choice.isConfiguration());
41         assertEquals(1, choice.getCases().size());
42
43         // this choice is augmented (see main-impl.yang.xml)
44         final Iterator<CaseSchemaNode> casesIterator = choice.getCases().values().iterator();
45         final CaseSchemaNode caseNode = casesIterator.next();
46         assertEquals("main-impl", caseNode.getQName().getLocalName());
47         assertEquals(13, caseNode.getChildNodes().size());
48
49         assertTrue(caseNode.getWhenCondition().isPresent());
50
51         choice = (ChoiceSchemaNode) list.findDataChildByName(QName.create(testModule.getQNameModule(), "state")).get();
52
53         assertEquals("state", choice.getQName().getLocalName());
54         assertFalse(choice.isMandatory());
55         assertFalse(choice.isConfiguration());
56         assertTrue(choice.getCases().isEmpty());
57     }
58 }