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
9 package org.opendaylight.yangtools.yang.stmt;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertFalse;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertNull;
15 import static org.junit.Assert.assertTrue;
17 import java.io.IOException;
19 import java.net.URISyntaxException;
20 import java.text.ParseException;
21 import java.util.Collection;
23 import org.junit.Test;
24 import org.opendaylight.yangtools.yang.common.QName;
25 import org.opendaylight.yangtools.yang.common.Revision;
26 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
27 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
28 import org.opendaylight.yangtools.yang.model.api.Module;
29 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
30 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
31 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
32 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
33 import org.opendaylight.yangtools.yang.model.api.Status;
34 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
35 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
36 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
37 import org.opendaylight.yangtools.yang.model.util.SimpleSchemaContext;
38 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
39 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
40 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
41 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveSchemaContext;
43 public class EffectiveSchemaContextTest {
46 public void testEffectiveSchemaContext() throws ReactorException, ParseException, URISyntaxException, IOException,
47 YangSyntaxErrorException {
48 final EffectiveSchemaContext schemaContext = RFC7950Reactors.defaultReactor().newBuild()
49 .addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource(
50 "/effective-schema-context-test/foo.yang")))
51 .addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource(
52 "/effective-schema-context-test/bar.yang")))
53 .addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource(
54 "/effective-schema-context-test/baz.yang")))
56 assertNotNull(schemaContext);
58 final Collection<? extends DataSchemaNode> dataDefinitions = schemaContext.getDataDefinitions();
59 assertEquals(3, dataDefinitions.size());
61 final Collection<? extends DataSchemaNode> childNodes = schemaContext.getChildNodes();
62 assertEquals(3, childNodes.size());
64 final Collection<? extends NotificationDefinition> notifications = schemaContext.getNotifications();
65 assertEquals(3, notifications.size());
67 final Collection<? extends RpcDefinition> rpcs = schemaContext.getOperations();
68 assertEquals(3, rpcs.size());
70 final Collection<? extends ExtensionDefinition> extensions = schemaContext.getExtensions();
71 assertEquals(3, extensions.size());
73 final Collection<? extends UnknownSchemaNode> unknownSchemaNodes = schemaContext.getUnknownSchemaNodes();
74 assertEquals(3, unknownSchemaNodes.size());
76 assertNull(schemaContext.getDataChildByName(QName.create("foo-namespace", "2016-09-21", "foo-cont")));
78 assertFalse(schemaContext.findModule("foo", Revision.of("2016-08-21")).isPresent());
79 assertFalse(schemaContext.findModule(URI.create("foo-namespace"), Revision.of("2016-08-21")).isPresent());
81 assertFalse(schemaContext.isAugmenting());
82 assertFalse(schemaContext.isAddedByUses());
83 assertFalse(schemaContext.isConfiguration());
84 assertFalse(schemaContext.getWhenCondition().isPresent());
85 assertEquals(0, schemaContext.getMustConstraints().size());
86 assertFalse(schemaContext.getDescription().isPresent());
87 assertFalse(schemaContext.getReference().isPresent());
88 assertEquals(SchemaContext.NAME, schemaContext.getQName());
89 assertEquals(SchemaPath.ROOT, schemaContext.getPath());
90 assertEquals(Status.CURRENT, schemaContext.getStatus());
91 assertNotNull(schemaContext.getUses());
92 assertTrue(schemaContext.getUses().isEmpty());
93 assertNotNull(schemaContext.getAvailableAugmentations());
94 assertTrue(schemaContext.getAvailableAugmentations().isEmpty());
96 Module fooModule = schemaContext.findModule("foo", Revision.of("2016-09-21")).get();
97 assertEquals(3, schemaContext.getModules().size());
98 assertEquals(3, schemaContext.getRootDeclaredStatements().size());
99 assertEquals(3, schemaContext.getModuleStatements().size());
101 final Set<Module> modules = schemaContext.getModules();
102 final SchemaContext copiedSchemaContext = SimpleSchemaContext.forModules(modules);
103 assertNotNull(copiedSchemaContext);
104 assertEquals(modules, copiedSchemaContext.getModules());