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.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;
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;
30 class IncludedStmtsTest extends AbstractYangTest {
31 private static EffectiveModelContext result;
35 result = assertEffectiveModelDir("/included-statements-test");
39 static void teardown() {
44 void includedTypedefsTest() {
45 final Module testModule = result.findModules("root-module").iterator().next();
46 assertNotNull(testModule);
48 final Collection<? extends TypeDefinition<?>> typedefs = testModule.getTypeDefinitions();
49 assertEquals(2, typedefs.size());
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")));
61 void includedFeaturesTest() {
62 final Module testModule = result.findModules("root-module").iterator().next();
63 assertNotNull(testModule);
65 final Collection<? extends FeatureDefinition> features = testModule.getFeatures();
66 assertEquals(2, features.size());
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")));
76 void includedContainersAndListsTest() {
77 final Module testModule = result.findModules("root-module").iterator().next();
78 assertNotNull(testModule);
80 ContainerSchemaNode cont = (ContainerSchemaNode) testModule.getDataChildByName(
81 QName.create(testModule.getQNameModule(), "parent-container"));
83 cont = (ContainerSchemaNode) cont.getDataChildByName(
84 QName.create(testModule.getQNameModule(), "child-container"));
86 assertEquals(2, cont.getChildNodes().size());
88 LeafSchemaNode leaf = (LeafSchemaNode) cont.getDataChildByName(
89 QName.create(testModule.getQNameModule(), "autumn-leaf"));
91 leaf = (LeafSchemaNode) cont.getDataChildByName(QName.create(testModule.getQNameModule(), "winter-snow"));
96 void submoduleNamespaceTest() {
97 final Module testModule = result.findModules("root-module").iterator().next();
98 assertNotNull(testModule);
100 final Submodule subModule = testModule.getSubmodules().iterator().next();
101 assertEquals("urn:opendaylight.org/root-module", subModule.getNamespace().toString());