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;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
23 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
25 public class ChoiceStmtTest {
27 private static final StatementStreamSource CHOICE_MODULE = sourceForResource("/model/foo.yang");
28 private static final StatementStreamSource IMPORTED_MODULE1 = sourceForResource("/model/bar.yang");
29 private static final StatementStreamSource IMPORTED_MODULE2 = sourceForResource("/model/baz.yang");
30 private static final StatementStreamSource INCLUDED_MODULE = sourceForResource("/model/subfoo.yang");
33 public void choiceAndCaseTest() throws ReactorException {
34 final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
35 .addSources(CHOICE_MODULE, IMPORTED_MODULE1, IMPORTED_MODULE2, INCLUDED_MODULE)
37 assertNotNull(result);
39 final Module testModule = result.findModules("foo").iterator().next();
40 assertNotNull(testModule);
42 final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(QName.create(
43 testModule.getQNameModule(), "transfer"));
44 assertNotNull(container);
46 final ChoiceSchemaNode choice = (ChoiceSchemaNode) container.getDataChildByName(QName.create(
47 testModule.getQNameModule(), "how"));
48 assertNotNull(choice);
49 assertEquals(5, choice.getCases().size());
51 CaseSchemaNode caseNode = choice.findCaseNodes("input").iterator().next();
52 assertNotNull(caseNode);
53 caseNode = choice.findCaseNodes("output").iterator().next();
54 assertNotNull(caseNode);
55 caseNode = choice.findCaseNodes("interval").iterator().next();
56 assertNotNull(caseNode);
57 caseNode = choice.findCaseNodes("daily").iterator().next();
58 assertNotNull(caseNode);
59 caseNode = choice.findCaseNodes("manual").iterator().next();
60 assertNotNull(caseNode);
61 assertEquals("interval", choice.getDefaultCase().get().getQName().getLocalName());