324bdee2119c87fb528438b0bf8de8d62f6d6a13
[aai/schema-service.git] /
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2025 Deutsche Telekom. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.aai.schemaservice.nodeschema.validation;
21
22 import org.junit.jupiter.api.BeforeEach;
23 import org.junit.jupiter.api.Test;
24 import org.mockito.InjectMocks;
25 import org.mockito.Mock;
26 import org.mockito.MockitoAnnotations;
27 import org.onap.aai.schemaservice.config.ConfigTranslator;
28 import org.onap.aai.schemaservice.nodeschema.SchemaVersion;
29 import org.onap.aai.schemaservice.nodeschema.SchemaVersions;
30 import java.util.Arrays;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Map;
34 import static org.mockito.Mockito.*;
35 import static org.junit.jupiter.api.Assertions.assertEquals;
36
37 class DefaultVersionValidationModuleTest {
38
39     @Mock
40     private ConfigTranslator configTranslator;
41
42     @Mock
43     private SchemaVersions schemaVersions;
44
45     @InjectMocks
46     private DefaultVersionValidationModule validationModule;
47
48     @BeforeEach
49     void setUp() {
50         MockitoAnnotations.openMocks(this);
51     }
52
53     @Test
54     void testValidate_AllSchemasPresent() {
55         SchemaVersion version1 = new SchemaVersion("v1");
56         SchemaVersion version2 = new SchemaVersion("v2");
57
58         Map<SchemaVersion, List<String>> nodeFiles = new HashMap<>();
59         nodeFiles.put(version1, Arrays.asList("nodeFile1"));
60         nodeFiles.put(version2, Arrays.asList("nodeFile2"));
61
62         Map<SchemaVersion, List<String>> edgeFiles = new HashMap<>();
63         edgeFiles.put(version1, Arrays.asList("edgeFile1"));
64         edgeFiles.put(version2, Arrays.asList("edgeFile2"));
65
66         when(configTranslator.getNodeFiles()).thenReturn(nodeFiles);
67         when(configTranslator.getEdgeFiles()).thenReturn(edgeFiles);
68         when(configTranslator.getSchemaVersions()).thenReturn(schemaVersions);
69         when(schemaVersions.getVersions()).thenReturn(Arrays.asList(version1, version2));
70
71         String result = validationModule.validate();
72
73         assertEquals("", result, "There should be no missing schemas.");
74     }
75
76     @Test
77     void testValidate_NodeSchemaMissing() {
78         SchemaVersion version1 = new SchemaVersion("v1");
79         SchemaVersion version2 = new SchemaVersion("v2");
80
81         Map<SchemaVersion, List<String>> nodeFiles = new HashMap<>();
82         nodeFiles.put(version1, Arrays.asList("nodeFile1"));
83         nodeFiles.put(version2, null);
84
85         Map<SchemaVersion, List<String>> edgeFiles = new HashMap<>();
86         edgeFiles.put(version1, Arrays.asList("edgeFile1"));
87         edgeFiles.put(version2, Arrays.asList("edgeFile2"));
88
89         when(configTranslator.getNodeFiles()).thenReturn(nodeFiles);
90         when(configTranslator.getEdgeFiles()).thenReturn(edgeFiles);
91         when(configTranslator.getSchemaVersions()).thenReturn(schemaVersions);
92         when(schemaVersions.getVersions()).thenReturn(Arrays.asList(version1, version2));
93
94         String result = validationModule.validate();
95
96         assertEquals("Missing schema for the following versions: v2 has no OXM configured. ", result);
97     }
98
99     @Test
100     void testValidate_EdgeSchemaMissing() {
101         SchemaVersion version1 = new SchemaVersion("v1");
102         SchemaVersion version2 = new SchemaVersion("v2");
103
104         Map<SchemaVersion, List<String>> nodeFiles = new HashMap<>();
105         nodeFiles.put(version1, Arrays.asList("nodeFile1"));
106         nodeFiles.put(version2, Arrays.asList("nodeFile2"));
107
108         Map<SchemaVersion, List<String>> edgeFiles = new HashMap<>();
109         edgeFiles.put(version1, Arrays.asList("edgeFile1"));
110         edgeFiles.put(version2, null);
111
112         when(configTranslator.getNodeFiles()).thenReturn(nodeFiles);
113         when(configTranslator.getEdgeFiles()).thenReturn(edgeFiles);
114         when(configTranslator.getSchemaVersions()).thenReturn(schemaVersions);
115         when(schemaVersions.getVersions()).thenReturn(Arrays.asList(version1, version2));
116
117         String result = validationModule.validate();
118
119         assertEquals("Missing schema for the following versions: v2 has no edge rules configured. ", result);
120     }
121
122     @Test
123     void testValidate_BothNodeAndEdgeSchemasMissing() {
124         SchemaVersion version1 = new SchemaVersion("v1");
125         SchemaVersion version2 = new SchemaVersion("v2");
126
127         Map<SchemaVersion, List<String>> nodeFiles = new HashMap<>();
128         nodeFiles.put(version1, Arrays.asList("nodeFile1"));
129         nodeFiles.put(version2, null);
130
131         Map<SchemaVersion, List<String>> edgeFiles = new HashMap<>();
132         edgeFiles.put(version1, Arrays.asList("edgeFile1"));
133         edgeFiles.put(version2, null);
134
135         when(configTranslator.getNodeFiles()).thenReturn(nodeFiles);
136         when(configTranslator.getEdgeFiles()).thenReturn(edgeFiles);
137         when(configTranslator.getSchemaVersions()).thenReturn(schemaVersions);
138         when(schemaVersions.getVersions()).thenReturn(Arrays.asList(version1, version2));
139
140         String result = validationModule.validate();
141
142         assertEquals("Missing schema for the following versions: v2 has no OXM configured. v2 has no edge rules configured. ", result);
143     }
144 }