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