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.hamcrest.MatcherAssert.assertThat;
11 import static org.hamcrest.Matchers.isA;
12 import static org.junit.Assert.assertNotNull;
14 import java.util.Iterator;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.common.Revision;
18 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.Module;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
26 public class Bug5884Test {
27 private static final String NS = "urn:yang.foo";
28 private static final String REV = "2016-01-01";
31 public void testBug5884() throws Exception {
32 final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5884");
33 assertNotNull(context);
35 final QName root = QName.create(NS, REV, "main-container");
36 final QName choice = QName.create(NS, REV, "test-choice");
37 final QName testContainerQname = QName.create(NS, REV, "test");
38 final Module foo = context.findModule("foo", Revision.of("2016-01-01")).get();
39 final ContainerSchemaNode rootContainer = (ContainerSchemaNode) context.getDataChildByName(root);
40 final ContainerSchemaNode testContainer = (ContainerSchemaNode) rootContainer.getDataChildByName(
42 final ChoiceSchemaNode dataChildByName = (ChoiceSchemaNode) testContainer.getDataChildByName(choice);
44 testIterator(foo.getAugmentations().iterator());
45 testIterator(dataChildByName.getAvailableAugmentations().iterator());
48 private static void testIterator(final Iterator<? extends AugmentationSchemaNode> iterator) {
49 while (iterator.hasNext()) {
50 AugmentationSchemaNode allAugments = iterator.next();
51 final DataSchemaNode currentChoice = allAugments.getChildNodes().iterator().next();
52 assertThat(currentChoice, isA(CaseSchemaNode.class));