74d05dac60680bea179354dee8a0c934bf2c1660
[yangtools.git] / parser / 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.MatcherAssert.assertThat;
11 import static org.hamcrest.Matchers.isA;
12 import static org.junit.Assert.assertNotNull;
13
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;
25
26 public class Bug5884Test {
27     private static final String NS = "urn:yang.foo";
28     private static final String REV = "2016-01-01";
29
30     @Test
31     public void testBug5884() throws Exception {
32         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5884");
33         assertNotNull(context);
34
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(
41             testContainerQname);
42         final ChoiceSchemaNode dataChildByName = (ChoiceSchemaNode) testContainer.getDataChildByName(choice);
43
44         testIterator(foo.getAugmentations().iterator());
45         testIterator(dataChildByName.getAvailableAugmentations().iterator());
46     }
47
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));
53         }
54     }
55 }