2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.aai.schemaservice.nodeschema.validation;
22 import org.junit.jupiter.api.BeforeEach;
23 import org.junit.jupiter.api.Test;
25 import org.onap.aai.schemaservice.config.ConfigTranslator;
26 import org.onap.aai.schemaservice.nodeschema.SchemaVersion;
28 import static org.mockito.Mockito.*;
30 import static org.junit.jupiter.api.Assertions.*;
32 class NodeValidatorTest {
35 private ConfigTranslator mockTranslator;
38 private SchemaErrorStrategy mockErrorStrategy;
41 private DuplicateNodeDefinitionValidationModule mockDupChecker;
43 private NodeValidator nodeValidator;
47 MockitoAnnotations.openMocks(this);
48 nodeValidator = new NodeValidator(mockTranslator, mockErrorStrategy, mockDupChecker);
52 void testValidate_NoDuplicates_ShouldReturnTrue() {
53 SchemaVersion schemaVersion = mock(SchemaVersion.class);
54 List<String> nodeFiles = Arrays.asList("file1", "file2", "file3");
56 Map<SchemaVersion, List<String>> mockNodeFiles = new HashMap<>();
57 mockNodeFiles.put(schemaVersion, nodeFiles);
59 when(mockTranslator.getNodeFiles()).thenReturn(mockNodeFiles);
60 when(mockDupChecker.findDuplicates(nodeFiles, schemaVersion)).thenReturn("");
62 boolean result = nodeValidator.validate();
65 verify(mockErrorStrategy, never()).notifyOnError(anyString());
69 void testValidate_WithDuplicates_ShouldReturnFalse() {
70 SchemaVersion schemaVersion = mock(SchemaVersion.class);
71 List<String> nodeFiles = Arrays.asList("file1", "file2", "file3");
73 Map<SchemaVersion, List<String>> mockNodeFiles = new HashMap<>();
74 mockNodeFiles.put(schemaVersion, nodeFiles);
76 when(mockTranslator.getNodeFiles()).thenReturn(mockNodeFiles);
77 when(mockDupChecker.findDuplicates(nodeFiles, schemaVersion)).thenReturn("Duplicate found!");
78 boolean result = nodeValidator.validate();
81 verify(mockErrorStrategy).notifyOnError("Duplicate found!");
85 void testGetErrorMsg_WithoutError_ShouldReturnEmptyString() {
86 when(mockErrorStrategy.getErrorMsg()).thenReturn("");
88 String errorMsg = nodeValidator.getErrorMsg();
90 assertEquals("", errorMsg);
94 void testGetErrorMsg_WithError_ShouldReturnErrorMessage() {
95 when(mockErrorStrategy.getErrorMsg()).thenReturn("Some error occurred");
97 String errorMsg = nodeValidator.getErrorMsg();
99 assertEquals("Some error occurred", errorMsg);