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.assertNotNull;
11 import static org.junit.Assert.assertTrue;
13 import java.util.Iterator;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
18 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
19 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.Module;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25 public class Bug5884Test {
26 private static final String NS = "urn:yang.foo";
27 private static final String REV = "2016-01-01";
30 public void testBug5884() throws Exception {
31 final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5884");
32 assertNotNull(context);
34 final QName root = QName.create(NS, REV, "main-container");
35 final QName choice = QName.create(NS, REV, "test-choice");
36 final QName testContainerQname = QName.create(NS, REV, "test");
37 final Module foo = context.findModule("foo", QName.parseRevision("2016-01-01")).get();
38 final ContainerSchemaNode rootContainer = (ContainerSchemaNode) context.getDataChildByName(root);
39 final ContainerSchemaNode testContainer = (ContainerSchemaNode) rootContainer.getDataChildByName(
41 final ChoiceSchemaNode dataChildByName = (ChoiceSchemaNode) testContainer.getDataChildByName(choice);
42 final Set<AugmentationSchema> augmentations = foo.getAugmentations();
43 final Set<AugmentationSchema> availableAugmentations = dataChildByName.getAvailableAugmentations();
44 final Iterator<AugmentationSchema> iterator = augmentations.iterator();
45 final Iterator<AugmentationSchema> availableIterator = availableAugmentations.iterator();
47 testIterator(iterator);
48 testIterator(availableIterator);
51 private static void testIterator(final Iterator<AugmentationSchema> iterator) {
52 while (iterator.hasNext()) {
53 AugmentationSchema allAugments = iterator.next();
54 final DataSchemaNode currentChoice = allAugments.getChildNodes().iterator().next();
55 assertTrue(currentChoice instanceof ChoiceCaseNode);