5db1a261b49025c143dc3babe3a2593f5f0e4e6e
[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.*;
25 import static org.mockito.Mockito.*;
26 import static org.junit.jupiter.api.Assertions.*;
27
28 class VersionValidatorTest {
29
30     @Mock
31     private SchemaErrorStrategy mockErrorStrategy;
32
33     @Mock
34     private VersionValidationModule mockVersionValidationModule;
35
36     private VersionValidator versionValidator;
37
38     @BeforeEach
39     void setUp() {
40         MockitoAnnotations.openMocks(this);
41         versionValidator = new VersionValidator(mockErrorStrategy, mockVersionValidationModule);
42     }
43
44     @Test
45     void testValidate_NoError_ShouldReturnTrue() {
46         when(mockVersionValidationModule.validate()).thenReturn("");
47         when(mockErrorStrategy.isOK()).thenReturn(true);
48
49         boolean result = versionValidator.validate();
50
51         assertTrue(result);
52         verify(mockErrorStrategy, never()).notifyOnError(anyString());
53     }
54
55     @Test
56     void testValidate_WithError_ShouldReturnFalse() {
57         String errorMessage = "Version validation failed";
58         when(mockVersionValidationModule.validate()).thenReturn(errorMessage);
59         when(mockErrorStrategy.isOK()).thenReturn(false);
60
61         boolean result = versionValidator.validate();
62
63         assertFalse(result);
64         verify(mockErrorStrategy).notifyOnError(errorMessage);
65     }
66
67     @Test
68     void testGetErrorMsg() {
69         String errorMessage = "Error in version validation";
70         when(mockErrorStrategy.getErrorMsg()).thenReturn(errorMessage);
71
72         String errorMsg = versionValidator.getErrorMsg();
73
74         assertEquals(errorMessage, errorMsg);
75     }
76 }