*
* @return true if another process is running, false if not
*/
- private static boolean isDataImportRunning() {
+ static boolean isDataImportRunning() {
Process process = null;
* The findPayExportedPayload method tries to find the latest exported payload.
* Also deletes the old files if any or any other file in this directory
*/
- private static File findExportedPayload() throws AAIException {
+ static File findExportedPayload() throws AAIException {
String targetDir = AAIConstants.AAI_HOME_BUNDLECONFIG + AAIConfig.get("aai.dataimport.input.location");
File targetDirFile = new File(targetDir);
File payloadFile = null;
*
* @param script The script/command arguments
*/
- private static void runAddManualDataScript(String... script) {
+ static void runAddManualDataScript(String... script) {
Process process = null;
try {
process = new ProcessBuilder().command(script).start();
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
+import static org.junit.Assert.assertNull;\r
+import static org.junit.jupiter.api.Assertions.*;\r
+import static org.mockito.ArgumentMatchers.any;\r
+import static org.mockito.ArgumentMatchers.anyString;\r
+\r
+import org.mockito.MockedStatic;\r
+import static org.mockito.Mockito.*;\r
\r
import java.io.File;\r
import java.io.IOException;\r
import java.nio.file.Files;\r
import java.nio.file.Path;\r
+import java.lang.reflect.Method;\r
+import java.lang.reflect.Field;\r
\r
import org.junit.jupiter.api.BeforeEach;\r
import org.junit.jupiter.api.Test;\r
assertTrue(result, "Should return false when unpacking fails");\r
}\r
\r
+ @Test\r
+ void testImportTask_FullFlow() throws Exception {\r
+ try (MockedStatic<AAIConfig> mockedAAIConfig = mockStatic(AAIConfig.class);\r
+ MockedStatic<DataImportTasks> mockedDataImportTasks = mockStatic(DataImportTasks.class)) {\r
+\r
+ mockedAAIConfig.when(() -> AAIConfig.get("aai.dataimport.enable"))\r
+ .thenReturn("true");\r
+\r
+ Path inputDir = Files.createTempDirectory("withGoodPayload");\r
+ mockedAAIConfig.when(() -> AAIConfig.get("aai.dataimport.input.location"))\r
+ .thenReturn(inputDir.toString());\r
+\r
+ // create a "payload" tar.gz file\r
+ Path fakePayload = inputDir.resolve("fullPayload.tar.gz");\r
+ Files.createFile(fakePayload);\r
+\r
+ // stub static methods\r
+ mockedDataImportTasks.when(() -> DataImportTasks.findExportedPayload())\r
+ .thenReturn(fakePayload.toFile());\r
+\r
+ mockedDataImportTasks.when(() -> DataImportTasks.unpackPayloadFile(fakePayload.toString()))\r
+ .thenReturn(true);\r
+\r
+ mockedDataImportTasks.when(() -> DataImportTasks.runAddManualDataScript(new String[] {\r
+ AAIConstants.AAI_HOME + AAIConstants.AAI_FILESEP + "bin"\r
+ + AAIConstants.AAI_FILESEP + "install"\r
+ + AAIConstants.AAI_FILESEP + "addManualData.sh",\r
+ "tenant_isolation"\r
+ })).thenAnswer(invocation -> null); // no-op\r
+\r
+ DataImportTasks task = new DataImportTasks();\r
+\r
+ assertDoesNotThrow(task::importTask);\r
+\r
+ // verify cleanup\r
+ assert !fakePayload.toFile().exists();\r
+ }\r
+ }\r
+\r
+ @Test\r
+ void testRunAddManualDataScript_WithValidCommand() throws Exception {\r
+ Method method = DataImportTasks.class.getDeclaredMethod(\r
+ "runAddManualDataScript", String[].class\r
+ );\r
+ method.setAccessible(true);\r
+\r
+ // Using a harmless command that exists on most systems\r
+ assertDoesNotThrow(() -> \r
+ method.invoke(null, (Object) new String[]{"echo", "hello"})\r
+ );\r
+ }\r
+\r
+ @Test\r
+ void testRunAddManualDataScript_WithInvalidCommand() throws Exception {\r
+ Method method = DataImportTasks.class.getDeclaredMethod(\r
+ "runAddManualDataScript", String[].class\r
+ );\r
+ method.setAccessible(true);\r
+\r
+ // Invalid command to trigger the catch block\r
+ assertDoesNotThrow(() -> \r
+ method.invoke(null, (Object) new String[]{"nonexistent-command-xyz"})\r
+ );\r
+ }\r
}\r
<parent>
<groupId>org.onap.aai.aai-common</groupId>
<artifactId>aai-parent</artifactId>
- <version>1.16.1-SNAPSHOT</version>
+ <version>1.16.1</version>
</parent>
<groupId>org.onap.aai.resources</groupId>
<artifactId>resources</artifactId>
<staging.path>/content/repositories/staging/</staging.path>
<!-- GMaven plugin uses this property to figure out the name of the docker tag -->
<aai.project.version>${project.version}</aai.project.version>
- <aai.common.version>1.16.1-SNAPSHOT</aai.common.version>
+ <aai.common.version>1.16.1</aai.common.version>
<aai.schema.service.version>1.12.7</aai.schema.service.version>
<sonar.scanner.version>3.11.0.3922</sonar.scanner.version>
</properties>