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.Assert.assertEquals;
14 import static org.junit.Assert.assertNotNull;
15 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
17 import java.util.Collection;
18 import java.util.Iterator;
19 import org.junit.AfterClass;
20 import org.junit.BeforeClass;
21 import org.junit.Test;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
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.SchemaContext;
28 import org.opendaylight.yangtools.yang.model.api.Submodule;
29 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
30 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
31 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
33 public class IncludedStmtsTest {
34 private static SchemaContext result;
37 public static void setup() throws ReactorException {
38 result = RFC7950Reactors.defaultReactor().newBuild()
39 .addSource(sourceForResource("/included-statements-test/root-module.yang"))
40 .addSource(sourceForResource("/included-statements-test/child-module.yang"))
45 public static void teardown() {
50 public void includedTypedefsTest() {
51 final Module testModule = result.findModules("root-module").iterator().next();
52 assertNotNull(testModule);
54 final Collection<? extends TypeDefinition<?>> typedefs = testModule.getTypeDefinitions();
55 assertEquals(2, typedefs.size());
57 final Iterator<? extends TypeDefinition<?>> typedefsIterator = typedefs.iterator();
58 TypeDefinition<?> typedef = typedefsIterator.next();
59 assertThat(typedef.getQName().getLocalName(), anyOf(is("new-string-type"), is("new-int32-type")));
60 assertThat(typedef.getBaseType().getQName().getLocalName(), anyOf(is("string"), is("int32")));
61 typedef = typedefsIterator.next();
62 assertThat(typedef.getQName().getLocalName(), anyOf(is("new-string-type"), is("new-int32-type")));
63 assertThat(typedef.getBaseType().getQName().getLocalName(), anyOf(is("string"), is("int32")));
67 public void includedFeaturesTest() {
68 final Module testModule = result.findModules("root-module").iterator().next();
69 assertNotNull(testModule);
71 final Collection<? extends FeatureDefinition> features = testModule.getFeatures();
72 assertEquals(2, features.size());
74 final Iterator<? extends FeatureDefinition> featuresIterator = features.iterator();
75 FeatureDefinition feature = featuresIterator.next();
76 assertThat(feature.getQName().getLocalName(), anyOf(is("new-feature1"), is("new-feature2")));
77 feature = featuresIterator.next();
78 assertThat(feature.getQName().getLocalName(), anyOf(is("new-feature1"), is("new-feature2")));
82 public void includedContainersAndListsTest() {
83 final Module testModule = result.findModules("root-module").iterator().next();
84 assertNotNull(testModule);
86 ContainerSchemaNode cont = (ContainerSchemaNode) testModule.getDataChildByName(
87 QName.create(testModule.getQNameModule(), "parent-container"));
89 cont = (ContainerSchemaNode) cont.getDataChildByName(
90 QName.create(testModule.getQNameModule(), "child-container"));
92 assertEquals(2, cont.getChildNodes().size());
94 LeafSchemaNode leaf = (LeafSchemaNode) cont.getDataChildByName(
95 QName.create(testModule.getQNameModule(), "autumn-leaf"));
97 leaf = (LeafSchemaNode) cont.getDataChildByName(QName.create(testModule.getQNameModule(), "winter-snow"));
102 public void submoduleNamespaceTest() {
103 final Module testModule = result.findModules("root-module").iterator().next();
104 assertNotNull(testModule);
106 final Submodule subModule = testModule.getSubmodules().iterator().next();
107 assertEquals("urn:opendaylight.org/root-module", subModule.getNamespace().toString());