Refactoring of input validation
Move application file validation to provisionK3s. Add an ApplicationFileRepository. Also unit tests for the functions.merge-requests/2/head
parent
1ad357ba44
commit
05821540fe
@ -1,5 +1,5 @@
|
|||||||
package org.domaindrivenarchitecture.provs.server.domain.k3s
|
package org.domaindrivenarchitecture.provs.server.domain.k3s
|
||||||
|
|
||||||
interface ApplicationFileRepository {
|
interface ApplicationFileRepository {
|
||||||
fun exists(applicationFileName: ApplicationFileName?): Boolean
|
fun exists(applicationFileName: ApplicationFileName?)
|
||||||
}
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
package org.domaindrivenarchitecture.provs.server.infrastructure
|
||||||
|
|
||||||
|
import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileName
|
||||||
|
import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileRepository
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.api.assertThrows
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import java.io.File
|
||||||
|
import java.nio.file.Paths
|
||||||
|
|
||||||
|
internal class DefaultApplicationFileRepositoryKtTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun existsThrowsRuntimeException() {
|
||||||
|
//when
|
||||||
|
val invalidFileName: ApplicationFileName = ApplicationFileName("iDontExist")
|
||||||
|
val repo: ApplicationFileRepository = DefaultApplicationFileRepository()
|
||||||
|
|
||||||
|
// then
|
||||||
|
val exception = assertThrows<RuntimeException>(
|
||||||
|
"Should not find the file."
|
||||||
|
) { repo.exists(invalidFileName) }
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
"Application file not found. Please check if path is correct.",
|
||||||
|
exception.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun existsPasses() {
|
||||||
|
//when
|
||||||
|
val validFileName = "iExist"
|
||||||
|
File(validFileName).createNewFile()
|
||||||
|
|
||||||
|
val validFile: ApplicationFileName =
|
||||||
|
ApplicationFileName(File(validFileName).absolutePath)
|
||||||
|
val repo: ApplicationFileRepository = DefaultApplicationFileRepository()
|
||||||
|
|
||||||
|
// then
|
||||||
|
repo.exists(validFile)
|
||||||
|
|
||||||
|
File(validFileName).deleteOnExit()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue