-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1879 from scireum/feature/smo/junit-migrate-objec…
…tstoretest Junit: Migrate objectstoretest to kotlin
- Loading branch information
Showing
2 changed files
with
114 additions
and
101 deletions.
There are no files selected for viewing
101 changes: 0 additions & 101 deletions
101
src/test/java/sirius/biz/storage/s3/ObjectStoresSpec.groovy
This file was deleted.
Oops, something went wrong.
114 changes: 114 additions & 0 deletions
114
src/test/kotlin/sirius/biz/storage/s3/ObjectStoresTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Made with all the love in the world | ||
* by scireum in Remshalden, Germany | ||
* | ||
* Copyright by scireum GmbH | ||
* http://www.scireum.de - info@scireum.de | ||
*/ | ||
|
||
package sirius.biz.storage.s3 | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import sirius.kernel.SiriusExtension | ||
import sirius.kernel.commons.Files | ||
import sirius.kernel.commons.Tuple | ||
import sirius.kernel.di.std.Part | ||
import java.io.File | ||
import java.io.FileOutputStream | ||
import java.net.URL | ||
import java.nio.file.Files as files_ | ||
import java.nio.charset.StandardCharsets | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertFalse | ||
/** | ||
* Tests the [ObjectStores]. | ||
*/ | ||
@ExtendWith(SiriusExtension::class) | ||
class ObjectStoresTest { | ||
|
||
@Test | ||
fun `create bucket works`() { | ||
val file = File.createTempFile("test", "") | ||
val fout = FileOutputStream(file) | ||
repeat(10024) { | ||
fout.write("This is a test.".toByteArray(StandardCharsets.UTF_8)) | ||
} | ||
fout.close() | ||
stores.store().upload(stores.store().getBucketName("test"), "test", file, null) | ||
val download = stores.store().download(stores.store().getBucketName("test"), "test") | ||
val expectedContents = files_.readString(file.toPath(), StandardCharsets.UTF_8) | ||
val downloadedContents = files_.readString(download.toPath(), StandardCharsets.UTF_8) | ||
assertEquals(expectedContents, downloadedContents) | ||
Files.delete(file) | ||
Files.delete(download) | ||
} | ||
|
||
@Test | ||
fun `PUT and GET works`() { | ||
val file = File.createTempFile("test", "") | ||
val fout = FileOutputStream(file) | ||
repeat(10024) { | ||
fout.write("This is a test.".toByteArray(StandardCharsets.UTF_8)) | ||
} | ||
fout.close() | ||
stores.store().upload(stores.store().getBucketName("test"), "test", file, null) | ||
val download = stores.store().download(stores.store().getBucketName("test"), "test") | ||
val c = URL( | ||
stores.store().objectUrl(stores.store().getBucketName("test"), "test") | ||
).openConnection() | ||
|
||
val expectedContents = files_.readString(file.toPath(), StandardCharsets.UTF_8) | ||
val downloadedContents = files_.readString(download.toPath(), StandardCharsets.UTF_8) | ||
val downloadedData = String(c.getInputStream().readAllBytes(), StandardCharsets.UTF_8) | ||
|
||
assertEquals(expectedContents, downloadedData) | ||
assertEquals(expectedContents, downloadedContents) | ||
Files.delete(file) | ||
Files.delete(download) | ||
} | ||
|
||
@Test | ||
fun `ensure bucket exists`() { | ||
stores.store().ensureBucketExists(stores.store().getBucketName("exists")) | ||
stores.store().doesBucketExist(stores.store().getBucketName("exists")) | ||
stores.bucketCache.get( | ||
Tuple.create( | ||
stores.store().name, | ||
stores.store().getBucketName("exists").getName() | ||
) | ||
) | ||
!stores.store().doesBucketExist(stores.store().getBucketName("not-exists")) | ||
assertEquals( | ||
null, stores.bucketCache.get( | ||
Tuple.create( | ||
stores.store().name, | ||
stores.store().getBucketName("not-exists").getName() | ||
) | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun `delete Bucket works`() { | ||
stores.store().ensureBucketExists(stores.store().getBucketName("deleted")) | ||
stores.store().doesBucketExist(stores.store().getBucketName("deleted")) | ||
stores.store().deleteBucket(stores.store().getBucketName("deleted")) | ||
assertFalse { stores.store().doesBucketExist(stores.store().getBucketName("deleted")) } | ||
assertEquals( | ||
null, stores.bucketCache.get( | ||
Tuple.create( | ||
stores.store().name, | ||
stores.store().getBucketName("deleted").getName() | ||
) | ||
) | ||
) | ||
} | ||
|
||
companion object { | ||
@Part | ||
@JvmStatic | ||
private lateinit var stores: ObjectStores | ||
|
||
} | ||
} |