Search in sources :

Example 1 with GetParametersByPathResponse

use of software.amazon.awssdk.services.ssm.model.GetParametersByPathResponse in project athenz by yahoo.

the class ConfigProviderAwsParametersStoreTest method testConfigProviderAwsParametersStore.

@Test
public void testConfigProviderAwsParametersStore() {
    ConfigProviderAwsParametersStore provider = new ConfigProviderAwsParametersStore() {

        @Override
        protected SsmClient buildSsmClient() {
            SsmClient mockSsmClient = Mockito.mock(SsmClient.class);
            Mockito.when(mockSsmClient.getParametersByPath(Mockito.any(GetParametersByPathRequest.class))).thenAnswer(invocation -> {
                GetParametersByPathRequest request = invocation.getArgument(0);
                assertEquals(request.path(), "/test/prefix");
                assertTrue(request.recursive());
                // Mock 3 response pages.
                GetParametersByPathResponse response = Mockito.mock(GetParametersByPathResponse.class);
                String nextToken = request.nextToken();
                if (nextToken == null) {
                    Mockito.when(response.parameters()).thenAnswer(invocation2 -> Arrays.asList(buildParameter("/test/prefix/01", "value-01"), buildParameter("02", "value-02")));
                    Mockito.when(response.nextToken()).thenReturn("A");
                } else if (nextToken.equals("A")) {
                    Mockito.when(response.parameters()).thenAnswer(invocation2 -> Arrays.asList(buildParameter("/test/prefix/11", "value-11"), buildParameter("12", "value-12")));
                    Mockito.when(response.nextToken()).thenReturn("B");
                } else if (nextToken.equals("B")) {
                    Mockito.when(response.parameters()).thenAnswer(invocation2 -> Arrays.asList(buildParameter("/test/prefix/21", "value-21"), buildParameter("22", "value-22")));
                    Mockito.when(response.nextToken()).thenReturn(null);
                } else {
                    fail("Unexpected nextToken()");
                }
                return response;
            });
            return mockSsmClient;
        }
    };
    assertNull(provider.tryToBuildConfigSource("non-relevant"));
    ConfigProviderAwsParametersStore.ConfigSourceAwsParametersStore source = provider.tryToBuildConfigSource("aws-param-store://test/prefix");
    assertNotNull(source);
    assertEquals(source.toString(), "AWS-Parameters-Store path \"/test/prefix\"");
    assertEquals(source.path, "/test/prefix");
    assertEquals(source.parameterNamesRedundantPrefix, "/test/prefix/");
    Map<String, String> unsortedEntries = source.getConfigEntries().stream().collect(Collectors.toMap(entry -> entry.key, entry -> entry.value));
    Map<String, String> sortedEntries = new TreeMap<>(unsortedEntries);
    assertEquals("{\"01\":\"value-01\",\"02\":\"value-02\",\"11\":\"value-11\",\"12\":\"value-12\",\"21\":\"value-21\",\"22\":\"value-22\"}", Utils.jsonSerializeForLog(sortedEntries));
}
Also used : GetParametersByPathRequest(software.amazon.awssdk.services.ssm.model.GetParametersByPathRequest) Mockito(org.mockito.Mockito) GetParametersByPathResponse(software.amazon.awssdk.services.ssm.model.GetParametersByPathResponse) Arrays(java.util.Arrays) TreeMap(java.util.TreeMap) Assert(org.testng.Assert) SsmClient(software.amazon.awssdk.services.ssm.SsmClient) Map(java.util.Map) Test(org.testng.annotations.Test) Parameter(software.amazon.awssdk.services.ssm.model.Parameter) Collectors(java.util.stream.Collectors) Utils(com.yahoo.athenz.common.server.util.Utils) GetParametersByPathResponse(software.amazon.awssdk.services.ssm.model.GetParametersByPathResponse) GetParametersByPathRequest(software.amazon.awssdk.services.ssm.model.GetParametersByPathRequest) TreeMap(java.util.TreeMap) SsmClient(software.amazon.awssdk.services.ssm.SsmClient) Test(org.testng.annotations.Test)

Aggregations

Utils (com.yahoo.athenz.common.server.util.Utils)1 Arrays (java.util.Arrays)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Collectors (java.util.stream.Collectors)1 Mockito (org.mockito.Mockito)1 Assert (org.testng.Assert)1 Test (org.testng.annotations.Test)1 SsmClient (software.amazon.awssdk.services.ssm.SsmClient)1 GetParametersByPathRequest (software.amazon.awssdk.services.ssm.model.GetParametersByPathRequest)1 GetParametersByPathResponse (software.amazon.awssdk.services.ssm.model.GetParametersByPathResponse)1 Parameter (software.amazon.awssdk.services.ssm.model.Parameter)1