Skip to content

Commit

Permalink
test: fix test execution with amazon/dynamodb-local:latest
Browse files Browse the repository at this point in the history
Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
  • Loading branch information
dearrudam committed Mar 12, 2024
1 parent cd7aea6 commit 8a7bc57
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

@EnabledIfSystemProperty(named = NAMED, matches = MATCHES)
public class DynamoDBKeyValueEntityManagerTest {
class DynamoDBKeyValueEntityManagerTest {

private BucketManager keyValueEntityManager;

Expand All @@ -53,30 +53,30 @@ public class DynamoDBKeyValueEntityManagerTest {
private KeyValueEntity keyValueSoro = KeyValueEntity.of("soro", Value.of(userSoro));

@BeforeEach
public void init() {
keyValueEntityManagerFactory = DynamoDBTestUtils.INSTANCE.get();
void init() {
keyValueEntityManagerFactory = DynamoDBTestUtils.INSTANCE.getBucketManagerFactory();
keyValueEntityManager = keyValueEntityManagerFactory.apply("users-entity");
}


@Test
public void shouldPutValue() {
void shouldPutValue() {
keyValueEntityManager.put("otavio", userOtavio);
Optional<Value> otavio = keyValueEntityManager.get("otavio");
assertTrue(otavio.isPresent());
assertEquals(userOtavio, otavio.get().get(User.class));
}

@Test
public void shouldPutKeyValue() {
void shouldPutKeyValue() {
keyValueEntityManager.put(keyValueOtavio);
Optional<Value> otavio = keyValueEntityManager.get("otavio");
assertTrue(otavio.isPresent());
assertEquals(userOtavio, otavio.get().get(User.class));
}

@Test
public void shouldPutIterableKeyValue() {
void shouldPutIterableKeyValue() {

keyValueEntityManager.put(asList(keyValueSoro, keyValueOtavio));
Optional<Value> otavio = keyValueEntityManager.get("otavio");
Expand All @@ -89,23 +89,23 @@ public void shouldPutIterableKeyValue() {
}

@Test
public void shouldMultiGet() {
void shouldMultiGet() {
User user = new User("otavio");
KeyValueEntity keyValue = KeyValueEntity.of("otavio", Value.of(user));
keyValueEntityManager.put(keyValue);
assertNotNull(keyValueEntityManager.get("otavio"));
}

@Test
public void shouldRemoveKey() {
void shouldRemoveKey() {
keyValueEntityManager.put(keyValueOtavio);
assertTrue(keyValueEntityManager.get("otavio").isPresent());
keyValueEntityManager.delete("otavio");
assertFalse(keyValueEntityManager.get("otavio").isPresent());
}

@Test
public void shouldRemoveMultiKey() {
void shouldRemoveMultiKey() {
keyValueEntityManager.put(asList(keyValueSoro, keyValueOtavio));
List<String> keys = asList("otavio", "soro");
Iterable<Value> values = keyValueEntityManager.get(keys);
Expand All @@ -117,7 +117,7 @@ public void shouldRemoveMultiKey() {
}

@AfterAll
public static void shutDown() {
static void shutDown() {
DynamoDBTestUtils.INSTANCE.shutDown();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;

import java.util.function.Supplier;

public enum DynamoDBTestUtils implements Supplier<BucketManagerFactory> {
enum DynamoDBTestUtils {

INSTANCE;

Expand All @@ -30,15 +28,22 @@ public enum DynamoDBTestUtils implements Supplier<BucketManagerFactory> {
.withExposedPorts(8000)
.waitingFor(Wait.defaultWaitStrategy());

public BucketManagerFactory get() {
dynamodb.start();
BucketManagerFactory getBucketManagerFactory() {
Settings settings = getSettings();
DynamoDBKeyValueConfiguration configuration = new DynamoDBKeyValueConfiguration();
String endpoint = "http://" + dynamodb.getHost() + ":" + dynamodb.getFirstMappedPort();
return configuration.apply(Settings.builder()
.put(DynamoDBConfigurations.ENDPOINT, endpoint).build());
return configuration.apply(settings);
}

Settings getSettings() {
dynamodb.start();
return Settings.builder()
.put(DynamoDBConfigurations.ENDPOINT, "http://" + dynamodb.getHost() + ":" + dynamodb.getFirstMappedPort())
.put(DynamoDBConfigurations.AWS_ACCESSKEY, System.getProperty("AWS_ACCESS_KEY_ID","DUMMYIDEXAMPLE"))
.put(DynamoDBConfigurations.AWS_SECRET_ACCESS, System.getProperty("AWS_SECRET_ACCESS_KEY","DUMMYEXAMPLEKEY"))
.put(DynamoDBConfigurations.REGION, "us-west-2").build();
}

public void shutDown() {
void shutDown() {
dynamodb.close();
}
}

0 comments on commit 8a7bc57

Please sign in to comment.