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