6b273c6195814db72ff1d8ea332f9a7ee3c4a621
[smo/teiv.git] /
1 /*
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
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21 package org.oran.smo.yangtools.parser.util.test;
22
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertTrue;
25
26 import org.junit.Test;
27
28 import org.oran.smo.yangtools.parser.model.schema.ModuleAndNamespaceResolver;
29 import org.oran.smo.yangtools.parser.util.NamespaceModuleIdentifier;
30
31 public class NamespaceAndIdentifierTest {
32
33     @Test
34     public void test_all_ok() {
35
36         final NamespaceModuleIdentifier nsai1 = new NamespaceModuleIdentifier("namespace", "module", "identifier");
37
38         assertTrue(nsai1.getNamespace().equals("namespace"));
39         assertTrue(nsai1.getModuleName().equals("module"));
40         assertTrue(nsai1.getIdentifier().equals("identifier"));
41         assertTrue(nsai1.hashCode() == "identifier".hashCode());
42         assertTrue(nsai1.toString().equals("namespace/module/identifier"));
43         assertTrue(nsai1.equals(new NamespaceModuleIdentifier("namespace", "module", "identifier")));
44         assertFalse(nsai1.equals(new NamespaceModuleIdentifier("namespace", "module", "identifier2")));
45         assertFalse(nsai1.equals(new NamespaceModuleIdentifier("namespace2", "module2", "identifier")));
46         assertFalse(nsai1.equals(""));
47         assertFalse(nsai1.equals(null));
48
49         final ModuleAndNamespaceResolver namespaceResolver = new ModuleAndNamespaceResolver();
50         namespaceResolver.recordModuleMapping("module", "namespace");
51         namespaceResolver.recordNamespaceMapping("namespace", "module");
52
53         final NamespaceModuleIdentifier nsai2 = new NamespaceModuleIdentifier("namespace", null, "identifier");
54         assertTrue(nsai2.getNamespace().equals("namespace"));
55         assertTrue(nsai2.getModuleName() == null);
56         assertTrue(nsai2.getIdentifier().equals("identifier"));
57         assertTrue(nsai2.equals(new NamespaceModuleIdentifier("namespace", "module", "identifier")));
58         assertFalse(nsai2.equals(new NamespaceModuleIdentifier(null, "module", "identifier")));
59
60         nsai2.resolveModuleOrNamespace(namespaceResolver);
61         assertTrue(nsai2.getModuleName().equals("module"));
62
63         final NamespaceModuleIdentifier nsai3 = new NamespaceModuleIdentifier(null, "module", "identifier");
64         assertTrue(nsai3.getNamespace() == null);
65         assertTrue(nsai3.getModuleName().equals("module"));
66         assertTrue(nsai3.getIdentifier().equals("identifier"));
67         assertTrue(nsai3.equals(new NamespaceModuleIdentifier("namespace", "module", "identifier")));
68         assertFalse(nsai3.equals(new NamespaceModuleIdentifier("namespace", null, "identifier")));
69
70         nsai3.resolveModuleOrNamespace(namespaceResolver);
71         assertTrue(nsai3.getNamespace().equals("namespace"));
72     }
73 }