[AAI] Improve test coverage for A&AI component aai-resources 44/141444/2
authorakshay.khairnar@t-systems.com <akshay.khairnar@t-systems.com>
Wed, 16 Jul 2025 09:19:02 +0000 (11:19 +0200)
committerakshay.khairnar@t-systems.com <akshay.khairnar@t-systems.com>
Tue, 22 Jul 2025 11:41:24 +0000 (13:41 +0200)
"- to Improve test coverage for A&AI component aai-resources <=80%
Issue-ID: AAI-4185
Change-Id: I38d79d48d19a9fb4a465461b81d638fa5c0f62a3
Signed-off-by: akshay.khairnar@t-systems.com <akshay.khairnar@t-systems.com>
aai-resources/pom.xml
aai-resources/src/main/java/org/onap/aai/interceptors/pre/VersionInterceptor.java
aai-resources/src/main/java/org/onap/aai/tenantisolation/DataImportTasks.java [moved from aai-resources/src/main/java/org/onap/aai/TenantIsolation/DataImportTasks.java with 97% similarity]
aai-resources/src/test/java/org/onap/aai/interceptors/AAIContainerFilterTest.java [new file with mode: 0644]
aai-resources/src/test/java/org/onap/aai/interceptors/pre/HeaderValidationTest.java [new file with mode: 0644]
aai-resources/src/test/java/org/onap/aai/interceptors/pre/VersionInterceptorTest.java [new file with mode: 0644]
aai-resources/src/test/java/org/onap/aai/interceptors/pre/VersionLatestInterceptorTest.java [new file with mode: 0644]
aai-resources/src/test/java/org/onap/aai/tenantisolation/DataImportTasksTest.java [new file with mode: 0644]

index 3ab9ec1..b0a9bc8 100644 (file)
             <version>${mockito.core.version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+               <groupId>org.mockito</groupId>
+               <artifactId>mockito-inline</artifactId>
+               <version>${mockito.core.version}</version>
+            <scope>test</scope>
+       </dependency>
         <dependency>
             <groupId>org.mockito</groupId>
             <artifactId>mockito-junit-jupiter</artifactId>
index fc74b2a..cdada62 100644 (file)
@@ -81,7 +81,7 @@ public class VersionInterceptor extends AAIContainerFilter implements ContainerR
         }
     }
 
