|
| 1 | +package software.amazon.lambda.powertools; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 4 | +import org.junit.jupiter.api.*; |
| 5 | +import software.amazon.lambda.powertools.testutils.AppConfig; |
| 6 | +import software.amazon.lambda.powertools.testutils.Infrastructure; |
| 7 | +import software.amazon.lambda.powertools.testutils.lambda.InvocationResult; |
| 8 | + |
| 9 | +import java.util.HashMap; |
| 10 | +import java.util.Map; |
| 11 | +import java.util.concurrent.TimeUnit; |
| 12 | +import java.util.stream.Collectors; |
| 13 | +import java.util.stream.Stream; |
| 14 | + |
| 15 | +import static org.assertj.core.api.Assertions.assertThat; |
| 16 | +import static software.amazon.lambda.powertools.testutils.lambda.LambdaInvoker.invokeFunction; |
| 17 | + |
| 18 | +@TestInstance(TestInstance.Lifecycle.PER_CLASS) |
| 19 | +public class ParametersE2ET { |
| 20 | + |
| 21 | + |
| 22 | + private final ObjectMapper objectMapper = new ObjectMapper(); |
| 23 | + |
| 24 | + private Infrastructure infrastructure; |
| 25 | + private String functionName; |
| 26 | + private final AppConfig appConfig; |
| 27 | + |
| 28 | + public ParametersE2ET() { |
| 29 | + Map<String,String> params = new HashMap<>(); |
| 30 | + params.put("key1", "value1"); |
| 31 | + params.put("key2", "value2"); |
| 32 | + appConfig = new AppConfig("e2eApp", "e2etest", params); |
| 33 | + } |
| 34 | + @BeforeAll |
| 35 | + @Timeout(value = 5, unit = TimeUnit.MINUTES) |
| 36 | + public void setup() { |
| 37 | + infrastructure = Infrastructure.builder() |
| 38 | + .testName(ParametersE2ET.class.getSimpleName()) |
| 39 | + .pathToFunction("parameters") |
| 40 | + .appConfig(appConfig) |
| 41 | + .environmentVariables( |
| 42 | + Stream.of(new String[][]{ |
| 43 | + {"POWERTOOLS_LOG_LEVEL", "INFO"}, |
| 44 | + {"POWERTOOLS_SERVICE_NAME", ParametersE2ET.class.getSimpleName()} |
| 45 | + }) |
| 46 | + .collect(Collectors.toMap(data -> data[0], data -> data[1]))) |
| 47 | + .build(); |
| 48 | + functionName = infrastructure.deploy(); |
| 49 | + } |
| 50 | + |
| 51 | + @AfterAll |
| 52 | + public void tearDown() { |
| 53 | + if (infrastructure != null) |
| 54 | + infrastructure.destroy(); |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + public void test_getAppConfigValue() { |
| 59 | + for (Map.Entry<String, String >configKey: appConfig.getConfigurationValues().entrySet()) { |
| 60 | + |
| 61 | + // Arrange |
| 62 | + String event1 = "{" + |
| 63 | + "\"app\": \"" + appConfig.getApplication() + "\", " + |
| 64 | + "\"environment\": \"" + appConfig.getEnvironment() + "\", " + |
| 65 | + "\"key\": \"" + configKey.getKey() + "\"" + |
| 66 | + "}"; |
| 67 | + |
| 68 | + // Act |
| 69 | + InvocationResult invocationResult = invokeFunction(functionName, event1); |
| 70 | + |
| 71 | + // Assert |
| 72 | + assertThat(invocationResult.getResult()).isEqualTo("\"" + configKey.getValue() + "\""); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | +} |
0 commit comments