From 9c8cdecefea0fd2e260c777947bb880d12c77071 Mon Sep 17 00:00:00 2001 From: Scott Leberknight <174812+sleberknight@users.noreply.github.com> Date: Fri, 18 Aug 2023 11:53:44 -0400 Subject: [PATCH] Add tests in KeyValueClientITest for getting nested keys (#267) e.g. a key named resources/refdata Closes #266 --- .../consul/KeyValueClientITest.java | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/itest/java/org/kiwiproject/consul/KeyValueClientITest.java b/src/itest/java/org/kiwiproject/consul/KeyValueClientITest.java index 0efecc4..b42d362 100644 --- a/src/itest/java/org/kiwiproject/consul/KeyValueClientITest.java +++ b/src/itest/java/org/kiwiproject/consul/KeyValueClientITest.java @@ -1,6 +1,8 @@ package org.kiwiproject.consul; +import static java.util.stream.Collectors.toMap; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; import static org.kiwiproject.consul.TestUtils.randomUUIDString; import org.apache.commons.codec.binary.Base64; @@ -173,6 +175,48 @@ void shouldPutAndReceiveStringsWithAnotherCharset() { assertThat(new HashSet<>(keyValueClient.getValuesAsString(key, TEST_CHARSET))).isEqualTo(Set.of(value, value2)); } + @Test + void shouldGetNestedValue() { + var topLevelKey = "folder-" + randomUUIDString(); + var childKey = "child-" + randomUUIDString(); + var key = topLevelKey + "/" + childKey; + var value = randomUUIDString(); + + assertThat(keyValueClient.putValue(key, value)).isTrue(); + var receivedValue = keyValueClient.getValue(key).orElseThrow(); + assertThat(receivedValue.getValueAsString()).contains(value); + } + + @Test + void shouldGetNestedValues() { + var topLevelKey = "folder-" + randomUUIDString(); + + var childKey1 = "child-" + randomUUIDString(); + var key1 = topLevelKey + "/" + childKey1; + var value1 = randomUUIDString(); + assertThat(keyValueClient.putValue(key1, value1)).isTrue(); + + var childKey2 = "child-" + randomUUIDString(); + var key2 = topLevelKey + "/" + childKey2; + var value2 = randomUUIDString(); + assertThat(keyValueClient.putValue(key2, value2)).isTrue(); + + var childKey3 = "child-" + randomUUIDString(); + var key3 = topLevelKey + "/" + childKey3; + var value3 = randomUUIDString(); + assertThat(keyValueClient.putValue(key3, value3)).isTrue(); + + var valuesMap = keyValueClient.getValues(topLevelKey) + .stream() + .collect(toMap(Value::getKey, value -> value.getValueAsString().orElseThrow())); + + assertThat(valuesMap).containsOnly( + entry(key1, value1), + entry(key2, value2), + entry(key3, value3) + ); + } + @Test void shouldDelete() { var key = randomUUIDString(); @@ -401,7 +445,7 @@ void testGetConsulResponseWithValues() { keyValueClient.deleteKey(key); - assertThat(!response.getResponse().isEmpty()).isTrue(); + assertThat(response.getResponse()).isNotEmpty(); assertThat(response.getIndex()).isNotNull(); }