Skip to content

Commit

Permalink
Add tests in KeyValueClientITest for getting nested keys (#267)
Browse files Browse the repository at this point in the history
e.g. a key named resources/refdata

Closes #266
  • Loading branch information
sleberknight authored Aug 18, 2023
1 parent 25756a8 commit 9c8cdec
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/itest/java/org/kiwiproject/consul/KeyValueClientITest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -401,7 +445,7 @@ void testGetConsulResponseWithValues() {

keyValueClient.deleteKey(key);

assertThat(!response.getResponse().isEmpty()).isTrue();
assertThat(response.getResponse()).isNotEmpty();
assertThat(response.getIndex()).isNotNull();
}

Expand Down

0 comments on commit 9c8cdec

Please sign in to comment.