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 static org.mockito.Mockito.*;
26 import static org.junit.jupiter.api.Assertions.*;
28 class VersionValidatorTest {
31 private SchemaErrorStrategy mockErrorStrategy;
34 private VersionValidationModule mockVersionValidationModule;
36 private VersionValidator versionValidator;
40 MockitoAnnotations.openMocks(this);
41 versionValidator = new VersionValidator(mockErrorStrategy, mockVersionValidationModule);
45 void testValidate_NoError_ShouldReturnTrue() {
46 when(mockVersionValidationModule.validate()).thenReturn("");
47 when(mockErrorStrategy.isOK()).thenReturn(true);
49 boolean result = versionValidator.validate();
52 verify(mockErrorStrategy, never()).notifyOnError(anyString());
56 void testValidate_WithError_ShouldReturnFalse() {
57 String errorMessage = "Version validation failed";
58 when(mockVersionValidationModule.validate()).thenReturn(errorMessage);
59 when(mockErrorStrategy.isOK()).thenReturn(false);
61 boolean result = versionValidator.validate();
64 verify(mockErrorStrategy).notifyOnError(errorMessage);
68 void testGetErrorMsg() {
69 String errorMessage = "Error in version validation";
70 when(mockErrorStrategy.getErrorMsg()).thenReturn(errorMessage);
72 String errorMsg = versionValidator.getErrorMsg();
74 assertEquals(errorMessage, errorMsg);