From d5fd21a8191cb8c53fc13b6f4d0e2c32ed615b5d Mon Sep 17 00:00:00 2001 From: sband Date: Sun, 18 Jun 2023 17:41:43 +0530 Subject: [PATCH] fix#582 : Test case --- bundles/sirix-core/build.gradle | 1 + .../io/cloud/amazon/AWSS3StorageTest.java | 76 +++++++++++++++++++ libraries.gradle | 3 +- 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 bundles/sirix-core/src/test/java/org/sirix/io/cloud/amazon/AWSS3StorageTest.java diff --git a/bundles/sirix-core/build.gradle b/bundles/sirix-core/build.gradle index 816e04fa2..6ccbd7afa 100644 --- a/bundles/sirix-core/build.gradle +++ b/bundles/sirix-core/build.gradle @@ -43,6 +43,7 @@ dependencies { testImplementation testLibraries.commonsCollections4 testImplementation testLibraries.commonsCollections4Tests testImplementation testLibraries.assertjCore + testImplementation testLibraries.s3Mock } description = 'SirixDB is a hybrid on-disk and in-memory document oriented, versioned database system. It has a ' + diff --git a/bundles/sirix-core/src/test/java/org/sirix/io/cloud/amazon/AWSS3StorageTest.java b/bundles/sirix-core/src/test/java/org/sirix/io/cloud/amazon/AWSS3StorageTest.java new file mode 100644 index 000000000..811774895 --- /dev/null +++ b/bundles/sirix-core/src/test/java/org/sirix/io/cloud/amazon/AWSS3StorageTest.java @@ -0,0 +1,76 @@ +package org.sirix.io.cloud.amazon; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.net.URI; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.sirix.XmlTestHelper; +import org.sirix.XmlTestHelper.PATHS; +import org.sirix.access.ResourceConfiguration; +import org.sirix.api.Database; +import org.sirix.api.xml.XmlResourceSession; +import org.sirix.io.StorageType; + +import io.findify.s3mock.S3Mock; +import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.s3.S3Client; + +public class AWSS3StorageTest { + + private AmazonS3Storage awsStorage; + private S3Client s3Client; + private AmazonS3StorageWriter cloudWriter; + private AmazonS3StorageReader cloudReader; + + @Before + public void setup() { + final ResourceConfiguration.Builder resourceConfig = new ResourceConfiguration.Builder(XmlTestHelper.RESOURCE); + resourceConfig.storageType(StorageType.CLOUD); + Database xmlDatabase = XmlTestHelper.getDatabase(PATHS.PATH1.getFile()); + resourceConfig.awsStoreInfo(new ResourceConfiguration.AWSStorageInformation("default", + Region.US_EAST_1.id(), xmlDatabase.getName(), true)); + ResourceConfiguration testResources = resourceConfig.build(); + S3Mock api = S3Mock.create(8001, "."); + api.start(); + s3Client = S3Client.builder().region(Region.of(testResources.awsStoreInfo.getAwsRegion())) + .credentialsProvider(AnonymousCredentialsProvider.create()) + .dualstackEnabled(true) + .endpointOverride(URI.create("http://127.0.0.1:8001")) + .build(); + testResources.resourcePath = PATHS.PATH1.getFile(); + + awsStorage = (AmazonS3Storage)StorageType.CLOUD.getInstance(testResources); + awsStorage.setS3Client(s3Client); + cloudWriter = (AmazonS3StorageWriter)awsStorage.createWriter(); + cloudReader = (AmazonS3StorageReader)awsStorage.createReader(); + } + + @Test + public void testS3StorageWriterNotNull() { + assertNotNull(cloudWriter); + } + + @Test + public void testS3StorageReaderNotNull() { + assertNotNull(cloudReader); + } + + @Test + public void testCreateBucket() { + awsStorage.createBucket(); + assertTrue(awsStorage.isBucketExists()); + } + + + @After + public void tearDown() { + XmlTestHelper.deleteEverything(); + s3Client.close(); + } + + +} \ No newline at end of file diff --git a/libraries.gradle b/libraries.gradle index f7b8d66ec..9cad91620 100644 --- a/libraries.gradle +++ b/libraries.gradle @@ -67,5 +67,6 @@ testLibraries = [ kotestAssertions : 'io.kotest:kotest-assertions-core-jvm:4.0.5', commonsCollections4 : 'org.apache.commons:commons-collections4:4.3', commonsCollections4Tests : 'org.apache.commons:commons-collections4:4.3:tests', - assertjCore : 'org.assertj:assertj-core:3.23.1' + assertjCore : 'org.assertj:assertj-core:3.23.1', + s3Mock : 'io.findify:s3mock_2.13:0.2.6' ]