Deprecate simple DataTreeFactory.create()
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / IncludedStmtsTest.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.CoreMatchers.anyOf;
11 import static org.hamcrest.CoreMatchers.is;
12 import static org.hamcrest.MatcherAssert.assertThat;
13 import static org.junit.jupiter.api.Assertions.assertEquals;
14 import static org.junit.jupiter.api.Assertions.assertNotNull;
15
16 import java.util.Collection;
17 import java.util.Iterator;
18 import org.junit.jupiter.api.AfterAll;
19 import org.junit.jupiter.api.BeforeAll;
20 import org.junit.jupiter.api.Test;
21 import org.opendaylight.yangtools.yang.common.QName;
22 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
24 import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
25 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
26 import org.opendaylight.yangtools.yang.model.api.Module;
27 import org.opendaylight.yangtools.yang.model.api.Submodule;
28 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
29
30 class IncludedStmtsTest extends AbstractYangTest {
31     private static EffectiveModelContext result;
32
33     @BeforeAll
34     static void setup() {
35         result = assertEffectiveModelDir("/included-statements-test");
36     }
37
38     @AfterAll
39     static void teardown() {
40         result = null;
41     }
42
43     @Test
44     void includedTypedefsTest() {
45         final Module testModule = result.findModules("root-module").iterator().next();
46         assertNotNull(testModule);
47
48         final Collection<? extends TypeDefinition<?>> typedefs = testModule.getTypeDefinitions();
49         assertEquals(2, typedefs.size());
50
51         final Iterator<? extends TypeDefinition<?>> typedefsIterator = typedefs.iterator();
52         TypeDefinition<?> typedef = typedefsIterator.next();
53         assertThat(typedef.getQName().getLocalName(), anyOf(is("new-string-type"), is("new-int32-type")));
54         assertThat(typedef.getBaseType().getQName().getLocalName(), anyOf(is("string"), is("int32")));
55         typedef = typedefsIterator.next();
56         assertThat(typedef.getQName().getLocalName(), anyOf(is("new-string-type"), is("new-int32-type")));
57         assertThat(typedef.getBaseType().getQName().getLocalName(), anyOf(is("string"), is("int32")));
58     }
59
60     @Test
61     void includedFeaturesTest() {
62         final Module testModule = result.findModules("root-module").iterator().next();
63         assertNotNull(testModule);
64
65         final Collection<? extends FeatureDefinition> features = testModule.getFeatures();
66         assertEquals(2, features.size());
67
68         final Iterator<? extends FeatureDefinition> featuresIterator = features.iterator();
69         FeatureDefinition feature = featuresIterator.next();
70         assertThat(feature.getQName().getLocalName(), anyOf(is("new-feature1"), is("new-feature2")));
71         feature = featuresIterator.next();
72         assertThat(feature.getQName().getLocalName(), anyOf(is("new-feature1"), is("new-feature2")));
73     }
74
75     @Test
76     void includedContainersAndListsTest() {
77         final Module testModule = result.findModules("root-module").iterator().next();
78         assertNotNull(testModule);
79
80         ContainerSchemaNode cont = (ContainerSchemaNode) testModule.getDataChildByName(
81             QName.create(testModule.getQNameModule(), "parent-container"));
82         assertNotNull(cont);
83         cont = (ContainerSchemaNode) cont.getDataChildByName(
84             QName.create(testModule.getQNameModule(), "child-container"));
85         assertNotNull(cont);
86         assertEquals(2, cont.getChildNodes().size());
87
88         LeafSchemaNode leaf = (LeafSchemaNode) cont.getDataChildByName(
89             QName.create(testModule.getQNameModule(), "autumn-leaf"));
90         assertNotNull(leaf);
91         leaf = (LeafSchemaNode) cont.getDataChildByName(QName.create(testModule.getQNameModule(), "winter-snow"));
92         assertNotNull(leaf);
93     }
94
95     @Test
96     void submoduleNamespaceTest() {
97         final Module testModule = result.findModules("root-module").iterator().next();
98         assertNotNull(testModule);
99
100         final Submodule subModule = testModule.getSubmodules().iterator().next();
101         assertEquals("urn:opendaylight.org/root-module", subModule.getNamespace().toString());
102     }
103 }