From 9bcce572856c35499a38217b386c10a0b26f7b90 Mon Sep 17 00:00:00 2001 From: Andrey G Date: Mon, 20 Feb 2023 16:53:47 +0200 Subject: [PATCH] FMWK-146 Code format (#92) Co-authored-by: yrizhkov --- .editorconfig | 20 +++++ .../documentapi/DocumentApiException.java | 8 +- .../documentapi/IAerospikeDocumentClient.java | 10 +-- .../IAerospikeDocumentRepository.java | 3 +- .../batch/AppendBatchOperation.java | 6 +- .../batch/DeleteBatchOperation.java | 6 +- .../documentapi/batch/PutBatchOperation.java | 6 +- .../documentapi/jsonpath/JsonPathParser.java | 4 +- .../documentapi/jsonpath/PathDetails.java | 3 +- .../documentapi/policy/DocumentPolicy.java | 1 + .../documentapi/token/ListToken.java | 80 +++++++++---------- .../aerospike/documentapi/token/MapToken.java | 43 +++++----- .../aerospike/documentapi/token/Token.java | 16 ++-- .../documentapi/util/JsonConverters.java | 4 +- .../com/aerospike/documentapi/util/Utils.java | 3 +- .../documentapi/DocumentAPIBatchTests.java | 14 ++-- .../documentapi/DocumentAPITests.java | 15 ++-- .../documentapi/InsertPutGetTest.java | 45 +++++++++++ .../documentapi/MultipleBinsTests.java | 6 +- .../documentapi/util/TestJsonConverters.java | 4 +- 20 files changed, 193 insertions(+), 104 deletions(-) create mode 100644 .editorconfig create mode 100644 src/test/java/com/aerospike/documentapi/InsertPutGetTest.java diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..21a0cfd --- /dev/null +++ b/.editorconfig @@ -0,0 +1,20 @@ +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +charset = utf-8 +end_of_line = lf + +[*.java] +indent_style = space +indent_size = 4 +insert_final_newline = true +max_line_length = 120 +ij_continuation_indent_size = 8 +ij_java_wrap_long_lines = true +ij_java_wrap_comments = true +ij_java_method_call_chain_wrap = normal +ij_java_blank_lines_after_class_header = 1 +ij_java_class_count_to_use_import_on_demand = 10 +ij_java_names_count_to_use_import_on_demand = 10 \ No newline at end of file diff --git a/src/main/java/com/aerospike/documentapi/DocumentApiException.java b/src/main/java/com/aerospike/documentapi/DocumentApiException.java index 6dec4ab..68df530 100644 --- a/src/main/java/com/aerospike/documentapi/DocumentApiException.java +++ b/src/main/java/com/aerospike/documentapi/DocumentApiException.java @@ -25,8 +25,8 @@ public static DocumentApiException wrapAerospikeException(AerospikeException ae) } /** - * Utility method to wrap an Exception. - * {@link AerospikeException} is processed separately to display its result code name. + * Utility method to wrap an Exception. {@link AerospikeException} is processed separately to display its result + * code name. * * @param e the original exception. * @return a DocumentApiException wrapping the original exception. @@ -41,6 +41,7 @@ public static DocumentApiException toDocumentException(Exception e) { * Exception to be thrown in case of invalid json prefix. */ public static class JsonPrefixException extends DocumentApiException { + public JsonPrefixException(String jsonString) { super(String.format("'%s' should start with either a '$.' or '$['", jsonString)); } @@ -50,6 +51,7 @@ public JsonPrefixException(String jsonString) { * Exception to be thrown in case of invalid json path. */ public static class JsonPathException extends DocumentApiException { + public JsonPathException(String jsonString) { super(String.format("'%s' does not match JSONPath format", jsonString)); } @@ -59,6 +61,7 @@ public JsonPathException(String jsonString) { * Exception to be thrown in case of invalid appending to json. */ public static class JsonAppendException extends DocumentApiException { + public JsonAppendException(String jsonString) { super(String.format("Cannot append to '%s'", jsonString)); } @@ -68,6 +71,7 @@ public JsonAppendException(String jsonString) { * Exception to be thrown in case of invalid json path. */ public static class JsonPathParseException extends DocumentApiException { + public JsonPathParseException(String jsonPathPart) { super(String.format("Unable to parse '%s' as JSONPath token", jsonPathPart)); } diff --git a/src/main/java/com/aerospike/documentapi/IAerospikeDocumentClient.java b/src/main/java/com/aerospike/documentapi/IAerospikeDocumentClient.java index e4e4231..8efb1d7 100644 --- a/src/main/java/com/aerospike/documentapi/IAerospikeDocumentClient.java +++ b/src/main/java/com/aerospike/documentapi/IAerospikeDocumentClient.java @@ -108,11 +108,11 @@ public interface IAerospikeDocumentClient { /** * Perform batch operations. - * - *

Operations order is preserved only for those 1-step operations - * (with JSONPath that contains only array and/or map elements) - * that have unique Aerospike keys within a batch.

- *

Every 2-step operation (with JSONPath containing wildcards, recursive descent, filters, functions, scripts) + *

+ * Operations order is preserved only for those 1-step operations (with JSONPath that contains only array and/or map + * elements) that have unique Aerospike keys within a batch. + *

+ * Every 2-step operation (with JSONPath containing wildcards, recursive descent, filters, functions, scripts) * should have unique Aerospike key within a batch. * * @param batchOperations a list of batch operations to apply. diff --git a/src/main/java/com/aerospike/documentapi/IAerospikeDocumentRepository.java b/src/main/java/com/aerospike/documentapi/IAerospikeDocumentRepository.java index f842137..e7a775c 100644 --- a/src/main/java/com/aerospike/documentapi/IAerospikeDocumentRepository.java +++ b/src/main/java/com/aerospike/documentapi/IAerospikeDocumentRepository.java @@ -23,7 +23,8 @@ Map get(Policy readPolicy, Key key, Collection binNames, void put(WritePolicy writePolicy, Key key, String binName, Map jsonMap); - void put(WritePolicy writePolicy, Key key, Collection binNames, Object jsonObject, JsonPathObject jsonPathObject); + void put(WritePolicy writePolicy, Key key, Collection binNames, Object jsonObject, + JsonPathObject jsonPathObject); void put(WritePolicy writePolicy, Key key, Map queryResults, JsonPathObject jsonPathObject); diff --git a/src/main/java/com/aerospike/documentapi/batch/AppendBatchOperation.java b/src/main/java/com/aerospike/documentapi/batch/AppendBatchOperation.java index ded0677..6d51bd9 100644 --- a/src/main/java/com/aerospike/documentapi/batch/AppendBatchOperation.java +++ b/src/main/java/com/aerospike/documentapi/batch/AppendBatchOperation.java @@ -40,14 +40,16 @@ public BatchRecord setSecondStepRecordAndGet() { } else { if (isRequiringJsonPathQuery()) { // using the original object as the initially parsed one has already been changed within the 1st step - final PathDetails pathDetails = getPathDetails(originalJsonPathObject.getTokensNotRequiringSecondStepQuery(), true); + final PathDetails pathDetails = + getPathDetails(originalJsonPathObject.getTokensNotRequiringSecondStepQuery(), true); batchOps = firstStepQueryResults().entrySet().stream() .map(entry -> toPutOperation(entry.getKey(), entry.getValue(), pathDetails)) .filter(Objects::nonNull) .toArray(Operation[]::new); } else { // needs to be treated without modifying - final PathDetails pathDetails = getPathDetails(jsonPathObject.getTokensNotRequiringSecondStepQuery(), false); + final PathDetails pathDetails = getPathDetails(jsonPathObject.getTokensNotRequiringSecondStepQuery(), + false); batchOps = binNames.stream() .map(binName -> toAppendOperation(binName, objToAppend, pathDetails)) .filter(Objects::nonNull) diff --git a/src/main/java/com/aerospike/documentapi/batch/DeleteBatchOperation.java b/src/main/java/com/aerospike/documentapi/batch/DeleteBatchOperation.java index df1d4ba..4924fea 100644 --- a/src/main/java/com/aerospike/documentapi/batch/DeleteBatchOperation.java +++ b/src/main/java/com/aerospike/documentapi/batch/DeleteBatchOperation.java @@ -38,13 +38,15 @@ public BatchRecord setSecondStepRecordAndGet() { } else { if (isRequiringJsonPathQuery()) { // using the original object as the initially parsed one has already been changed within the 1st step - final PathDetails pathDetails = getPathDetails(originalJsonPathObject.getTokensNotRequiringSecondStepQuery(), true); + final PathDetails pathDetails = + getPathDetails(originalJsonPathObject.getTokensNotRequiringSecondStepQuery(), true); batchOps = firstStepQueryResults().entrySet().stream() .map(entry -> pathDetails.getFinalToken() .toAerospikePutOperation(entry.getKey(), entry.getValue(), pathDetails.getCtxArray())) .toArray(Operation[]::new); } else { - final PathDetails pathDetails = getPathDetails(jsonPathObject.getTokensNotRequiringSecondStepQuery(), true); + final PathDetails pathDetails = getPathDetails(jsonPathObject.getTokensNotRequiringSecondStepQuery(), + true); batchOps = binNames.stream() .map(binName -> pathDetails.getFinalToken() .toAerospikeDeleteOperation(binName, pathDetails.getCtxArray())) diff --git a/src/main/java/com/aerospike/documentapi/batch/PutBatchOperation.java b/src/main/java/com/aerospike/documentapi/batch/PutBatchOperation.java index 871aae7..4553a75 100644 --- a/src/main/java/com/aerospike/documentapi/batch/PutBatchOperation.java +++ b/src/main/java/com/aerospike/documentapi/batch/PutBatchOperation.java @@ -42,13 +42,15 @@ public BatchRecord setSecondStepRecordAndGet() { } else { if (isRequiringJsonPathQuery()) { // using the original object as the initially parsed one has already been changed within the 1st step - final PathDetails pathDetails = getPathDetails(originalJsonPathObject.getTokensNotRequiringSecondStepQuery(), true); + final PathDetails pathDetails = + getPathDetails(originalJsonPathObject.getTokensNotRequiringSecondStepQuery(), true); batchOps = firstStepQueryResults().entrySet().stream() .map(entry -> toPutOperation(entry.getKey(), entry.getValue(), pathDetails)) .filter(Objects::nonNull) .toArray(Operation[]::new); } else { - final PathDetails pathDetails = getPathDetails(jsonPathObject.getTokensNotRequiringSecondStepQuery(), true); + final PathDetails pathDetails = getPathDetails(jsonPathObject.getTokensNotRequiringSecondStepQuery(), + true); batchOps = binNames.stream() .map(binName -> toPutOperation(binName, objToPut, pathDetails)) .filter(Objects::nonNull) diff --git a/src/main/java/com/aerospike/documentapi/jsonpath/JsonPathParser.java b/src/main/java/com/aerospike/documentapi/jsonpath/JsonPathParser.java index 8eac854..ebf725c 100644 --- a/src/main/java/com/aerospike/documentapi/jsonpath/JsonPathParser.java +++ b/src/main/java/com/aerospike/documentapi/jsonpath/JsonPathParser.java @@ -53,8 +53,8 @@ public static ContextAwareToken extractLastPathPartAndModifyList(List parseToList(String strPart) { + List list = new ArrayList<>(); + Token token; + + Matcher keyMatcher = PATH_PATTERN.matcher(strPart); + if ((!strPart.contains("[")) && (!strPart.contains("]"))) { + // ignoring * wildcard after a dot + if (!strPart.equals(String.valueOf(WILDCARD)) && !strPart.equals(String.valueOf(DOC_ROOT))) { + token = new MapToken(strPart); + list.add(token); + } + } else if (keyMatcher.find()) { + String key = keyMatcher.group(1); + if (!key.equals(String.valueOf(DOC_ROOT)) + && key.length() > 0 + && key.charAt(0) != OPEN_BRACKET && key.charAt(key.length() - 1) != CLOSE_BRACKET) { + token = new MapToken(key); + list.add(token); + } + } + + Matcher indexMatcher = INDEX_PATTERN.matcher(strPart); + while (indexMatcher.find()) { + String res = indexMatcher.group(2); + if (res.equals("*")) { + token = new WildcardToken(res, true); + } else { + token = new ListToken(Integer.parseInt(res)); + } + list.add(token); + } + + return list; + } public int getListPosition() { return listPosition; @@ -81,42 +119,4 @@ public Operation toAerospikeDeleteOperation(String binName, CTX[] contexts) { public TokenType getType() { return TokenType.LIST; } - - // For reading a path part into a list of tokens (map, list or wildcard). - // Appends parsed tokens to a list. - // Expected form of path part is key[index1][index2]. - public static List parseToList(String strPart) { - List list = new ArrayList<>(); - Token token; - - Matcher keyMatcher = PATH_PATTERN.matcher(strPart); - if ((!strPart.contains("[")) && (!strPart.contains("]"))) { - // ignoring * wildcard after a dot - if (!strPart.equals(String.valueOf(WILDCARD)) && !strPart.equals(String.valueOf(DOC_ROOT))) { - token = new MapToken(strPart); - list.add(token); - } - } else if (keyMatcher.find()) { - String key = keyMatcher.group(1); - if (!key.equals(String.valueOf(DOC_ROOT)) - && key.length() > 0 - && key.charAt(0) != OPEN_BRACKET && key.charAt(key.length() - 1) != CLOSE_BRACKET) { - token = new MapToken(key); - list.add(token); - } - } - - Matcher indexMatcher = INDEX_PATTERN.matcher(strPart); - while (indexMatcher.find()) { - String res = indexMatcher.group(2); - if (res.equals("*")) { - token = new WildcardToken(res, true); - } else { - token = new ListToken(Integer.parseInt(res)); - } - list.add(token); - } - - return list; - } } diff --git a/src/main/java/com/aerospike/documentapi/token/MapToken.java b/src/main/java/com/aerospike/documentapi/token/MapToken.java index 8af909d..552ae19 100644 --- a/src/main/java/com/aerospike/documentapi/token/MapToken.java +++ b/src/main/java/com/aerospike/documentapi/token/MapToken.java @@ -21,6 +21,8 @@ */ public class MapToken extends ContextAwareToken { + static final Pattern PATH_PATTERN = Pattern.compile("^([^\\[^\\]]*)(\\[(\\d+)\\])*$"); + private final String key; public MapToken(String key) { @@ -28,7 +30,25 @@ public MapToken(String key) { setString(key); } - static final Pattern PATH_PATTERN = Pattern.compile("^([^\\[^\\]]*)(\\[(\\d+)\\])*$"); + public static Optional match(String strPart) { + Token token; + Matcher keyMatcher = PATH_PATTERN.matcher(strPart); + if ((!strPart.contains("[")) && (!strPart.contains("]"))) { + // ignoring * wildcard after a dot, it's the same as ending with a .path + if (!strPart.equals(String.valueOf(WILDCARD)) && !strPart.equals(String.valueOf(DOC_ROOT))) { + token = new MapToken(strPart); + return Optional.of(token); + } + } else if (keyMatcher.find()) { + String key = keyMatcher.group(1); + if (!key.equals(String.valueOf(DOC_ROOT))) { + token = new MapToken(strPart); + return Optional.of(token); + } + } + + return Optional.empty(); + } public String getKey() { return key; @@ -78,25 +98,4 @@ public Operation toAerospikeDeleteOperation(String binName, CTX[] contexts) { public TokenType getType() { return TokenType.MAP; } - - public static Optional match(String strPart) { - Token token; - - Matcher keyMatcher = PATH_PATTERN.matcher(strPart); - if ((!strPart.contains("[")) && (!strPart.contains("]"))) { - // ignoring * wildcard after a dot, it's the same as ending with a .path - if (!strPart.equals(String.valueOf(WILDCARD)) && !strPart.equals(String.valueOf(DOC_ROOT))) { - token = new MapToken(strPart); - return Optional.of(token); - } - } else if (keyMatcher.find()) { - String key = keyMatcher.group(1); - if (!key.equals(String.valueOf(DOC_ROOT))) { - token = new MapToken(strPart); - return Optional.of(token); - } - } - - return Optional.empty(); - } } diff --git a/src/main/java/com/aerospike/documentapi/token/Token.java b/src/main/java/com/aerospike/documentapi/token/Token.java index 31d94b4..5bb653d 100644 --- a/src/main/java/com/aerospike/documentapi/token/Token.java +++ b/src/main/java/com/aerospike/documentapi/token/Token.java @@ -5,23 +5,23 @@ public abstract class Token { private String string; private String queryConcatString; + public String getString() { + return string; + } + protected void setString(String string) { this.string = string; this.queryConcatString = string; } - protected void setQueryConcatString(String queryConcatString) { - this.queryConcatString = queryConcatString; - } - - public String getString() { - return string; - } - public String getQueryConcatString() { return queryConcatString; } + protected void setQueryConcatString(String queryConcatString) { + this.queryConcatString = queryConcatString; + } + public abstract TokenType getType(); public boolean requiresJsonQuery() { diff --git a/src/main/java/com/aerospike/documentapi/util/JsonConverters.java b/src/main/java/com/aerospike/documentapi/util/JsonConverters.java index 15e754b..2617786 100644 --- a/src/main/java/com/aerospike/documentapi/util/JsonConverters.java +++ b/src/main/java/com/aerospike/documentapi/util/JsonConverters.java @@ -53,8 +53,8 @@ public static List convertJsonNodeToList(JsonNode jsonNode) { } /** - * Given an object that represents a list or a map for example an Aerospike database result, - * return its equivalent representation as a Json string. + * Given an object that represents a list or a map for example an Aerospike database result, return its equivalent + * representation as a Json string. * * @param object the object to parse as a Json string. * @return the JSON string representation of the object. diff --git a/src/main/java/com/aerospike/documentapi/util/Utils.java b/src/main/java/com/aerospike/documentapi/util/Utils.java index 7478bfb..c049d3c 100644 --- a/src/main/java/com/aerospike/documentapi/util/Utils.java +++ b/src/main/java/com/aerospike/documentapi/util/Utils.java @@ -34,7 +34,8 @@ public static Bin createBin(String binName, Object jsonObject) { public static void validateNotArray(Object object) throws IllegalArgumentException { if (object.getClass().isArray()) { - throw new IllegalArgumentException("Putting/appending an array is not allowed, consider providing a Collection"); + throw new IllegalArgumentException("Putting/appending an array is not allowed, consider providing a " + + "Collection"); } } diff --git a/src/test/java/com/aerospike/documentapi/DocumentAPIBatchTests.java b/src/test/java/com/aerospike/documentapi/DocumentAPIBatchTests.java index 52fefb0..be36ae3 100644 --- a/src/test/java/com/aerospike/documentapi/DocumentAPIBatchTests.java +++ b/src/test/java/com/aerospike/documentapi/DocumentAPIBatchTests.java @@ -89,8 +89,8 @@ void testPositiveBatchGet() { } /** - * Check the correct response of retrieving document content in a batch - * of single step operations using incorrect path. + * Check the correct response of retrieving document content in a batch of single step operations using incorrect + * path. *
    *
  • Non-existing key.
  • *
  • Referencing a map as if it were a list.
  • @@ -786,7 +786,8 @@ void testPositiveBatchMix2StepWildcard() { objFromDb = documentClient.get(batchOp.getKey(), batchOp.getBinNames().iterator().next(), batchOp.getJsonPath() ); - modifiedJson = JsonPath.parse(testMaterialJson).set(inputsList.get(i).getJsonPath(), objToPut).json(); + modifiedJson = JsonPath.parse(testMaterialJson).set(inputsList.get(i).getJsonPath(), objToPut) + .json(); expectedObject = JsonPath.read(modifiedJson, inputsList.get(i).getJsonPath()); assertNotNull(objFromDb); @@ -796,7 +797,8 @@ void testPositiveBatchMix2StepWildcard() { objFromDb = documentClient.get(batchOp.getKey(), batchOp.getBinNames().iterator().next(), batchOp.getJsonPath() ); - modifiedJson = JsonPath.parse(testMaterialJson).add(inputsList.get(i).getJsonPath(), objToAppend).json(); + modifiedJson = JsonPath.parse(testMaterialJson).add(inputsList.get(i).getJsonPath(), objToAppend) + .json(); expectedObject = JsonPath.read(modifiedJson, inputsList.get(i).getJsonPath()); assertNotNull(objFromDb); @@ -1102,7 +1104,8 @@ void testBatchMix2StepWildcardNegativeAndPositive() { case 1: objFromDb = documentClient.get(batchOp.getKey(), batchOp.getBinNames().iterator().next(), batchOp.getJsonPath()); - modifiedJson = JsonPath.parse(testMaterialJson).set(inputsList.get(i).getJsonPath(), objToPut).json(); + modifiedJson = JsonPath.parse(testMaterialJson).set(inputsList.get(i).getJsonPath(), objToPut) + .json(); expectedObject = JsonPath.read(modifiedJson, inputsList.get(i).getJsonPath()); assertNotNull(objFromDb); @@ -1223,6 +1226,7 @@ protected enum BatchOperationEnum { @Getter private static class BatchOperationInput { + private final String jsonPath; private final BatchOperationEnum batchOpEnum; @Setter diff --git a/src/test/java/com/aerospike/documentapi/DocumentAPITests.java b/src/test/java/com/aerospike/documentapi/DocumentAPITests.java index 047677e..75d86ee 100644 --- a/src/test/java/com/aerospike/documentapi/DocumentAPITests.java +++ b/src/test/java/com/aerospike/documentapi/DocumentAPITests.java @@ -99,12 +99,14 @@ void testPositivePathRetrieval() { jsonPath = "$.example4.key13.key15[1]"; objectFromDB = documentClient.get(TEST_AEROSPIKE_KEY, DOCUMENT_BIN_NAME, jsonPath); - expectedObject = ((List) ((Map) ((Map) jsonNodeAsMap.get("example4")).get("key13")).get("key15")).get(1); + expectedObject = ((List) ((Map) ((Map) jsonNodeAsMap.get("example4")).get("key13")).get("key15")) + .get(1); assertTrue(TestJsonConverters.jsonEquals(objectFromDB, expectedObject)); jsonPath = "$.example4.key19[2].key21"; objectFromDB = documentClient.get(TEST_AEROSPIKE_KEY, DOCUMENT_BIN_NAME, jsonPath); - expectedObject = ((Map) ((List) ((Map) jsonNodeAsMap.get("example4")).get("key19")).get(2)).get("key21"); + expectedObject = + ((Map) ((List) ((Map) jsonNodeAsMap.get("example4")).get("key19")).get(2)).get("key21"); assertTrue(TestJsonConverters.jsonEquals(objectFromDB, expectedObject)); jsonPath = "$.example4.key19[2].key20[1]"; @@ -115,7 +117,8 @@ void testPositivePathRetrieval() { jsonPath = "$.example3[2].key21.key23"; objectFromDB = documentClient.get(TEST_AEROSPIKE_KEY, DOCUMENT_BIN_NAME, jsonPath); - expectedObject = ((Map) ((Map) ((List) jsonNodeAsMap.get("example3")).get(2)).get("key21")).get("key23"); + expectedObject = + ((Map) ((Map) ((List) jsonNodeAsMap.get("example3")).get(2)).get("key21")).get("key23"); assertTrue(TestJsonConverters.jsonEquals(objectFromDB, expectedObject)); jsonPath = "$.example3[1].key08[1].key16"; @@ -576,7 +579,8 @@ void testPositiveDelete() { documentClient.delete(TEST_AEROSPIKE_KEY, DOCUMENT_BIN_NAME, jsonPath); try { deletedObjectRead = documentClient.get(TEST_AEROSPIKE_KEY, DOCUMENT_BIN_NAME, jsonPath); - // Check the deleted object does not exist, or that we now have a different object (possible in a list delete) + // Check the deleted object does not exist, or that we now have a different object + // (possible in a list delete) assertTrue(deletedObjectRead == null || !deletedObjectRead.equals(originalObject)); } catch (DocumentApiException ignored) { } @@ -589,7 +593,8 @@ void testPositiveDelete() { documentClient.delete(TEST_AEROSPIKE_KEY, DOCUMENT_BIN_NAME, jsonPath); try { deletedObjectRead = documentClient.get(TEST_AEROSPIKE_KEY, DOCUMENT_BIN_NAME, jsonPath); - // Check the deleted object does not exist, or that we now have a different object (possible in a list delete) + // Check the deleted object does not exist, or that we now have a different object + // (possible in a list delete) assertTrue(deletedObjectRead == null || !deletedObjectRead.equals(originalObject)); } catch (DocumentApiException ignored) { } diff --git a/src/test/java/com/aerospike/documentapi/InsertPutGetTest.java b/src/test/java/com/aerospike/documentapi/InsertPutGetTest.java new file mode 100644 index 0000000..1feb408 --- /dev/null +++ b/src/test/java/com/aerospike/documentapi/InsertPutGetTest.java @@ -0,0 +1,45 @@ +package com.aerospike.documentapi; + +import com.aerospike.client.AerospikeClient; +import com.aerospike.client.Bin; +import com.aerospike.client.Key; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static com.aerospike.documentapi.BaseTestConfig.AEROSPIKE_SERVER_IP; +import static com.aerospike.documentapi.BaseTestConfig.AEROSPIKE_SERVER_PORT; + +class InsertPutGetTest { + + @Test + void test() { + AerospikeClient client = new AerospikeClient(null, AEROSPIKE_SERVER_IP, AEROSPIKE_SERVER_PORT); + Key key = new Key("test", "customer1", 1); + + Map address1 = new HashMap<>(); + address1.put("street", "123 Main St"); + address1.put("city", "Denver"); + address1.put("zip", "80014"); + + Map address2 = new HashMap<>(); + address2.put("street", "222 Smith St"); + address2.put("city", "Atlanta"); + address2.put("zip", "30033"); + + List addresses = Arrays.asList(address1, address2); + client.put(null, key, + new Bin("name", "Joe"), + new Bin("age", 28), + new Bin("addresses", addresses) + ); + + AerospikeDocumentClient docClient = new AerospikeDocumentClient(client); + docClient.put(key, "addresses", "$.[1].zip", "80015"); + Object docResult = docClient.get(key, "addresses", "$.[*].zip"); + System.out.println(docResult); + } +} diff --git a/src/test/java/com/aerospike/documentapi/MultipleBinsTests.java b/src/test/java/com/aerospike/documentapi/MultipleBinsTests.java index 1501ff6..e15e9c4 100644 --- a/src/test/java/com/aerospike/documentapi/MultipleBinsTests.java +++ b/src/test/java/com/aerospike/documentapi/MultipleBinsTests.java @@ -33,8 +33,10 @@ void testMultipleGetOperations() { String jsonPath = "$.authentication.logout.name"; Object objectFromDB = documentClient.get(TEST_AEROSPIKE_KEY, bins, jsonPath); - Object expectedObject1 = ((Map) ((Map) jsonNodeAsMapEvents1.get("authentication")).get("logout")).get("name"); - Object expectedObject2 = ((Map) ((Map) jsonNodeAsMapEvents2.get("authentication")).get("logout")).get("name"); + Object expectedObject1 = + ((Map) ((Map) jsonNodeAsMapEvents1.get("authentication")).get("logout")).get("name"); + Object expectedObject2 = + ((Map) ((Map) jsonNodeAsMapEvents2.get("authentication")).get("logout")).get("name"); Map expectedObjectsCombined = new HashMap<>(); expectedObjectsCombined.put(documentBinName1, expectedObject1); expectedObjectsCombined.put(documentBinName2, expectedObject2); diff --git a/src/test/java/com/aerospike/documentapi/util/TestJsonConverters.java b/src/test/java/com/aerospike/documentapi/util/TestJsonConverters.java index b4530b6..688087c 100644 --- a/src/test/java/com/aerospike/documentapi/util/TestJsonConverters.java +++ b/src/test/java/com/aerospike/documentapi/util/TestJsonConverters.java @@ -15,8 +15,8 @@ public class TestJsonConverters { /** - * Determine whether two JSON objects are equivalent - - * by serializing maps and list in a specific way and then testing serializations to see if they are equal. + * Determine whether two JSON objects are equivalent - by serializing maps and list in a specific way and then + * testing serializations to see if they are equal. */ @SuppressWarnings("unchecked") public static boolean jsonEquals(Object object1, Object object2) {