2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.stmt.yin;
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;
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;
23 public class YinFileChoiceStmtTest extends AbstractYinModulesTest {
25 public void testChoiceAndCases() {
26 final Module testModule = context.findModules("config").iterator().next();
27 assertNotNull(testModule);
29 final ListSchemaNode list = (ListSchemaNode) testModule.findDataChildByName(
30 QName.create(testModule.getQNameModule(), "modules"),
31 QName.create(testModule.getQNameModule(), "module")).get();
33 ChoiceSchemaNode choice = (ChoiceSchemaNode) list.findDataChildByName(QName.create(testModule.getQNameModule(),
34 "configuration")).get();
36 assertEquals("configuration", choice.getQName().getLocalName());
37 assertTrue(choice.isMandatory());
38 assertEquals(Optional.of(Boolean.TRUE), choice.effectiveConfig());
39 assertEquals(1, choice.getCases().size());
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());
47 assertTrue(caseNode.getWhenCondition().isPresent());
49 choice = (ChoiceSchemaNode) list.findDataChildByName(QName.create(testModule.getQNameModule(), "state")).get();
51 assertEquals("state", choice.getQName().getLocalName());
52 assertFalse(choice.isMandatory());
53 assertEquals(Optional.of(Boolean.FALSE), choice.effectiveConfig());
54 assertTrue(choice.getCases().isEmpty());