Promote SchemaSourceRepresentation
[yangtools.git] / model / yang-model-util / src / test / java / org / opendaylight / yangtools / yang / model / util / YT691Test.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.model.util;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertTrue;
12
13 import java.util.Set;
14 import org.junit.jupiter.api.Test;
15 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
16 import org.opendaylight.yangtools.yang.model.spi.SimpleSchemaContext;
17 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
18
19 class YT691Test {
20     @Test
21     void testGetAllModuleIdentifiers() {
22         final var foo = new SourceIdentifier("foo", "2016-01-01");
23         final var sub1Foo = new SourceIdentifier("sub1-foo", "2016-01-01");
24         final var sub2Foo = new SourceIdentifier("sub2-foo", "2016-01-01");
25         final var bar = new SourceIdentifier("bar", "2016-01-01");
26         final var sub1Bar = new SourceIdentifier("sub1-bar", "2016-01-01");
27         final var baz = new SourceIdentifier("baz", "2016-01-01");
28         final var context = YangParserTestUtils.parseYang("""
29             module bar {
30               namespace "bar";
31               prefix bar;
32               revision 2016-01-01;
33
34               include sub1-bar;
35
36               leaf bar-leaf {
37                 type string;
38               }
39             }""", """
40             submodule sub1-bar {
41               belongs-to bar {
42                 prefix bar;
43               }
44
45               revision 2016-01-01;
46
47               leaf sub1-bar-leaf {
48                 type string;
49               }
50             }""", """
51             module baz {
52               namespace "baz";
53               prefix baz;
54               revision 2016-01-01;
55
56               leaf baz-leaf {
57                 type string;
58               }
59             }""", """
60             module foo {
61               namespace "foo";
62               prefix foo;
63               revision 2016-01-01;
64
65               include sub1-foo;
66               include sub2-foo;
67
68               leaf foo-leaf {
69                 type string;
70               }
71             }""", """
72             submodule sub1-foo {
73               belongs-to foo {
74                 prefix foo;
75               }
76
77               revision 2016-01-01;
78
79               leaf sub1-foo-leaf {
80                 type string;
81               }
82             }""", """
83             submodule sub2-foo {
84               belongs-to foo {
85                 prefix foo;
86               }
87
88               revision 2016-01-01;
89
90               leaf sub2-foo-leaf {
91                 type string;
92               }
93             }""");
94         final var allModuleIdentifiers = SchemaContextUtil.getConstituentModuleIdentifiers(context);
95         assertEquals(6, allModuleIdentifiers.size());
96         final var allModuleIdentifiersResolved = SchemaContextUtil.getConstituentModuleIdentifiers(
97                 SimpleSchemaContext.forModules(context.getModules()));
98         assertEquals(6, allModuleIdentifiersResolved.size());
99         assertEquals(allModuleIdentifiersResolved, allModuleIdentifiers);
100         assertEquals(Set.of(foo, sub1Foo, sub2Foo, bar, sub1Bar, baz), allModuleIdentifiers);
101         assertTrue(allModuleIdentifiers.contains(foo));
102     }
103 }