diff --git a/theodolite-quarkus/build.gradle b/theodolite-quarkus/build.gradle index 8b61bf506dd241c5b0d4e75b1357ef3fd5966135..8c0a13d1f24cfde01c8604285c49d3f48fe6a3b7 100644 --- a/theodolite-quarkus/build.gradle +++ b/theodolite-quarkus/build.gradle @@ -25,9 +25,12 @@ dependencies { implementation 'io.quarkus:quarkus-kubernetes-client' implementation 'org.apache.kafka:kafka-clients:2.7.0' implementation 'khttp:khttp:1.0.0' + compile 'junit:junit:4.12' + testImplementation 'io.quarkus:quarkus-junit5' testImplementation 'io.rest-assured:rest-assured' + testImplementation 'org.junit-pioneer:junit-pioneer:1.4.0' } group 'theodolite' diff --git a/theodolite-quarkus/src/test/kotlin/theodolite/util/IOHandlerTest.kt b/theodolite-quarkus/src/test/kotlin/theodolite/util/IOHandlerTest.kt index 76e3d506b4c19c6d81800a762ec8282c1765c79b..88207e7655a7056ae50d025f672dce2fa17eff94 100644 --- a/theodolite-quarkus/src/test/kotlin/theodolite/util/IOHandlerTest.kt +++ b/theodolite-quarkus/src/test/kotlin/theodolite/util/IOHandlerTest.kt @@ -2,10 +2,14 @@ package theodolite.util import com.google.gson.GsonBuilder import io.quarkus.test.junit.QuarkusTest +import org.hamcrest.CoreMatchers.containsString +import org.hamcrest.MatcherAssert.assertThat import org.junit.Rule import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.junit.rules.TemporaryFolder +import org.junitpioneer.jupiter.ClearEnvironmentVariable +import org.junitpioneer.jupiter.SetEnvironmentVariable const val FOLDER_URL = "Test-Folder" @@ -13,7 +17,7 @@ const val FOLDER_URL = "Test-Folder" internal class IOHandlerTest { @Rule - var temporaryFolder = TemporaryFolder() + private var temporaryFolder = TemporaryFolder() @Test fun testWriteStringToText() { @@ -73,4 +77,44 @@ internal class IOHandlerTest { IOHandler().readFileAsString("${folder.absolutePath}/test-file.json") ) } + + // Test the function `getResultFolderString + + @Test + @ClearEnvironmentVariable.ClearEnvironmentVariables( + ClearEnvironmentVariable(key = "RESULTS_FOLDER"), + ClearEnvironmentVariable(key = "CREATE_RESULTS_FOLDER") + ) + fun testGetResultFolderURL_emptyEnvironmentVars() { + assertEquals("",IOHandler().getResultFolderURL()) + } + + @Test() + @SetEnvironmentVariable.SetEnvironmentVariables( + SetEnvironmentVariable(key = "RESULTS_FOLDER", value = FOLDER_URL), + SetEnvironmentVariable(key = "CREATE_RESULTS_FOLDER", value = "false") + ) + fun testGetResultFolderURL_FolderNotExist() { + try { + IOHandler().getResultFolderURL() + } catch (e: Exception){ + assertThat(e.toString(), containsString("Folder not found")); + } + } + + @Test() + @SetEnvironmentVariable.SetEnvironmentVariables( + SetEnvironmentVariable(key = "RESULTS_FOLDER", value = FOLDER_URL), + SetEnvironmentVariable(key = "CREATE_RESULTS_FOLDER", value = "true") + ) + fun testGetResultFolderURL_CreateFolderIfNotExist() { + assertEquals("$FOLDER_URL/", IOHandler().getResultFolderURL()) + } + + @Test() + @ClearEnvironmentVariable(key = "RESULTS_FOLDER" ) + @SetEnvironmentVariable(key = "CREATE_RESULTS_FOLDER", value = "true") + fun testGetResultFolderURL_CreateFolderButNoFolderGiven() { + assertEquals("", IOHandler().getResultFolderURL()) + } }