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;
13 import java.io.IOException;
14 import java.net.URISyntaxException;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
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.model.api.SchemaContext;
22 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
25 public class ChoiceStmtTest {
27 public void choiceAndCaseTest() throws ReactorException, YangSyntaxErrorException, URISyntaxException, IOException {
28 final SchemaContext result = StmtTestUtils.parseYangSources("/model");
29 assertNotNull(result);
31 final Module testModule = result.findModules("foo").iterator().next();
32 assertNotNull(testModule);
34 final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(QName.create(
35 testModule.getQNameModule(), "transfer"));
36 assertNotNull(container);
38 final ChoiceSchemaNode choice = (ChoiceSchemaNode) container.getDataChildByName(QName.create(
39 testModule.getQNameModule(), "how"));
40 assertNotNull(choice);
41 assertEquals(5, choice.getCases().size());
43 CaseSchemaNode caseNode = choice.findCaseNodes("input").iterator().next();
44 assertNotNull(caseNode);
45 caseNode = choice.findCaseNodes("output").iterator().next();
46 assertNotNull(caseNode);
47 caseNode = choice.findCaseNodes("interval").iterator().next();
48 assertNotNull(caseNode);
49 caseNode = choice.findCaseNodes("daily").iterator().next();
50 assertNotNull(caseNode);
51 caseNode = choice.findCaseNodes("manual").iterator().next();
52 assertNotNull(caseNode);
53 assertEquals("interval", choice.getDefaultCase().get().getQName().getLocalName());