Introduce yangtools.binding.meta
[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.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertFalse;
12 import static org.junit.jupiter.api.Assertions.assertNotNull;
13 import static org.junit.jupiter.api.Assertions.assertNull;
14 import static org.junit.jupiter.api.Assertions.assertTrue;
15
16 import java.util.Optional;
17 import org.junit.jupiter.api.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.common.Revision;
20 import org.opendaylight.yangtools.yang.common.XMLNamespace;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 import org.opendaylight.yangtools.yang.model.api.Status;
23 import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
24 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveSchemaContext;
25
26 class EffectiveSchemaContextTest extends AbstractYangTest {
27     @Test
28     void testEffectiveSchemaContext() {
29         final var schemaContext = assertEffectiveModel(
30             "/effective-schema-context-test/foo.yang",
31             "/effective-schema-context-test/bar.yang",
32             "/effective-schema-context-test/baz.yang");
33
34         assertEquals(3, schemaContext.getDataDefinitions().size());
35         assertEquals(3, schemaContext.getChildNodes().size());
36         assertEquals(3, schemaContext.getNotifications().size());
37         assertEquals(3, schemaContext.getOperations().size());
38         assertEquals(3, schemaContext.getExtensions().size());
39
40         for (var module : schemaContext.getModuleStatements().values()) {
41             assertEquals(1, module.getDeclared().declaredSubstatements(UnrecognizedStatement.class).size());
42         }
43
44         assertNull(schemaContext.dataChildByName(QName.create("foo-namespace", "2016-09-21", "foo-cont")));
45
46         assertFalse(schemaContext.findModule("foo", Revision.of("2016-08-21")).isPresent());
47         assertFalse(schemaContext.findModule(XMLNamespace.of("foo-namespace"), Revision.of("2016-08-21")).isPresent());
48
49         assertFalse(schemaContext.isAugmenting());
50         assertFalse(schemaContext.isAddedByUses());
51         assertEquals(Optional.empty(), schemaContext.effectiveConfig());
52         assertFalse(schemaContext.getWhenCondition().isPresent());
53         assertEquals(0, schemaContext.getMustConstraints().size());
54         assertFalse(schemaContext.getDescription().isPresent());
55         assertFalse(schemaContext.getReference().isPresent());
56         assertEquals(SchemaContext.NAME, schemaContext.getQName());
57         assertEquals(Status.CURRENT, schemaContext.getStatus());
58         assertNotNull(schemaContext.getUses());
59         assertTrue(schemaContext.getUses().isEmpty());
60         assertNotNull(schemaContext.getAvailableAugmentations());
61         assertTrue(schemaContext.getAvailableAugmentations().isEmpty());
62
63         assertTrue(schemaContext.findModule("foo", Revision.of("2016-09-21")).isPresent());
64         assertEquals(3, schemaContext.getModules().size());
65         assertEquals(3, ((EffectiveSchemaContext) schemaContext).getRootDeclaredStatements().size());
66         assertEquals(3, schemaContext.getModuleStatements().size());
67     }
68 }