diff --git a/lib/java/src/test/kotlin/org/veupathdb/lib/s3/workspaces/S3WorkspaceFactoryTest.kt b/lib/java/src/test/kotlin/org/veupathdb/lib/s3/workspaces/S3WorkspaceFactoryTest.kt deleted file mode 100644 index c30979e..0000000 --- a/lib/java/src/test/kotlin/org/veupathdb/lib/s3/workspaces/S3WorkspaceFactoryTest.kt +++ /dev/null @@ -1,172 +0,0 @@ -package org.veupathdb.lib.s3.workspaces - -import org.junit.jupiter.api.DisplayName -import org.junit.jupiter.api.Nested -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertThrows -import org.mockito.Mockito.* -import org.veupathdb.lib.hash_id.HashID -import org.veupathdb.lib.s3.s34k.S3Client -import org.veupathdb.lib.s3.s34k.buckets.BucketContainer -import org.veupathdb.lib.s3.s34k.buckets.S3Bucket -import org.veupathdb.lib.s3.s34k.fields.BucketName -import org.veupathdb.lib.s3.s34k.objects.ObjectContainer -import org.veupathdb.lib.s3.s34k.objects.S3Object -import kotlin.test.assertNotNull -import kotlin.test.assertNull - -@DisplayName("WorkspaceFactory") -internal class S3WorkspaceFactoryTest { - - private val provisionClient: S3Client get() = mock(S3Client::class.java) - - @Nested - @DisplayName("::init") - inner class Init { - - @Nested - @DisplayName("Throws IllegalArgumentException") - inner class ThrowsIAE { - - @Test - @DisplayName("when the input bucket name is not a valid S3 bucket name") - fun t1() { - - assertThrows { - S3WorkspaceFactory(provisionClient, "hello world") - } - } - } - - @Nested - @DisplayName("Throws IllegalStateException") - inner class ThrowsISE { - - @Test - @DisplayName("when the target bucket does not exist") - fun t1() { - val client = provisionClient - val buckets = mock(BucketContainer::class.java) - - `when`(client.buckets).thenReturn(buckets) - `when`(buckets.exists(BucketName("hello-world"))).thenReturn(false) - - assertThrows { - S3WorkspaceFactory(client, "hello-world") - } - } - } - } - - @Nested - @DisplayName("#get(HashID)") - inner class Get { - - @Nested - @DisplayName("Returns null") - inner class RNull { - - @Test - @DisplayName("when the target workspace does not exist.") - fun t1() { - val name = BucketName("hello-world") - val client = provisionClient - val buckets = mock(BucketContainer::class.java) - val objects = mock(ObjectContainer::class.java) - val bucket = mock(S3Bucket::class.java) - - val id = HashID("12345678901234561234567890123456") - - `when`(client.buckets).thenReturn(buckets) - `when`(buckets.exists(name)).thenReturn(true) - `when`(buckets[name]).thenReturn(bucket) - `when`(bucket.objects).thenReturn(objects) - `when`(objects.contains("12345678901234561234567890123456/.workspace")).thenReturn(false) - - assertNull(S3WorkspaceFactory(client, "hello-world")[id]) - } - } - - @Nested - @DisplayName("Returns a Workspace instance") - inner class RWorkspace { - - @Test - @DisplayName("when the target workspace exists") - fun t1() { - val name = BucketName("goodbye-world") - val client = provisionClient - val buckets = mock(BucketContainer::class.java) - val objects = mock(ObjectContainer::class.java) - val bucket = mock(S3Bucket::class.java) - val hash = HashID("12345678901234561234567890123456") - - `when`(client.buckets).thenReturn(buckets) - `when`(buckets.exists(name)).thenReturn(true) - `when`(buckets[name]).thenReturn(bucket) - `when`(bucket.objects).thenReturn(objects) - `when`(objects.contains("12345678901234561234567890123456/.workspace")).thenReturn(true) - - assertNotNull(S3WorkspaceFactory(client, name.name)[hash]) - } - } - } - - @Nested - @DisplayName("#create(HashID)") - inner class Create { - - @Nested - @DisplayName("Throws WorkspaceAlreadyExistsError") - inner class ThrowsWAEE { - - @Test - @DisplayName("when the target workspace already exists") - fun t1() { - val client = provisionClient - val bucket = mock(S3Bucket::class.java) - val buckets = mock(BucketContainer::class.java) - val objects = mock(ObjectContainer::class.java) - val name = BucketName("waka-waka-waka") - val hash = HashID("12345678901234561234567890123456") - - `when`(client.buckets).thenReturn(buckets) - `when`(buckets.exists(name)).thenReturn(true) - `when`(buckets.exists(name)).thenReturn(true) - `when`(buckets[name]).thenReturn(bucket) - `when`(bucket.objects).thenReturn(objects) - `when`(objects.contains("12345678901234561234567890123456/.workspace")).thenReturn(true) - - assertThrows { - S3WorkspaceFactory(client, name.name).create(hash) - } - } - } - - @Nested - @DisplayName("Returns a workspace instance") - inner class RWorkspace { - - @Test - @DisplayName("when the target workspace does not already exist") - fun t1() { - val name = BucketName("taco-smell") - val client = provisionClient - val buckets = mock(BucketContainer::class.java) - val objects = mock(ObjectContainer::class.java) - val bucket = mock(S3Bucket::class.java) - val derps = mock(S3Object::class.java) - val hash = HashID("12345678901234561234567890123456") - - `when`(client.buckets).thenReturn(buckets) - `when`(buckets.exists(name)).thenReturn(true) - `when`(buckets[name]).thenReturn(bucket) - `when`(bucket.objects).thenReturn(objects) - `when`(objects.contains("12345678901234561234567890123456/.workspace")).thenReturn(false) - `when`(objects.touch("12345678901234561234567890123456/.workspace")).thenReturn(derps) - - assertNotNull(S3WorkspaceFactory(client, name.name).create(hash)) - } - } - } -} \ No newline at end of file diff --git a/lib/java/src/test/kotlin/org/veupathdb/lib/s3/workspaces/util/StringKtTest.kt b/lib/java/src/test/kotlin/org/veupathdb/lib/s3/workspaces/util/StringKtTest.kt deleted file mode 100644 index 71a381a..0000000 --- a/lib/java/src/test/kotlin/org/veupathdb/lib/s3/workspaces/util/StringKtTest.kt +++ /dev/null @@ -1,154 +0,0 @@ -package org.veupathdb.lib.s3.workspaces.util - -import org.junit.jupiter.api.DisplayName -import org.junit.jupiter.api.Nested -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertThrows -import kotlin.test.assertEquals - -@DisplayName("string.kt") -class StringKtTest { - - @Nested - @DisplayName("String.extendPath(String)") - inner class ExtendPath1 { - - @Nested - @DisplayName("Returns the input string") - inner class Input { - - @Test - @DisplayName("when the receiver string is empty") - fun t1() { - assertEquals("foo", "".extendPath("foo")) - } - - @Test - @DisplayName("when the receiver string is a single '/' character") - fun t3() { - assertEquals("foo", "/".extendPath("foo")) - } - } - } - - @Nested - @DisplayName("String.extendPath(String, String)") - inner class ExtendPath2 {} - - @Nested - @DisplayName("String.toDirPath()") - inner class ToDirPath { - - @Nested - @DisplayName("Returns an empty string") - inner class Empty { - - @Test - @DisplayName("when the receiver string is empty") - fun t1() { - assertEquals("", "".toDirPath()) - } - - @Test - @DisplayName("when the receiver string is blank") - fun t2() { - assertEquals("", " ".toDirPath()) - } - - @Test - @DisplayName("when the receiver string is '/'") - fun t3() { - assertEquals("", "/".toDirPath()) - } - } - - @Nested - @DisplayName("Returns the receiver string") - inner class Same { - - @Test - @DisplayName("when the receiver string ends with a '/' character") - fun t1() { - assertEquals("foo/", "foo/".toDirPath()) - } - } - - @Nested - @DisplayName("Returns a string with the leading slash trimmed off") - inner class TrimLeft { - - @Test - @DisplayName("when the receiver string begins with a '/' character") - fun t1() { - assertEquals("foo/", "/foo".toDirPath()) - } - - @Test - @DisplayName("when the receiver string begins and ends with a '/' character") - fun t2() { - assertEquals("foo/", "/foo/".toDirPath()) - } - } - - @Nested - @DisplayName("Returns the input string with a trailing '/'") - inner class Append { - - @Test - @DisplayName("when the receiver string does not end with a '/' character") - fun t1() { - assertEquals("foo/", "foo".toDirPath()) - } - } - } - - @Nested - @DisplayName("joinPaths(String...)") - inner class JoinPaths { - - @Nested - @DisplayName("Throws IllegalArgumentException") - inner class ThrowsIAE { - - @Test - @DisplayName("when an input string is not a valid path segment") - fun t1() { - assertThrows { - joinPaths("foo", "b a r") - } - } - } - - @Nested - @DisplayName("trims out extra slashes in the input params") - inner class TrimsSlashes { - - @Test - @DisplayName("when the input strings contain leading/trailing slashes") - fun t1() { - assertEquals("foo/bar/", joinPaths("/foo/", "/bar/")) - } - - @Test - @DisplayName("when the input strings contain single '/' strings") - fun t2() { - assertEquals("foo/bar", joinPaths("/", "/foo/", "/", "/bar")) - } - - @Test - @DisplayName("when the input strings contain empty strings") - fun t3() { - assertEquals("foo/bar", joinPaths("", "/foo", "", "bar")) - } - } - - @Nested - inner class Join { - - @Test - fun t1() { - assertEquals("foo/.workspace", joinPaths("foo", ".workspace")) - } - } - } -} \ No newline at end of file diff --git a/lib/java/src/test/resources/log4j2.xml b/lib/java/src/test/resources/log4j2.xml deleted file mode 100644 index 0441ce4..0000000 --- a/lib/java/src/test/resources/log4j2.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/lib/kotlin/src/test/kotlin/org/veupathdb/lib/s3/workspaces/S3WorkspaceFactoryTest.kt b/lib/kotlin/src/test/kotlin/org/veupathdb/lib/s3/workspaces/S3WorkspaceFactoryTest.kt index c30979e..9bf70b5 100644 --- a/lib/kotlin/src/test/kotlin/org/veupathdb/lib/s3/workspaces/S3WorkspaceFactoryTest.kt +++ b/lib/kotlin/src/test/kotlin/org/veupathdb/lib/s3/workspaces/S3WorkspaceFactoryTest.kt @@ -1,5 +1,6 @@ package org.veupathdb.lib.s3.workspaces +import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test @@ -83,7 +84,7 @@ internal class S3WorkspaceFactoryTest { `when`(bucket.objects).thenReturn(objects) `when`(objects.contains("12345678901234561234567890123456/.workspace")).thenReturn(false) - assertNull(S3WorkspaceFactory(client, "hello-world")[id]) + assertNull(runBlocking { S3WorkspaceFactory(client, "hello-world").get(id) }) } } @@ -107,7 +108,7 @@ internal class S3WorkspaceFactoryTest { `when`(bucket.objects).thenReturn(objects) `when`(objects.contains("12345678901234561234567890123456/.workspace")).thenReturn(true) - assertNotNull(S3WorkspaceFactory(client, name.name)[hash]) + assertNotNull(runBlocking { S3WorkspaceFactory(client, name.name).get(hash) }) } } } @@ -138,7 +139,7 @@ internal class S3WorkspaceFactoryTest { `when`(objects.contains("12345678901234561234567890123456/.workspace")).thenReturn(true) assertThrows { - S3WorkspaceFactory(client, name.name).create(hash) + runBlocking { S3WorkspaceFactory(client, name.name).create(hash) } } } } @@ -165,7 +166,7 @@ internal class S3WorkspaceFactoryTest { `when`(objects.contains("12345678901234561234567890123456/.workspace")).thenReturn(false) `when`(objects.touch("12345678901234561234567890123456/.workspace")).thenReturn(derps) - assertNotNull(S3WorkspaceFactory(client, name.name).create(hash)) + assertNotNull(runBlocking { S3WorkspaceFactory(client, name.name).create(hash) }) } } } diff --git a/test/build.gradle.kts b/test/build.gradle.kts index 5e398a1..c090c2d 100644 --- a/test/build.gradle.kts +++ b/test/build.gradle.kts @@ -3,6 +3,10 @@ plugins { id("com.github.johnrengelman.shadow") version "7.1.2" } +kotlin { + jvmToolchain(16) +} + repositories { mavenLocal() mavenCentral() @@ -37,11 +41,6 @@ tasks.shadowJar { exclude("**/Log4j2Plugins.dat") } -java { - sourceCompatibility = JavaVersion.VERSION_16 - targetCompatibility = JavaVersion.VERSION_16 -} - tasks.test { useJUnitPlatform() } \ No newline at end of file