Use local variable type inference
[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.Optional;
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
23 public class YinFileChoiceStmtTest extends AbstractYinModulesTest {
24     @Test
25     public void testChoiceAndCases() {
26         final Module testModule = context.findModules("config").iterator().next();
27         assertNotNull(testModule);
28
29         final ListSchemaNode list = (ListSchemaNode) testModule.findDataChildByName(
30             QName.create(testModule.getQNameModule(), "modules"),
31             QName.create(testModule.getQNameModule(), "module")).get();
32
33         ChoiceSchemaNode choice = (ChoiceSchemaNode) list.findDataChildByName(QName.create(testModule.getQNameModule(),
34                 "configuration")).get();
35
36         assertEquals("configuration", choice.getQName().getLocalName());
37         assertTrue(choice.isMandatory());
38         assertEquals(Optional.of(Boolean.TRUE), choice.effectiveConfig());
39         assertEquals(1, choice.getCases().size());
40
41         // this choice is augmented (see main-impl.yang.xml)
42         final var casesIterator = choice.getCases().iterator();
43         final CaseSchemaNode caseNode = casesIterator.next();
44         assertEquals("main-impl", caseNode.getQName().getLocalName());
45         assertEquals(13, caseNode.getChildNodes().size());
46
47         assertTrue(caseNode.getWhenCondition().isPresent());
48
49         choice = (ChoiceSchemaNode) list.findDataChildByName(QName.create(testModule.getQNameModule(), "state")).get();
50
51         assertEquals("state", choice.getQName().getLocalName());
52         assertFalse(choice.isMandatory());
53         assertEquals(Optional.of(Boolean.FALSE), choice.effectiveConfig());
54         assertTrue(choice.getCases().isEmpty());
55     }
56 }