Remove deprecated Yin/YangStatementSourceImpl
[yangtools.git] / yang / yang-parser-impl / 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.io.IOException;
16 import java.net.URISyntaxException;
17 import java.util.Iterator;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
22 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
25 import org.opendaylight.yangtools.yang.model.api.Module;
26 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
27 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
28 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
29 import org.opendaylight.yangtools.yang.stmt.TestUtils;
30 import org.xml.sax.SAXException;
31
32 public class YinFileChoiceStmtTest {
33
34     private SchemaContext context;
35
36     @Before
37     public void init() throws ReactorException, SAXException, IOException, URISyntaxException {
38         context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
39         assertEquals(9, context.getModules().size());
40     }
41
42     @Test
43     public void testChoiceAndCases() {
44         final Module testModule = TestUtils.findModule(context, "config").get();
45         assertNotNull(testModule);
46
47         final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(QName.create(
48                 testModule.getQNameModule(), "modules"));
49         assertNotNull(container);
50
51         final ListSchemaNode list = (ListSchemaNode) container.getDataChildByName(QName.create(
52                 testModule.getQNameModule(), "module"));
53         assertNotNull(list);
54
55         ChoiceSchemaNode choice = (ChoiceSchemaNode) list.getDataChildByName(QName.create(testModule.getQNameModule(),
56                 "configuration"));
57         assertNotNull(choice);
58
59         assertEquals("configuration", choice.getQName().getLocalName());
60         assertTrue(choice.getConstraints().isMandatory());
61         assertTrue(choice.isConfiguration());
62         assertEquals(1, choice.getCases().size());
63
64         // this choice is augmented (see main-impl.yang.xml)
65         final Iterator<ChoiceCaseNode> casesIterator = choice.getCases().iterator();
66         final ChoiceCaseNode caseNode = casesIterator.next();
67         assertEquals("main-impl", caseNode.getQName().getLocalName());
68         assertEquals(13, caseNode.getChildNodes().size());
69
70         final RevisionAwareXPath whenCondition = caseNode.getConstraints().getWhenCondition();
71         assertNotNull(whenCondition);
72
73         choice = (ChoiceSchemaNode) list.getDataChildByName(QName.create(testModule.getQNameModule(), "state"));
74         assertNotNull(choice);
75
76         assertEquals("state", choice.getQName().getLocalName());
77         assertFalse(choice.getConstraints().isMandatory());
78         assertFalse(choice.isConfiguration());
79         assertTrue(choice.getCases().isEmpty());
80     }
81 }