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.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;
24 public class YinFileChoiceStmtTest extends AbstractYinModulesTest {
27 public void testChoiceAndCases() {
28 final Module testModule = TestUtils.findModule(context, "config").get();
29 assertNotNull(testModule);
31 final ListSchemaNode list = (ListSchemaNode) testModule.findDataChildByName(
32 QName.create(testModule.getQNameModule(), "modules"),
33 QName.create(testModule.getQNameModule(), "module")).get();
35 ChoiceSchemaNode choice = (ChoiceSchemaNode) list.findDataChildByName(QName.create(testModule.getQNameModule(),
36 "configuration")).get();
38 assertEquals("configuration", choice.getQName().getLocalName());
39 assertTrue(choice.isMandatory());
40 assertTrue(choice.isConfiguration());
41 assertEquals(1, choice.getCases().size());
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());
49 assertTrue(caseNode.getWhenCondition().isPresent());
51 choice = (ChoiceSchemaNode) list.findDataChildByName(QName.create(testModule.getQNameModule(), "state")).get();
53 assertEquals("state", choice.getQName().getLocalName());
54 assertFalse(choice.isMandatory());
55 assertFalse(choice.isConfiguration());
56 assertTrue(choice.getCases().isEmpty());