Remove unneeded throws
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / EffectiveSchemaContextTest.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.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertNull;
14 import static org.junit.Assert.assertTrue;
15
16 import java.io.IOException;
17 import java.net.URISyntaxException;
18 import java.text.ParseException;
19 import java.util.Collection;
20 import java.util.Optional;
21 import org.junit.Test;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.common.Revision;
24 import org.opendaylight.yangtools.yang.common.XMLNamespace;
25 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
26 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
27 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
28 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
29 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
30 import org.opendaylight.yangtools.yang.model.api.Status;
31 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
32 import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
33 import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
34 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
35 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
36 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveSchemaContext;
37
38 public class EffectiveSchemaContextTest {
39     @Test
40     public void testEffectiveSchemaContext() throws ReactorException, ParseException, URISyntaxException, IOException,
41             YangSyntaxErrorException {
42         final EffectiveSchemaContext schemaContext = RFC7950Reactors.defaultReactor().newBuild()
43             .addSource(StmtTestUtils.sourceForResource("/effective-schema-context-test/foo.yang"))
44             .addSource(StmtTestUtils.sourceForResource("/effective-schema-context-test/bar.yang"))
45             .addSource(StmtTestUtils.sourceForResource("/effective-schema-context-test/baz.yang"))
46             .buildEffective();
47         assertNotNull(schemaContext);
48
49         final Collection<? extends DataSchemaNode> dataDefinitions = schemaContext.getDataDefinitions();
50         assertEquals(3, dataDefinitions.size());
51
52         final Collection<? extends DataSchemaNode> childNodes = schemaContext.getChildNodes();
53         assertEquals(3, childNodes.size());
54
55         final Collection<? extends NotificationDefinition> notifications = schemaContext.getNotifications();
56         assertEquals(3, notifications.size());
57
58         final Collection<? extends RpcDefinition> rpcs = schemaContext.getOperations();
59         assertEquals(3, rpcs.size());
60
61         final Collection<? extends ExtensionDefinition> extensions = schemaContext.getExtensions();
62         assertEquals(3, extensions.size());
63
64         for (ModuleEffectiveStatement module : schemaContext.getModuleStatements().values()) {
65             assertEquals(1, module.getDeclared().declaredSubstatements(UnrecognizedStatement.class).size());
66         }
67
68         assertNull(schemaContext.dataChildByName(QName.create("foo-namespace", "2016-09-21", "foo-cont")));
69
70         assertFalse(schemaContext.findModule("foo", Revision.of("2016-08-21")).isPresent());
71         assertFalse(schemaContext.findModule(XMLNamespace.of("foo-namespace"), Revision.of("2016-08-21")).isPresent());
72
73         assertFalse(schemaContext.isAugmenting());
74         assertFalse(schemaContext.isAddedByUses());
75         assertEquals(Optional.empty(), schemaContext.effectiveConfig());
76         assertFalse(schemaContext.getWhenCondition().isPresent());
77         assertEquals(0, schemaContext.getMustConstraints().size());
78         assertFalse(schemaContext.getDescription().isPresent());
79         assertFalse(schemaContext.getReference().isPresent());
80         assertEquals(SchemaContext.NAME, schemaContext.getQName());
81         assertEquals(Status.CURRENT, schemaContext.getStatus());
82         assertNotNull(schemaContext.getUses());
83         assertTrue(schemaContext.getUses().isEmpty());
84         assertNotNull(schemaContext.getAvailableAugmentations());
85         assertTrue(schemaContext.getAvailableAugmentations().isEmpty());
86
87         assertTrue(schemaContext.findModule("foo", Revision.of("2016-09-21")).isPresent());
88         assertEquals(3, schemaContext.getModules().size());
89         assertEquals(3, schemaContext.getRootDeclaredStatements().size());
90         assertEquals(3, schemaContext.getModuleStatements().size());
91     }
92 }