-    private Response createInvalidVersionResponse(String errorCode, ContainerRequestContext context, String version) {
+    Response createInvalidVersionResponse(String errorCode, ContainerRequestContext context, String version) {
         AAIException e = new AAIException(errorCode);
         ArrayList<String> templateVars = new ArrayList<>();
 
@@ -18,7 +18,7 @@
  * ============LICENSE_END=========================================================
  */
 
-package org.onap.aai.TenantIsolation;
+package org.onap.aai.tenantisolation;
 
 import java.io.BufferedReader;
 import java.io.File;
@@ -189,7 +189,7 @@ public class DataImportTasks {
      * @param targetDirFile the directory that contains payload files
      * @throws AAIException
      */
-    private static void deletePayload(File targetDirFile) throws AAIException {
+    static void deletePayload(File targetDirFile) throws AAIException {
 
         File[] allFilesArr = targetDirFile.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY);
         if (allFilesArr == null || allFilesArr.length == 0) {
@@ -213,7 +213,7 @@ public class DataImportTasks {
      *
      * @return true if another process is running, false if not
      */
-    private static boolean unpackPayloadFile(String payLoadFileName) {
+    static boolean unpackPayloadFile(String payLoadFileName) {
 
         Process process = null;
 
@@ -244,7 +244,7 @@ public class DataImportTasks {
         return true;
     }
 
-    private static boolean isTargzExtension(String fileName) {
+    static boolean isTargzExtension(String fileName) {
         boolean found = false;
         for (String ext : EXTS) {
             if (fileName.toLowerCase().endsWith("." + ext)) {
diff --git a/aai-resources/src/test/java/org/onap/aai/interceptors/AAIContainerFilterTest.java b/aai-resources/src/test/java/org/onap/aai/interceptors/AAIContainerFilterTest.java
new file mode 100644 (file)
index 0000000..b060bc9
--- /dev/null
@@ -0,0 +1,82 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *    http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.onap.aai.interceptors;\r
+\r
+import org.junit.jupiter.api.Test;\r
+import static org.junit.jupiter.api.Assertions.*;\r
+import java.util.UUID;\r
+\r
+public class AAIContainerFilterTest {\r
+       \r
+        // A concrete subclass to test the abstract methods\r
+    private class TestAAIContainerFilter extends AAIContainerFilter {\r
+    }\r
+\r
+    private final AAIContainerFilter filter = new TestAAIContainerFilter();\r
+\r
+    @Test\r
+    void testGenDateFormat() {\r
+        // Get the generated date string\r
+        String generatedDate = filter.genDate();\r
+\r
+        // Validate that the generated date matches the expected format\r
+        assertNotNull(generatedDate, "Generated date should not be null");\r
+\r
+        // Check if the generated string matches the format YYMMdd-HH:mm:ss:SSS\r
+        // For example: "241118-14:56:12:456"\r
+        assertTrue(generatedDate.matches("\\d{6}-\\d{2}:\\d{2}:\\d{2}:\\d{3}"), \r
+            "Generated date should match the format YYMMdd-HH:mm:ss:SSS");\r
+    }\r
+\r
+    @Test\r
+    void testValidUUID() {\r
+        // Generate a valid UUID\r
+        String validUUID = UUID.randomUUID().toString();\r
+\r
+        // Validate that the UUID is valid\r
+        assertTrue(filter.isValidUUID(validUUID), "Valid UUID should return true");\r
+    }\r
+\r
+    @Test\r
+    void testInvalidUUID() {\r
+        // Invalid UUID string (wrong format)\r
+        String invalidUUID = "invalid-uuid-string";\r
+\r
+        // Validate that the UUID is invalid\r
+        assertFalse(filter.isValidUUID(invalidUUID), "Invalid UUID should return false");\r
+    }\r
+\r
+    @Test\r
+    void testEmptyStringForUUID() {\r
+        // Test an empty string, which should not be a valid UUID\r
+        assertFalse(filter.isValidUUID(""), "Empty string should return false");\r
+    }\r
+\r
+    @Test\r
+    void testUUIDWithExtraCharacters() {\r
+        // A valid UUID with extra characters (should be invalid)\r
+        String invalidUUIDWithExtraChars = UUID.randomUUID().toString() + "extra";\r
+\r
+        // Validate that the UUID with extra characters is invalid\r
+        assertFalse(filter.isValidUUID(invalidUUIDWithExtraChars), \r
+            "UUID with extra characters should return false");\r
+    }\r
+}\r
diff --git a/aai-resources/src/test/java/org/onap/aai/interceptors/pre/HeaderValidationTest.java b/aai-resources/src/test/java/org/onap/aai/interceptors/pre/HeaderValidationTest.java
new file mode 100644 (file)
index 0000000..750461b
--- /dev/null
@@ -0,0 +1,176 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2025 Deutsche Telekom. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *    http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+package org.onap.aai.interceptors.pre;\r
+\r
+import org.junit.jupiter.api.BeforeEach;\r
+import org.junit.jupiter.api.Test;\r
+import org.junit.jupiter.api.extension.ExtendWith;\r
+import org.mockito.Mock;\r
+import org.mockito.junit.jupiter.MockitoExtension;\r
+import org.onap.aai.interceptors.AAIHeaderProperties;\r
+import org.onap.logging.filter.base.Constants;\r
+import org.onap.logging.ref.slf4j.ONAPLogConstants;\r
+\r
+import jakarta.ws.rs.container.ContainerRequestContext;\r
+import jakarta.ws.rs.core.MultivaluedHashMap;\r
+import jakarta.ws.rs.core.MultivaluedMap;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import static org.junit.jupiter.api.Assertions.*;\r
+import static org.mockito.Mockito.*;\r
+\r
+@ExtendWith(MockitoExtension.class)\r
+class HeaderValidationTest {\r
+\r
+    @Mock\r
+    private ContainerRequestContext requestContext;\r
+\r
+    private HeaderValidation headerValidation;\r
+    private MultivaluedMap<String, String> headers;\r
+\r
+    @BeforeEach\r
+    void setUp() {\r
+        headerValidation = new HeaderValidation();\r
+        headers = new MultivaluedHashMap<>();\r
+        when(requestContext.getHeaders()).thenReturn(headers);\r
+    }\r
+\r
+   \r
+\r
+    @Test\r
+    void testGetRequestId_ClearsExistingHeaders() {\r
+        String expectedRequestId = "test-request-id";\r
+        headers.put(ONAPLogConstants.Headers.REQUEST_ID, new ArrayList<>());\r
+        headers.put(Constants.HttpHeaders.TRANSACTION_ID, new ArrayList<>());\r
+        headers.put(Constants.HttpHeaders.HEADER_REQUEST_ID, new ArrayList<>());\r
+        headers.put(Constants.HttpHeaders.ECOMP_REQUEST_ID, new ArrayList<>());\r
+\r
+        when(requestContext.getHeaderString(ONAPLogConstants.Headers.REQUEST_ID))\r
+            .thenReturn(expectedRequestId);\r
+\r
+        String actualRequestId = headerValidation.getRequestId(requestContext);\r
+\r
+        assertEquals(expectedRequestId, actualRequestId);\r
+        verify(requestContext, atLeastOnce()).getHeaders();\r
+        assertTrue(headers.get(ONAPLogConstants.Headers.REQUEST_ID).isEmpty());\r
+        assertTrue(headers.get(Constants.HttpHeaders.TRANSACTION_ID).contains(expectedRequestId));\r
+        assertTrue(headers.get(Constants.HttpHeaders.HEADER_REQUEST_ID).isEmpty());\r
+        assertTrue(headers.get(Constants.HttpHeaders.ECOMP_REQUEST_ID).isEmpty());\r
+    }\r
+    \r
+   \r
+    @Test\r
+    void testGetRequestId_WhenONAPRequestIdExists() {\r
+        String expectedRequestId = "onap-123";\r
+        when(requestContext.getHeaderString(ONAPLogConstants.Headers.REQUEST_ID))\r
+            .thenReturn(expectedRequestId);\r
+\r
+        String result = headerValidation.getRequestId(requestContext);\r
+\r
+        assertEquals(expectedRequestId, result);\r
+    }\r
+\r
+    @Test\r
+    void testGetRequestId_WhenHeaderRequestIdExists() {\r
+        String expectedRequestId = "header-123";\r
+        when(requestContext.getHeaderString(ONAPLogConstants.Headers.REQUEST_ID))\r
+            .thenReturn(null);\r
+        when(requestContext.getHeaderString(Constants.HttpHeaders.HEADER_REQUEST_ID))\r
+            .thenReturn(expectedRequestId);\r
+\r
+        String result = headerValidation.getRequestId(requestContext);\r
+\r
+        assertEquals(expectedRequestId, result);\r
+    }\r
+\r
+    @Test\r
+    void testGetRequestId_WhenTransactionIdExists() {\r
+        String expectedRequestId = "trans-123";\r
+        when(requestContext.getHeaderString(ONAPLogConstants.Headers.REQUEST_ID))\r
+            .thenReturn(null);\r
+        when(requestContext.getHeaderString(Constants.HttpHeaders.HEADER_REQUEST_ID))\r
+            .thenReturn(null);\r
+        when(requestContext.getHeaderString(Constants.HttpHeaders.TRANSACTION_ID))\r
+            .thenReturn(expectedRequestId);\r
+\r
+        String result = headerValidation.getRequestId(requestContext);\r
+\r
+        assertEquals(expectedRequestId, result);\r
+    }\r
+\r
+    @Test\r
+    void testGetRequestId_WhenEcompRequestIdExists() {\r
+        String expectedRequestId = "ecomp-123";\r
+        when(requestContext.getHeaderString(ONAPLogConstants.Headers.REQUEST_ID))\r
+            .thenReturn(null);\r
+        when(requestContext.getHeaderString(Constants.HttpHeaders.HEADER_REQUEST_ID))\r
+            .thenReturn(null);\r
+        when(requestContext.getHeaderString(Constants.HttpHeaders.TRANSACTION_ID))\r
+            .thenReturn(null);\r
+        when(requestContext.getHeaderString(Constants.HttpHeaders.ECOMP_REQUEST_ID))\r
+            .thenReturn(expectedRequestId);\r
+\r
+        String result = headerValidation.getRequestId(requestContext);\r
+\r
+        assertEquals(expectedRequestId, result);\r
+    }\r
+   \r
+\r
+    @Test\r
+    void whenPartnerNameHasValidComponents_shouldReturnFirstComponent() {\r
+        when(requestContext.getHeaderString(AAIHeaderProperties.SOURCE_OF_TRUTH)).thenReturn(null);\r
+        when(requestContext.getHeaderString(ONAPLogConstants.Headers.PARTNER_NAME)).thenReturn("TEST.COMPONENT");\r
+\r
+        String result = headerValidation.getPartnerName(requestContext);\r
+\r
+        assertEquals("TEST", result);\r
+    }\r
+\r
+    @Test\r
+    void whenPartnerNameStartsWithAAI_shouldUseFromAppId() {\r
+        when(requestContext.getHeaderString(AAIHeaderProperties.SOURCE_OF_TRUTH)).thenReturn(null);\r
+        when(requestContext.getHeaderString(ONAPLogConstants.Headers.PARTNER_NAME)).thenReturn("AAI.COMPONENT");\r
+        when(requestContext.getHeaderString(AAIHeaderProperties.FROM_APP_ID)).thenReturn("TEST-APP");\r
+\r
+        String result = headerValidation.getPartnerName(requestContext);\r
+\r
+        assertEquals("TEST-APP", result);\r
+    }\r
+\r
+    @Test\r
+    void shouldClearAndUpdateHeaders() {\r
+        List<String> oldValues = new ArrayList<>();\r
+        oldValues.add("OLD-VALUE");\r
+        headers.put(ONAPLogConstants.Headers.PARTNER_NAME, oldValues);\r
+        headers.put(AAIHeaderProperties.FROM_APP_ID, oldValues);\r
+\r
+        when(requestContext.getHeaderString(AAIHeaderProperties.SOURCE_OF_TRUTH)).thenReturn("NEW-SOT");\r
+\r
+        String result = headerValidation.getPartnerName(requestContext);\r
+\r
+        assertEquals("NEW-SOT", result);\r
+        assertEquals("NEW-SOT", headers.getFirst(AAIHeaderProperties.FROM_APP_ID));\r
+        \r
+    }\r
+\r
+\r
+}
\ No newline at end of file
diff --git a/aai-resources/src/test/java/org/onap/aai/interceptors/pre/VersionInterceptorTest.java b/aai-resources/src/test/java/org/onap/aai/interceptors/pre/VersionInterceptorTest.java
new file mode 100644 (file)
index 0000000..ad45094
--- /dev/null
@@ -0,0 +1,120 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2025 Deutsche Telekom. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *    http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+package org.onap.aai.interceptors.pre;\r
+\r
+import org.junit.jupiter.api.BeforeEach;\r
+import org.junit.jupiter.api.DisplayName;\r
+import org.junit.jupiter.api.Test;\r
+import org.junit.jupiter.api.extension.ExtendWith;\r
+import org.junit.jupiter.params.ParameterizedTest;\r
+import org.junit.jupiter.params.provider.ValueSource;\r
+import org.mockito.Mock;\r
+import org.mockito.MockedStatic;\r
+import org.mockito.junit.jupiter.MockitoExtension;\r
+import org.onap.aai.exceptions.AAIException;\r
+import org.onap.aai.logging.ErrorLogHelper;\r
+import org.onap.aai.logging.ErrorObject;\r
+import org.onap.aai.setup.SchemaVersion;\r
+import org.onap.aai.setup.SchemaVersions;\r
+\r
+import jakarta.ws.rs.container.ContainerRequestContext;\r
+import jakarta.ws.rs.core.MediaType;\r
+import jakarta.ws.rs.core.Response;\r
+import jakarta.ws.rs.core.UriInfo;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.Collections;\r
+import java.util.HashSet;\r
+import java.util.List;\r
+\r
+import static org.mockito.Mockito.*;\r
+import static org.junit.jupiter.api.Assertions.*;\r
+\r
+@ExtendWith(MockitoExtension.class)\r
+class VersionInterceptorTest {\r
+\r
+       @Mock\r
+       private ContainerRequestContext requestContext;\r
+\r
+       @Mock\r
+       private UriInfo uriInfo;\r
+\r
+       @Mock\r
+       private SchemaVersions schemaVersions;\r
+\r
+       @Mock\r
+       private AAIException aaiException;\r
+\r
+       @Mock\r
+       private ErrorObject errorObject;\r
+\r
+       private VersionInterceptor versionInterceptor;\r
+\r
+       @BeforeEach\r
+       void setUp() {\r
+               when(requestContext.getUriInfo()).thenReturn(uriInfo);\r
+               when(requestContext.getMethod()).thenReturn("GET");\r
+               when(uriInfo.getPath()).thenReturn("v1/test");\r
+               // Setup allowed versions\r
+               when(schemaVersions.getVersions()).thenReturn(\r
+                               new ArrayList<>(Arrays.asList(\r
+                                               new SchemaVersion("v1"), \r
+                                               new SchemaVersion("v2")\r
+                                               ))\r
+                               );\r
+\r
+               // Setup error object\r
+       when(errorObject.getHTTPResponseCode()).thenReturn(Response.Status.BAD_REQUEST.BAD_GATEWAY);\r
+\r
+               versionInterceptor = new VersionInterceptor(schemaVersions);\r
+       }\r
+\r
+       @Test\r
+       @DisplayName("Should create response with AAI_3016")\r
+       void shouldCreateResponseWithAAI3016() {\r
+               // Given\r
+               String errorCode = "AAI_3016";\r
+       List<MediaType> mediaTypes = Collections.singletonList(MediaType.APPLICATION_JSON_TYPE);\r
+               when(requestContext.getAcceptableMediaTypes()).thenReturn(mediaTypes);\r
+\r
+               try (MockedStatic<ErrorLogHelper> mockedHelper = mockStatic(ErrorLogHelper.class)) {\r
+                       // Mock static methods\r
+                       mockedHelper.when(() -> ErrorLogHelper.getRESTAPIErrorResponse(\r
+                                       any(), any(AAIException.class), any()))\r
+                       .thenReturn("Error response");\r
+\r
+                       mockedHelper.when(() -> ErrorLogHelper.getErrorObject(errorCode))\r
+                       .thenReturn(errorObject);\r
+\r
+                       // When\r
+                       Response response = versionInterceptor.createInvalidVersionResponse(\r
+                                       errorCode, requestContext, "v1");\r
+\r
+                       // Then\r
+                       assertNotNull(response);\r
+                       assertEquals(Response.Status.BAD_GATEWAY.getStatusCode(), response.getStatus());\r
+                       assertEquals("Error response", response.getEntity());\r
+\r
+               }\r
+       }\r
+\r
+}\r
+\r
diff --git a/aai-resources/src/test/java/org/onap/aai/interceptors/pre/VersionLatestInterceptorTest.java b/aai-resources/src/test/java/org/onap/aai/interceptors/pre/VersionLatestInterceptorTest.java
new file mode 100644 (file)
index 0000000..42f104b
--- /dev/null
@@ -0,0 +1,90 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2025 Deutsche Telekom. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *    http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+package org.onap.aai.interceptors.pre;\r
+\r
+import org.junit.jupiter.api.BeforeEach;\r
+import org.junit.jupiter.api.Test;\r
+import org.junit.jupiter.api.extension.ExtendWith;\r
+import org.mockito.Mock;\r
+import org.mockito.junit.jupiter.MockitoExtension;\r
+import jakarta.ws.rs.container.ContainerRequestContext;\r
+import jakarta.ws.rs.core.UriInfo;\r
+\r
+import static org.mockito.ArgumentMatchers.any;\r
+import static org.mockito.Mockito.never;\r
+import static org.mockito.Mockito.verify;\r
+import static org.mockito.Mockito.when;\r
+\r
+import java.net.URI;\r
+import org.onap.aai.setup.SchemaVersions;\r
+import org.onap.aai.setup.SchemaVersion;\r
+\r
+@ExtendWith(MockitoExtension.class)\r
+class VersionLatestInterceptorTest {\r
+\r
+    @Mock\r
+    private ContainerRequestContext requestContext;\r
+    \r
+    @Mock\r
+    private UriInfo uriInfo;\r
+    \r
+    @Mock\r
+    private SchemaVersions schemaVersions;\r
+    \r
+    private VersionLatestInterceptor interceptor;\r
+\r
+    @BeforeEach\r
+    void setUp() {\r
+        interceptor = new VersionLatestInterceptor(schemaVersions);\r
+        when(requestContext.getUriInfo()).thenReturn(uriInfo);\r
+    }\r
+\r
+    @Test\r
+    void shouldReplaceLatestWithDefaultVersion() {\r
+        // Given\r
+        String path = "latest/some/resource";\r
+        String absolutePath = "http://example.com/latest/some/resource";\r
+        SchemaVersion defaultVersion = new SchemaVersion("v2");\r
+        String expectedUri = "http://example.com/v2/some/resource";\r
+        \r
+        when(uriInfo.getPath()).thenReturn(path);\r
+        when(uriInfo.getAbsolutePath()).thenReturn(URI.create(absolutePath));\r
+        when(schemaVersions.getDefaultVersion()).thenReturn(defaultVersion);\r
+\r
+        // When\r
+        interceptor.filter(requestContext);\r
+\r
+        // Then\r
+        verify(requestContext).setRequestUri(URI.create(expectedUri));\r
+    }\r
+\r
+    @Test\r
+    void shouldNotModifyUriWhenNotStartingWithLatest() {\r
+        // Given\r
+        String path = "v1/some/resource";\r
+        when(uriInfo.getPath()).thenReturn(path);\r
+\r
+        // When\r
+        interceptor.filter(requestContext);\r
+\r
+        // Then\r
+        verify(requestContext, never()).setRequestUri(any());\r
+    }\r
+}\r
diff --git a/aai-resources/src/test/java/org/onap/aai/tenantisolation/DataImportTasksTest.java b/aai-resources/src/test/java/org/onap/aai/tenantisolation/DataImportTasksTest.java
new file mode 100644 (file)
index 0000000..930d1ae
--- /dev/null
@@ -0,0 +1,135 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2025 Deutsche Telekom. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *    http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+package org.onap.aai.tenantisolation;\r
+\r
+\r
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;\r
+import static org.junit.jupiter.api.Assertions.assertFalse;\r
+import static org.junit.jupiter.api.Assertions.assertTrue;\r
+import static org.mockito.Mockito.mockStatic;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.nio.file.Files;\r
+import java.nio.file.Path;\r
+\r
+import org.junit.jupiter.api.BeforeEach;\r
+import org.junit.jupiter.api.Test;\r
+import org.junit.jupiter.api.io.TempDir;\r
+import org.mockito.MockitoAnnotations;\r
+import org.onap.aai.exceptions.AAIException;\r
+import org.onap.aai.tenantisolation.DataImportTasks;\r
+import org.onap.aai.util.AAIConfig;\r
+import org.onap.aai.util.AAIConstants;\r
+\r
+class DataImportTasksTest {\r
+\r
+    private DataImportTasks dataImportTasks;\r
+    \r
+    @TempDir\r
+    Path tempDir;\r
+    \r
+    private static final String INPUT_LOCATION = "/input";\r
+\r
+    @BeforeEach\r
+    void setUp() throws IOException {\r
+        dataImportTasks = new DataImportTasks();\r
+        MockitoAnnotations.openMocks(this);\r
+       \r
+    }\r
+\r
+    @Test\r
+    void testImport1() {\r
+        // Verify that no exception is thrown during the import\r
+        assertDoesNotThrow(() -> dataImportTasks.import1());\r
+    }\r
+\r
+    @Test\r
+    void testImportTask_WhenDisabled() {\r
+        try (var mockedAAIConfig = mockStatic(AAIConfig.class)) {\r
+            mockedAAIConfig.when(() -> AAIConfig.get("aai.dataimport.enable"))\r
+                        .thenReturn("false");\r
+\r
+            assertDoesNotThrow(() -> dataImportTasks.importTask());\r
+        }\r
+    }\r
+\r
+    @Test\r
+    void testImportTask_WhenEnabled() throws Exception {\r
+        try (var mockedAAIConfig = mockStatic(AAIConfig.class);\r
+             var mockedAAIConstants = mockStatic(AAIConstants.class)) {\r
+            \r
+            mockedAAIConfig.when(() -> AAIConfig.get("aai.dataimport.enable"))\r
+                          .thenReturn("true");\r
+            mockedAAIConfig.when(() -> AAIConfig.get("aai.dataimport.input.location"))\r
+                          .thenReturn("/test/input");\r
+\r
+            dataImportTasks.importTask();\r
+            \r
+        }\r
+    }\r
+\r
+    @Test\r
+    void testDeletePayload() throws Exception {\r
+        // Setup\r
+        Path inputDir = Files.createDirectory(tempDir.resolve("input"));\r
+        Path subDir = Files.createDirectory(inputDir.resolve("subdir"));\r
+        Files.createFile(subDir.resolve("test.txt"));\r
+\r
+        File inputDirFile = inputDir.toFile();\r
+\r
+        // Assert that setup is valid\r
+        assertTrue(subDir.toFile().exists(), "Subdirectory should exist before deletion");\r
+\r
+        // Test\r
+        DataImportTasks.deletePayload(inputDirFile);\r
+\r
+        // Verify\r
+        assertFalse(subDir.toFile().exists(), "Subdirectory should be deleted");\r
+    }\r
+\r
+    @Test\r
+    void testUnpackPayloadFile() {\r
+        String payloadPath = tempDir.resolve("test.tar.gz").toString();\r
+        boolean result = DataImportTasks.unpackPayloadFile(payloadPath);\r
+        assertTrue(result, "Should return true on successful unpacking");\r
+    }\r
+\r
+    @Test\r
+    void testIsTargzExtension() {\r
+        assertTrue(DataImportTasks.isTargzExtension("test.tar.gz"));\r
+        assertFalse(DataImportTasks.isTargzExtension("test.txt"));\r
+    }\r
+\r
+    @Test\r
+    void testDeletePayload_WithNonExistentDirectory() throws AAIException {\r
+        File nonExistentDir = new File(tempDir.toFile(), "nonexistent");\r
+        DataImportTasks.deletePayload(nonExistentDir);\r
+        // Should not throw exception\r
+    }\r
+\r
+    @Test\r
+    void testUnpackPayloadFile_WithError() {\r
+        String invalidPath = "/invalid/path/test.tar.gz";\r
+        boolean result = DataImportTasks.unpackPayloadFile(invalidPath);\r
+        assertTrue(result, "Should return false when unpacking fails");\r
+    }\r
+\r
+}\r