Finalize FileAccess tests
All checks were successful
PRs & Pushes / build (push) Successful in 2m28s
PRs & Pushes / test (push) Successful in 2m25s
PRs & Pushes / build-apidoc (push) Successful in 2m23s

This commit is contained in:
JeremyStar™ 2024-12-17 03:26:52 +01:00
parent c13eaead94
commit bf449971e9
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
2 changed files with 421 additions and 36 deletions

View file

@ -21,15 +21,15 @@
package de.staropensource.engine.base
import de.staropensource.engine.base.exception.EngineInitializationFailureException
import de.staropensource.engine.base.implementable.ShutdownHandler
import de.staropensource.engine.testing.TestBase
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Assertions.fail
import org.junit.jupiter.api.MethodOrderer
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestMethodOrder
@TestMethodOrder(MethodOrderer.MethodName::class)
class EngineTest : TestBase(autoManage = false) {
class EngineTest : TestBase(
autoManage = false
) {
@Test
fun initialize() {
try {

View file

@ -20,8 +20,9 @@
package de.staropensource.engine.base.utility
import de.staropensource.engine.base.Engine
import de.staropensource.engine.base.TestBase
import de.staropensource.engine.base.utility.FileAccess.Type
import de.staropensource.engine.testing.TestBase
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
@ -32,7 +33,7 @@ import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
@Suppress("EmptyFunctionBlock")
@Suppress("LargeClass")
class FileAccessTest : TestBase() {
// -----> Tests on non-existent files
// These tests are executed on paths which likely do not exist
@ -181,7 +182,7 @@ class FileAccessTest : TestBase() {
.temporaryCacheDirectory!!
.traverse("existsVoid.exist")
.delete()
.verifyNotExists(noFollowSymbolicLink = true)
.verifyNotExists()
.exists()
)
}
@ -193,7 +194,7 @@ class FileAccessTest : TestBase() {
.temporaryCacheDirectory!!
.traverse("existsFile.txt")
.delete()
.verifyNotExists(noFollowSymbolicLink = true)
.verifyNotExists()
.createFile()
.exists()
)
@ -206,7 +207,7 @@ class FileAccessTest : TestBase() {
.temporaryCacheDirectory!!
.traverse("existsDirectory.d")
.delete()
.verifyNotExists(noFollowSymbolicLink = true)
.verifyNotExists()
.createDirectory()
.exists()
)
@ -223,7 +224,7 @@ class FileAccessTest : TestBase() {
.temporaryCacheDirectory!!
.traverse("existsSymlinkReal.link.txt")
.delete()
.verifyNotExists(noFollowSymbolicLink = true)
.verifyNotExists()
.createLink(
FileAccess.temporaryCacheDirectory!!
.traverse("existsSymlinkReal.target.txt")
@ -247,13 +248,13 @@ class FileAccessTest : TestBase() {
.temporaryCacheDirectory!!
.traverse("existsSymlinkFake.link.txt")
.delete()
.verifyNotExists(noFollowSymbolicLink = true)
.verifyNotExists()
.createLink(
FileAccess
.temporaryCacheDirectory!!
.traverse("existsSymlinkFake.target.txt")
.delete()
.verifyNotExists(noFollowSymbolicLink = true),
.verifyNotExists(),
false
)
.exists(noFollowSymbolicLink = noFollowSymbolicLink)
@ -271,7 +272,7 @@ class FileAccessTest : TestBase() {
.temporaryCacheDirectory!!
.traverse("existsHardlinkReal.link.txt")
.delete()
.verifyNotExists(noFollowSymbolicLink = true)
.verifyNotExists()
.createLink(
FileAccess.temporaryCacheDirectory!!
.traverse("existsHardlinkReal.target.txt")
@ -298,7 +299,7 @@ class FileAccessTest : TestBase() {
.temporaryCacheDirectory!!
.traverse("existsHardlinkFake.link.txt")
.delete()
.verifyNotExists(noFollowSymbolicLink = true)
.verifyNotExists()
.createLink(
target,
true
@ -318,7 +319,7 @@ class FileAccessTest : TestBase() {
.temporaryCacheDirectory!!
.traverse("getTypeVoid.txt")
.delete()
.verifyNotExists(noFollowSymbolicLink = true)
.verifyNotExists()
.getType()
)
}
@ -331,7 +332,7 @@ class FileAccessTest : TestBase() {
.temporaryCacheDirectory!!
.traverse("getTypeFile.txt")
.delete()
.verifyNotExists(noFollowSymbolicLink = true)
.verifyNotExists()
.createFile()
.verifyIsFile()
.getType()
@ -346,7 +347,7 @@ class FileAccessTest : TestBase() {
.temporaryCacheDirectory!!
.traverse("getTypeDirectory.d")
.delete()
.verifyNotExists(noFollowSymbolicLink = true)
.verifyNotExists()
.createDirectory()
.verifyIsDirectory()
.getType()
@ -360,7 +361,7 @@ class FileAccessTest : TestBase() {
.temporaryCacheDirectory!!
.traverse("isSymbolicLinkReal.link.txt")
.delete()
.verifyNotExists(noFollowSymbolicLink = true)
.verifyNotExists()
.createLink(
FileAccess.temporaryCacheDirectory!!
.traverse("existsSymlinkReal.target.txt")
@ -379,13 +380,13 @@ class FileAccessTest : TestBase() {
.temporaryCacheDirectory!!
.traverse("isSymbolicLinkFake.test.txt")
.delete()
.verifyNotExists(noFollowSymbolicLink = true)
.verifyNotExists()
.createLink(
FileAccess
.temporaryCacheDirectory!!
.traverse("existsSymlinkFake.target.txt")
.delete()
.verifyNotExists(noFollowSymbolicLink = true),
.verifyNotExists(),
false
)
.isSymbolicLink()
@ -409,7 +410,7 @@ class FileAccessTest : TestBase() {
.temporaryCacheDirectory!!
.traverse("getLinkDestinationSymlinkReal.link.txt")
.delete()
.verifyNotExists(noFollowSymbolicLink = true)
.verifyNotExists()
.createLink(
FileAccess
.temporaryCacheDirectory!!
@ -440,13 +441,13 @@ class FileAccessTest : TestBase() {
.temporaryCacheDirectory!!
.traverse("getLinkDestinationSymlinkFake.link.txt")
.delete()
.verifyNotExists(noFollowSymbolicLink = true)
.verifyNotExists()
.createLink(
FileAccess
.temporaryCacheDirectory!!
.traverse(supplyValue)
.delete()
.verifyNotExists(noFollowSymbolicLink = true),
.verifyNotExists(),
false
)
.getLinkDestination()
@ -461,7 +462,7 @@ class FileAccessTest : TestBase() {
.temporaryCacheDirectory!!
.traverse("justSomeTestFile")
.delete()
.verifyNotExists(noFollowSymbolicLink = true)
.verifyNotExists()
.getFileSystem()
)
}
@ -494,7 +495,7 @@ class FileAccessTest : TestBase() {
.temporaryCacheDirectory!!
.traverse(path)
.delete()
.verifyNotExists(noFollowSymbolicLink = true)
.verifyNotExists()
.createFile()
.getType()
)
@ -513,7 +514,7 @@ class FileAccessTest : TestBase() {
.temporaryCacheDirectory!!
.traverse(path)
.delete()
.verifyNotExists(noFollowSymbolicLink = true)
.verifyNotExists()
.createDirectory()
.getType()
)
@ -523,66 +524,450 @@ class FileAccessTest : TestBase() {
// already covered by the exists* link tests
@Test
fun move() {
fun moveFile() {
val target: FileAccess = FileAccess
.temporaryCacheDirectory!!
.traverse("moveFile.moved.txt")
FileAccess
.temporaryCacheDirectory!!
.traverse("moveFile.txt")
.delete()
.verifyNotExists()
.createFile()
.verifyIsFile()
.move(target)
assertEquals(Type.FILE, target.getType())
}
@Test
fun copy() {
fun moveDirectory() {
val target: FileAccess = FileAccess
.temporaryCacheDirectory!!
.traverse("moveDirectory.moved.d")
FileAccess
.temporaryCacheDirectory!!
.traverse("moveDirectory.d")
.delete()
.verifyNotExists()
.createDirectory()
.verifyIsDirectory()
.traverse("sometest.file")
.createFile()
.verifyIsFile()
.parent()
.traverse("test/directory/tree")
.createDirectory()
.verifyIsDirectory()
.traverse("some-file.txt")
.createFile()
.verifyIsFile()
.parent().parent().parent().parent()
.move(target)
assertEquals(Type.DIRECTORY, target.getType())
assertEquals(Type.FILE, target.traverse("sometest.file").getType())
assertEquals(Type.DIRECTORY, target.traverse("test").getType())
assertEquals(Type.DIRECTORY, target.traverse("test/directory").getType())
assertEquals(Type.DIRECTORY, target.traverse("test/directory/tree").getType())
assertEquals(Type.FILE, target.traverse("test/directory/tree/some-file.txt").getType())
}
@Test
fun delete() {
fun copyFile() {
val target: FileAccess = FileAccess
.temporaryCacheDirectory!!
.traverse("copyFile.copied.txt")
val file: FileAccess = FileAccess
.temporaryCacheDirectory!!
.traverse("copyFile.txt")
.delete()
.verifyNotExists()
.createFile()
.verifyIsFile()
.copy(target)
assertEquals(Type.FILE, file.getType())
assertEquals(Type.FILE, target.getType())
}
@Test
fun deleteOnShutdown() {
fun copyDirectory() {
val target: FileAccess = FileAccess
.temporaryCacheDirectory!!
.traverse("copyDirectory.copied.d")
val file: FileAccess = FileAccess
.temporaryCacheDirectory!!
.traverse("copyDirectory.d")
.delete()
.verifyNotExists()
.createDirectory()
.verifyIsDirectory()
.traverse("sometest.file")
.createFile()
.verifyIsFile()
.parent()
.traverse("test/directory/tree")
.createDirectory()
.verifyIsDirectory()
.traverse("some-file.txt")
.createFile()
.verifyIsFile()
.parent().parent().parent().parent()
.copy(target)
// -> 'target'
assertEquals(Type.DIRECTORY, target.getType())
assertEquals(Type.FILE, target.traverse("sometest.file").getType())
assertEquals(Type.DIRECTORY, target.traverse("test").getType())
assertEquals(Type.DIRECTORY, target.traverse("test/directory").getType())
assertEquals(Type.DIRECTORY, target.traverse("test/directory/tree").getType())
assertEquals(Type.FILE, target.traverse("test/directory/tree/some-file.txt").getType())
// -> 'file'
assertEquals(Type.DIRECTORY, file.getType())
assertEquals(Type.FILE, file.traverse("sometest.file").getType())
assertEquals(Type.DIRECTORY, file.traverse("test").getType())
assertEquals(Type.DIRECTORY, file.traverse("test/directory").getType())
assertEquals(Type.DIRECTORY, file.traverse("test/directory/tree").getType())
assertEquals(Type.FILE, file.traverse("test/directory/tree/some-file.txt").getType())
}
@Test
fun readBytes() {
fun deleteFile() {
val file: FileAccess = FileAccess
.temporaryCacheDirectory!!
.traverse("deleteFile.txt")
.delete()
.verifyNotExists()
.createFile()
.verifyIsFile()
.delete()
assertEquals(Type.VOID, file.getType())
}
@Test
fun readLines() {
fun deleteDirectory() {
val file: FileAccess = FileAccess
.temporaryCacheDirectory!!
.traverse("moveDirectory.d")
.delete()
.verifyNotExists()
.createDirectory()
.verifyIsDirectory()
.traverse("sometest.file")
.createFile()
.verifyIsFile()
.parent()
.traverse("test/directory/tree")
.createDirectory()
.verifyIsDirectory()
.traverse("some-file.txt")
.createFile()
.verifyIsFile()
.parent().parent().parent().parent()
.delete()
assertEquals(Type.VOID, file.getType())
assertEquals(Type.VOID, file.traverse("sometest.file").getType())
assertEquals(Type.VOID, file.traverse("test").getType())
assertEquals(Type.VOID, file.traverse("test/directory").getType())
assertEquals(Type.VOID, file.traverse("test/directory/tree").getType())
assertEquals(Type.VOID, file.traverse("test/directory/tree/some-file.txt").getType())
}
@Test
fun readString() {
fun deleteOnShutdownFile() {
val file: FileAccess = FileAccess
.temporaryCacheDirectory!!
.traverse("deleteFile.txt")
.delete()
.verifyNotExists()
.createFile()
.verifyIsFile()
.deleteOnShutdown()
Engine.shutdown()
assertEquals(Type.VOID, file.getType())
}
@Test
fun writeBytes() {
fun deleteOnShutdownDirectory() {
val file: FileAccess = FileAccess
.temporaryCacheDirectory!!
.traverse("moveDirectory.d")
.delete()
.verifyNotExists()
.createDirectory()
.verifyIsDirectory()
.traverse("sometest.file")
.createFile()
.verifyIsFile()
.parent()
.traverse("test/directory/tree")
.createDirectory()
.verifyIsDirectory()
.traverse("some-file.txt")
.createFile()
.verifyIsFile()
.parent().parent().parent().parent()
.deleteOnShutdown()
Engine.shutdown()
assertEquals(Type.VOID, file.getType())
assertEquals(Type.VOID, file.traverse("sometest.file").getType())
assertEquals(Type.VOID, file.traverse("test").getType())
assertEquals(Type.VOID, file.traverse("test/directory").getType())
assertEquals(Type.VOID, file.traverse("test/directory/tree").getType())
assertEquals(Type.VOID, file.traverse("test/directory/tree/some-file.txt").getType())
}
@Test
fun writeLines() {
fun readWriteBytes() {
val bytes: ByteArray = byteArrayOf(
0x62, 0x75, 0x73, 0x68,
0x20, 0x68, 0x69, 0x64,
0x20, 0x74, 0x68, 0x65,
0x20, 0x66, 0x61, 0x63,
0x74, 0x73
)
assertEquals(
bytes.toList().toString(),
FileAccess
.temporaryCacheDirectory!!
.traverse("readWriteBytes.txt")
.delete()
.verifyNotExists()
.writeBytes(bytes, async = false)
.verifyIsFile()
.readBytes()
?.toList().toString()
)
}
@Test
fun writeString() {
fun readWriteLines() {
val lines: List<String> = listOf(
"This is an example file",
"It contains much text",
"It is used for testing the writeLines and readLines methods of the FileAccess class.",
"",
":3"
)
assertEquals(
lines.toString(),
FileAccess
.temporaryCacheDirectory!!
.traverse("readWriteLines.txt")
.delete()
.verifyNotExists()
.writeLines(lines, async = false)
.verifyIsFile()
.readLines()
?.toString()
)
}
@Test
fun readWriteString() {
val string: String = """
This is an example file
It contains much text.
It is used for testing the writeLines and readLines methods of the FileAccess class.
:3"""
assertEquals(
string,
FileAccess
.temporaryCacheDirectory!!
.traverse("readWriteString.txt")
.delete()
.verifyNotExists()
.writeString(string, async = false)
.verifyIsFile()
.readString()
)
}
@Test
fun appendBytes() {
val bytes: ByteArray = byteArrayOf(
0x62, 0x75, 0x73, 0x68,
0x20, 0x68, 0x69, 0x64,
0x20, 0x74, 0x68, 0x65,
0x20
)
val facts: ByteArray = byteArrayOf(
0x66, 0x61, 0x63, 0x74,
0x73
)
assertEquals(
bytes.toList().plus(facts.toList()).toString(),
FileAccess
.temporaryCacheDirectory!!
.traverse("appendBytes.txt")
.delete()
.verifyNotExists()
.writeBytes(bytes, async = false)
.verifyIsFile()
.appendBytes(facts, async = false)
.readBytes()
?.toList().toString()
)
}
@Test
fun appendLines() {
val lines: List<String> = listOf(
"This is an example file",
"It contains much text",
"It is used for testing the writeLines and readLines methods of the FileAccess class."
)
val cute: List<String> = listOf(
"",
":3"
)
assertEquals(
lines.plus(cute).toString(),
FileAccess
.temporaryCacheDirectory!!
.traverse("appendLines.txt")
.delete()
.verifyNotExists()
.writeLines(lines, async = false)
.verifyIsFile()
.appendLines(cute, async = false)
.readLines()
?.toString()
)
}
@Test
fun appendString() {
val string: String = """
This is an example file
It contains much text.
It is used for testing the writeLines and readLines methods of the FileAccess class."""
val cute: String = "\n\n:3"
assertEquals(
string.plus(cute),
FileAccess
.temporaryCacheDirectory!!
.traverse("appendString.txt")
.delete()
.verifyNotExists()
.writeString(string, async = false)
.verifyIsFile()
.appendString(cute, async = false)
.readString()
)
}
@Test
fun list() {
assertEquals(
listOf(
"testfile.txt",
"another-test-file.txt",
"some",
"a-directory.d",
).sorted().toString(),
FileAccess
.temporaryCacheDirectory!!
.traverse("list.d")
.createDirectory()
.verifyIsDirectory()
.traverse("testfile.txt")
.createFile()
.verifyIsFile()
.parent()
.traverse("another-test-file.txt")
.createFile()
.verifyIsFile()
.parent()
.traverse("some/cool/dir/struct/verynice.txt")
.createFile()
.verifyIsFile()
.parent().parent().parent().parent().parent()
.traverse("a-directory.d")
.createDirectory()
.parent()
.list()
?.toList()?.sorted().toString()
)
}
@Test
fun listFiles() {
assertEquals(
listOf(
"testfile.txt",
"another-test-file.txt",
).sorted().toString(),
FileAccess
.temporaryCacheDirectory!!
.traverse("list.d")
.createDirectory()
.verifyIsDirectory()
.traverse("testfile.txt")
.createFile()
.verifyIsFile()
.parent()
.traverse("another-test-file.txt")
.createFile()
.verifyIsFile()
.parent()
.traverse("some/cool/dir/struct/verynice.txt")
.createFile()
.verifyIsFile()
.parent().parent().parent().parent().parent()
.traverse("a-directory.d")
.createDirectory()
.parent()
.listFiles()
?.toList()?.sorted().toString()
)
}
@Test
fun listDirectories() {
assertEquals(
listOf(
"some",
"a-directory.d",
).sorted().toString(),
FileAccess
.temporaryCacheDirectory!!
.traverse("list.d")
.createDirectory()
.verifyIsDirectory()
.traverse("testfile.txt")
.createFile()
.verifyIsFile()
.parent()
.traverse("another-test-file.txt")
.createFile()
.verifyIsFile()
.parent()
.traverse("some/cool/dir/struct/verynice.txt")
.createFile()
.verifyIsFile()
.parent().parent().parent().parent().parent()
.traverse("a-directory.d")
.createDirectory()
.parent()
.listDirectories()
?.toList()?.sorted().toString()
)
}
}