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.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;
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;
26 class EffectiveSchemaContextTest extends AbstractYangTest {
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");
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());
40 for (var module : schemaContext.getModuleStatements().values()) {
41 assertEquals(1, module.getDeclared().declaredSubstatements(UnrecognizedStatement.class).size());
44 assertNull(schemaContext.dataChildByName(QName.create("foo-namespace", "2016-09-21", "foo-cont")));
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());
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());
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());