Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

package software.amazon.lambda.powertools.parameters.appconfig;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import software.amazon.awssdk.core.SdkBytes;
import software.amazon.awssdk.services.appconfigdata.AppConfigDataClient;
Expand Down Expand Up @@ -46,7 +46,7 @@ public class AppConfigProvider extends BaseProvider {
private final AppConfigDataClient client;
private final String application;
private final String environment;
private final Map<String, EstablishedSession> establishedSessions = new HashMap<>();
private final Map<String, EstablishedSession> establishedSessions = new ConcurrentHashMap<>();

AppConfigProvider(CacheManager cacheManager, TransformationManager transformationManager,
AppConfigDataClient client, String environment, String application) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

public class AppConfigParamAspectTest {
class AppConfigParamAspectTest {

@Test
public void parameterInjectedByProvider() throws Exception {
void parameterInjectedByProvider() throws Exception {
// Setup our aspect to return a mocked AppConfigProvider
String environment = "myEnvironment";
String appName = "myApp";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

public class DynamoDbParamAspectTest {
class DynamoDbParamAspectTest {

@Test
public void parameterInjectedByProvider() throws Exception {
void parameterInjectedByProvider() throws Exception {
// Setup our aspect to return a mocked DynamoDbProvider
String tableName = "my-test-tablename";
String key = "myKey";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
* will move this across.
*/
@Disabled
public class DynamoDbProviderE2ETest {
class DynamoDbProviderE2ETest {

final String ParamsTestTable = "ddb-params-test";
final String MultiparamsTestTable = "ddb-multiparams-test";
private static final String PARAMS_TEST_TABLE = "ddb-params-test";
private static final String MULTI_PARAMS_TEST_TABLE = "ddb-multiparams-test";
private final DynamoDbClient ddbClient;

public DynamoDbProviderE2ETest() {
Expand All @@ -52,49 +52,49 @@ public DynamoDbProviderE2ETest() {
}

@Test
public void TestGetValue() {
void TestGetValue() {

// Arrange
HashMap<String, AttributeValue> testItem = new HashMap<String, AttributeValue>();
Map<String, AttributeValue> testItem = new HashMap<>();
testItem.put("id", AttributeValue.fromS("test_param"));
testItem.put("value", AttributeValue.fromS("the_value_is_hello!"));
ddbClient.putItem(PutItemRequest.builder()
.tableName(ParamsTestTable)
.tableName(PARAMS_TEST_TABLE)
.item(testItem)
.build());

// Act
DynamoDbProvider provider = makeProvider(ParamsTestTable);
DynamoDbProvider provider = makeProvider(PARAMS_TEST_TABLE);
String value = provider.getValue("test_param");

// Assert
assertThat(value).isEqualTo("the_value_is_hello!");
}

@Test
public void TestGetValues() {
void TestGetValues() {

// Arrange
HashMap<String, AttributeValue> testItem = new HashMap<String, AttributeValue>();
Map<String, AttributeValue> testItem = new HashMap<>();
testItem.put("id", AttributeValue.fromS("test_param"));
testItem.put("sk", AttributeValue.fromS("test_param_part_1"));
testItem.put("value", AttributeValue.fromS("the_value_is_hello!"));
ddbClient.putItem(PutItemRequest.builder()
.tableName(MultiparamsTestTable)
.tableName(MULTI_PARAMS_TEST_TABLE)
.item(testItem)
.build());

HashMap<String, AttributeValue> testItem2 = new HashMap<String, AttributeValue>();
Map<String, AttributeValue> testItem2 = new HashMap<>();
testItem2.put("id", AttributeValue.fromS("test_param"));
testItem2.put("sk", AttributeValue.fromS("test_param_part_2"));
testItem2.put("value", AttributeValue.fromS("the_value_is_still_hello!"));
ddbClient.putItem(PutItemRequest.builder()
.tableName(MultiparamsTestTable)
.tableName(MULTI_PARAMS_TEST_TABLE)
.item(testItem2)
.build());

// Act
DynamoDbProvider provider = makeProvider(MultiparamsTestTable);
DynamoDbProvider provider = makeProvider(MULTI_PARAMS_TEST_TABLE);
Map<String, String> values = provider.getMultipleValues("test_param");

// Assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
import software.amazon.lambda.powertools.parameters.transform.TransformationManager;

@ExtendWith(MockitoExtension.class)
public class DynamoDbProviderTest {
class DynamoDbProviderTest {

private final String tableName = "ddb-test-table";
private static final String TABLE_NAME = "ddb-test-table";

@Mock
DynamoDbClient client;
Expand All @@ -64,19 +64,19 @@ public class DynamoDbProviderTest {
private DynamoDbProvider provider;

@BeforeEach
public void init() {
void init() {
openMocks(this);
CacheManager cacheManager = new CacheManager();
provider = new DynamoDbProvider(cacheManager, transformationManager, client, tableName);
provider = new DynamoDbProvider(cacheManager, transformationManager, client, TABLE_NAME);
}

@Test
public void getValue() {
void getValue() {

// Arrange
String key = "Key1";
String expectedValue = "Value1";
HashMap<String, AttributeValue> responseData = new HashMap<String, AttributeValue>();
Map<String, AttributeValue> responseData = new HashMap<>();
responseData.put("id", AttributeValue.fromS(key));
responseData.put("value", AttributeValue.fromS(expectedValue));
GetItemResponse response = GetItemResponse.builder()
Expand All @@ -89,12 +89,12 @@ public void getValue() {

// Assert
assertThat(value).isEqualTo(expectedValue);
assertThat(getItemValueCaptor.getValue().tableName()).isEqualTo(tableName);
assertThat(getItemValueCaptor.getValue().tableName()).isEqualTo(TABLE_NAME);
assertThat(getItemValueCaptor.getValue().key().get("id").s()).isEqualTo(key);
}

@Test
public void getValueWithNullResultsReturnsNull() {
void getValueWithNullResultsReturnsNull() {
// Arrange
Mockito.when(client.getItem(getItemValueCaptor.capture())).thenReturn(GetItemResponse.builder()
.item(null)
Expand All @@ -108,7 +108,7 @@ public void getValueWithNullResultsReturnsNull() {
}

@Test
public void getValueWithoutResultsReturnsNull() {
void getValueWithoutResultsReturnsNull() {
// Arrange
Mockito.when(client.getItem(getItemValueCaptor.capture())).thenReturn(GetItemResponse.builder()
.item(new HashMap<>())
Expand All @@ -122,10 +122,10 @@ public void getValueWithoutResultsReturnsNull() {
}

@Test
public void getValueWithMalformedRowThrows() {
void getValueWithMalformedRowThrows() {
// Arrange
String key = "Key1";
HashMap<String, AttributeValue> responseData = new HashMap<String, AttributeValue>();
Map<String, AttributeValue> responseData = new HashMap<>();
responseData.put("id", AttributeValue.fromS(key));
responseData.put("not-value", AttributeValue.fromS("something"));
Mockito.when(client.getItem(getItemValueCaptor.capture())).thenReturn(GetItemResponse.builder()
Expand All @@ -138,19 +138,19 @@ public void getValueWithMalformedRowThrows() {
}

@Test
public void getValues() {
void getValues() {

// Arrange
String key = "Key1";
String subkey1 = "Subkey1";
String val1 = "Val1";
String subkey2 = "Subkey2";
String val2 = "Val2";
HashMap<String, AttributeValue> item1 = new HashMap<String, AttributeValue>();
Map<String, AttributeValue> item1 = new HashMap<>();
item1.put("id", AttributeValue.fromS(key));
item1.put("sk", AttributeValue.fromS(subkey1));
item1.put("value", AttributeValue.fromS(val1));
HashMap<String, AttributeValue> item2 = new HashMap<String, AttributeValue>();
Map<String, AttributeValue> item2 = new HashMap<>();
item2.put("id", AttributeValue.fromS(key));
item2.put("sk", AttributeValue.fromS(subkey2));
item2.put("value", AttributeValue.fromS(val2));
Expand All @@ -166,13 +166,13 @@ public void getValues() {
assertThat(values.size()).isEqualTo(2);
assertThat(values.get(subkey1)).isEqualTo(val1);
assertThat(values.get(subkey2)).isEqualTo(val2);
assertThat(queryRequestCaptor.getValue().tableName()).isEqualTo(tableName);
assertThat(queryRequestCaptor.getValue().tableName()).isEqualTo(TABLE_NAME);
assertThat(queryRequestCaptor.getValue().keyConditionExpression()).isEqualTo("id = :v_id");
assertThat(queryRequestCaptor.getValue().expressionAttributeValues().get(":v_id").s()).isEqualTo(key);
}

@Test
public void getValuesWithoutResultsReturnsNull() {
void getValuesWithoutResultsReturnsNull() {
// Arrange
Mockito.when(client.query(queryRequestCaptor.capture())).thenReturn(
QueryResponse.builder().items().build());
Expand All @@ -185,10 +185,10 @@ public void getValuesWithoutResultsReturnsNull() {
}

@Test
public void getMultipleValuesMissingSortKey_throwsException() {
void getMultipleValuesMissingSortKey_throwsException() {
// Arrange
String key = "Key1";
HashMap<String, AttributeValue> item = new HashMap<String, AttributeValue>();
Map<String, AttributeValue> item = new HashMap<>();
item.put("id", AttributeValue.fromS(key));
item.put("value", AttributeValue.fromS("somevalue"));
QueryResponse response = QueryResponse.builder()
Expand All @@ -204,10 +204,10 @@ public void getMultipleValuesMissingSortKey_throwsException() {
}

@Test
public void getValuesWithMalformedRowThrows() {
void getValuesWithMalformedRowThrows() {
// Arrange
String key = "Key1";
HashMap<String, AttributeValue> item1 = new HashMap<String, AttributeValue>();
Map<String, AttributeValue> item1 = new HashMap<>();
item1.put("id", AttributeValue.fromS(key));
item1.put("sk", AttributeValue.fromS("some-subkey"));
item1.put("not-value", AttributeValue.fromS("somevalue"));
Expand All @@ -224,7 +224,7 @@ public void getValuesWithMalformedRowThrows() {
}

@Test
public void testDynamoDBBuilderMissingTable_throwsException() {
void testDynamoDBBuilderMissingTable_throwsException() {

// Act & Assert
assertThatIllegalStateException().isThrownBy(() -> DynamoDbProvider.builder()
Expand All @@ -233,7 +233,7 @@ public void testDynamoDBBuilderMissingTable_throwsException() {
}

@Test
public void testDynamoDBBuilder_withoutParameter_shouldHaveDefaultTransformationManager() {
void testDynamoDBBuilder_withoutParameter_shouldHaveDefaultTransformationManager() {

// Act
DynamoDbProvider dynamoDbProvider = DynamoDbProvider.builder().withTable("test-table")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

public class SecretsParamAspectTest {
class SecretsParamAspectTest {

@Test
public void parameterInjectedByProvider() throws Exception {
void parameterInjectedByProvider() throws Exception {
// Setup our aspect to return a mocked SecretsProvider
String key = "myKey";
String value = "mySecretValue";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import software.amazon.lambda.powertools.parameters.transform.TransformationManager;

@ExtendWith(MockitoExtension.class)
public class SecretsProviderTest {
class SecretsProviderTest {

@Mock
SecretsManagerClient client;
Expand All @@ -56,13 +56,13 @@ public class SecretsProviderTest {
SecretsProvider provider;

@BeforeEach
public void init() {
void init() {
cacheManager = new CacheManager();
provider = new SecretsProvider(cacheManager, transformationManager, client);
}

@Test
public void getValue() {
void getValue() {
String key = "Key1";
String expectedValue = "Value1";
GetSecretValueResponse response = GetSecretValueResponse.builder().secretString(expectedValue).build();
Expand All @@ -76,7 +76,7 @@ public void getValue() {
}

@Test
public void getValueBase64() {
void getValueBase64() {
String key = "Key2";
String expectedValue = "Value2";
byte[] valueb64 = Base64.getEncoder().encode(expectedValue.getBytes());
Expand All @@ -91,14 +91,14 @@ public void getValueBase64() {
}

@Test
public void getMultipleValuesThrowsException() {
void getMultipleValuesThrowsException() {
// Act & Assert
assertThatRuntimeException().isThrownBy(() -> provider.getMultipleValues("path"))
.withMessage("Impossible to get multiple values from AWS Secrets Manager");
}

@Test
public void testGetSecretsProvider_withoutParameter_shouldCreateDefaultClient() {
void testGetSecretsProvider_withoutParameter_shouldCreateDefaultClient() {
// Act
SecretsProvider secretsProvider = SecretsProvider.builder()
.build();
Expand All @@ -109,7 +109,7 @@ public void testGetSecretsProvider_withoutParameter_shouldCreateDefaultClient()
}

@Test
public void testGetSecretsProvider_withoutParameter_shouldHaveDefaultTransformationManager() {
void testGetSecretsProvider_withoutParameter_shouldHaveDefaultTransformationManager() {
// Act
SecretsProvider secretsProvider = SecretsProvider.builder()
.build();
Expand Down
Loading
Loading