|
14 | 14 |
|
15 | 15 | package software.amazon.lambda.powertools.parameters; |
16 | 16 |
|
17 | | -import static org.assertj.core.api.Assertions.assertThat; |
18 | | -import static org.assertj.core.api.Assertions.assertThatIllegalStateException; |
19 | | -import static org.assertj.core.api.Assertions.assertThatRuntimeException; |
20 | | -import static org.mockito.MockitoAnnotations.openMocks; |
21 | | - |
22 | 17 | import org.junit.jupiter.api.BeforeEach; |
23 | 18 | import org.junit.jupiter.api.Test; |
24 | 19 | import org.mockito.ArgumentCaptor; |
|
34 | 29 | import software.amazon.lambda.powertools.parameters.cache.CacheManager; |
35 | 30 | import software.amazon.lambda.powertools.parameters.transform.TransformationManager; |
36 | 31 |
|
| 32 | +import static org.assertj.core.api.Assertions.assertThat; |
| 33 | +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; |
| 34 | +import static org.assertj.core.api.Assertions.assertThatRuntimeException; |
| 35 | +import static org.mockito.MockitoAnnotations.openMocks; |
| 36 | + |
37 | 37 | public class AppConfigProviderTest { |
38 | 38 |
|
39 | 39 | private final String environmentName = "test"; |
@@ -90,21 +90,29 @@ public void getValueRetrievesValue() { |
90 | 90 | GetLatestConfigurationResponse thirdResponse = GetLatestConfigurationResponse.builder() |
91 | 91 | .nextPollConfigurationToken("token4") |
92 | 92 | .build(); |
| 93 | + // Forth response returns empty, which means the provider should yield the previous value again |
| 94 | + GetLatestConfigurationResponse forthResponse = GetLatestConfigurationResponse.builder() |
| 95 | + .nextPollConfigurationToken("token5") |
| 96 | + .configuration(SdkBytes.fromUtf8String("")) |
| 97 | + .build(); |
93 | 98 | Mockito.when(client.startConfigurationSession(startSessionRequestCaptor.capture())) |
94 | 99 | .thenReturn(firstSession); |
95 | 100 | Mockito.when(client.getLatestConfiguration(getLatestConfigurationRequestCaptor.capture())) |
96 | | - .thenReturn(firstResponse, secondResponse, thirdResponse); |
| 101 | + .thenReturn(firstResponse, secondResponse, thirdResponse, forthResponse); |
97 | 102 |
|
98 | 103 | // Act |
99 | 104 | String returnedValue1 = provider.getValue(defaultTestKey); |
100 | 105 | String returnedValue2 = provider.getValue(defaultTestKey); |
101 | 106 | String returnedValue3 = provider.getValue(defaultTestKey); |
| 107 | + String returnedValue4 = provider.getValue(defaultTestKey); |
102 | 108 |
|
103 | 109 | // Assert |
104 | 110 | assertThat(returnedValue1).isEqualTo(firstResponse.configuration().asUtf8String()); |
105 | 111 | assertThat(returnedValue2).isEqualTo(secondResponse.configuration().asUtf8String()); |
106 | 112 | assertThat(returnedValue3).isEqualTo(secondResponse.configuration() |
107 | 113 | .asUtf8String()); // Third response is mocked to return null and should re-use previous value |
| 114 | + assertThat(returnedValue4).isEqualTo(secondResponse.configuration() |
| 115 | + .asUtf8String()); // Forth response is mocked to return empty and should re-use previous value |
108 | 116 | assertThat(startSessionRequestCaptor.getValue().applicationIdentifier()).isEqualTo(applicationName); |
109 | 117 | assertThat(startSessionRequestCaptor.getValue().environmentIdentifier()).isEqualTo(environmentName); |
110 | 118 | assertThat(startSessionRequestCaptor.getValue().configurationProfileIdentifier()).isEqualTo(defaultTestKey); |
|
0 commit comments