2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024 Ericsson
4 * Modifications Copyright (C) 2024 OpenInfra Foundation Europe
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
21 package org.oran.smo.yangtools.parser.model.schema.test;
23 import static org.junit.Assert.assertTrue;
25 import java.util.Arrays;
26 import java.util.Collections;
27 import java.util.List;
30 import org.junit.Test;
32 import org.oran.smo.yangtools.parser.model.schema.IdentityRegistry;
33 import org.oran.smo.yangtools.parser.model.util.YangIdentity;
34 import org.oran.smo.yangtools.parser.testutils.YangTestCommon;
36 public class IdentityRegistryTest extends YangTestCommon {
39 public void test_all_modules() {
41 final List<String> absoluteImplementsFilePath = Arrays.asList(
42 "src/test/resources/model-schema/identity-registry-test/module1.yang",
43 "src/test/resources/model-schema/identity-registry-test/module2.yang",
44 "src/test/resources/model-schema/identity-registry-test/module3.yang",
45 "src/test/resources/model-schema/identity-registry-test/submodule4.yang");
46 final List<String> absoluteImportsFilePath = Collections.<String> emptyList();
48 parseAbsoluteYangModels(absoluteImplementsFilePath, absoluteImportsFilePath);
52 final IdentityRegistry identityRegistry = yangDeviceModel.getTopLevelSchema().getIdentityRegistry();
54 // ---- module 1 ---- bases ------
56 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module1", "module1", "identity11"))
58 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module1", "module1", "identity12"))
60 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module1", "module1", "identity13"))
63 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module1", "module1", "identity14"))
65 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module1", "module1", "identity14")).contains(
66 new YangIdentity("test:module1", "module1", "identity11")));
67 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module1", "module1", "identity14")).contains(
68 new YangIdentity("test:module1", "module1", "identity12")));
69 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module1", "module1", "identity14")).contains(
70 new YangIdentity("test:module1", "module1", "identity13")));
72 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module1", "module1", "identity15"))
74 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module1", "module1", "identity15")).contains(
75 new YangIdentity("test:module1", "module1", "identity14")));
77 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module1", "module1", "identity61"))
79 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module1", "module1", "identity61")).contains(
80 new YangIdentity("test:module1", "module1", "identity14")));
81 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module1", "module1", "identity61")).contains(
82 new YangIdentity("test:module1", "module1", "identity42")));
84 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module1", "module1", "identity99"))
86 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module1", "module1", "identity99")).contains(
87 new YangIdentity("test:module2", "module2", "identity99")));
89 // ---- module 2 ---- bases ------
91 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module2", "module2", "identity21"))
94 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module2", "module2", "identity22"))
96 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module2", "module2", "identity22")).contains(
97 new YangIdentity("test:module2", "module2", "identity21")));
99 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module2", "module2", "identity23"))
101 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module2", "module2", "identity23")).contains(
102 new YangIdentity("test:module1", "module1", "identity11")));
104 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module2", "module2", "identity99"))
107 // ---- module 3 ---- bases ------
109 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module3", "module3", "identity31"))
112 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module3", "module3", "identity32"))
114 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module3", "module3", "identity32")).contains(
115 new YangIdentity("test:module3", "module3", "identity31")));
117 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module3", "module3", "identity33"))
119 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module3", "module3", "identity33")).contains(
120 new YangIdentity("test:module2", "module2", "identity21")));
122 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module3", "module3", "identity99"))
125 // ---- submodule 4 ---- bases ------
127 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module1", "module1", "identity41"))
129 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module1", "module1", "identity42"))
132 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module1", "module1", "identity43"))
134 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module1", "module1", "identity43")).contains(
135 new YangIdentity("test:module1", "module1", "identity41")));
136 assertTrue(identityRegistry.getBasesForIdentity(new YangIdentity("test:module1", "module1", "identity43")).contains(
137 new YangIdentity("test:module1", "module1", "identity42")));
139 // ---- module 1 ---- derivates ------
141 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module1", "module1", "identity11"))
143 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module1", "module1", "identity11"))
144 .contains(new YangIdentity("test:module1", "module1", "identity14")));
145 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module1", "module1", "identity11"))
146 .contains(new YangIdentity("test:module2", "module2", "identity23")));
148 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module1", "module1", "identity12"))
150 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module1", "module1", "identity12"))
151 .contains(new YangIdentity("test:module1", "module1", "identity14")));
153 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module1", "module1", "identity13"))
155 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module1", "module1", "identity13"))
156 .contains(new YangIdentity("test:module1", "module1", "identity14")));
158 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module1", "module1", "identity14"))
160 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module1", "module1", "identity14"))
161 .contains(new YangIdentity("test:module1", "module1", "identity15")));
162 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module1", "module1", "identity14"))
163 .contains(new YangIdentity("test:module1", "module1", "identity61")));
165 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module1", "module1", "identity15"))
168 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module1", "module1", "identity61"))
171 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module1", "module1", "identity99"))
174 // ---- module 2 ---- derivates ------
176 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module2", "module2", "identity21"))
178 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module2", "module2", "identity21"))
179 .contains(new YangIdentity("test:module2", "module2", "identity22")));
180 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module2", "module2", "identity21"))
181 .contains(new YangIdentity("test:module3", "module3", "identity33")));
183 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module2", "module2", "identity22"))
186 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module2", "module2", "identity23"))
189 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module2", "module2", "identity99"))
191 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module2", "module2", "identity99"))
192 .contains(new YangIdentity("test:module1", "module1", "identity99")));
194 // ---- module 3 ---- derivates ------
196 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module3", "module3", "identity31"))
198 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module3", "module3", "identity31"))
199 .contains(new YangIdentity("test:module3", "module3", "identity32")));
201 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module3", "module3", "identity32"))
204 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module3", "module3", "identity33"))
207 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module3", "module3", "identity99"))
210 // ---- submodule 4 ---- derivates ------
212 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module1", "module1", "identity41"))
214 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module1", "module1", "identity41"))
215 .contains(new YangIdentity("test:module1", "module1", "identity43")));
217 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module1", "module1", "identity42"))
219 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module1", "module1", "identity42"))
220 .contains(new YangIdentity("test:module1", "module1", "identity43")));
221 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module1", "module1", "identity42"))
222 .contains(new YangIdentity("test:module1", "module1", "identity61")));
224 assertTrue(identityRegistry.getDerivatesOfIdentity(new YangIdentity("test:module1", "module1", "identity43"))
227 // ---------------- check the derived trees ---------------
229 Set<YangIdentity> identityAndDerivedIdentities = identityRegistry.getIdentityAndDerivedIdentitiesRecursively(
230 new YangIdentity("test:module1", "module1", "identity11"));
232 assertTrue(identityAndDerivedIdentities.contains(new YangIdentity("test:module1", "module1", "identity11")));
233 assertTrue(identityAndDerivedIdentities.contains(new YangIdentity("test:module1", "module1", "identity14")));
234 assertTrue(identityAndDerivedIdentities.contains(new YangIdentity("test:module1", "module1", "identity15")));
235 assertTrue(identityAndDerivedIdentities.contains(new YangIdentity("test:module1", "module1", "identity61")));
236 assertTrue(identityAndDerivedIdentities.contains(new YangIdentity("test:module2", "module2", "identity23")));
237 assertTrue(identityAndDerivedIdentities.size() == 5);
239 identityAndDerivedIdentities = identityRegistry.getIdentityAndDerivedIdentitiesRecursively(new YangIdentity(
240 "test:module1", "module1", "identity12"));
242 assertTrue(identityAndDerivedIdentities.contains(new YangIdentity("test:module1", "module1", "identity12")));
243 assertTrue(identityAndDerivedIdentities.contains(new YangIdentity("test:module1", "module1", "identity14")));
244 assertTrue(identityAndDerivedIdentities.contains(new YangIdentity("test:module1", "module1", "identity15")));
245 assertTrue(identityAndDerivedIdentities.contains(new YangIdentity("test:module1", "module1", "identity61")));
246 assertTrue(identityAndDerivedIdentities.size() == 4);
248 identityAndDerivedIdentities = identityRegistry.getIdentityAndDerivedIdentitiesRecursively(new YangIdentity(
249 "unknown-namespace", "unknown-module", "unknown-identity"));
250 assertTrue(identityAndDerivedIdentities.size() == 0);