Skip to content

Bug/fix propdeps plugin not available #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
95b036b
[US642] JSON Patch Query (#1)
piotrdytkowski Jan 27, 2022
02fd39d
[US-642] implement json patch queries (#2)
piotrdytkowski Feb 4, 2022
918c702
Set up CI with Azure Pipelines
gravity9piotr Feb 6, 2022
30e2ba5
[US642] Update project settings (#3)
piotrdytkowski Feb 7, 2022
f690d44
Set up CI with Azure Pipelines (#4)
gravity9piotr Feb 7, 2022
5522d66
[US642] Add gradle release and versioning plugin
piotrdytkowski Feb 7, 2022
ef90fbf
[US642] Add gradle release and versioning plugin (#5)
piotrdytkowski Feb 8, 2022
c6241e0
Merge branch 'master' into master
gravity9piotr Feb 8, 2022
4e525b9
Merge pull request #1 from piotrdytkowski/master
gravity9piotr Feb 8, 2022
fca54f8
[US642] Change pipeline user
piotrdytkowski Feb 8, 2022
2824810
Merge branch 'master' into feature/prepare-release-and-versioning
gravity9piotr Feb 8, 2022
5d141a5
Merge pull request #2 from piotrdytkowski/feature/prepare-release-and…
gravity9piotr Feb 8, 2022
c02ac1e
revert user name
piotrdytkowski Feb 8, 2022
36638c0
Merge pull request #3 from gravity9piotr/revert-user-name
gravity9piotr Feb 8, 2022
8cedcde
[US642] Add gradle properties with version
piotrdytkowski Feb 8, 2022
f8f2e14
[Gradle Release Plugin] - new version commit: '2.0.1-SNAPSHOT'.
piotrdytkowski Feb 8, 2022
53a29f6
[US642] Try checkout instead of script
piotrdytkowski Feb 8, 2022
c1f6371
[US642] Try checking out particular branch
piotrdytkowski Feb 8, 2022
337c73d
[US642] Try persisting credentials in script
piotrdytkowski Feb 8, 2022
0421daf
[US642] Remove persisting credentials
piotrdytkowski Feb 8, 2022
3e2c5b4
[US642] Try to auth and store credentials before branch checkout
piotrdytkowski Feb 8, 2022
6a8d898
[Gradle Release Plugin] - pre tag commit: '2.0.0'.
Feb 8, 2022
f26553d
[US642] Try setting new version in both files
piotrdytkowski Feb 8, 2022
45f0bfc
[Gradle Release Plugin] - pre tag commit: '2.0.1'.
Feb 8, 2022
160c33a
[Gradle Release Plugin] - new version commit: '2.0.2-SNAPSHOT'.
Feb 8, 2022
a2a0049
[Gradle Release Plugin] - pre tag commit: '2.0.1'.
Feb 8, 2022
e727c09
[US642] Try old artifact targetPath and update remove unused version
piotrdytkowski Feb 8, 2022
c267d8c
[Gradle Release Plugin] - pre tag commit: '2.0.2'.
Feb 8, 2022
ac3b2e1
[Gradle Release Plugin] - new version commit: '2.0.3-SNAPSHOT'.
Feb 8, 2022
de0062a
[Gradle Release Plugin] - pre tag commit: '2.0.3'.
Feb 8, 2022
06159d5
[Gradle Release Plugin] - new version commit: '2.0.4-SNAPSHOT'.
Feb 8, 2022
f19ee10
[Gradle Release Plugin] - pre tag commit: '2.0.4'.
Feb 8, 2022
223001e
[Gradle Release Plugin] - new version commit: '2.0.5-SNAPSHOT'.
Feb 8, 2022
3f116c7
[Gradle Release Plugin] - pre tag commit: '2.0.5'.
Feb 8, 2022
3196b14
[Gradle Release Plugin] - new version commit: '2.0.6-SNAPSHOT'.
Feb 8, 2022
05dedef
[Gradle Release Plugin] - pre tag commit: '2.0.6'.
Feb 8, 2022
93adfcd
[Gradle Release Plugin] - new version commit: '2.0.7-SNAPSHOT'.
Feb 8, 2022
bf9935f
[US642] Try a tag to skip ci after version updates in release plugin
piotrdytkowski Feb 8, 2022
e41f950
[Gradle Release Plugin][skip ci] - pre tag commit: '2.0.7'.
Feb 8, 2022
53252cb
[Gradle Release Plugin][skip ci] - new version commit: '2.0.8-SNAPSH…
Feb 8, 2022
18d4b78
[Gradle Release Plugin][skip ci] - pre tag commit: '2.0.8'.
piotrdytkowski Feb 8, 2022
8d0685b
[Gradle Release Plugin][skip ci] - new version commit: '2.0.9-SNAPSH…
piotrdytkowski Feb 8, 2022
9a666d0
[US642] try to publish artifacts
piotrdytkowski Feb 8, 2022
c0ad591
[Gradle Release Plugin][skip ci] - pre tag commit: '2.0.9'.
Feb 8, 2022
6cadae6
[Gradle Release Plugin][skip ci] - new version commit: '2.0.10-SNAPS…
Feb 8, 2022
45b1c18
[US642] Try to publish artifacts
piotrdytkowski Feb 8, 2022
8cb2541
Merge branch 'master' of github.com:gravity9piotr/json-patch
piotrdytkowski Feb 8, 2022
dfef079
[US642] Try separate publish step
piotrdytkowski Feb 8, 2022
b4247f6
[Gradle Release Plugin][skip ci] - pre tag commit: '2.0.10'.
Feb 8, 2022
041d256
[Gradle Release Plugin][skip ci] - new version commit: '2.0.11-SNAPS…
Feb 8, 2022
3861a7c
[US642] Remove signing
piotrdytkowski Feb 8, 2022
dad202a
Merge branch 'master' of github.com:gravity9piotr/json-patch
piotrdytkowski Feb 8, 2022
509362f
[Gradle Release Plugin][skip ci] - pre tag commit: '2.0.11'.
Feb 8, 2022
dd20c26
[Gradle Release Plugin][skip ci] - new version commit: '2.0.12-SNAPS…
Feb 8, 2022
b4c24c0
[US642] Try to add repo id
piotrdytkowski Feb 8, 2022
4f5b1b4
[US642] Try to use repo name instead of id
piotrdytkowski Feb 8, 2022
96ad3f2
[Gradle Release Plugin][skip ci] - pre tag commit: '2.0.12'.
Feb 8, 2022
9c6a39c
[Gradle Release Plugin][skip ci] - new version commit: '2.0.13-SNAPS…
Feb 8, 2022
46d1b52
[Gradle Release Plugin][skip ci] - pre tag commit: '2.0.13'.
Feb 9, 2022
714421d
[Gradle Release Plugin][skip ci] - new version commit: '2.0.14-SNAPS…
Feb 9, 2022
2b336e4
[US642] Try adding basic auth
piotrdytkowski Feb 9, 2022
6ea1b13
[Gradle Release Plugin][skip ci] - pre tag commit: '2.0.14'.
Feb 9, 2022
106797f
[Gradle Release Plugin][skip ci] - new version commit: '2.0.15-SNAPS…
Feb 9, 2022
7352527
[US642] Try to expose maven properties
piotrdytkowski Feb 9, 2022
e97b242
Merge remote-tracking branch 'origin/master'
piotrdytkowski Feb 9, 2022
37fa43d
[Gradle Release Plugin][skip ci] - pre tag commit: '2.0.15'.
Feb 9, 2022
9ccbcb2
[Gradle Release Plugin][skip ci] - new version commit: '2.0.16-SNAPS…
Feb 9, 2022
ac070a4
[Gradle Release Plugin][skip ci] - new version commit: '2.0.16-SNAPS…
Feb 9, 2022
bea55f9
Merge remote-tracking branch 'origin/master'
piotrdytkowski Feb 9, 2022
f27555d
[US642] Remove unused plugin
piotrdytkowski Feb 9, 2022
8f0f12b
[Gradle Release Plugin][skip ci] - pre tag commit: '2.0.16'.
Feb 9, 2022
7d2eaad
[Gradle Release Plugin][skip ci] - new version commit: '2.0.17-SNAPS…
Feb 9, 2022
564a4e1
[US642] Allow raw json path and add test for nested array manipulations
piotrdytkowski Feb 11, 2022
5c5e3b4
Merge pull request #4 from gravity9piotr/feature/handle-json-path-dir…
gravity9piotr Feb 11, 2022
20ecd4c
[Gradle Release Plugin][skip ci] - pre tag commit: '2.0.17'.
Feb 11, 2022
4fd80c3
[Gradle Release Plugin][skip ci] - new version commit: '2.0.18-SNAPS…
Feb 11, 2022
7753715
Return json path errors instead of swallowing them
piotrdytkowski Mar 15, 2022
7bf73bc
Add test for empty array
piotrdytkowski Mar 16, 2022
85ba664
Merge pull request #5 from gravity9piotr/json-path-errors
gravity9piotr Mar 16, 2022
0292442
[Gradle Release Plugin][skip ci] - pre tag commit: '2.0.18'.
Mar 16, 2022
8a04196
[Gradle Release Plugin][skip ci] - new version commit: '2.0.19-SNAPS…
Mar 16, 2022
7b504bc
Hide internal JsonPath exception
piotrdytkowski Mar 24, 2022
b4bdbfd
Merge pull request #6 from gravity9piotr/bug/handle-jsonpath-exceptions
gravity9piotr Mar 25, 2022
b60567a
[Gradle Release Plugin][skip ci] - pre tag commit: '2.0.19'.
Mar 25, 2022
8415df7
[Gradle Release Plugin][skip ci] - new version commit: '2.0.20-SNAPS…
Mar 25, 2022
614dbb4
Remove json patch query, leaving json pointer and json path
piotrdytkowski Mar 25, 2022
e5b1000
Clearer exception for unsupported JPQ syntax
piotrdytkowski Mar 25, 2022
f2ca96c
Update major version due to backwards incompatible changes
piotrdytkowski Apr 20, 2022
4e0a319
Merge pull request #7 from gravity9piotr/feature/remove-query-parsing
gravity9piotr Apr 20, 2022
d3e7452
[Gradle Release Plugin][skip ci] - pre tag commit: '3.0.0'.
Apr 20, 2022
e340719
[Gradle Release Plugin][skip ci] - new version commit: '3.0.1-SNAPSH…
Apr 20, 2022
a442352
#787 JsonPath parsing - getting parentPath and new node name from pro…
Jun 20, 2022
57f9c87
#787 JsonPath parsing - renamed method name
Jun 20, 2022
2fdea67
#787 JsonPath parsing - fixes after review. Added more test cases
Jun 21, 2022
0379a5e
#787 JsonPath parsing - Added test cases for `-` at the end
Jun 21, 2022
0bf0b03
Merge pull request #8 from gravity9piotr/feature/787_json_path_parser
pbugara Jun 21, 2022
7f65374
#787 JsonPath parsing - added throws to java doc
Jun 21, 2022
3a57ce0
Merge pull request #9 from gravity9piotr/feature/787_json_path_parser
pbugara Jun 21, 2022
0b4beb2
[Gradle Release Plugin][skip ci] - pre tag commit: '3.0.1'.
Jun 21, 2022
7263b1b
[Gradle Release Plugin][skip ci] - new version commit: '3.0.2-SNAPSH…
Jun 21, 2022
f1bf677
#807 JsonPointer double slashes validation
Jul 22, 2022
ad576e9
#807 JsonPointer double slashes validation
Jul 22, 2022
a7d8e11
Merge pull request #10 from gravity9piotr/bugfix/807_json_pointer_dou…
pbugara Jul 22, 2022
29730eb
[Gradle Release Plugin][skip ci] - pre tag commit: '3.0.2'.
Jul 22, 2022
b474d44
[Gradle Release Plugin][skip ci] - new version commit: '3.0.3-SNAPSH…
Jul 22, 2022
e440488
Spring gradle propdeps plugin not available
BartekGravity Jun 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[US-642] implement json patch queries (#2)
* [US642] Implement filtering

* [US642] Add filtering tests and query parsing

* [US642] Handle booleans, integers and floating point numbers

* [US642] Add some test cases

* [US642] Handle nested array filter queries

* [US642] Add a couple more tests for an add operation

* [US642] Improve naming - fix review comments

* [US642] Additional tests for add operation

* [US642] Optimize imports
  • Loading branch information
piotrdytkowski authored Feb 4, 2022
commit 02fd39d73a7d24179546a9af491e1100e7287f3a
64 changes: 42 additions & 22 deletions src/main/java/com/github/fge/jsonpatch/AddOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.github.fge.jackson.jsonpointer.JsonPointer;
import com.github.fge.jackson.jsonpointer.ReferenceToken;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;

Expand Down Expand Up @@ -83,23 +79,41 @@ public JsonNode apply(final JsonNode node) throws JsonPatchException {
* Check the parent node: it must exist and be a container (ie an array
* or an object) for the add operation to work.
*/
final int lastSlashIndex = path.lastIndexOf('/');
final String newNodeName = path.substring(lastSlashIndex + 1);
final String pathToParent = path.substring(0, lastSlashIndex);
final String jsonPath = JsonPathParser.tmfStringToJsonPath(pathToParent);
final String fullJsonPath = JsonPathParser.tmfStringToJsonPath(path);
final int lastDotIndex = fullJsonPath.lastIndexOf('.');
final String newNodeName = fullJsonPath.substring(lastDotIndex + 1)
.replace("[", "").replace("]", "");
final String pathToParent = fullJsonPath.substring(0, lastDotIndex);

final DocumentContext nodeContext = JsonPath.parse(node.deepCopy());

final JsonNode parentNode = nodeContext.read(jsonPath);
if (parentNode == null) {
final JsonNode evaluatedJsonParents = nodeContext.read(pathToParent);
if (evaluatedJsonParents == null) {
throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.noSuchParent"));
}
if (!parentNode.isContainerNode()) {
if (!evaluatedJsonParents.isContainerNode()) {
throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.parentNotContainer"));
}

return parentNode.isArray()
? addToArray(nodeContext, jsonPath, newNodeName)
: addToObject(nodeContext, jsonPath, newNodeName);
if (pathToParent.contains("[?(")) { // json filter result is always a list
for (int i = 0; i < evaluatedJsonParents.size(); i++) {
JsonNode parentNode = evaluatedJsonParents.get(i);
if (!parentNode.isContainerNode()) {
throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.parentNotContainer"));
}
DocumentContext containerContext = JsonPath.parse(parentNode);
if (parentNode.isArray()) {
addToArray(containerContext, "$", newNodeName);
} else {
addToObject(containerContext, "$", newNodeName);
}
}
return nodeContext.read("$");
} else {
return evaluatedJsonParents.isArray()
? addToArray(nodeContext, pathToParent, newNodeName)
: addToObject(nodeContext, pathToParent, newNodeName);
}
}

private JsonNode addToArray(final DocumentContext node, String jsonPath, String newNodeName) throws JsonPatchException {
Expand All @@ -108,14 +122,7 @@ private JsonNode addToArray(final DocumentContext node, String jsonPath, String
}

final int size = node.read(jsonPath, JsonNode.class).size();
final int index;
try {
index = Integer.parseInt(newNodeName);
} catch (NumberFormatException ignored) {
throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.notAnIndex"));
}
if (index < 0 || index > size)
throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.noSuchIndex"));
final int index = verifyAndGetArrayIndex(newNodeName, size);

ArrayNode updatedArray = node.read(jsonPath, ArrayNode.class).insert(index, value);
return "$".equals(jsonPath) ? updatedArray : node.set(jsonPath, updatedArray).read("$", JsonNode.class);
Expand All @@ -126,4 +133,17 @@ private JsonNode addToObject(final DocumentContext node, String jsonPath, String
.put(jsonPath, newNodeName, value)
.read("$", JsonNode.class);
}

private int verifyAndGetArrayIndex(String stringIndex, int size) throws JsonPatchException {
int index;
try {
index = Integer.parseInt(stringIndex);
} catch (NumberFormatException ignored) {
throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.notAnIndex"));
}
if (index < 0 || index > size) {
throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.noSuchIndex"));
}
return index;
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/github/fge/jsonpatch/DualPathOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ protected DualPathOperation(final String op, final String from, final String pat
public final void serialize(final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException {
jgen.writeStartObject();
jgen.writeStringField("op", op);
jgen.writeStringField("path", path.toString());
jgen.writeStringField("from", from.toString());
jgen.writeStringField("path", path);
jgen.writeStringField("from", from);
jgen.writeEndObject();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.JsonSerializable;
import com.github.fge.jackson.jsonpointer.JsonPointer;
import com.github.fge.msgsimple.bundle.MessageBundle;
import com.github.fge.msgsimple.load.MessageBundles;
import com.jayway.jsonpath.Configuration;
Expand Down
38 changes: 35 additions & 3 deletions src/main/java/com/github/fge/jsonpatch/JsonPathParser.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,49 @@
package com.github.fge.jsonpatch;

import static com.github.fge.jsonpatch.JsonPatchOperation.BUNDLE;

public class JsonPathParser {

private static final String ARRAY_ELEMENT_REGEX = "\\.(\\d+)\\.";
private static final String ARRAY_ELEMENT_LAST_REGEX = "\\.(\\d+)$";

public static String tmfStringToJsonPath(String path) {
public static String tmfStringToJsonPath(String path) throws JsonPatchException {
if (!path.startsWith("/") && !path.isEmpty()) {
return "$." + path;
}
if ("/".equals(path)) {
return "$";
}
final String jsonPath = "$" + path.replace('/', '.')
final String[] pointerAndQuery = path
.replaceAll("(\\w)\\?", "$1#THIS_IS_SPLIT_PLACEHOLDER#")
.split("#THIS_IS_SPLIT_PLACEHOLDER#", -1);
if (pointerAndQuery.length > 2) {
throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.invalidPathExpression"));
}

final String jsonPath = "$" + pointerAndQuery[0].replace('/', '.')
.replaceAll(ARRAY_ELEMENT_REGEX, ".[$1].")
.replaceAll(ARRAY_ELEMENT_REGEX, ".[$1].") // has to be repeated due to positive lookahead not working properly
.replaceAll(ARRAY_ELEMENT_LAST_REGEX, ".[$1]");
return jsonPath;
final String jsonPathWithQuery = addQueryIfApplicable(jsonPath, pointerAndQuery);
return jsonPathWithQuery;
}

private static String addQueryIfApplicable(String jsonPath, String[] pointerAndQuery) {
if (pointerAndQuery.length == 2) {
String preparedFilter = pointerAndQuery[1]
.replaceAll("]", "] empty false") // add empty false to nested array expressions
.replaceAll("(\\w)=(\\w)", "$1==$2") // replace single equals with double
.replaceAll("==([\\w .]+)", "=='$1'") // surround strings with single quotes
.replaceFirst("\\w+", "@") // jsonpath expression should start with @ as the name of item
.replaceAll("([&|])\\w+", " $1$1 @"); // replace single | and & with doubles
String filterWithBooleansAndNumbers = preparedFilter
.replaceAll("@([\\w.]+)=='(true|false)'", "(@$1==$2 || @$1=='$2')") // prepare a statement for boolean and boolean as string
.replaceAll("@([\\w.]+)=='(\\d+)'", "(@$1==$2 || @$1=='$2')") // prepare a statement for an integer and integer as string
.replaceAll("@([\\w.]+)=='(\\d+\\.\\d+)'", "(@$1==$2 || @$1=='$2')"); // prepare a statement for float and float as string
return jsonPath.replaceFirst("(\\w+)", "$1[?(" + filterWithBooleansAndNumbers + ")]");
} else {
return jsonPath;
}
}
}
1 change: 0 additions & 1 deletion src/main/java/com/github/fge/jsonpatch/MoveOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import com.github.fge.jackson.jsonpointer.JsonPointer;
import com.jayway.jsonpath.JsonPath;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.github.fge.jackson.jsonpointer.JsonPointer;

import java.io.IOException;

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/github/fge/jsonpatch/ReplaceOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.github.fge.jackson.jsonpointer.JsonPointer;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ jsonPatch.noSuchIndex=no such index in target array
jsonPatch.noSuchPath=no such path in target JSON document
jsonPatch.parentNotContainer=parent of path to add to is not a container
jsonPatch.valueTestFailure=value differs from expectations
jsonPatch.invalidPathExpression=invalid path expression
mergePatch.notContainer=value is neither an object or an array (found %s)
81 changes: 81 additions & 0 deletions src/test/java/com/github/fge/jsonpatch/JsonPathParserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.github.fge.jsonpatch;

import org.testng.annotations.Test;

import static org.testng.Assert.*;

public class JsonPathParserTest {

@Test
public void shouldConvertQueryToJsonPath() throws JsonPatchException {
String jsonPointerWithQuery = "/productPrice/prodPriceAlteration?productPrice.name=Regular Price";
String expected = "$.productPrice[?(@.name=='Regular Price')].prodPriceAlteration";
String result = JsonPathParser.tmfStringToJsonPath(jsonPointerWithQuery);
assertEquals(result, expected);
}

@Test
public void shouldConvertArrayPathToJsonPath() throws JsonPatchException {
String jsonPointerWithQuery = "/2/1/-";
String expected = "$.[2].[1].-";
String result = JsonPathParser.tmfStringToJsonPath(jsonPointerWithQuery);
assertEquals(result, expected);
}

@Test
public void shouldConvertBooleans() throws JsonPatchException {
String jsonPointerWithQuery = "/orderItem/quantity?orderItem.productOffering.valid=true&orderItem.product.relatedParty.role=customer";
String expected = "$.orderItem[?((@.productOffering.valid==true || @.productOffering.valid=='true') && @.product.relatedParty.role=='customer')].quantity";
String result = JsonPathParser.tmfStringToJsonPath(jsonPointerWithQuery);
assertEquals(result, expected);
}

@Test
public void shouldConvertFloatingPoint() throws JsonPatchException {
String jsonPointerWithQuery = "/orderItem/quantity?orderItem.productOffering.price=1513.77&orderItem.product.relatedParty.role=customer";
String expected = "$.orderItem[?((@.productOffering.price==1513.77 || @.productOffering.price=='1513.77') && @.product.relatedParty.role=='customer')].quantity";
String result = JsonPathParser.tmfStringToJsonPath(jsonPointerWithQuery);
assertEquals(result, expected);
}

@Test
public void shouldConvertIntegers() throws JsonPatchException {
String jsonPointerWithQuery = "/orderItem/quantity?orderItem.productOffering.id=1513&orderItem.product.relatedParty.role=customer";
String expected = "$.orderItem[?((@.productOffering.id==1513 || @.productOffering.id=='1513') && @.product.relatedParty.role=='customer')].quantity";
String result = JsonPathParser.tmfStringToJsonPath(jsonPointerWithQuery);
assertEquals(result, expected);
}

@Test
public void shouldConvertManyConditions() throws JsonPatchException {
String jsonPointerWithQuery = "/orderItem/quantity?orderItem.product.relatedParty.role=customer&orderItem.product.relatedParty.name=Mary";
String expected = "$.orderItem[?(@.product.relatedParty.role=='customer' && @.product.relatedParty.name=='Mary')].quantity";
String result = JsonPathParser.tmfStringToJsonPath(jsonPointerWithQuery);
assertEquals(result, expected);
}

@Test
public void shouldConvertNestedArrayQuery() throws JsonPatchException {
String jsonPointerWithQuery = "/orderItem/quantity?orderItem.productOffering.id=1513&orderItem.product.relatedParty[?(@.role=='customer' && @.name=='Mary')]";
String expected = "$.orderItem[?((@.productOffering.id==1513 || @.productOffering.id=='1513') && @.product.relatedParty[?(@.role=='customer' && @.name=='Mary')] empty false)].quantity";
String result = JsonPathParser.tmfStringToJsonPath(jsonPointerWithQuery);
assertEquals(result, expected);
}

@Test
public void shouldConvertNestedArrayQueryWhichIsNotLastStatement() throws JsonPatchException {
String jsonPointerWithQuery = "/orderItem/quantity?orderItem.product.relatedParty[?(@.role=='customer' && @.name=='Mary')]&orderItem.productOffering.id=1513";
String expected = "$.orderItem[?(@.product.relatedParty[?(@.role=='customer' && @.name=='Mary')] empty false && (@.productOffering.id==1513 || @.productOffering.id=='1513'))].quantity";
String result = JsonPathParser.tmfStringToJsonPath(jsonPointerWithQuery);
assertEquals(result, expected);
}

@Test
public void shouldConvertFilterQuery() throws JsonPatchException {
String filterQuery = "note[?(@.author=='John Doe')].date";
String expected = "$.note[?(@.author=='John Doe')].date";
String result = JsonPathParser.tmfStringToJsonPath(filterQuery);
assertEquals(result, expected);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import com.github.fge.jsonpatch.JsonPatchOperationTest;

import java.io.IOException;
// TODO extend with JsonPatchOperationTest and uncomment constructor when this test needs to be active, couldn't ignore it otherway
public class AddQueryOperationTest extends Object {

public class AddQueryOperationTest extends JsonPatchOperationTest {

public AddQueryOperationTest() throws IOException {
//super("query/add");
super("query/add");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.github.fge.jsonpatch.query;

import com.github.fge.jsonpatch.JsonPatchOperationTest;

import java.io.IOException;

public class FilterOperationTest extends JsonPatchOperationTest {

public FilterOperationTest() throws IOException {
super("query/filter");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.github.fge.jsonpatch.query;

import com.github.fge.jsonpatch.JsonPatchOperationTest;

import java.io.IOException;

public class IndividualEntityTest extends JsonPatchOperationTest {

public IndividualEntityTest() throws IOException {
super("query/individual");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

import java.io.IOException;

// TODO extend with JsonPatchOperationTest and uncomment constructor when this test needs to be active, couldn't ignore it otherway
public class RemoveQueryOperationTest extends Object {
public class RemoveQueryOperationTest extends JsonPatchOperationTest {

public RemoveQueryOperationTest() throws IOException {
//super("query/remove");
super("query/remove");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

import java.io.IOException;

// TODO extend with JsonPatchOperationTest and uncomment constructor when this test needs to be active, couldn't ignore it otherway
public class ReplaceQueryOperationTest extends Object {
public class ReplaceQueryOperationTest extends JsonPatchOperationTest {

public ReplaceQueryOperationTest() throws IOException {
//super("query/replace");
super("query/replace");
}
}
Loading