Merge branch 'master' of ../controller
[yangtools.git] / yang / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug5884Test.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.stmt;
9
10 import static org.hamcrest.Matchers.isA;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertThat;
13
14 import java.util.Iterator;
15 import java.util.Set;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.common.Revision;
19 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.Module;
25 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
26
27 public class Bug5884Test {
28     private static final String NS = "urn:yang.foo";
29     private static final String REV = "2016-01-01";
30
31     @Test
32     public void testBug5884() throws Exception {
33         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5884");
34         assertNotNull(context);
35
36         final QName root = QName.create(NS, REV, "main-container");
37         final QName choice = QName.create(NS, REV, "test-choice");
38         final QName testContainerQname = QName.create(NS, REV, "test");
39         final Module foo = context.findModule("foo", Revision.of("2016-01-01")).get();
40         final ContainerSchemaNode rootContainer = (ContainerSchemaNode) context.getDataChildByName(root);
41         final ContainerSchemaNode testContainer = (ContainerSchemaNode) rootContainer.getDataChildByName(
42             testContainerQname);
43         final ChoiceSchemaNode dataChildByName = (ChoiceSchemaNode) testContainer.getDataChildByName(choice);
44         final Set<AugmentationSchemaNode> augmentations = foo.getAugmentations();
45         final Set<AugmentationSchemaNode> availableAugmentations = dataChildByName.getAvailableAugmentations();
46         final Iterator<AugmentationSchemaNode> iterator = augmentations.iterator();
47         final Iterator<AugmentationSchemaNode> availableIterator = availableAugmentations.iterator();
48
49         testIterator(iterator);
50         testIterator(availableIterator);
51     }
52
53     private static void testIterator(final Iterator<AugmentationSchemaNode> iterator) {
54         while (iterator.hasNext()) {
55             AugmentationSchemaNode allAugments = iterator.next();
56             final DataSchemaNode currentChoice = allAugments.getChildNodes().iterator().next();
57             assertThat(currentChoice, isA(CaseSchemaNode.class));
58         }
59     }
60 }