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.TypeDefinition;
29 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
30 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
32 public class IncludedStmtsTest {
33 private static SchemaContext result;
36 public static void setup() throws ReactorException {
37 result = RFC7950Reactors.defaultReactor().newBuild()
38 .addSource(sourceForResource("/included-statements-test/root-module.yang"))
39 .addSource(sourceForResource("/included-statements-test/child-module.yang"))
44 public static void teardown() {
49 public void includedTypedefsTest() {
50 final Module testModule = result.findModules("root-module").iterator().next();
51 assertNotNull(testModule);
53 final Collection<? extends TypeDefinition<?>> typedefs = testModule.getTypeDefinitions();
54 assertEquals(2, typedefs.size());
56 final Iterator<? extends TypeDefinition<?>> typedefsIterator = typedefs.iterator();
57 TypeDefinition<?> typedef = typedefsIterator.next();
58 assertThat(typedef.getQName().getLocalName(), anyOf(is("new-string-type"), is("new-int32-type")));
59 assertThat(typedef.getBaseType().getQName().getLocalName(), anyOf(is("string"), is("int32")));
60 typedef = typedefsIterator.next();
61 assertThat(typedef.getQName().getLocalName(), anyOf(is("new-string-type"), is("new-int32-type")));
62 assertThat(typedef.getBaseType().getQName().getLocalName(), anyOf(is("string"), is("int32")));
66 public void includedFeaturesTest() {
67 final Module testModule = result.findModules("root-module").iterator().next();
68 assertNotNull(testModule);
70 final Collection<? extends FeatureDefinition> features = testModule.getFeatures();
71 assertEquals(2, features.size());
73 final Iterator<? extends FeatureDefinition> featuresIterator = features.iterator();
74 FeatureDefinition feature = featuresIterator.next();
75 assertThat(feature.getQName().getLocalName(), anyOf(is("new-feature1"), is("new-feature2")));
76 feature = featuresIterator.next();
77 assertThat(feature.getQName().getLocalName(), anyOf(is("new-feature1"), is("new-feature2")));
81 public void includedContainersAndListsTest() {
82 final Module testModule = result.findModules("root-module").iterator().next();
83 assertNotNull(testModule);
85 ContainerSchemaNode cont = (ContainerSchemaNode) testModule.getDataChildByName(
86 QName.create(testModule.getQNameModule(), "parent-container"));
88 cont = (ContainerSchemaNode) cont.getDataChildByName(
89 QName.create(testModule.getQNameModule(), "child-container"));
91 assertEquals(2, cont.getChildNodes().size());
93 LeafSchemaNode leaf = (LeafSchemaNode) cont.getDataChildByName(
94 QName.create(testModule.getQNameModule(), "autumn-leaf"));
96 leaf = (LeafSchemaNode) cont.getDataChildByName(QName.create(testModule.getQNameModule(), "winter-snow"));
101 public void submoduleNamespaceTest() {
102 final Module testModule = result.findModules("root-module").iterator().next();
103 assertNotNull(testModule);
105 final Module subModule = testModule.getSubmodules().iterator().next();
106 assertEquals("urn:opendaylight.org/root-module", subModule.getNamespace().toString());