Skip to content

Commit

Permalink
fix#582 : Test case
Browse files Browse the repository at this point in the history
  • Loading branch information
sband committed Jun 18, 2023
1 parent 1e92222 commit d5fd21a
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
1 change: 1 addition & 0 deletions bundles/sirix-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.sirix.io.cloud.amazon;
import static org.junit.jupiter.api.Assertions.assertNotNull;

This comment has been minimized.

Copy link
@JohannesLichtenberger

JohannesLichtenberger Jun 19, 2023

Member

You're mixing JUnit 4 and 5. You can of course use 5 ;-)

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<XmlResourceSession> 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();
}


}
3 changes: 2 additions & 1 deletion libraries.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]

0 comments on commit d5fd21a

Please sign in to comment.