diff --git a/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java b/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java index 82b23df407..0c9df0aa34 100644 --- a/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java +++ b/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java @@ -1508,7 +1508,7 @@ public RedisFuture>> jsonGet(K key, JsonGetArgs options, Js } @Override - public RedisFuture jsonMerge(K key, JsonPath jsonPath, JsonValue value) { + public RedisFuture jsonMerge(K key, JsonPath jsonPath, JsonValue value) { return dispatch(jsonCommandBuilder.jsonMerge(key, jsonPath, value)); } diff --git a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java index de618e13ce..38c19eb098 100644 --- a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java +++ b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java @@ -1573,7 +1573,7 @@ public Flux> jsonGet(K key, JsonGetArgs options, JsonPath... jso } @Override - public Mono jsonMerge(K key, JsonPath jsonPath, JsonValue value) { + public Mono jsonMerge(K key, JsonPath jsonPath, JsonValue value) { return createMono(() -> jsonCommandBuilder.jsonMerge(key, jsonPath, value)); } diff --git a/src/main/java/io/lettuce/core/RedisJsonCommandBuilder.java b/src/main/java/io/lettuce/core/RedisJsonCommandBuilder.java index 74abb1d73b..3c3cf7def7 100644 --- a/src/main/java/io/lettuce/core/RedisJsonCommandBuilder.java +++ b/src/main/java/io/lettuce/core/RedisJsonCommandBuilder.java @@ -171,7 +171,7 @@ Command>> jsonGet(K key, JsonGetArgs options, JsonPat return createCommand(JSON_GET, new JsonValueListOutput<>(codec), args); } - Command jsonMerge(K key, JsonPath jsonPath, JsonValue value) { + Command jsonMerge(K key, JsonPath jsonPath, JsonValue value) { notNullKey(key); @@ -183,7 +183,7 @@ Command jsonMerge(K key, JsonPath jsonPath, JsonValue value args.add(value.asByteBuffer().array()); - return createCommand(JSON_MERGE, new BooleanOutput<>(codec), args); + return createCommand(JSON_MERGE, new StatusOutput<>(codec), args); } Command>> jsonMGet(JsonPath jsonPath, K... keys) { diff --git a/src/main/java/io/lettuce/core/api/async/RedisJsonAsyncCommands.java b/src/main/java/io/lettuce/core/api/async/RedisJsonAsyncCommands.java index aa68d7277f..dd7ac9b28b 100644 --- a/src/main/java/io/lettuce/core/api/async/RedisJsonAsyncCommands.java +++ b/src/main/java/io/lettuce/core/api/async/RedisJsonAsyncCommands.java @@ -174,11 +174,11 @@ public interface RedisJsonAsyncCommands { * @param key the key holding the JSON document. * @param jsonPath the {@link JsonPath} pointing to the value to merge. * @param value the {@link JsonValue} to merge. - * @return Boolean true if the merge was successful, false otherwise. + * @return String "OK" if the set was successful, error if the operation failed. * @since 6.5 * @see RFC7396 */ - RedisFuture jsonMerge(K key, JsonPath jsonPath, JsonValue value); + RedisFuture jsonMerge(K key, JsonPath jsonPath, JsonValue value); /** * Return the values at path from multiple key arguments. diff --git a/src/main/java/io/lettuce/core/api/reactive/RedisJsonReactiveCommands.java b/src/main/java/io/lettuce/core/api/reactive/RedisJsonReactiveCommands.java index 91446ea6b9..f29e7ca1b0 100644 --- a/src/main/java/io/lettuce/core/api/reactive/RedisJsonReactiveCommands.java +++ b/src/main/java/io/lettuce/core/api/reactive/RedisJsonReactiveCommands.java @@ -174,11 +174,11 @@ public interface RedisJsonReactiveCommands { * @param key the key holding the JSON document. * @param jsonPath the {@link JsonPath} pointing to the value to merge. * @param value the {@link JsonValue} to merge. - * @return Boolean true if the merge was successful, false otherwise. + * @return String "OK" if the set was successful, error if the operation failed. * @since 6.5 * @see RFC7396 */ - Mono jsonMerge(K key, JsonPath jsonPath, JsonValue value); + Mono jsonMerge(K key, JsonPath jsonPath, JsonValue value); /** * Return the values at path from multiple key arguments. diff --git a/src/main/java/io/lettuce/core/api/sync/RedisJsonCommands.java b/src/main/java/io/lettuce/core/api/sync/RedisJsonCommands.java index 09aab63272..504f304f8f 100644 --- a/src/main/java/io/lettuce/core/api/sync/RedisJsonCommands.java +++ b/src/main/java/io/lettuce/core/api/sync/RedisJsonCommands.java @@ -173,11 +173,11 @@ public interface RedisJsonCommands { * @param key the key holding the JSON document. * @param jsonPath the {@link JsonPath} pointing to the value to merge. * @param value the {@link JsonValue} to merge. - * @return Boolean true if the merge was successful, false otherwise. + * @return String "OK" if the set was successful, error if the operation failed. * @since 6.5 * @see RFC7396 */ - Boolean jsonMerge(K key, JsonPath jsonPath, JsonValue value); + String jsonMerge(K key, JsonPath jsonPath, JsonValue value); /** * Return the values at path from multiple key arguments. diff --git a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionJsonAsyncCommands.java b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionJsonAsyncCommands.java index be54374e6e..1c511305f5 100644 --- a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionJsonAsyncCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionJsonAsyncCommands.java @@ -173,11 +173,11 @@ public interface NodeSelectionJsonAsyncCommands { * @param key the key holding the JSON document. * @param jsonPath the {@link JsonPath} pointing to the value to merge. * @param value the {@link JsonValue} to merge. - * @return Boolean true if the merge was successful, false otherwise. + * @return String "OK" if the set was successful, error if the operation failed. * @since 6.5 * @see RFC7396 */ - AsyncExecutions jsonMerge(K key, JsonPath jsonPath, JsonValue value); + AsyncExecutions jsonMerge(K key, JsonPath jsonPath, JsonValue value); /** * Return the values at path from multiple key arguments. diff --git a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionJsonCommands.java b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionJsonCommands.java index c5743ec69b..041013d7e9 100644 --- a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionJsonCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionJsonCommands.java @@ -173,11 +173,11 @@ public interface NodeSelectionJsonCommands { * @param key the key holding the JSON document. * @param jsonPath the {@link JsonPath} pointing to the value to merge. * @param value the {@link JsonValue} to merge. - * @return Boolean true if the merge was successful, false otherwise. + * @return String "OK" if the set was successful, error if the operation failed. * @since 6.5 * @see RFC7396 */ - Executions jsonMerge(K key, JsonPath jsonPath, JsonValue value); + Executions jsonMerge(K key, JsonPath jsonPath, JsonValue value); /** * Return the values at path from multiple key arguments. diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisJsonCoroutinesCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisJsonCoroutinesCommands.kt index 74b41c01dd..5e651cc175 100644 --- a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisJsonCoroutinesCommands.kt +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisJsonCoroutinesCommands.kt @@ -37,7 +37,7 @@ import io.lettuce.core.json.arguments.JsonSetArgs * @author Tihomir Mateev * @see Redis JSON * @since 6.5 - * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesApi + * @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesApi */ @ExperimentalLettuceCoroutinesApi interface RedisJsonCoroutinesCommands { @@ -176,11 +176,11 @@ interface RedisJsonCoroutinesCommands { * @param key the key holding the JSON document. * @param jsonPath the [JsonPath] pointing to the value to merge. * @param value the [JsonValue] to merge. - * @return Boolean true if the merge was successful, false otherwise. + * @return String "OK" if the set was successful, error if the operation failed. * @since 6.5 * @see RFC7396 */ - suspend fun jsonMerge(key: K, jsonPath: JsonPath, value: JsonValue): Boolean? + suspend fun jsonMerge(key: K, jsonPath: JsonPath, value: JsonValue): String? /** * Return the values at path from multiple key arguments. diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisJsonCoroutinesCommandsImpl.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisJsonCoroutinesCommandsImpl.kt index 787f540d37..7954f9ea6e 100644 --- a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisJsonCoroutinesCommandsImpl.kt +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisJsonCoroutinesCommandsImpl.kt @@ -83,7 +83,7 @@ internal class RedisJsonCoroutinesCommandsImpl(internal val op override suspend fun jsonGet(key: K, options: JsonGetArgs, vararg jsonPaths: JsonPath): List> = ops.jsonGet(key, options, *jsonPaths).asFlow().toList() - override suspend fun jsonMerge(key: K, jsonPath: JsonPath, value: JsonValue): Boolean? = + override suspend fun jsonMerge(key: K, jsonPath: JsonPath, value: JsonValue): String? = ops.jsonMerge(key, jsonPath, value).awaitFirstOrNull() override suspend fun jsonMGet(jsonPath: JsonPath, vararg keys: K): List> = diff --git a/src/main/templates/io/lettuce/core/api/RedisJsonCommands.java b/src/main/templates/io/lettuce/core/api/RedisJsonCommands.java index e29d01f98b..f66d10a1a3 100644 --- a/src/main/templates/io/lettuce/core/api/RedisJsonCommands.java +++ b/src/main/templates/io/lettuce/core/api/RedisJsonCommands.java @@ -173,11 +173,11 @@ public interface RedisJsonCommands { * @param key the key holding the JSON document. * @param jsonPath the {@link JsonPath} pointing to the value to merge. * @param value the {@link JsonValue} to merge. - * @return Boolean true if the merge was successful, false otherwise. + * @return String "OK" if the set was successful, error if the operation failed. * @since 6.5 * @see RFC7396 */ - Boolean jsonMerge(K key, JsonPath jsonPath, JsonValue value); + String jsonMerge(K key, JsonPath jsonPath, JsonValue value); /** * Return the values at path from multiple key arguments. diff --git a/src/test/java/io/lettuce/core/RedisContainerIntegrationTests.java b/src/test/java/io/lettuce/core/RedisContainerIntegrationTests.java index eb9ecdc6c2..0b55d9fc3b 100644 --- a/src/test/java/io/lettuce/core/RedisContainerIntegrationTests.java +++ b/src/test/java/io/lettuce/core/RedisContainerIntegrationTests.java @@ -11,6 +11,7 @@ import io.lettuce.core.json.JsonPath; import io.lettuce.core.json.JsonValue; import io.lettuce.core.json.arguments.JsonSetArgs; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.AfterAll; import org.testcontainers.containers.GenericContainer; @@ -26,17 +27,17 @@ @Testcontainers public class RedisContainerIntegrationTests { - @Container - public GenericContainer redisContainer = new GenericContainer(image).withExposedPorts(6379).withReuse(true);; - private static DockerImageName image = DockerImageName.parse("redis/redis-stack:latest"); + @Container + public static GenericContainer redisContainer = new GenericContainer(image).withExposedPorts(6379).withReuse(true);; + private static RedisClient client; protected static RedisCommands redis; - @BeforeEach - public void prepare() throws IOException { + @BeforeAll + public static void setup() { if (!redisContainer.isRunning()) { redisContainer.start(); } @@ -47,7 +48,10 @@ public void prepare() throws IOException { client = RedisClient.create(redisURI); redis = client.connect().sync(); + } + @BeforeEach + public void prepare() throws IOException { redis.flushall(); Path path = Paths.get("src/test/resources/bike-inventory.json"); diff --git a/src/test/java/io/lettuce/core/RedisJsonCommandBuilderUnitTests.java b/src/test/java/io/lettuce/core/RedisJsonCommandBuilderUnitTests.java index 3c1b6424d4..709b2b6f10 100644 --- a/src/test/java/io/lettuce/core/RedisJsonCommandBuilderUnitTests.java +++ b/src/test/java/io/lettuce/core/RedisJsonCommandBuilderUnitTests.java @@ -129,7 +129,7 @@ void shouldCorrectlyConstructJsonGet() { @Test void shouldCorrectlyConstructJsonMerge() { - Command command = builder.jsonMerge(MY_KEY, MY_PATH, ELEMENT); + Command command = builder.jsonMerge(MY_KEY, MY_PATH, ELEMENT); ByteBuf buf = Unpooled.directBuffer(); command.encode(buf); diff --git a/src/test/java/io/lettuce/core/json/RedisJsonIntegrationTests.java b/src/test/java/io/lettuce/core/json/RedisJsonIntegrationTests.java index 3aced7c4c0..a39b3eb831 100644 --- a/src/test/java/io/lettuce/core/json/RedisJsonIntegrationTests.java +++ b/src/test/java/io/lettuce/core/json/RedisJsonIntegrationTests.java @@ -9,11 +9,12 @@ import io.lettuce.core.RedisContainerIntegrationTests; import io.lettuce.core.json.arguments.JsonGetArgs; +import io.lettuce.core.json.arguments.JsonMsetArgs; +import io.lettuce.core.json.arguments.JsonRangeArgs; import io.lettuce.core.json.arguments.JsonSetArgs; import org.junit.jupiter.api.Test; import java.util.List; -import java.util.concurrent.ExecutionException; import static org.assertj.core.api.Assertions.assertThat; @@ -23,10 +24,8 @@ public class RedisJsonIntegrationTests extends RedisContainerIntegrationTests { private static final String BIKES_INVENTORY = "bikes:inventory"; - private static final String COMMUTER_BIKES = "$..commuter_bikes"; - @Test - void jsonArrappend() throws ExecutionException, InterruptedException { + void jsonArrappend() { JsonParser parser = redis.getJsonParser(); JsonValue element = parser.createJsonValue("\"{id:bike6}\""); @@ -36,29 +35,38 @@ void jsonArrappend() throws ExecutionException, InterruptedException { } @Test - void jsonArrindex() throws ExecutionException, InterruptedException { + void jsonArrindex() { JsonParser parser = redis.getJsonParser(); - JsonValue element = parser.createJsonValue("\"id\": \"bike:2\""); + JsonPath myPath = JsonPath.of("$..mountain_bikes[1].colors"); + JsonValue element = parser.createJsonValue("\"white\""); - List arrayIndex = redis.jsonArrindex(BIKES_INVENTORY, MOUNTAIN_BIKES_PATH, element, null); + List arrayIndex = redis.jsonArrindex(BIKES_INVENTORY, myPath, element, null); assertThat(arrayIndex).isNotNull(); - assertThat(arrayIndex.get(0).longValue()).isEqualTo(3L); + assertThat(arrayIndex).hasSize(1); + assertThat(arrayIndex.get(0).longValue()).isEqualTo(1L); } @Test void jsonArrinsert() { - throw new RuntimeException("Not implemented"); + JsonParser parser = redis.getJsonParser(); + JsonPath myPath = JsonPath.of("$..mountain_bikes[1].colors"); + JsonValue element = parser.createJsonValue("\"ultramarine\""); + + List arrayIndex = redis.jsonArrinsert(BIKES_INVENTORY, myPath, 1, element); + assertThat(arrayIndex).isNotNull(); + assertThat(arrayIndex).hasSize(1); + assertThat(arrayIndex.get(0).longValue()).isEqualTo(3L); } @Test - void jsonArrlen() throws ExecutionException, InterruptedException { + void jsonArrlen() { List poppedJson = redis.jsonArrlen(BIKES_INVENTORY, MOUNTAIN_BIKES_PATH); assertThat(poppedJson).hasSize(1); assertThat(poppedJson.get(0).longValue()).isEqualTo(3); } @Test - void jsonArrpop() throws ExecutionException, InterruptedException { + void jsonArrpop() { List> poppedJson = redis.jsonArrpop(BIKES_INVENTORY, MOUNTAIN_BIKES_PATH, -1); assertThat(poppedJson).hasSize(1); assertThat(poppedJson.get(0).toValue()).contains( @@ -66,17 +74,27 @@ void jsonArrpop() throws ExecutionException, InterruptedException { } @Test - void jsonArrtrim() throws ExecutionException, InterruptedException { - throw new RuntimeException("Not implemented"); + void jsonArrtrim() { + JsonPath myPath = JsonPath.of("$..mountain_bikes[1].colors"); + JsonRangeArgs range = JsonRangeArgs.Builder.start(1).stop(2); + + List arrayIndex = redis.jsonArrtrim(BIKES_INVENTORY, myPath, range); + assertThat(arrayIndex).isNotNull(); + assertThat(arrayIndex).hasSize(1); + assertThat(arrayIndex.get(0).longValue()).isEqualTo(1L); } @Test - void jsonClear() throws ExecutionException, InterruptedException { - throw new RuntimeException("Not implemented"); + void jsonClear() { + JsonPath myPath = JsonPath.of("$..mountain_bikes[1].colors"); + + Long result = redis.jsonClear(BIKES_INVENTORY, myPath); + assertThat(result).isNotNull(); + assertThat(result).isEqualTo(1L); } @Test - void jsonGet() throws ExecutionException, InterruptedException { + void jsonGet() { JsonPath path = JsonPath.of("$..mountain_bikes[0:2].model"); // Verify codec parsing @@ -98,12 +116,18 @@ void jsonGet() throws ExecutionException, InterruptedException { } @Test - void jsonMerge() throws ExecutionException, InterruptedException { - throw new RuntimeException("Not implemented"); + void jsonMerge() { + JsonParser parser = redis.getJsonParser(); + JsonPath myPath = JsonPath.of("$..mountain_bikes[1]"); + JsonValue element = parser.createJsonValue("\"ultramarine\""); + + String result = redis.jsonMerge(BIKES_INVENTORY, myPath, element); + assertThat(result).isNotNull(); + assertThat(result).isEqualTo("OK"); } @Test - void jsonMGet() throws ExecutionException, InterruptedException { + void jsonMGet() { JsonPath path = JsonPath.of("$..model"); List> value = redis.jsonMGet(path, BIKES_INVENTORY); @@ -112,12 +136,49 @@ void jsonMGet() throws ExecutionException, InterruptedException { } @Test - void jsonMset() throws ExecutionException, InterruptedException { - throw new RuntimeException("Not implemented"); + void jsonMset() { + JsonParser parser = redis.getJsonParser(); + JsonPath myPath = JsonPath.of("$..mountain_bikes[1]"); + + JsonObject bikeRecord = parser.createEmptyJsonObject(); + JsonObject bikeSpecs = parser.createEmptyJsonObject(); + JsonArray bikeColors = parser.createEmptyJsonArray(); + bikeSpecs.put("material", parser.createJsonValue("\"composite\"")); + bikeSpecs.put("weight", parser.createJsonValue("11")); + bikeColors.add(parser.createJsonValue("\"yellow\"")); + bikeColors.add(parser.createJsonValue("\"orange\"")); + bikeRecord.put("id", parser.createJsonValue("\"bike:43\"")); + bikeRecord.put("model", parser.createJsonValue("\"DesertFox\"")); + bikeRecord.put("description", parser.createJsonValue("\"The DesertFox is a versatile bike for all terrains\"")); + bikeRecord.put("price", parser.createJsonValue("\"1299\"")); + bikeRecord.put("specs", bikeSpecs); + bikeRecord.put("colors", bikeColors); + + JsonMsetArgs args1 = JsonMsetArgs.Builder.key(BIKES_INVENTORY).path(myPath).element(bikeRecord); + + bikeRecord = parser.createEmptyJsonObject(); + bikeSpecs = parser.createEmptyJsonObject(); + bikeColors = parser.createEmptyJsonArray(); + bikeSpecs.put("material", parser.createJsonValue("\"wood\"")); + bikeSpecs.put("weight", parser.createJsonValue("19")); + bikeColors.add(parser.createJsonValue("\"walnut\"")); + bikeColors.add(parser.createJsonValue("\"chestnut\"")); + bikeRecord.put("id", parser.createJsonValue("\"bike:13\"")); + bikeRecord.put("model", parser.createJsonValue("\"Woody\"")); + bikeRecord.put("description", parser.createJsonValue("\"The Woody is an environmentally-friendly wooden bike\"")); + bikeRecord.put("price", parser.createJsonValue("\"1112\"")); + bikeRecord.put("specs", bikeSpecs); + bikeRecord.put("colors", bikeColors); + + JsonMsetArgs args2 = JsonMsetArgs.Builder.key(BIKES_INVENTORY).path(myPath).element(bikeRecord); + + String result = redis.jsonMSet(args1, args2); + assertThat(result).isNotNull(); + assertThat(result).isEqualTo("OK"); } @Test - void jsonNumincrby() throws ExecutionException, InterruptedException { + void jsonNumincrby() { JsonPath path = JsonPath.of("$..mountain_bikes[0:1].price"); List value = redis.jsonNumincrby(BIKES_INVENTORY, path, 5L); @@ -126,17 +187,27 @@ void jsonNumincrby() throws ExecutionException, InterruptedException { } @Test - void jsonObjkeys() throws ExecutionException, InterruptedException { - throw new RuntimeException("Not implemented"); + void jsonObjkeys() { + JsonPath myPath = JsonPath.of("$..mountain_bikes[1]"); + + List result = redis.jsonObjkeys(BIKES_INVENTORY, myPath); + assertThat(result).isNotNull(); + assertThat(result).hasSize(6); + assertThat(result).contains("id", "model", "description", "price", "specs", "colors"); } @Test - void jsonObjlen() throws ExecutionException, InterruptedException { - throw new RuntimeException("Not implemented"); + void jsonObjlen() { + JsonPath myPath = JsonPath.of("$..mountain_bikes[1]"); + + List result = redis.jsonObjlen(BIKES_INVENTORY, myPath); + assertThat(result).isNotNull(); + assertThat(result).hasSize(1); + assertThat(result.get(0)).isEqualTo(6L); } @Test - void jsonSet() throws ExecutionException, InterruptedException { + void jsonSet() { JsonParser parser = redis.getJsonParser(); JsonObject bikeRecord = parser.createEmptyJsonObject(); JsonObject bikeSpecs = parser.createEmptyJsonObject(); @@ -162,22 +233,41 @@ void jsonSet() throws ExecutionException, InterruptedException { } @Test - void jsonStrappend() throws ExecutionException, InterruptedException { - throw new RuntimeException("Not implemented"); + void jsonStrappend() { + JsonParser parser = redis.getJsonParser(); + JsonPath myPath = JsonPath.of("$..mountain_bikes[1].colors[1]"); + JsonValue element = parser.createJsonValue("\"-light\""); + + List result = redis.jsonStrappend(BIKES_INVENTORY, myPath, element); + assertThat(result).isNotNull(); + assertThat(result).hasSize(1); + assertThat(result.get(0)).isEqualTo(11L); } @Test - void jsonStrlen() throws ExecutionException, InterruptedException { - throw new RuntimeException("Not implemented"); + void jsonStrlen() { + JsonParser parser = redis.getJsonParser(); + JsonPath myPath = JsonPath.of("$..mountain_bikes[1].colors[1]"); + + List result = redis.jsonStrlen(BIKES_INVENTORY, myPath); + assertThat(result).isNotNull(); + assertThat(result).hasSize(1); + assertThat(result.get(0)).isEqualTo(5L); } @Test - void jsonToggle() throws ExecutionException, InterruptedException { - throw new RuntimeException("Not implemented"); + void jsonToggle() { + JsonParser parser = redis.getJsonParser(); + JsonPath myPath = JsonPath.of("$..complete"); + + List result = redis.jsonToggle(BIKES_INVENTORY, myPath); + assertThat(result).isNotNull(); + assertThat(result).hasSize(1); + assertThat(result.get(0)).isEqualTo(1L); } @Test - void jsonDel() throws ExecutionException, InterruptedException { + void jsonDel() { JsonPath path = JsonPath.of("$..mountain_bikes[2:3]"); Long value = redis.jsonDel(BIKES_INVENTORY, path); @@ -185,7 +275,7 @@ void jsonDel() throws ExecutionException, InterruptedException { } @Test - void jsonType() throws ExecutionException, InterruptedException { + void jsonType() { String jsonType = redis.jsonType(BIKES_INVENTORY, MOUNTAIN_BIKES_PATH).get(0); assertThat(jsonType).isEqualTo("array"); } diff --git a/src/test/resources/bike-inventory.json b/src/test/resources/bike-inventory.json index 303f7a5b5f..c316c626dd 100644 --- a/src/test/resources/bike-inventory.json +++ b/src/test/resources/bike-inventory.json @@ -1,5 +1,6 @@ { "inventory": { + "complete": false, "mountain_bikes": [ { "id": "bike:1",