Further cleanup of tests
[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
13 import java.util.Iterator;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.common.Revision;
17 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
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
24 public class Bug5884Test extends AbstractYangTest {
25     private static final String NS = "urn:yang.foo";
26     private static final String REV = "2016-01-01";
27
28     @Test
29     public void testBug5884() {
30         final var context = assertEffectiveModelDir("/bugs/bug5884");
31
32         final QName root = QName.create(NS, REV, "main-container");
33         final QName choice = QName.create(NS, REV, "test-choice");
34         final QName testContainerQname = QName.create(NS, REV, "test");
35         final Module foo = context.findModule("foo", Revision.of("2016-01-01")).get();
36         final ContainerSchemaNode rootContainer = (ContainerSchemaNode) context.getDataChildByName(root);
37         final ContainerSchemaNode testContainer = (ContainerSchemaNode) rootContainer.getDataChildByName(
38             testContainerQname);
39         final ChoiceSchemaNode dataChildByName = (ChoiceSchemaNode) testContainer.getDataChildByName(choice);
40
41         testIterator(foo.getAugmentations().iterator());
42         testIterator(dataChildByName.getAvailableAugmentations().iterator());
43     }
44
45     private static void testIterator(final Iterator<? extends AugmentationSchemaNode> iterator) {
46         while (iterator.hasNext()) {
47             AugmentationSchemaNode allAugments = iterator.next();
48             final DataSchemaNode currentChoice = allAugments.getChildNodes().iterator().next();
49             assertThat(currentChoice, isA(CaseSchemaNode.class));
50         }
51     }
52 }