Bug 4540: Yang parser exceptions should follow consistent path
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / test / ChoiceStmtTest.java
1 /*
2  * Copyright (c) 2015 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
9 package org.opendaylight.yangtools.yang.stmt.test;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
16 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.Module;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
20 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
22 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
24
25 public class ChoiceStmtTest {
26
27     private static final YangStatementSourceImpl CHOICE_MODULE = new YangStatementSourceImpl("/model/foo.yang", false);
28     private static final YangStatementSourceImpl IMPORTED_MODULE1 = new YangStatementSourceImpl("/model/bar.yang",
29             false);
30     private static final YangStatementSourceImpl IMPORTED_MODULE2 = new YangStatementSourceImpl("/model/baz.yang",
31             false);
32     private static final YangStatementSourceImpl INCLUDED_MODULE = new YangStatementSourceImpl("/model/subfoo.yang",
33             false);
34
35     @Test
36     public void choiceAndCaseTest() throws ReactorException {
37         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
38         StmtTestUtils.addSources(reactor, CHOICE_MODULE, IMPORTED_MODULE1, IMPORTED_MODULE2, INCLUDED_MODULE);
39
40         EffectiveSchemaContext result = reactor.buildEffective();
41         assertNotNull(result);
42
43         Module testModule = result.findModuleByName("foo", null);
44         assertNotNull(testModule);
45
46         ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName("transfer");
47         assertNotNull(container);
48
49         ChoiceSchemaNode choice = (ChoiceSchemaNode) container.getDataChildByName("how");
50         assertNotNull(choice);
51         assertEquals(5, choice.getCases().size());
52
53         ChoiceCaseNode caseNode = choice.getCaseNodeByName("input");
54         assertNotNull(caseNode);
55         caseNode = choice.getCaseNodeByName("output");
56         assertNotNull(caseNode);
57         caseNode = choice.getCaseNodeByName("interval");
58         assertNotNull(caseNode);
59         caseNode = choice.getCaseNodeByName("daily");
60         assertNotNull(caseNode);
61         caseNode = choice.getCaseNodeByName("manual");
62         assertNotNull(caseNode);
63         assertEquals("interval", choice.getDefaultCase());
64     }
65 }