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
9 package org.opendaylight.yangtools.yang.stmt;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
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;
25 public class ChoiceStmtTest {
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",
30 private static final YangStatementSourceImpl IMPORTED_MODULE2 = new YangStatementSourceImpl("/model/baz.yang",
32 private static final YangStatementSourceImpl INCLUDED_MODULE = new YangStatementSourceImpl("/model/subfoo.yang",
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);
40 EffectiveSchemaContext result = reactor.buildEffective();
41 assertNotNull(result);
43 Module testModule = result.findModuleByName("foo", null);
44 assertNotNull(testModule);
46 ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName("transfer");
47 assertNotNull(container);
49 ChoiceSchemaNode choice = (ChoiceSchemaNode) container.getDataChildByName("how");
50 assertNotNull(choice);
51 assertEquals(5, choice.getCases().size());
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());