Browse Source

Merge branch 'json-path:master' into functionParameterWithNoArgs

pull/990/head
abhishek kumar tiwari 1 year ago committed by GitHub
parent
commit
87bfad030c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 29
      build.gradle
  2. 6
      json-path-assert/build.gradle
  3. 24
      json-path-assert/src/test/java/com/jayway/jsonassert/JsonAssertTest.java
  4. 8
      json-path-assert/src/test/java/com/jayway/jsonpath/matchers/DemoTest.java
  5. 4
      json-path-assert/src/test/java/com/jayway/jsonpath/matchers/HasNoJsonPathTest.java
  6. 12
      json-path-assert/src/test/java/com/jayway/jsonpath/matchers/IsJsonFileTest.java
  7. 12
      json-path-assert/src/test/java/com/jayway/jsonpath/matchers/IsJsonStringTest.java
  8. 12
      json-path-assert/src/test/java/com/jayway/jsonpath/matchers/IsJsonTest.java
  9. 12
      json-path-assert/src/test/java/com/jayway/jsonpath/matchers/JsonPathMatchersTest.java
  10. 9
      json-path-assert/src/test/java/com/jayway/jsonpath/matchers/WithJsonPathTest.java
  11. 4
      json-path-assert/src/test/java/com/jayway/jsonpath/matchers/WithoutJsonPathTest.java
  12. 46
      json-path-web-test/build.gradle
  13. 156
      json-path-web-test/src/main/java/com/jayway/jsonpath/web/bench/Bench.java
  14. 18
      json-path-web-test/src/main/java/com/jayway/jsonpath/web/bench/Result.java
  15. 75
      json-path-web-test/src/main/java/com/jayway/jsonpath/web/boot/Main.java
  16. 86
      json-path-web-test/src/main/java/com/jayway/jsonpath/web/resource/ApiResource.java
  17. 2
      json-path-web-test/src/main/resources/simplelogger.properties
  18. 361
      json-path-web-test/src/main/resources/webapp/index.html
  19. 87
      json-path-web-test/src/main/resources/webapp/js/jsonpath-0.8.0.js
  20. 926
      json-path-web-test/src/main/resources/webapp/json/20k.json
  21. 50469
      json-path-web-test/src/main/resources/webapp/json/citm_catalog.json
  22. 1
      json-path-web-test/src/main/resources/webapp/json/goessner.json
  23. 298
      json-path-web-test/src/main/resources/webapp/json/twitter.json
  24. 100
      json-path-web-test/src/main/resources/webapp/json/webxml.json
  25. 12
      json-path/build.gradle
  26. 2
      json-path/src/test/java/com/jayway/jsonpath/DeepScanTest.java
  27. 10
      json-path/src/test/java/com/jayway/jsonpath/EscapeTest.java
  28. 2
      json-path/src/test/java/com/jayway/jsonpath/EvaluationListenerTest.java
  29. 14
      json-path/src/test/java/com/jayway/jsonpath/FilterCompilerTest.java
  30. 2
      json-path/src/test/java/com/jayway/jsonpath/FilterParseTest.java
  31. 2
      json-path/src/test/java/com/jayway/jsonpath/FilterTest.java
  32. 113
      json-path/src/test/java/com/jayway/jsonpath/GsonJsonProviderTest.java
  33. 163
      json-path/src/test/java/com/jayway/jsonpath/InlineFilterTest.java
  34. 2
      json-path/src/test/java/com/jayway/jsonpath/Issue_487.java
  35. 2
      json-path/src/test/java/com/jayway/jsonpath/Issue_537.java
  36. 6
      json-path/src/test/java/com/jayway/jsonpath/Issue_721.java
  37. 4
      json-path/src/test/java/com/jayway/jsonpath/Issue_762.java
  38. 2
      json-path/src/test/java/com/jayway/jsonpath/Issue_786.java
  39. 2
      json-path/src/test/java/com/jayway/jsonpath/Issue_970.java
  40. 2
      json-path/src/test/java/com/jayway/jsonpath/Issue_973.java
  41. 35
      json-path/src/test/java/com/jayway/jsonpath/JacksonJsonNodeJsonProviderMapperSupportTest.java
  42. 8
      json-path/src/test/java/com/jayway/jsonpath/JacksonJsonNodeJsonProviderTest.java
  43. 3
      json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java
  44. 547
      json-path/src/test/java/com/jayway/jsonpath/JakartaJsonProviderTest.java
  45. 2
      json-path/src/test/java/com/jayway/jsonpath/JsonOrgJsonProviderTest.java
  46. 37
      json-path/src/test/java/com/jayway/jsonpath/JsonProviderTest.java
  47. 69
      json-path/src/test/java/com/jayway/jsonpath/JsonProviderTestObjectMapping.java
  48. 2
      json-path/src/test/java/com/jayway/jsonpath/MapperTest.java
  49. 7
      json-path/src/test/java/com/jayway/jsonpath/MultiPropTest.java
  50. 43
      json-path/src/test/java/com/jayway/jsonpath/OptionsTest.java
  51. 64
      json-path/src/test/java/com/jayway/jsonpath/PathCompilerTest.java
  52. 2
      json-path/src/test/java/com/jayway/jsonpath/PredicateTest.java
  53. 29
      json-path/src/test/java/com/jayway/jsonpath/ProviderInTest.java
  54. 2
      json-path/src/test/java/com/jayway/jsonpath/ReadContextTest.java
  55. 17
      json-path/src/test/java/com/jayway/jsonpath/ReturnTypeTest.java
  56. 2
      json-path/src/test/java/com/jayway/jsonpath/ScientificNotationTest.java
  57. 2
      json-path/src/test/java/com/jayway/jsonpath/TapestryJsonProviderTest.java
  58. 47
      json-path/src/test/java/com/jayway/jsonpath/TestSuppressExceptions.java
  59. 35
      json-path/src/test/java/com/jayway/jsonpath/WriteTest.java
  60. 2
      json-path/src/test/java/com/jayway/jsonpath/internal/JsonContextTest.java
  61. 126
      json-path/src/test/java/com/jayway/jsonpath/internal/UtilsTest.java
  62. 56
      json-path/src/test/java/com/jayway/jsonpath/internal/filter/PatternFlagTest.java
  63. 79
      json-path/src/test/java/com/jayway/jsonpath/internal/filter/RegexpEvaluatorTest.java
  64. 14
      json-path/src/test/java/com/jayway/jsonpath/internal/filter/RelationalOperatorTest.java
  65. 23
      json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue191.java
  66. 2
      json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue234.java
  67. 20
      json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue273.java
  68. 28
      json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue612.java
  69. 12
      json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue629.java
  70. 5
      json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue680.java
  71. 2
      json-path/src/test/java/com/jayway/jsonpath/internal/function/JSONEntityPathFunctionTest.java
  72. 2
      json-path/src/test/java/com/jayway/jsonpath/internal/function/KeySetFunctionTest.java
  73. 112
      json-path/src/test/java/com/jayway/jsonpath/internal/function/NestedFunctionTest.java
  74. 78
      json-path/src/test/java/com/jayway/jsonpath/internal/function/NumericPathFunctionTest.java
  75. 2
      json-path/src/test/java/com/jayway/jsonpath/internal/function/SequentialPathFunctionTest.java
  76. 2
      json-path/src/test/java/com/jayway/jsonpath/internal/path/PathTokenTest.java
  77. 2
      json-path/src/test/java/com/jayway/jsonpath/issue_613.java
  78. 41
      json-path/src/test/java/com/jayway/jsonpath/old/ArraySlicingTest.java
  79. 10
      json-path/src/test/java/com/jayway/jsonpath/old/ComplianceTest.java
  80. 29
      json-path/src/test/java/com/jayway/jsonpath/old/FilterTest.java
  81. 100
      json-path/src/test/java/com/jayway/jsonpath/old/IssuesTest.java
  82. 44
      json-path/src/test/java/com/jayway/jsonpath/old/JsonPathTest.java
  83. 2
      json-path/src/test/java/com/jayway/jsonpath/old/JsonProviderTest.java
  84. 12
      json-path/src/test/java/com/jayway/jsonpath/old/NullHandlingTest.java
  85. 10
      json-path/src/test/java/com/jayway/jsonpath/old/internal/ArrayIndexFilterTest.java
  86. 2
      json-path/src/test/java/com/jayway/jsonpath/old/internal/ArrayPathTokenTest.java
  87. 2
      json-path/src/test/java/com/jayway/jsonpath/old/internal/PredicatePathTokenTest.java
  88. 20
      json-path/src/test/java/com/jayway/jsonpath/old/internal/PropertyPathTokenTest.java
  89. 2
      json-path/src/test/java/com/jayway/jsonpath/old/internal/ScanPathTokenTest.java
  90. 2
      json-path/src/test/java/com/jayway/jsonpath/old/internal/TestInternal3.java
  91. 4
      settings.gradle

29
build.gradle

@ -13,26 +13,24 @@ buildscript {
ext {
libs = [
jsonSmart: 'net.minidev:json-smart:2.5.0',
slf4jApi: 'org.slf4j:slf4j-api:2.0.11',
gson: 'com.google.code.gson:gson:2.10.1',
hamcrest: 'org.hamcrest:hamcrest:2.2',
jsonSmart : 'net.minidev:json-smart:2.5.0',
slf4jApi : 'org.slf4j:slf4j-api:2.0.11',
gson : 'com.google.code.gson:gson:2.10.1',
hamcrest : 'org.hamcrest:hamcrest:2.2',
jacksonDatabind: 'com.fasterxml.jackson.core:jackson-databind:2.16.1',
jettison: 'org.codehaus.jettison:jettison:1.5.4',
jsonOrg: 'org.json:json:20231013',
tapestryJson: 'org.apache.tapestry:tapestry-json:5.8.3',
jakartaJsonP: 'jakarta.json:jakarta.json-api:2.0.2',
jakartaJsonB: 'jakarta.json.bind:jakarta.json.bind-api:2.0.0',
jettison : 'org.codehaus.jettison:jettison:1.5.4',
jsonOrg : 'org.json:json:20231013',
tapestryJson : 'org.apache.tapestry:tapestry-json:5.8.3',
jakartaJsonP : 'jakarta.json:jakarta.json-api:2.0.2',
jakartaJsonB : 'jakarta.json.bind:jakarta.json.bind-api:2.0.0',
test: [
test : [
'commons-io:commons-io:2.15.0',
'junit:junit:4.13.+',
'org.junit.vintage:junit-vintage-engine:5.10.+',
'org.junit.jupiter:junit-jupiter:5.10.1',
'org.assertj:assertj-core:3.25.1',
'org.hamcrest:hamcrest:2.2',
'org.glassfish:jakarta.json:2.0.1',
'org.eclipse:yasson:2.0.4',
//'org.apache.johnzon:johnzon-jsonb:1.2.21',
'org.slf4j:slf4j-simple:2.0.9',
'com.google.code.gson:gson:2.10.1',
'org.hamcrest:hamcrest:2.2',
@ -80,9 +78,6 @@ subprojects {
test {
useJUnitPlatform()
systemProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager")
testLogging {
events "passed", "skipped", "failed"
}
@ -98,7 +93,7 @@ subprojects {
options.addStringOption('Xdoclint:none', '-quiet')
}
if(JavaVersion.current().isJava9Compatible()) {
if (JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
}

6
json-path-assert/build.gradle

@ -1,10 +1,9 @@
description = "Assertions on Json using JsonPath"
jar {
baseName 'json-path-assert'
bnd (
'Implementation-Title': 'json-path-assert', 'Implementation-Version': archiveVersion
bnd(
'Implementation-Title': 'json-path-assert', 'Implementation-Version': archiveVersion
)
}
@ -15,5 +14,4 @@ dependencies {
testImplementation libs.jsonSmart
testImplementation libs.test
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}

24
json-path-assert/src/test/java/com/jayway/jsonassert/JsonAssertTest.java

@ -1,11 +1,12 @@
package com.jayway.jsonassert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.InputStream;
import static com.jayway.jsonassert.JsonAssert.*;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class JsonAssertTest {
@ -52,10 +53,10 @@ public class JsonAssertTest {
}
@Test(expected = AssertionError.class)
@Test
public void has_path() throws Exception {
with(JSON).assertNotDefined("$.store.bicycle[?(@.color == 'red' )]");
assertThrows(AssertionError.class, () -> with(JSON).assertNotDefined("$.store.bicycle[?(@.color == 'red' )]"));
}
@Test
@ -66,10 +67,10 @@ public class JsonAssertTest {
with(JSON).assertThat("$.store.bicycle[?(@.escape == 'Esc\\b\\f\\n\\r\\t\\u002A')]", is(collectionWithSize(equalTo(1))));
}
@Test(expected = AssertionError.class)
@Test
public void failed_error_message() throws Exception {
with(JSON).assertThat("$.store.book[0].category", endsWith("foobar"));
assertThrows(AssertionError.class, () -> with(JSON).assertThat("$.store.book[0].category", endsWith("foobar")));
}
@Test
@ -168,25 +169,26 @@ public class JsonAssertTest {
}
@Test(expected = AssertionError.class)
@Test
public void assert_that_invalid_path_is_thrown() {
JsonAsserter asserter = JsonAssert.with("{\"foo\":\"bar\"}");
asserter.assertEquals("$foo", "bar");
assertThrows(AssertionError.class, () -> asserter.assertEquals("$foo", "bar"));
}
@Test
public void testAssertEqualsInteger() throws Exception {
with(getResourceAsStream("lotto.json")).assertEquals("lotto.winners[0].winnerId", 23);
}
@Test(expected = AssertionError.class)
@Test
public void testAssertEqualsIntegerInvalidExpected() throws Exception {
with(getResourceAsStream("lotto.json")).assertEquals("lotto.winners[0].winnerId", 24);
assertThrows(AssertionError.class, () -> with(getResourceAsStream("lotto.json")).assertEquals("lotto.winners[0].winnerId", 24));
}
@Test(expected = AssertionError.class)
@Test
public void testAssertEqualsIntegerInvalidField() throws Exception {
with(getResourceAsStream("lotto.json")).assertEquals("lotto.winners[0].winnerId1", 24);
assertThrows(AssertionError.class, () -> with(getResourceAsStream("lotto.json")).assertEquals("lotto.winners[0].winnerId1", 24));
}
private InputStream getResourceAsStream(String resourceName) {

8
json-path-assert/src/test/java/com/jayway/jsonpath/matchers/DemoTest.java

@ -1,17 +1,17 @@
package com.jayway.jsonpath.matchers;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.io.File;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.*;
import static com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resource;
import static com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resourceAsFile;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
@Ignore
@Disabled
public class DemoTest {
@Test
public void shouldFailOnJsonString() {

4
json-path-assert/src/test/java/com/jayway/jsonpath/matchers/HasNoJsonPathTest.java

@ -1,10 +1,10 @@
package com.jayway.jsonpath.matchers;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasNoJsonPath;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
public class HasNoJsonPathTest {
private static final String JSON_STRING = "{" +

12
json-path-assert/src/test/java/com/jayway/jsonpath/matchers/IsJsonFileTest.java

@ -5,28 +5,28 @@ import com.jayway.jsonpath.matchers.helpers.StrictParsingConfiguration;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.StringDescription;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.io.File;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.isJsonFile;
import static com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resourceAsFile;
import static com.jayway.jsonpath.matchers.helpers.TestingMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
public class IsJsonFileTest {
private static final File BOOKS_JSON = resourceAsFile("books.json");
private static final File INVALID_JSON = resourceAsFile("invalid.json");
@BeforeClass
@BeforeAll
public static void setupStrictJsonParsing() {
Configuration.setDefaults(new StrictParsingConfiguration());
}
@AfterClass
@AfterAll
public static void setupDefaultJsonParsing() {
Configuration.setDefaults(null);
}

12
json-path-assert/src/test/java/com/jayway/jsonpath/matchers/IsJsonStringTest.java

@ -5,25 +5,25 @@ import com.jayway.jsonpath.matchers.helpers.StrictParsingConfiguration;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.StringDescription;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.isJsonString;
import static com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resource;
import static com.jayway.jsonpath.matchers.helpers.TestingMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
public class IsJsonStringTest {
private static final String BOOKS_JSON = resource("books.json");
@BeforeClass
@BeforeAll
public static void setupStrictJsonParsing() {
Configuration.setDefaults(new StrictParsingConfiguration());
}
@AfterClass
@AfterAll
public static void setupDefaultJsonParsing() {
Configuration.setDefaults(null);
}

12
json-path-assert/src/test/java/com/jayway/jsonpath/matchers/IsJsonTest.java

@ -6,9 +6,9 @@ import com.jayway.jsonpath.matchers.helpers.TestingMatchers;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.StringDescription;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.io.File;
@ -16,8 +16,8 @@ import static com.jayway.jsonpath.matchers.JsonPathMatchers.isJson;
import static com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resource;
import static com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resourceAsFile;
import static com.jayway.jsonpath.matchers.helpers.TestingMatchers.withPathEvaluatedTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
public class IsJsonTest {
private static final String VALID_JSON = resource("example.json");
@ -26,12 +26,12 @@ public class IsJsonTest {
private static final File BOOKS_JSON_FILE = resourceAsFile("books.json");
private static final Object BOOKS_JSON_PARSED = parseJson(BOOKS_JSON_STRING);
@BeforeClass
@BeforeAll
public static void setupStrictJsonParsing() {
Configuration.setDefaults(new StrictParsingConfiguration());
}
@AfterClass
@AfterAll
public static void setupDefaultJsonParsing() {
Configuration.setDefaults(null);
}

12
json-path-assert/src/test/java/com/jayway/jsonpath/matchers/JsonPathMatchersTest.java

@ -4,9 +4,9 @@ import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.ReadContext;
import com.jayway.jsonpath.matchers.helpers.StrictParsingConfiguration;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.List;
@ -15,21 +15,21 @@ import java.util.Map;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.*;
import static com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resource;
import static com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resourceAsFile;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
public class JsonPathMatchersTest {
private static final String BOOKS_JSON = resource("books.json");
private static final String INVALID_JSON = "{ invalid-json }";
private static final File BOOKS_JSON_FILE = resourceAsFile("books.json");
@BeforeClass
@BeforeAll
public static void setupStrictJsonParsing() {
// NOTE: Evaluation depends on the default configuration of JsonPath
Configuration.setDefaults(new StrictParsingConfiguration());
}
@AfterClass
@AfterAll
public static void setupDefaultJsonParsing() {
Configuration.setDefaults(null);
}

9
json-path-assert/src/test/java/com/jayway/jsonpath/matchers/WithJsonPathTest.java

@ -6,7 +6,7 @@ import com.jayway.jsonpath.ReadContext;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.StringDescription;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Collection;
import java.util.List;
@ -14,8 +14,9 @@ import java.util.List;
import static com.jayway.jsonpath.JsonPath.compile;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.withJsonPath;
import static com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resource;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class WithJsonPathTest {
private static final ReadContext BOOKS_JSON = JsonPath.parse(resource("books.json"));
@ -82,9 +83,9 @@ public class WithJsonPathTest {
assertThat(BOOKS_JSON, withJsonPath("$..book[2].title", hasItem("Moby Dick")));
}
@Test(expected = InvalidPathException.class)
@Test
public void shouldFailOnInvalidJsonPath() {
withJsonPath("$[}");
assertThrows(InvalidPathException.class, () -> withJsonPath("$[}"));
}
@Test

4
json-path-assert/src/test/java/com/jayway/jsonpath/matchers/WithoutJsonPathTest.java

@ -2,12 +2,12 @@ package com.jayway.jsonpath.matchers;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.ReadContext;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static com.jayway.jsonpath.JsonPath.compile;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.withoutJsonPath;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
public class WithoutJsonPathTest {
private static final String JSON_STRING = "{" +

46
json-path-web-test/build.gradle

@ -1,46 +0,0 @@
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'application'
description = "Web app that compares different JsonPath implementations."
mainClassName = 'com.jayway.jsonpath.web.boot.Main'
task createBuildInfoFile {
dependsOn compileJava
doLast {
def buildInfoFile = new File("$buildDir/classes/java/main/build-info.properties")
Properties props = new Properties()
props.setProperty('version', project.version.toString())
props.setProperty('timestamp', project.buildTimestamp)
props.store(buildInfoFile.newWriter(), null)
}
}
jar {
dependsOn createBuildInfoFile
baseName 'json-path-web-test'
bnd (
'Implementation-Title': 'json-path-web-test',
'Implementation-Version': version,
'Main-Class': mainClassName
)
}
dependencies {
implementation project(':json-path')
implementation 'commons-io:commons-io:2.4'
implementation libs.slf4jApi
implementation libs.jacksonDatabind
implementation libs.jsonSmart
implementation 'io.fastjson:boon:0.33'
implementation 'com.nebhale.jsonpath:jsonpath:1.2'
implementation 'io.gatling:jsonpath_2.10:0.6.4'
implementation 'org.eclipse.jetty:jetty-server:9.3.0.M1'
implementation 'org.eclipse.jetty:jetty-webapp:9.3.0.M1'
implementation 'org.glassfish.jersey.containers:jersey-container-servlet:2.20'
implementation('org.glassfish.jersey.media:jersey-media-json-jackson:2.20'){
exclude module: 'jackson-annotations:com.fasterxml.jackson.core'
exclude module: 'jackson-core:com.fasterxml.jackson.core'
}
}

156
json-path-web-test/src/main/java/com/jayway/jsonpath/web/bench/Bench.java

@ -1,156 +0,0 @@
package com.jayway.jsonpath.web.bench;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Option;
import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
import io.gatling.jsonpath.JsonPath$;
import org.boon.json.JsonParser;
import org.boon.json.ObjectMapper;
import org.boon.json.implementation.JsonParserCharArray;
import org.boon.json.implementation.ObjectMapperImpl;
import scala.collection.Iterator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Bench {
protected final String json;
protected final String path;
private final boolean optionAsValues;
private final boolean flagWrap;
private final boolean flagSuppress;
private final boolean flagNullLeaf;
private final boolean flagRequireProps;
public Bench(String json, String path, boolean optionAsValues, boolean flagWrap, boolean flagSuppress, boolean flagNullLeaf, boolean flagRequireProps) {
this.json = json;
this.path = path;
this.optionAsValues = optionAsValues;
this.flagWrap = flagWrap;
this.flagSuppress = flagSuppress;
this.flagNullLeaf = flagNullLeaf;
this.flagRequireProps = flagRequireProps;
}
public Result runJayway() {
String result = null;
String error = null;
long time;
Object res = null;
Configuration configuration = Configuration.defaultConfiguration();
if(flagWrap){
configuration = configuration.addOptions(Option.ALWAYS_RETURN_LIST);
}
if(flagSuppress){
configuration = configuration.addOptions(Option.SUPPRESS_EXCEPTIONS);
}
if (!optionAsValues) {
configuration = configuration.addOptions(Option.AS_PATH_LIST);
}
if(flagNullLeaf){
configuration = configuration.addOptions(Option.DEFAULT_PATH_LEAF_TO_NULL);
}
if(flagRequireProps){
configuration = configuration.addOptions(Option.REQUIRE_PROPERTIES);
}
long now = System.currentTimeMillis();
try {
res = JsonPath.using(configuration).parse(json).read(path);
} catch (Exception e) {
error = getError(e);
} finally {
time = System.currentTimeMillis() - now;
if (res instanceof String) {
result = "\"" + res + "\"";
} else if (res instanceof Number) {
result = res.toString();
} else if (res instanceof Boolean) {
result = res.toString();
} else {
result = res != null ? Configuration.defaultConfiguration().jsonProvider().toJson(res) : "null";
}
return new Result("jayway", time, result, error);
}
}
public Result runBoon() {
String result = null;
String error = null;
long time;
Iterator<Object> query = null;
long now = System.currentTimeMillis();
try {
if (!optionAsValues) {
throw new UnsupportedOperationException("Not supported!");
}
io.gatling.jsonpath.JsonPath jsonPath = JsonPath$.MODULE$.compile(path).right().get();
JsonParser jsonParser = new JsonParserCharArray();
Object jsonModel = jsonParser.parse(json);
query = jsonPath.query(jsonModel);
} catch (Exception e) {
error = getError(e);
} finally {
time = System.currentTimeMillis() - now;
if (query != null) {
List<Object> res = new ArrayList<Object>();
while (query.hasNext()) {
res.add(query.next());
}
ObjectMapper mapper = new ObjectMapperImpl();
result = mapper.toJson(res);
}
return new Result("boon", time, result, error);
}
}
public Result runNebhale() {
String result = null;
String error = null;
long time;
Object res = null;
JacksonJsonProvider jacksonProvider = new JacksonJsonProvider();
long now = System.currentTimeMillis();
try {
if (!optionAsValues) {
throw new UnsupportedOperationException("Not supported!");
}
com.nebhale.jsonpath.JsonPath compiled = com.nebhale.jsonpath.JsonPath.compile(path);
res = compiled.read(json, Object.class);
} catch (Exception e) {
error = getError(e);
} finally {
time = System.currentTimeMillis() - now;
result = res != null ? jacksonProvider.toJson(res) : null;
return new Result("nebhale", time, result, error);
}
}
public Map<String, Result> runAll() {
Map<String, Result> res = new HashMap<String, Result>();
res.put("jayway", runJayway());
res.put("boon", runBoon());
res.put("nebhale", runNebhale());
return res;
}
private String getError(Exception e) {
String ex = e.getMessage();
if (ex == null || ex.trim().isEmpty()) {
ex = "Undefined error";
}
return ex;
}
}

18
json-path-web-test/src/main/java/com/jayway/jsonpath/web/bench/Result.java

@ -1,18 +0,0 @@
package com.jayway.jsonpath.web.bench;
import com.jayway.jsonpath.internal.JsonFormatter;
public class Result {
public final String provider;
public final long time;
public final String result;
public final String error;
public Result(String provider, long time, String result, String error) {
this.provider = provider;
this.time = time;
this.result = result != null ? JsonFormatter.prettyPrint(result) : result;
this.error = error;
}
}

75
json-path-web-test/src/main/java/com/jayway/jsonpath/web/boot/Main.java

@ -1,75 +0,0 @@
package com.jayway.jsonpath.web.boot;
import com.jayway.jsonpath.web.resource.ApiResource;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.webapp.WebAppContext;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.servlet.ServletContainer;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws Exception {
String configPort = "8080";
if(args.length > 0){
configPort = args[0];
}
String port = System.getProperty("server.http.port", configPort);
System.out.println("Server started on port: " + port);
Server server = new Server();
server.setConnectors(new Connector[]{createConnector(server, Integer.parseInt(port))});
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.setContextPath("/api");
ServletHolder servletHolder = new ServletHolder(createJerseyServlet());
servletHolder.setInitOrder(1);
context.addServlet(servletHolder, "/*");
WebAppContext webAppContext = new WebAppContext();
webAppContext.setServer(server);
webAppContext.setContextPath("/");
String resourceBase = System.getProperty("resourceBase");
if(resourceBase != null){
webAppContext.setResourceBase(resourceBase);
} else {
webAppContext.setResourceBase(Main.class.getResource("/webapp").toExternalForm());
}
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[]{context, webAppContext});
server.setHandler(handlers);
server.start();
server.join();
}
private static ServerConnector createConnector(Server s, int port){
ServerConnector connector = new ServerConnector(s);
connector.setHost("0.0.0.0");
connector.setPort(port);
return connector;
}
private static ServletContainer createJerseyServlet() throws IOException {
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.register(JacksonFeature.class);
resourceConfig.register(new ApiResource());
return new ServletContainer(resourceConfig);
}
}

86
json-path-web-test/src/main/java/com/jayway/jsonpath/web/resource/ApiResource.java

@ -1,86 +0,0 @@
package com.jayway.jsonpath.web.resource;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.web.bench.Bench;
import com.jayway.jsonpath.web.bench.Result;
import net.minidev.json.JSONStyle;
import net.minidev.json.JSONValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
@Path("/")
@Produces(MediaType.TEXT_HTML)
public class ApiResource {
private static final Logger logger = LoggerFactory.getLogger(ApiResource.class);
static {
JSONValue.COMPRESSION = JSONStyle.LT_COMPRESS;
}
@GET
@Path("/info")
@Produces(MediaType.APPLICATION_JSON)
public Response info() {
Map<String, String> result = new HashMap<String, String>();
try {
ResourceBundle resource = ResourceBundle.getBundle("build-info");
result.put("version", resource.getString("version"));
result.put("timestamp", resource.getString("timestamp"));
} catch (Exception e){
result.put("version", "LOCAL");
result.put("timestamp", "NOW");
}
return Response.ok(result).build();
}
@GET
@Path("/validate")
@Produces(MediaType.APPLICATION_JSON)
public Response validate(@QueryParam("path") String path) {
int result = -1;
try {
JsonPath compiled = JsonPath.compile(path);
result = compiled.isDefinite() ? 0 : 1;
} catch (Exception e) {
}
return Response.ok(Collections.singletonMap("result", result)).build();
}
@POST
@Path("/eval")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
public Response getTemplate(@FormParam("json") String json,
@FormParam("path") String path,
@FormParam("type") String type,
@FormParam("flagWrap") boolean flagWrap,
@FormParam("flagNullLeaf") boolean flagNullLeaf,
@FormParam("flagSuppress") boolean flagSuppress,
@FormParam("flagRequireProps") boolean flagRequireProps) {
boolean value = "VALUE".equalsIgnoreCase(type);
Map<String, Result> resultMap = new Bench(json, path, value, flagWrap, flagSuppress, flagNullLeaf, flagRequireProps).runAll();
return Response.ok(resultMap).build();
}
}

2
json-path-web-test/src/main/resources/simplelogger.properties

@ -1,2 +0,0 @@
org.slf4j.simpleLogger.defaultLogLevel=warn
org.slf4j.simpleLogger.log.com.jayway=debug

361
json-path-web-test/src/main/resources/webapp/index.html

@ -1,361 +0,0 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Jayway JsonPath evaluator</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.js"></script>
<script type="text/javascript" src="js/jsonpath-0.8.0.js"></script>
</head>
<body role="document">
<div class="container">
<h3>Jayway JsonPath Evaluator</h3>
<div style="margin-top: -12px; margin-bottom: 10px;">
<span id="version" style="font-size: xx-small"></span>&nbsp;-&nbsp;<span id="timestamp" style="font-size: xx-small"></span>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<select id="selTemplates" name="template" class="form-control">
<option value="blank"></option>
<option value="goessner.json" selected>Goessner examle</option>
<option value="twitter.json">Twitter API</option>
<option value="webxml.json">Webapp</option>
<option value="20k.json">20k</option>
</select>
</div>
<div class="form-group">
<textarea id="txtJson" name="json" rows="15" class="form-control" placeholder="Select a template above or enter JSON">
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
</textarea>
</div>
<div class="input-group">
<span id="path-status-tool" class="input-group-addon" data-toggle="tooltip" data-placement="top" title="Invalid path"><span id="path-status" class="fa fa-ban"></span></span>
<input id="txtPath" name="path" placeholder="Enter path" autocomplete="off" class="form-control"/>
<span class="input-group-btn">
<button id="submit" class="btn btn-primary" type="button">Go!</button>
</span>
</div>
<br/>
<div class="row">
<div class="col-md-6">
<fieldset>
<legend>JSONPath options</legend>
<div class="radio">
<label>
<input type="radio" name="rbType" value="VALUE" checked/>
Matching values
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="rbType" value="PATH"/>
Normalized path expressions
</label>
</div>
</fieldset>
</div>
<div class="col-md-6">
<fieldset>
<legend>Jayway options</legend>
<div class="checkbox">
<label>
<input type="checkbox" name="flagSuppress" id="cbFlagSuppress" />
Suppress exceptions
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="flagWrap" id="cbFlagWrap" />
Always return result list
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="flagNullLeaf" id="cbFlagNullLeaf" />
Return null for missing leaf
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="flagRequireProps" id="cbFlagRequireProps" />
Require all properties
</label>
</div>
</fieldset>
</div>
</div>
</div>
<div class="col-md-6">
<ul id="tabs" class="nav nav-tabs" data-tabs="tabs">
<li class="active"><a href="#jayway-tab" data-toggle="tab">Jayway</a></li>
<li><a href="#boon-tab" data-toggle="tab">Gatling</a></li>
<li><a href="#nebhale-tab" data-toggle="tab">Nebhale</a></li>
<li><a href="#goessner-tab" data-toggle="tab">Goessner</a></li>
</ul>
<div id="my-tab-content" class="tab-content">
<div class="tab-pane active" id="jayway-tab">
<br/>
<a href="https://github.com/jayway/JsonPath" target="_blank" style="float: right">About implementation...</a>
<span id="jayway-time"></span>&nbsp;millis
<hr/>
<div class="row">
<div class="col-md-12">
<pre id="jayway-res" class="prettyprint result" style="background-color: transparent; border: none;"></pre>
</div>
</div>
<p id="jayway-error" class="bg-danger"></p>
</div>
<div class="tab-pane" id="boon-tab">
<br/>
<a href="https://github.com/gatling/jsonpath" target="_blank" style="float: right">About implementation...</a>
<span id="boon-time"></span>&nbsp;millis
<hr/>
<div class="row">
<div class="col-md-12">
<pre id="boon-res" class="prettyprint result" style="background-color: transparent; border: none;"></pre>
</div>
</div>
<p id="boon-error" class="bg-danger"></p>
</div>
<div class="tab-pane" id="nebhale-tab">
<br/>
<a href="https://github.com/nebhale/JsonPath" target="_blank" style="float: right">About implementation...</a>
<span id="nebhale-time"></span>&nbsp;millis
<hr/>
<div class="row">
<div class="col-md-12">
<pre id="nebhale-res" class="prettyprint result" style="background-color: transparent; border: none;"></pre>
</div>
</div>
<p id="nebhale-error" class="bg-danger"></p>
</div>
<div class="tab-pane" id="goessner-tab">
<br/>
<a href="http://goessner.net/articles/JsonPath/" target="_blank" style="float: right">About implementation...</a>
<span id="goessner-time"></span>&nbsp;millis
<hr/>
<div class="row">
<div class="col-md-12">
<pre id="goessner-res" class="prettyprint result" style="background-color: transparent; border: none;"></pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<script>
function getParameterByName( name ){
var regexS = "[\\?&]"+name+"=([^&#]*)",
regex = new RegExp( regexS ),
results = regex.exec( window.location.href );
if( results == null ){
return null;
} else{
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
}
$( document ).ready(function() {
$.get('/api/info', function(data) {
$("#version").text(data.version);
$("#timestamp").text(data.timestamp);
});
$('#path-status-tool').tooltip({
container: 'body',
delay: 0
});
$('#selTemplates').on('change', function() {
var val = this.value;
$.ajax({
url: "/json/" + val,
success: function(data){
if(data){
data = toJsonString(data);
}
$("#txtJson").val(data);
}
});
});
$('#txtPath').keyup(function(e) {
clearTimeout($.data(this, 'timer'));
if (e.keyCode === 13) {
$('#submit').click();
e.preventDefault();
} else {
$(this).data('timer', setTimeout(checkPath, 500));
}
});
function checkPath() {
var pathString = $("#txtPath").val();
var updateDisplay = function(icon, tooltip){
$('#path-status').removeClass().addClass('fa ' + icon);
$('#path-status-tool').attr('data-original-title', tooltip).tooltip('fixTitle');
};
if(pathString.length ==0){
updateDisplay('fa-ban', 'Invalid path');
return;
}
$.get('/api/validate/?path=' + pathString, function(data) {
if(data){
if(data.result === -1){
updateDisplay('fa-ban', 'Invalid path');
}
else if(data.result === 0){
updateDisplay('fa-bullseye', 'Path is definite');
}
else if(data.result === 1){
updateDisplay('fa-navicon', 'Path is indefinite');
}
}
});
}
$('#submit').on('click', function() {
$('.result').empty();
var json = $('#txtJson').val();
var path = $('#txtPath').val();
var data = {
json: json,
path: path,
type: $('input[name=rbType]:checked').val(),
flagWrap: $('#cbFlagWrap').prop('checked'),
flagNullLeaf: $('#cbFlagNullLeaf').prop('checked'),
flagSuppress: $('#cbFlagSuppress').prop('checked'),
flagRequireProps: $('#cbFlagRequireProps').prop('checked')
}
$.ajax({
url: "/api/eval",
type: 'POST',
dataType: 'json',
data: data,
success: function(data) {
$('#jayway-time').text(data.jayway.time);
$('#jayway-res').hide().empty();
if(data.jayway.error){
$('#jayway-error').text(data.jayway.error).show();
} else {
$('#jayway-error').css( "display", "none")
$('#jayway-res').text(data.jayway.result).fadeIn();
}
$('#boon-time').text(data.boon.time);
$('#boon-res').hide().text(data.boon.result).fadeIn();
if(data.boon.error){
$('#boon-error').text(data.boon.error).show();
} else {
$('#boon-error').css( "display", "none")
}
$('#nebhale-time').text(data.nebhale.time);
$('#nebhale-res').hide().text(data.nebhale.result).fadeIn();
if(data.nebhale.error){
$('#nebhale-error').text(data.nebhale.error).show();
} else {
$('#nebhale-error').css( "display", "none")
}
var start = new Date().getTime();
var res;
try {
res = jsonPath(JSON.parse(json), path, {resultType: $('input[name=rbType]:checked').val() });
res = toJsonString(res);
} catch(err){
res = err.message;
}
var elapsed = new Date().getTime() - start;
$("#goessner-time").text(elapsed);
$("#goessner-res").hide().text(res).fadeIn();
$('.prettyprinted').removeClass('prettyprinted');
prettyPrint();
}
});
});
var path = getParameterByName('path');
if(path !== null){
$("#txtPath").val(path);
$("#submit").click();
}
});
var toJsonString = function(src){
var str = JSON.stringify(src, null, ' ');
if(str){
str = str.replace(/": /g, '" : ');
str = str.replace(/": \[/g, '" : [');
str = str.replace(/": {/g, '" : {');
}
return str;
};
</script>
</html>

87
json-path-web-test/src/main/resources/webapp/js/jsonpath-0.8.0.js

@ -1,87 +0,0 @@
/* JSONPath 0.8.0 - XPath for JSON
*
* Copyright (c) 2007 Stefan Goessner (goessner.net)
* Licensed under the MIT (MIT-LICENSE.txt) licence.
*/
function jsonPath(obj, expr, arg) {
var P = {
resultType: arg && arg.resultType || "VALUE",
result: [],
normalize: function(expr) {
var subx = [];
return expr.replace(/[\['](\??\(.*?\))[\]']/g, function($0,$1){return "[#"+(subx.push($1)-1)+"]";})
.replace(/'?\.'?|\['?/g, ";")
.replace(/;;;|;;/g, ";..;")
.replace(/;$|'?\]|'$/g, "")
.replace(/#([0-9]+)/g, function($0,$1){return subx[$1];});
},
asPath: function(path) {
var x = path.split(";"), p = "$";
for (var i=1,n=x.length; i<n; i++)
p += /^[0-9*]+$/.test(x[i]) ? ("["+x[i]+"]") : ("['"+x[i]+"']");
return p;
},
store: function(p, v) {
if (p) P.result[P.result.length] = P.resultType == "PATH" ? P.asPath(p) : v;
return !!p;
},
trace: function(expr, val, path) {
if (expr) {
var x = expr.split(";"), loc = x.shift();
x = x.join(";");
if (val && val.hasOwnProperty(loc))
P.trace(x, val[loc], path + ";" + loc);
else if (loc === "*")
P.walk(loc, x, val, path, function(m,l,x,v,p) { P.trace(m+";"+x,v,p); });
else if (loc === "..") {
P.trace(x, val, path);
P.walk(loc, x, val, path, function(m,l,x,v,p) { typeof v[m] === "object" && P.trace("..;"+x,v[m],p+";"+m); });
}
else if (/,/.test(loc)) { // [name1,name2,...]
for (var s=loc.split(/'?,'?/),i=0,n=s.length; i<n; i++)
P.trace(s[i]+";"+x, val, path);
}
else if (/^\(.*?\)$/.test(loc)) // [(expr)]
P.trace(P.eval(loc, val, path.substr(path.lastIndexOf(";")+1))+";"+x, val, path);
else if (/^\?\(.*?\)$/.test(loc)) // [?(expr)]
P.walk(loc, x, val, path, function(m,l,x,v,p) { if (P.eval(l.replace(/^\?\((.*?)\)$/,"$1"),v[m],m)) P.trace(m+";"+x,v,p); });
else if (/^(-?[0-9]*):(-?[0-9]*):?([0-9]*)$/.test(loc)) // [start:end:step] phyton slice syntax
P.slice(loc, x, val, path);
}
else
P.store(path, val);
},
walk: function(loc, expr, val, path, f) {
if (val instanceof Array) {
for (var i=0,n=val.length; i<n; i++)
if (i in val)
f(i,loc,expr,val,path);
}
else if (typeof val === "object") {
for (var m in val)
if (val.hasOwnProperty(m))
f(m,loc,expr,val,path);
}
},
slice: function(loc, expr, val, path) {
if (val instanceof Array) {
var len=val.length, start=0, end=len, step=1;
loc.replace(/^(-?[0-9]*):(-?[0-9]*):?(-?[0-9]*)$/g, function($0,$1,$2,$3){start=parseInt($1||start);end=parseInt($2||end);step=parseInt($3||step);});
start = (start < 0) ? Math.max(0,start+len) : Math.min(len,start);
end = (end < 0) ? Math.max(0,end+len) : Math.min(len,end);
for (var i=start; i<end; i+=step)
P.trace(i+";"+expr, val, path);
}
},
eval: function(x, _v, _vname) {
try { return $ && _v && eval(x.replace(/@/g, "_v")); }
catch(e) { throw new SyntaxError("jsonPath: " + e.message + ": " + x.replace(/@/g, "_v").replace(/\^/g, "_a")); }
}
};
var $ = obj;
if (expr && obj && (P.resultType == "VALUE" || P.resultType == "PATH")) {
P.trace(P.normalize(expr).replace(/^\$;/,""), obj, "$");
return P.result.length ? P.result : false;
}
}

926
json-path-web-test/src/main/resources/webapp/json/20k.json

@ -1,926 +0,0 @@
[
{
"id": 0,
"guid": "d7c8d5e2-cfdc-43b9-9bd4-15e8fd344157",
"isActive": true,
"balance": "$3,772.00",
"picture": "http://placehold.it/32x32",
"age": 35,
"name": "Snow Rodriguez",
"gender": "male",
"company": "Applideck",
"email": "snowrodriguez@applideck.com",
"phone": "+1 (867) 551-3944",
"address": "548 Maple Avenue, Russellville, Pennsylvania, 2467",
"about": "Ex aute adipisicing incididunt labore est magna aliquip non consequat fugiat nostrud ex. Occaecat commodo irure ut mollit veniam fugiat esse esse laboris velit officia. Duis cillum aute ipsum sunt elit irure laborum nostrud. Dolor aliquip reprehenderit voluptate enim cupidatat nisi cillum enim quis aute fugiat id consequat.\r\n",
"registered": "1992-04-24T19:03:08 -02:00",
"latitude": -69.347636,
"longitude": 92.197293,
"tags": [
"enim",
"culpa",
"proident",
"duis",
"aute",
"tempor",
"anim"
],
"friends": [
{
"id": 0,
"name": "Garrison Tillman"
},
{
"id": 1,
"name": "Shawn Holman"
},
{
"id": 2,
"name": "Amy Guerra"
}
],
"randomArrayItem": "lemon"
},
{
"id": 1,
"guid": "2b7e2b0a-288f-404e-9fd0-ad2064cc49f4",
"isActive": true,
"balance": "$3,046.00",
"picture": "http://placehold.it/32x32",
"age": 24,
"name": "Phyllis Calhoun",
"gender": "female",
"company": "Olucore",
"email": "phylliscalhoun@olucore.com",
"phone": "+1 (890) 443-2093",
"address": "355 Brighton Avenue, Shrewsbury, Washington, 8719",
"about": "Excepteur magna culpa do exercitation anim cillum ad proident nostrud ex. Voluptate sint pariatur nisi magna et cillum Lorem Lorem in deserunt eu. Proident dolor laborum nisi anim. Veniam aliqua nulla minim adipisicing magna exercitation veniam sint ea minim nulla.\r\n",
"registered": "1996-12-05T15:20:59 -01:00",
"latitude": -19.65876,
"longitude": 168.158924,
"tags": [
"ad",
"exercitation",
"laboris",
"id",
"incididunt",
"nisi",
"non"
],
"friends": [
{
"id": 0,
"name": "Serena Collins"
},
{
"id": 1,
"name": "Carolina Anthony"
},
{
"id": 2,
"name": "Kendra Avery"
}
],
"randomArrayItem": "lemon"
},
{
"id": 2,
"guid": "523d89ac-63aa-4fac-9352-07cbd8f21a6a",
"isActive": true,
"balance": "$1,242.00",
"picture": "http://placehold.it/32x32",
"age": 38,
"name": "Lindsay Stuart",
"gender": "female",
"company": "Papricut",
"email": "lindsaystuart@papricut.com",
"phone": "+1 (859) 589-3940",
"address": "688 Wyckoff Street, Carrizo, California, 6999",
"about": "Do exercitation labore in excepteur laborum eiusmod enim officia proident nulla veniam. Do Lorem dolor eiusmod proident qui in consequat aliqua. Lorem nulla id consequat ea enim ad id exercitation dolor ad dolore.\r\n",
"registered": "1997-01-09T23:08:18 -01:00",
"latitude": 87.910568,
"longitude": 163.037238,
"tags": [
"qui",
"mollit",
"aute",
"et",
"veniam",
"elit",
"labore"
],
"friends": [
{
"id": 0,
"name": "Bullock Hutchinson"
},
{
"id": 1,
"name": "Guthrie Clark"
},
{
"id": 2,
"name": "Elena Delaney"
}
],
"randomArrayItem": "cherry"
},
{
"id": 3,
"guid": "bc7a2767-94e5-4ebc-8f9d-ead42c3e0107",
"isActive": true,
"balance": "$2,533.00",
"picture": "http://placehold.it/32x32",
"age": 33,
"name": "Mcmahon Adams",
"gender": "male",
"company": "Balooba",
"email": "mcmahonadams@balooba.com",
"phone": "+1 (984) 475-3671",
"address": "880 Pilling Street, Omar, Minnesota, 8563",
"about": "Excepteur incididunt commodo veniam enim esse magna. Exercitation dolor cupidatat consequat irure. Ex duis dolor non nostrud duis aliqua enim labore aliquip. Ad qui reprehenderit aute aliquip duis magna aliquip nisi nulla. Cillum ad sint reprehenderit officia id nostrud cillum excepteur cillum ea labore ullamco esse. Laboris sint ut id incididunt Lorem non reprehenderit adipisicing. Id sint laboris deserunt ea.\r\n",
"registered": "2005-03-01T02:26:24 -01:00",
"latitude": 6.359315,
"longitude": 33.053339,
"tags": [
"Lorem",
"ex",
"dolore",
"pariatur",
"officia",
"ipsum",
"dolore"
],
"friends": [
{
"id": 0,
"name": "Mollie Wilcox"
},
{
"id": 1,
"name": "Alta Hall"
},
{
"id": 2,
"name": "Paulette Pollard"
}
],
"randomArrayItem": "lemon"
},
{
"id": 4,
"guid": "9bbe7981-9e4c-4140-a7f4-be8fcae8ae18",
"isActive": true,
"balance": "$2,731.00",
"picture": "http://placehold.it/32x32",
"age": 29,
"name": "Nanette Butler",
"gender": "female",
"company": "Nikuda",
"email": "nanettebutler@nikuda.com",
"phone": "+1 (989) 498-2116",
"address": "637 Colby Court, Whitewater, Vermont, 1992",
"about": "Magna Lorem sit sit duis. Aliqua eiusmod dolor enim est duis nulla in eu deserunt commodo. Sit laboris deserunt sint duis reprehenderit in sunt excepteur proident. Elit ad aliquip deserunt in ad occaecat id elit non commodo adipisicing ullamco magna.\r\n",
"registered": "1995-04-25T05:22:25 -02:00",
"latitude": -45.069546,
"longitude": 83.01566,
"tags": [
"est",
"in",
"nulla",
"ea",
"dolore",
"aliqua",
"deserunt"
],
"friends": [
{
"id": 0,
"name": "Noble Rodgers"
},
{
"id": 1,
"name": "Haley Mayer"
},
{
"id": 2,
"name": "Hudson Gentry"
}
],
"randomArrayItem": "lemon"
},
{
"id": 5,
"guid": "f0449f33-5c39-4a94-a114-e96d466cc9a8",
"isActive": true,
"balance": "$1,769.00",
"picture": "http://placehold.it/32x32",
"age": 26,
"name": "Miranda Thomas",
"gender": "male",
"company": "Softmicro",
"email": "mirandathomas@softmicro.com",
"phone": "+1 (870) 591-2118",
"address": "503 Linden Street, Jackpot, Rhode Island, 419",
"about": "Consequat tempor esse pariatur minim magna ut ut dolor officia anim. Mollit mollit tempor do dolor ad aute proident commodo sit ea minim. Eu et laborum est in. Non exercitation est deserunt do mollit tempor duis. Nisi eu nulla ea cillum minim officia et duis quis sint. Consequat velit cupidatat Lorem sunt do do quis et ullamco. Elit eiusmod consectetur ullamco ea amet sint aute quis ipsum.\r\n",
"registered": "2010-10-07T07:31:46 -02:00",
"latitude": -28.329413,
"longitude": -17.80299,
"tags": [
"fugiat",
"reprehenderit",
"adipisicing",
"culpa",
"quis",
"pariatur",
"deserunt"
],
"friends": [
{
"id": 0,
"name": "Brewer Norton"
},
{
"id": 1,
"name": "Ramona Jacobs"
},
{
"id": 2,
"name": "Russo Hewitt"
}
],
"randomArrayItem": "apple"
},
{
"id": 6,
"guid": "18fb0572-e2b8-4f47-bd71-dc9349396227",
"isActive": true,
"balance": "$3,081.00",
"picture": "http://placehold.it/32x32",
"age": 30,
"name": "Ada Potter",
"gender": "female",
"company": "Melbacor",
"email": "adapotter@melbacor.com",
"phone": "+1 (913) 474-2861",
"address": "947 Sumner Place, Haena, North Dakota, 685",
"about": "Nostrud amet id id qui. Reprehenderit officia duis ad aute ipsum eiusmod excepteur Lorem voluptate. Cillum laborum cillum aliquip duis reprehenderit amet sint non nulla in culpa irure veniam aliqua.\r\n",
"registered": "2008-09-26T03:40:28 -02:00",
"latitude": -11.153539,
"longitude": 115.382908,
"tags": [
"laboris",
"proident",
"dolore",
"sunt",
"ut",
"irure",
"dolor"
],
"friends": [
{
"id": 0,
"name": "Bethany Carroll"
},
{
"id": 1,
"name": "Moody Andrews"
},
{
"id": 2,
"name": "Trujillo Hester"
}
],
"randomArrayItem": "cherry"
},
{
"id": 7,
"guid": "69cc1cdc-2953-4a00-84df-bed00120ab12",
"isActive": true,
"balance": "$2,520.00",
"picture": "http://placehold.it/32x32",
"age": 36,
"name": "Levine Deleon",
"gender": "male",
"company": "Dragbot",
"email": "levinedeleon@dragbot.com",
"phone": "+1 (979) 575-3162",
"address": "902 Elmwood Avenue, Caberfae, Delaware, 4651",
"about": "Laboris nulla velit dolor ex duis pariatur aute est. Incididunt incididunt laborum non culpa. Consequat elit ipsum et sint nisi dolore dolore nisi ut. Quis nostrud ex ad duis. Enim aliquip pariatur deserunt amet est ullamco in. Dolor sunt deserunt id deserunt labore reprehenderit enim ut in consectetur laboris incididunt in nisi. Ipsum sint in ipsum minim ipsum proident commodo excepteur cillum.\r\n",
"registered": "2000-08-15T05:06:23 -02:00",
"latitude": -48.334821,
"longitude": 66.328798,
"tags": [
"nostrud",
"labore",
"ipsum",
"reprehenderit",
"mollit",
"consequat",
"adipisicing"
],
"friends": [
{
"id": 0,
"name": "Jolene Vang"
},
{
"id": 1,
"name": "Diana Frost"
},
{
"id": 2,
"name": "Bobbi Franklin"
}
],
"randomArrayItem": "apple"
},
{
"id": 8,
"guid": "3a6bf80f-273e-40e9-b5b4-d6d7e07e76c6",
"isActive": false,
"balance": "$1,694.00",
"picture": "http://placehold.it/32x32",
"age": 32,
"name": "Sophia Duran",
"gender": "female",
"company": "Magmina",
"email": "sophiaduran@magmina.com",
"phone": "+1 (843) 415-3460",
"address": "133 Norfolk Street, Worcester, Virginia, 3631",
"about": "Lorem occaecat officia proident consectetur sint anim id sit anim. Deserunt veniam aute deserunt proident. Ut cillum aliquip deserunt ipsum Lorem est qui cupidatat. Ipsum irure ullamco do cillum duis est in officia et officia elit nisi dolore cillum. Occaecat eu ad pariatur ad Lorem incididunt exercitation nulla. Adipisicing id mollit labore incididunt eiusmod. Esse voluptate ad cupidatat est commodo velit velit laboris ad fugiat mollit.\r\n",
"registered": "2003-01-12T07:36:55 -01:00",
"latitude": 49.58874,
"longitude": 140.795001,
"tags": [
"nulla",
"officia",
"amet",
"irure",
"voluptate",
"exercitation",
"ad"
],
"friends": [
{
"id": 0,
"name": "Twila Holcomb"
},
{
"id": 1,
"name": "Katy Cruz"
},
{
"id": 2,
"name": "Winnie Savage"
}
],
"randomArrayItem": "apple"
},
{
"id": 9,
"guid": "bf01372f-e27c-4f56-9831-9599cc11a73a",
"isActive": true,
"balance": "$1,087.00",
"picture": "http://placehold.it/32x32",
"age": 37,
"name": "Boyd Tyson",
"gender": "male",
"company": "Skyplex",
"email": "boydtyson@skyplex.com",
"phone": "+1 (913) 438-2918",
"address": "966 Winthrop Street, Weogufka, Massachusetts, 2510",
"about": "Pariatur occaecat eiusmod incididunt elit irure sit enim proident et aute aliquip quis ea exercitation. Cillum et labore est anim sunt. Sint consectetur ullamco exercitation sit consequat laborum exercitation ea dolor deserunt. Proident fugiat ipsum voluptate commodo mollit pariatur commodo veniam eu ex duis nulla. Ex officia qui occaecat duis consectetur. Ullamco fugiat adipisicing quis Lorem velit laborum officia ex veniam id excepteur in.\r\n",
"registered": "2000-12-30T18:33:42 -01:00",
"latitude": 17.222712,
"longitude": 110.698092,
"tags": [
"esse",
"consequat",
"dolor",
"proident",
"Lorem",
"ex",
"ex"
],
"friends": [
{
"id": 0,
"name": "Stout Herring"
},
{
"id": 1,
"name": "Noemi Vincent"
},
{
"id": 2,
"name": "Johnnie Yates"
}
],
"randomArrayItem": "cherry"
},
{
"id": 10,
"guid": "ff535706-ea8c-44fe-b1aa-ae85c3e88931",
"isActive": false,
"balance": "$2,573.00",
"picture": "http://placehold.it/32x32",
"age": 34,
"name": "Lucille Juarez",
"gender": "female",
"company": "Essensia",
"email": "lucillejuarez@essensia.com",
"phone": "+1 (842) 518-3032",
"address": "976 Lexington Avenue, Jacumba, Tennessee, 2110",
"about": "Minim esse in nostrud et dolor ut dolore dolor. Eiusmod sint incididunt id dolore elit eu quis dolor. Reprehenderit occaecat reprehenderit minim aute tempor sit. Voluptate sunt eiusmod sit id cillum magna aliquip aliquip. Magna cillum qui id adipisicing irure quis laboris.\r\n",
"registered": "2002-08-18T00:54:13 -02:00",
"latitude": 23.945548,
"longitude": 34.181728,
"tags": [
"veniam",
"ex",
"aliquip",
"ex",
"ad",
"reprehenderit",
"et"
],
"friends": [
{
"id": 0,
"name": "Norma Weiss"
},
{
"id": 1,
"name": "Elnora Odom"
},
{
"id": 2,
"name": "Jennifer Puckett"
}
],
"randomArrayItem": "lemon"
},
{
"id": 11,
"guid": "30eb71bc-e76e-41eb-90db-b6607b2471b5",
"isActive": true,
"balance": "$3,019.00",
"picture": "http://placehold.it/32x32",
"age": 27,
"name": "Antonia Byers",
"gender": "female",
"company": "Pearlessa",
"email": "antoniabyers@pearlessa.com",
"phone": "+1 (986) 456-2695",
"address": "112 Montieth Street, Hegins, Arkansas, 614",
"about": "Consequat id Lorem pariatur sunt ea veniam anim aliquip amet duis. Minim id nulla est est cupidatat laboris commodo. Et eu magna commodo commodo esse ut deserunt cupidatat ea velit. Sint duis voluptate non amet ea laborum. Dolore ullamco ut Lorem aliquip pariatur laboris. Laborum deserunt Lorem sit eu elit duis exercitation proident sit proident.\r\n",
"registered": "2004-01-17T16:00:50 -01:00",
"latitude": -69.440764,
"longitude": -135.627868,
"tags": [
"adipisicing",
"voluptate",
"incididunt",
"laboris",
"veniam",
"commodo",
"velit"
],
"friends": [
{
"id": 0,
"name": "Melba Fields"
},
{
"id": 1,
"name": "Miles Holden"
},
{
"id": 2,
"name": "Lauren Goff"
}
],
"randomArrayItem": "apple"
},
{
"id": 12,
"guid": "5d1f9fd9-b3a6-4320-ba8a-cb9273bca3e9",
"isActive": false,
"balance": "$1,723.00",
"picture": "http://placehold.it/32x32",
"age": 28,
"name": "Wyatt Douglas",
"gender": "male",
"company": "Paragonia",
"email": "wyattdouglas@paragonia.com",
"phone": "+1 (885) 580-2488",
"address": "674 Gerritsen Avenue, Needmore, Michigan, 608",
"about": "Enim adipisicing ut proident occaecat cupidatat excepteur sint do id aute ad amet laboris est. Sit culpa consequat nisi sunt exercitation ullamco est commodo exercitation fugiat velit. Laboris et sit deserunt commodo exercitation nisi aliqua non incididunt id id. Tempor exercitation aute Lorem anim ad nulla dolor aliqua do dolore.\r\n",
"registered": "1991-09-02T02:08:08 -02:00",
"latitude": 66.105776,
"longitude": 91.843229,
"tags": [
"consectetur",
"sunt",
"ex",
"enim",
"labore",
"esse",
"ut"
],
"friends": [
{
"id": 0,
"name": "Mcpherson Velez"
},
{
"id": 1,
"name": "Cochran Bennett"
},
{
"id": 2,
"name": "Welch Glover"
}
],
"randomArrayItem": "cherry"
},
{
"id": 13,
"guid": "139ebd33-41d1-4a12-aaf0-e2957587ea9f",
"isActive": true,
"balance": "$1,838.00",
"picture": "http://placehold.it/32x32",
"age": 26,
"name": "Leah Downs",
"gender": "female",
"company": "Idealis",
"email": "leahdowns@idealis.com",
"phone": "+1 (878) 537-3328",
"address": "174 Herkimer Court, Hamilton, Indiana, 8465",
"about": "Elit deserunt ipsum exercitation dolor cillum excepteur culpa culpa ut sunt veniam. Elit non ut magna ea nostrud excepteur nisi aliquip pariatur. Veniam culpa officia ea nostrud minim et eiusmod. Sunt aliquip in non pariatur eu dolore aliquip magna. Velit exercitation et nisi deserunt exercitation voluptate Lorem enim elit fugiat adipisicing excepteur aliquip ut. Duis id reprehenderit ullamco commodo nulla nisi officia commodo occaecat sunt tempor veniam. Cillum minim do adipisicing cupidatat anim officia velit elit ea magna nisi do enim reprehenderit.\r\n",
"registered": "1988-08-25T19:07:19 -02:00",
"latitude": -73.977289,
"longitude": -116.135149,
"tags": [
"ex",
"et",
"non",
"commodo",
"cupidatat",
"cupidatat",
"nisi"
],
"friends": [
{
"id": 0,
"name": "Soto Brown"
},
{
"id": 1,
"name": "Henry Conrad"
},
{
"id": 2,
"name": "Marshall Wolf"
}
],
"randomArrayItem": "apple"
},
{
"id": 14,
"guid": "1082a62a-c042-4826-a50a-b5be72a07037",
"isActive": false,
"balance": "$3,349.00",
"picture": "http://placehold.it/32x32",
"age": 29,
"name": "Schneider Durham",
"gender": "male",
"company": "Memora",
"email": "schneiderdurham@memora.com",
"phone": "+1 (882) 421-2055",
"address": "166 Chauncey Street, Coultervillle, Idaho, 8121",
"about": "Aute laboris nisi elit do dolor tempor reprehenderit cillum esse non consectetur nostrud voluptate. Tempor mollit do dolor irure non in deserunt ut proident nisi cupidatat. Anim mollit labore quis nulla nostrud reprehenderit sit aliqua exercitation nisi.\r\n",
"registered": "2003-09-21T21:15:56 -02:00",
"latitude": -56.159995,
"longitude": 4.310579,
"tags": [
"adipisicing",
"ex",
"exercitation",
"aliquip",
"commodo",
"non",
"excepteur"
],
"friends": [
{
"id": 0,
"name": "Jo Lara"
},
{
"id": 1,
"name": "Merrill Gray"
},
{
"id": 2,
"name": "Jacobson Burris"
}
],
"randomArrayItem": "lemon"
},
{
"id": 15,
"guid": "b58c304c-cca9-482c-b2b5-810e8fa15ef6",
"isActive": true,
"balance": "$2,923.00",
"picture": "http://placehold.it/32x32",
"age": 30,
"name": "Shelton Burnett",
"gender": "male",
"company": "Geekola",
"email": "sheltonburnett@geekola.com",
"phone": "+1 (821) 501-3726",
"address": "117 Chase Court, Joes, Alabama, 774",
"about": "Non sit cupidatat laboris deserunt adipisicing nisi ipsum commodo. Labore duis sint eu dolor esse consectetur esse ullamco Lorem id nisi culpa sint. Cillum commodo incididunt occaecat reprehenderit enim aliquip velit. Sit voluptate dolore deserunt magna voluptate laborum fugiat ad. Voluptate ad aliqua ullamco eiusmod. Labore ut non ut reprehenderit enim non.\r\n",
"registered": "1992-10-02T12:42:44 -01:00",
"latitude": -58.765178,
"longitude": -155.109015,
"tags": [
"culpa",
"do",
"do",
"enim",
"minim",
"enim",
"nulla"
],
"friends": [
{
"id": 0,
"name": "Lillie Todd"
},
{
"id": 1,
"name": "Morales Crosby"
},
{
"id": 2,
"name": "Tracie Hamilton"
}
],
"randomArrayItem": "apple"
},
{
"id": 16,
"guid": "1a33e0ff-909e-4e31-b4f7-a6d0d0d72320",
"isActive": false,
"balance": "$1,693.00",
"picture": "http://placehold.it/32x32",
"age": 27,
"name": "Crane Livingston",
"gender": "male",
"company": "Enomen",
"email": "cranelivingston@enomen.com",
"phone": "+1 (990) 563-2727",
"address": "248 Elliott Place, Walland, New Jersey, 8005",
"about": "Culpa anim sunt esse commodo deserunt reprehenderit laboris commodo ullamco Lorem. Tempor veniam officia eiusmod excepteur pariatur quis excepteur qui dolore consequat. Dolore tempor duis occaecat deserunt aute elit ex quis do occaecat et.\r\n",
"registered": "2007-03-09T12:39:06 -01:00",
"latitude": 45.176807,
"longitude": -2.485176,
"tags": [
"ad",
"ea",
"in",
"consequat",
"aute",
"laborum",
"commodo"
],
"friends": [
{
"id": 0,
"name": "Katrina Hoover"
},
{
"id": 1,
"name": "Angeline Farmer"
},
{
"id": 2,
"name": "Perkins Haney"
}
],
"randomArrayItem": "apple"
},
{
"id": 17,
"guid": "e6e7cbf1-e991-4e7b-96b7-bef35f249ffd",
"isActive": true,
"balance": "$2,167.00",
"picture": "http://placehold.it/32x32",
"age": 21,
"name": "Bean Moody",
"gender": "male",
"company": "Terascape",
"email": "beanmoody@terascape.com",
"phone": "+1 (898) 582-2002",
"address": "773 Brighton Court, Kenwood, Missouri, 6928",
"about": "Id consequat cupidatat ex cupidatat eiusmod dolore ea incididunt sunt deserunt. Consequat dolor veniam amet incididunt Lorem exercitation dolore do velit tempor id culpa eiusmod. Occaecat esse est laboris nisi consectetur minim. Exercitation ea nostrud laboris aliqua consectetur aliquip nostrud dolor commodo. Elit officia quis in elit enim cupidatat sit sint deserunt dolore duis.\r\n",
"registered": "1997-10-19T10:30:44 -02:00",
"latitude": 48.493501,
"longitude": -53.665346,
"tags": [
"duis",
"proident",
"eu",
"dolor",
"occaecat",
"sit",
"eu"
],
"friends": [
{
"id": 0,
"name": "Beasley Mcmillan"
},
{
"id": 1,
"name": "Saundra Morales"
},
{
"id": 2,
"name": "Morrow Mcclure"
}
],
"randomArrayItem": "lemon"
},
{
"id": 18,
"guid": "53d4712a-aaad-4cf7-8de9-a0e2422a070c",
"isActive": true,
"balance": "$1,193.00",
"picture": "http://placehold.it/32x32",
"age": 20,
"name": "Hodges Lawson",
"gender": "male",
"company": "Medesign",
"email": "hodgeslawson@medesign.com",
"phone": "+1 (843) 453-3635",
"address": "216 Fairview Place, Balm, Louisiana, 5648",
"about": "Proident aliqua exercitation minim est. Esse veniam sunt dolore laborum dolor minim. Dolor id eiusmod fugiat qui anim incididunt occaecat pariatur non. Ea exercitation incididunt elit non eu.\r\n",
"registered": "2008-01-14T06:12:50 -01:00",
"latitude": 77.014486,
"longitude": 171.670465,
"tags": [
"dolor",
"ullamco",
"minim",
"sunt",
"laborum",
"dolor",
"ex"
],
"friends": [
{
"id": 0,
"name": "Mcconnell Hahn"
},
{
"id": 1,
"name": "King Baker"
},
{
"id": 2,
"name": "Virgie Holt"
}
],
"randomArrayItem": "cherry"
},
{
"id": 19,
"guid": "99db9ee5-bd4c-41f6-9f73-92f5644b7b97",
"isActive": true,
"balance": "$3,744.00",
"picture": "http://placehold.it/32x32",
"age": 40,
"name": "Lancaster Walton",
"gender": "male",
"company": "Codax",
"email": "lancasterwalton@codax.com",
"phone": "+1 (965) 409-3192",
"address": "646 Harwood Place, Bodega, New Hampshire, 606",
"about": "Proident nostrud enim consequat irure. Duis amet incididunt ex do quis consectetur nisi laboris est voluptate esse. Laboris consectetur esse ullamco nostrud aute fugiat ad dolore eiusmod. Sit commodo elit aute Lorem ad deserunt sit est Lorem reprehenderit dolor minim ex.\r\n",
"registered": "2011-03-05T16:51:53 -01:00",
"latitude": -67.193873,
"longitude": 45.464244,
"tags": [
"qui",
"ea",
"laborum",
"voluptate",
"occaecat",
"nisi",
"in"
],
"friends": [
{
"id": 0,
"name": "Zamora Trujillo"
},
{
"id": 1,
"name": "Latisha Fernandez"
},
{
"id": 2,
"name": "Mayo Harris"
}
],
"randomArrayItem": "apple"
},
{
"id": 20,
"guid": "d54147b7-09fe-4dfb-8828-a73a5d2654b9",
"isActive": true,
"balance": "$1,534.00",
"picture": "http://placehold.it/32x32",
"age": 36,
"name": "Lindsay Hawkins",
"gender": "male",
"company": "Isosphere",
"email": "lindsayhawkins@isosphere.com",
"phone": "+1 (957) 416-3291",
"address": "461 Conover Street, Epworth, Wyoming, 2303",
"about": "Enim amet sint minim pariatur aliquip proident fugiat consequat deserunt proident. Do excepteur Lorem velit sint proident ea aute eiusmod ipsum. Laborum id eiusmod do nostrud proident consequat eu fugiat elit nostrud nisi. Id aliqua est aliqua dolore ad id commodo est cillum in ipsum nostrud. Enim anim velit id adipisicing non exercitation dolore proident. Dolor sit amet commodo duis.\r\n",
"registered": "1991-07-10T19:55:25 -02:00",
"latitude": -71.393384,
"longitude": 129.718457,
"tags": [
"nostrud",
"reprehenderit",
"ea",
"elit",
"ipsum",
"cillum",
"nulla"
],
"friends": [
{
"id": 0,
"name": "Bartlett Shaw"
},
{
"id": 1,
"name": "Black Barron"
},
{
"id": 2,
"name": "Nona Mcgee"
}
],
"randomArrayItem": "apple"
},
{
"id": 21,
"guid": "d648f647-adaa-4bbe-9285-344a916f2241",
"isActive": true,
"balance": "$1,387.00",
"picture": "http://placehold.it/32x32",
"age": 22,
"name": "Jewel Mccoy",
"gender": "female",
"company": "Tetak",
"email": "jewelmccoy@tetak.com",
"phone": "+1 (931) 568-2889",
"address": "691 Putnam Avenue, Nettie, Arizona, 7175",
"about": "Enim proident occaecat culpa cupidatat exercitation aute ullamco aliquip id in et ea sit enim. Id Lorem veniam minim laborum labore minim fugiat eu anim. Eiusmod esse magna sunt ea. Proident deserunt dolore consequat mollit culpa laboris. Tempor veniam fugiat eu aliqua. Sint velit consequat in tempor velit non ullamco consequat duis dolore mollit cupidatat in consectetur. Culpa consequat et non nostrud amet fugiat ea do sit est reprehenderit incididunt aute.\r\n",
"registered": "2013-09-21T12:52:13 -02:00",
"latitude": 12.704629,
"longitude": 96.065025,
"tags": [
"irure",
"aliqua",
"excepteur",
"elit",
"occaecat",
"nostrud",
"dolore"
],
"friends": [
{
"id": 0,
"name": "Ida Harvey"
},
{
"id": 1,
"name": "Ora Santana"
},
{
"id": 2,
"name": "Lynnette Bullock"
}
],
"randomArrayItem": "lemon"
}
]

50469
json-path-web-test/src/main/resources/webapp/json/citm_catalog.json

File diff suppressed because it is too large Load Diff

1
json-path-web-test/src/main/resources/webapp/json/goessner.json

@ -1 +0,0 @@
{ "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ], "bicycle": { "color": "red", "price": 19.95 } }, "expensive": 10 }

298
json-path-web-test/src/main/resources/webapp/json/twitter.json

@ -1,298 +0,0 @@
{"completed_in": 0.072, "max_id": 336448826225328128, "max_id_str": "336448826225328128", "next_page": "?page=2&max_id=336448826225328128&q=gatling", "page": 1, "query": "gatling", "refresh_url": "?since_id=336448826225328128&q=gatling", "results": [
{
"created_at": "Mon, 20 May 2013 11:50:25 +0000",
"from_user": "anna_gatling",
"from_user_id": 1237619628,
"from_user_id_str": "1237619628",
"from_user_name": "Anna Gatling",
"geo": null,
"id": 336448826225328128,
"id_str": "336448826225328128",
"iso_language_code": "en",
"metadata": {
"result_type": "recent"
},
"profile_image_url": "http:\/\/a0.twimg.com\/profile_images\/3402698946\/bebb3fcb7a7a3977a69c30797cfce5db_normal.jpeg",
"profile_image_url_https": "https:\/\/si0.twimg.com\/profile_images\/3402698946\/bebb3fcb7a7a3977a69c30797cfce5db_normal.jpeg",
"source": "&lt;a href=&quot;http:\/\/twitter.com\/download\/iphone&quot;&gt;Twitter for iPhone&lt;\/a&gt;",
"text": "Last Monday of 6th grade yayyyyy"
},
{
"created_at": "Mon, 20 May 2013 11:49:40 +0000",
"from_user": "ddnn_",
"from_user_id": 482530993,
"from_user_id_str": "482530993",
"from_user_name": "D'\u306e\u7d14\u60c5",
"geo": null,
"id": 336448635355144192,
"id_str": "336448635355144192",
"iso_language_code": "tl",
"metadata": {
"result_type": "recent"
},
"profile_image_url": "http:\/\/a0.twimg.com\/profile_images\/3676715268\/74fa7666ffce02296cc7dfa25f6a8f9c_normal.png",
"profile_image_url_https": "https:\/\/si0.twimg.com\/profile_images\/3676715268\/74fa7666ffce02296cc7dfa25f6a8f9c_normal.png",
"source": "&lt;a href=&quot;http:\/\/m.ubersocial.com&quot;&gt;UberSocial Mobile&lt;\/a&gt;",
"text": "@Arc46_ gatling gun... as in minigun or what?",
"to_user": "Arc46_",
"to_user_id": 336528266,
"to_user_id_str": "336528266",
"to_user_name": "SamuelJunioPradipta",
"in_reply_to_status_id": 336448069233172480,
"in_reply_to_status_id_str": "336448069233172480"
},
{
"created_at": "Mon, 20 May 2013 11:48:56 +0000",
"from_user": "FonshudelSur",
"from_user_id": 300933633,
"from_user_id_str": "300933633",
"from_user_name": "Fonshu",
"geo": null,
"id": 336448452076634113,
"id_str": "336448452076634113",
"iso_language_code": "es",
"metadata": {
"result_type": "recent"
},
"profile_image_url": "http:\/\/a0.twimg.com\/profile_images\/3654066775\/8da1e0e3f2d9ef89f34ac66993bb8836_normal.jpeg",
"profile_image_url_https": "https:\/\/si0.twimg.com\/profile_images\/3654066775\/8da1e0e3f2d9ef89f34ac66993bb8836_normal.jpeg",
"source": "&lt;a href=&quot;http:\/\/www.tweetdeck.com&quot;&gt;TweetDeck&lt;\/a&gt;",
"text": "@IsaraMiau Y tengo que currarme un cosplay para ir del patriota mecanizado con la gatling steampunk, que es DE LO MEJOR &lt;3",
"to_user": "FonshudelSur",
"to_user_id": 300933633,
"to_user_id_str": "300933633",
"to_user_name": "Fonshu",
"in_reply_to_status_id": 336448304835608576,
"in_reply_to_status_id_str": "336448304835608576"
},
{
"created_at": "Mon, 20 May 2013 11:47:25 +0000",
"from_user": "Arc46_",
"from_user_id": 336528266,
"from_user_id_str": "336528266",
"from_user_name": "SamuelJunioPradipta",
"geo": null,
"id": 336448069233172480,
"id_str": "336448069233172480",
"iso_language_code": "en",
"metadata": {
"result_type": "recent"
},
"profile_image_url": "http:\/\/a0.twimg.com\/profile_images\/3684084503\/2e880c5f9b9d7d6030d6d972feb9f5c4_normal.jpeg",
"profile_image_url_https": "https:\/\/si0.twimg.com\/profile_images\/3684084503\/2e880c5f9b9d7d6030d6d972feb9f5c4_normal.jpeg",
"source": "&lt;a href=&quot;http:\/\/www.tweetdeck.com&quot;&gt;TweetDeck&lt;\/a&gt;",
"text": "Something like Gatling gun, Bazooka RT @ddnn_: what are you exactly trying to make?"
},
{
"created_at": "Mon, 20 May 2013 11:37:49 +0000",
"from_user": "anna_gatling",
"from_user_id": 1237619628,
"from_user_id_str": "1237619628",
"from_user_name": "Anna Gatling",
"geo": null,
"id": 336445653662191616,
"id_str": "336445653662191616",
"iso_language_code": "en",
"metadata": {
"result_type": "recent"
},
"profile_image_url": "http:\/\/a0.twimg.com\/profile_images\/3402698946\/bebb3fcb7a7a3977a69c30797cfce5db_normal.jpeg",
"profile_image_url_https": "https:\/\/si0.twimg.com\/profile_images\/3402698946\/bebb3fcb7a7a3977a69c30797cfce5db_normal.jpeg",
"source": "&lt;a href=&quot;http:\/\/twitter.com\/download\/iphone&quot;&gt;Twitter for iPhone&lt;\/a&gt;",
"text": "Mondays&lt;"
},
{
"created_at": "Mon, 20 May 2013 11:29:57 +0000",
"from_user": "GATLING_FIGHTER",
"from_user_id": 1184500015,
"from_user_id_str": "1184500015",
"from_user_name": "M134 \u307f\u306b-\u304c\u3093",
"geo": null,
"id": 336443676270157826,
"id_str": "336443676270157826",
"iso_language_code": "ja",
"metadata": {
"result_type": "recent"
},
"profile_image_url": "http:\/\/a0.twimg.com\/profile_images\/3607829622\/68059740f01d6532bc876e2e7ffb84d0_normal.jpeg",
"profile_image_url_https": "https:\/\/si0.twimg.com\/profile_images\/3607829622\/68059740f01d6532bc876e2e7ffb84d0_normal.jpeg",
"source": "&lt;a href=&quot;http:\/\/theworld09.com\/&quot;&gt;TheWorld\u2800&lt;\/a&gt;",
"text": "@Orz619 \u4f55\u3067\u3059\u3063\u3066\uff01\uff1f",
"to_user": "Orz619",
"to_user_id": 1393895851,
"to_user_id_str": "1393895851",
"to_user_name": "\u3050\u3063\u3055\u3093@\u9ed2\u732b\u306f\u53f7\u54ed\u3057\u3066\u3044\u307e\u3059\u3088\u3002",
"in_reply_to_status_id": 336443439870779394,
"in_reply_to_status_id_str": "336443439870779394"
},
{
"created_at": "Mon, 20 May 2013 11:29:48 +0000",
"from_user": "GATLING_FIGHTER",
"from_user_id": 1184500015,
"from_user_id_str": "1184500015",
"from_user_name": "M134 \u307f\u306b-\u304c\u3093",
"geo": null,
"id": 336443634872360960,
"id_str": "336443634872360960",
"iso_language_code": "ja",
"metadata": {
"result_type": "recent"
},
"profile_image_url": "http:\/\/a0.twimg.com\/profile_images\/3607829622\/68059740f01d6532bc876e2e7ffb84d0_normal.jpeg",
"profile_image_url_https": "https:\/\/si0.twimg.com\/profile_images\/3607829622\/68059740f01d6532bc876e2e7ffb84d0_normal.jpeg",
"source": "&lt;a href=&quot;http:\/\/theworld09.com\/&quot;&gt;TheWorld\u2800&lt;\/a&gt;",
"text": "RT @Orz619: \u307b\u3093\u304d\u3067\u30b9\u30d1\u30d6\u30ed\u3057\u3088\u3046\u304b\u3068\u691c\u8a0e\u4e2dw"
},
{
"created_at": "Mon, 20 May 2013 10:46:41 +0000",
"from_user": "Gatling_gun_k",
"from_user_id": 1126180920,
"from_user_id_str": "1126180920",
"from_user_name": "\uac1c\ud2c0\ub9c1 \uae30\uad00\ucd1d",
"geo": null,
"id": 336432787248787456,
"id_str": "336432787248787456",
"iso_language_code": "ko",
"metadata": {
"result_type": "recent"
},
"profile_image_url": "http:\/\/a0.twimg.com\/profile_images\/3171674022\/d318e014542845396c11662986b4285d_normal.png",
"profile_image_url_https": "https:\/\/si0.twimg.com\/profile_images\/3171674022\/d318e014542845396c11662986b4285d_normal.png",
"source": "&lt;a href=&quot;http:\/\/twittbot.net\/&quot;&gt;twittbot.net&lt;\/a&gt;",
"text": "\ud0c0\ud0c0\ud0c0\ud0c0\ud0c0\ud0c0\ud0c0\ud0c0\ud0c0\ud0c0\ud0c0\ud0c0\ud0c0\ud0c0!!"
},
{
"created_at": "Mon, 20 May 2013 10:22:40 +0000",
"from_user": "slam_gatling",
"from_user_id": 1316243516,
"from_user_id_str": "1316243516",
"from_user_name": "SxOxE",
"geo": null,
"id": 336426741893578754,
"id_str": "336426741893578754",
"iso_language_code": "ja",
"metadata": {
"result_type": "recent"
},
"profile_image_url": "http:\/\/a0.twimg.com\/profile_images\/3606289395\/106dee12ccd2fb0bca99ba4b85304d54_normal.jpeg",
"profile_image_url_https": "https:\/\/si0.twimg.com\/profile_images\/3606289395\/106dee12ccd2fb0bca99ba4b85304d54_normal.jpeg",
"source": "&lt;a href=&quot;http:\/\/twitter.com\/&quot;&gt;web&lt;\/a&gt;",
"text": "\u59b9\u304cHUNTER\u00d7HUNTER\u3092\u8aad\u3093\u3067\u308b\u305b\u3044\u304b\u3001\u4ffa\u3082\u4e2d\u5b66\u4ee5\u6765\u4e45\u3005\u306b\u30cf\u30de\u3063\u305f\u3002\u6697\u9ed2\u5927\u9678\u7de8\u304c\u3069\u3046\u306a\u308b\u304b\u6c17\u306b\u306a\u308b\u3051\u3069\u3001\u5927\u66ae\u7dad\u4eba\u307f\u305f\u3044\u306b\u8a71\u3092\u30c7\u30ab\u304f\u3057\u3059\u304e\u3066\u53ce\u96c6\u3064\u304b\u306a\u304f\u306a\u308b\u53ef\u80fd\u6027\u3082\u5fae\u30ec\u5b58\u3002\u3042\u3068\u30af\u30e9\u30d4\u30ab\u304c\u4eca\u5f8c\u3069\u3046\u95a2\u308f\u3063\u3066\u304f\u308b\u306e\u304b\u3082\u6c17\u306b\u306a\u308b\u3068\u3053\u308d\u3002"
},
{
"created_at": "Mon, 20 May 2013 09:46:45 +0000",
"from_user": "Gatling_gun_k",
"from_user_id": 1126180920,
"from_user_id_str": "1126180920",
"from_user_name": "\uac1c\ud2c0\ub9c1 \uae30\uad00\ucd1d",
"geo": null,
"id": 336417701356507136,
"id_str": "336417701356507136",
"iso_language_code": "ko",
"metadata": {
"result_type": "recent"
},
"profile_image_url": "http:\/\/a0.twimg.com\/profile_images\/3171674022\/d318e014542845396c11662986b4285d_normal.png",
"profile_image_url_https": "https:\/\/si0.twimg.com\/profile_images\/3171674022\/d318e014542845396c11662986b4285d_normal.png",
"source": "&lt;a href=&quot;http:\/\/twittbot.net\/&quot;&gt;twittbot.net&lt;\/a&gt;",
"text": "\ud22c\ud22c\ud22c\ud22c\ud22c\ud22c\ud22c\ud22c\ud22c\ud22c\ud22c\ud22c\ud22c\ud22c\ud22c!!"
},
{
"created_at": "Mon, 20 May 2013 09:17:47 +0000",
"from_user": "Gatling_gun_k",
"from_user_id": 1126180920,
"from_user_id_str": "1126180920",
"from_user_name": "\uac1c\ud2c0\ub9c1 \uae30\uad00\ucd1d",
"geo": null,
"id": 336410413707169792,
"id_str": "336410413707169792",
"iso_language_code": "ko",
"metadata": {
"result_type": "recent"
},
"profile_image_url": "http:\/\/a0.twimg.com\/profile_images\/3171674022\/d318e014542845396c11662986b4285d_normal.png",
"profile_image_url_https": "https:\/\/si0.twimg.com\/profile_images\/3171674022\/d318e014542845396c11662986b4285d_normal.png",
"source": "&lt;a href=&quot;http:\/\/twittbot.net\/&quot;&gt;twittbot.net&lt;\/a&gt;",
"text": "\ub69c\ub450\ub450\ub450\ub457\ub450\ub450\ub450\ub450\ub450\ub450\ub450\ub450\ub450\ub450!!"
},
{
"created_at": "Mon, 20 May 2013 09:03:00 +0000",
"from_user": "Rebelzonderrede",
"from_user_id": 983435376,
"from_user_id_str": "983435376",
"from_user_name": "Rebel South",
"geo": null,
"id": 336406693384708096,
"id_str": "336406693384708096",
"iso_language_code": "nl",
"metadata": {
"result_type": "recent"
},
"profile_image_url": "http:\/\/a0.twimg.com\/profile_images\/2920503711\/6db32e22de8ee8efa92ba1e16ef341b6_normal.jpeg",
"profile_image_url_https": "https:\/\/si0.twimg.com\/profile_images\/2920503711\/6db32e22de8ee8efa92ba1e16ef341b6_normal.jpeg",
"source": "&lt;a href=&quot;http:\/\/www.tweetdeck.com&quot;&gt;TweetDeck&lt;\/a&gt;",
"text": "20-5-1874: Sterfdag Alexander B. Dyer, Gen vd Unie. 1e Generaal die aanschaf Gatling gun nastreefde #amerikaanseburgeroorlog"
},
{
"created_at": "Mon, 20 May 2013 08:45:00 +0000",
"from_user": "MahdayMayday",
"from_user_id": 896598301,
"from_user_id_str": "896598301",
"from_user_name": "C H E ' N G A P !",
"geo": null,
"id": 336402162995310592,
"id_str": "336402162995310592",
"iso_language_code": "in",
"metadata": {
"result_type": "recent"
},
"profile_image_url": "http:\/\/a0.twimg.com\/profile_images\/3089084467\/b5406e2a17e115108d798220ef872e59_normal.jpeg",
"profile_image_url_https": "https:\/\/si0.twimg.com\/profile_images\/3089084467\/b5406e2a17e115108d798220ef872e59_normal.jpeg",
"source": "&lt;a href=&quot;http:\/\/twitter.com\/&quot;&gt;web&lt;\/a&gt;",
"text": "RT @mnhfz92: @MahdayMayday ah ye..bg Gomu Gomu no Elephant Gatling kang",
"in_reply_to_status_id": 336401088506900480,
"in_reply_to_status_id_str": "336401088506900480"
},
{
"created_at": "Mon, 20 May 2013 08:43:55 +0000",
"from_user": "mnhfz92",
"from_user_id": 282901250,
"from_user_id_str": "282901250",
"from_user_name": "Nor Hafiz",
"geo": null,
"id": 336401891959402496,
"id_str": "336401891959402496",
"iso_language_code": "in",
"metadata": {
"result_type": "recent"
},
"profile_image_url": "http:\/\/a0.twimg.com\/profile_images\/2661900827\/f41fc3f51c58daac67f1aa481de43819_normal.jpeg",
"profile_image_url_https": "https:\/\/si0.twimg.com\/profile_images\/2661900827\/f41fc3f51c58daac67f1aa481de43819_normal.jpeg",
"source": "&lt;a href=&quot;http:\/\/twitter.com\/&quot;&gt;web&lt;\/a&gt;",
"text": "@MahdayMayday ah ye..bg Gomu Gomu no Elephant Gatling kang",
"to_user": "MahdayMayday",
"to_user_id": 896598301,
"to_user_id_str": "896598301",
"to_user_name": "C H E ' N G A P !",
"in_reply_to_status_id": 336401088506900480,
"in_reply_to_status_id_str": "336401088506900480"
},
{
"created_at": "Mon, 20 May 2013 08:00:00 +0000",
"from_user": "origichara_bot",
"from_user_id": 410573195,
"from_user_id_str": "410573195",
"from_user_name": "\u307f\u3093\u306a\u306e\u30aa\u30ea\u30ad\u30e3\u30e9\u7d39\u4ecbbot",
"geo": null,
"id": 336390837846020096,
"id_str": "336390837846020096",
"iso_language_code": "ja",
"metadata": {
"result_type": "recent"
},
"profile_image_url": "http:\/\/a0.twimg.com\/profile_images\/1634960810\/_____bot_normal.jpg",
"profile_image_url_https": "https:\/\/si0.twimg.com\/profile_images\/1634960810\/_____bot_normal.jpg",
"source": "&lt;a href=&quot;http:\/\/twittbot.net\/&quot;&gt;twittbot.net&lt;\/a&gt;",
"text": "\u300c\u6551\u4e16\u4e3b(\u30e1\u30b7\u30a2)\u3068\u3088\u3079\u3001\u3044\u3044\u306a\uff1f\u300d\u300c\u9ed9\u308c\u5909\u614b\u5909\u4eba\u30b1\u30df\u30ab\u30eb\u30d6\u30ec\u30a4\u30f3\u5973\u304c\u3002\u79c1\u3060\u3063\u3066\u5143\u306f\u4eba\u9593\u3060\u300d\uff0f\u516b\u30f6\u5cf0\u81e8\u592a\u90ce\uff08\u7537\uff6515\u6b73\u30fb\u81ea\u79f0\u6551\u4e16\u4e3b\u306e\u4e2d\u4e8c\u75c5\u30cf\u30a4\u30ab\u30e9\u5c11\u5e74\uff09http:\/\/t.co\/FS7av2d077"
}
], "results_per_page": 15, "since_id": 0, "since_id_str": "0"}

100
json-path-web-test/src/main/resources/webapp/json/webxml.json

@ -1,100 +0,0 @@
{"web-app": {
"servlet": [
{
"servlet-name": "cofaxCDS",
"servlet-class": "org.cofax.cds.CDSServlet",
"init-param": {
"configGlossary:installationAt": "Philadelphia, PA",
"configGlossary:adminEmail": "ksm@pobox.com",
"configGlossary:poweredBy": "Cofax",
"configGlossary:poweredByIcon": "/images/cofax.gif",
"configGlossary:staticPath": "/content/static",
"templateProcessorClass": "org.cofax.WysiwygTemplate",
"templateLoaderClass": "org.cofax.FilesTemplateLoader",
"templatePath": "templates",
"templateOverridePath": "",
"defaultListTemplate": "listTemplate.htm",
"defaultFileTemplate": "articleTemplate.htm",
"useJSP": false,
"jspListTemplate": "listTemplate.jsp",
"jspFileTemplate": "articleTemplate.jsp",
"cachePackageTagsTrack": 200,
"cachePackageTagsStore": 200,
"cachePackageTagsRefresh": 60,
"cacheTemplatesTrack": 100,
"cacheTemplatesStore": 50,
"cacheTemplatesRefresh": 15,
"cachePagesTrack": 200,
"cachePagesStore": 100,
"cachePagesRefresh": 10,
"cachePagesDirtyRead": 10,
"searchEngineListTemplate": "forSearchEnginesList.htm",
"searchEngineFileTemplate": "forSearchEngines.htm",
"searchEngineRobotsDb": "WEB-INF/robots.db",
"useDataStore": true,
"dataStoreClass": "org.cofax.SqlDataStore",
"redirectionClass": "org.cofax.SqlRedirection",
"dataStoreName": "cofax",
"dataStoreDriver": "com.microsoft.jdbc.sqlserver.SQLServerDriver",
"dataStoreUrl": "jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon",
"dataStoreUser": "sa",
"dataStorePassword": "dataStoreTestQuery",
"dataStoreTestQuery": "SET NOCOUNT ON;select test='test';",
"dataStoreLogFile": "/usr/local/tomcat/logs/datastore.log",
"dataStoreInitConns": 10,
"dataStoreMaxConns": 100,
"dataStoreConnUsageLimit": 100,
"dataStoreLogLevel": "debug",
"maxUrlLength": 500
}
},
{
"servlet-name": "cofaxEmail",
"servlet-class": "org.cofax.cds.EmailServlet",
"init-param": {
"mailHost": "mail1",
"mailHostOverride": "mail2"
}
},
{
"servlet-name": "cofaxAdmin",
"servlet-class": "org.cofax.cds.AdminServlet"
},
{
"servlet-name": "fileServlet",
"servlet-class": "org.cofax.cds.FileServlet"
},
{
"servlet-name": "cofaxTools",
"servlet-class": "org.cofax.cms.CofaxToolsServlet",
"init-param": {
"templatePath": "toolstemplates/",
"log": 1,
"logLocation": "/usr/local/tomcat/logs/CofaxTools.log",
"logMaxSize": "",
"dataLog": 1,
"dataLogLocation": "/usr/local/tomcat/logs/dataLog.log",
"dataLogMaxSize": "",
"removePageCache": "/content/admin/remove?cache=pages&id=",
"removeTemplateCache": "/content/admin/remove?cache=templates&id=",
"fileTransferFolder": "/usr/local/tomcat/webapps/content/fileTransferFolder",
"lookInContext": 1,
"adminGroupID": 4,
"betaServer": true
}
}
],
"servlet-mapping": {
"cofaxCDS": "/",
"cofaxEmail": "/cofaxutil/aemail/*",
"cofaxAdmin": "/admin/*",
"fileServlet": "/static/*",
"cofaxTools": "/tools/*"
},
"taglib": {
"taglib-uri": "cofax.tld",
"taglib-location": "/WEB-INF/tlds/cofax.tld"
}
}}

12
json-path/build.gradle

@ -1,13 +1,12 @@
description = "Java port of Stefan Goessner JsonPath."
jar {
baseName 'json-path'
bnd (
'Automatic-Module-Name': 'json.path',
'Implementation-Title': 'json-path', 'Implementation-Version': archiveVersion,
'Import-Package': 'org.json.*;resolution:=optional, com.google.gson.*;resolution:=optional, com.fasterxml.jackson.*;resolution:=optional, org.apache.tapestry5.json.*;resolution:=optional, org.codehaus.jettison.*;resolution:=optional, jakarta.json.*;resolution:=optional, *',
'Export-Package': 'com.jayway.jsonpath,com.jayway.jsonpath.spi,com.jayway.jsonpath.spi.cache,com.jayway.jsonpath.spi.json,com.jayway.jsonpath.spi.mapper'
bnd(
'Automatic-Module-Name': 'json.path',
'Implementation-Title': 'json-path', 'Implementation-Version': archiveVersion,
'Import-Package': 'org.json.*;resolution:=optional, com.google.gson.*;resolution:=optional, com.fasterxml.jackson.*;resolution:=optional, org.apache.tapestry5.json.*;resolution:=optional, org.codehaus.jettison.*;resolution:=optional, jakarta.json.*;resolution:=optional, *',
'Export-Package': 'com.jayway.jsonpath,com.jayway.jsonpath.spi,com.jayway.jsonpath.spi.cache,com.jayway.jsonpath.spi.json,com.jayway.jsonpath.spi.mapper'
)
}
@ -23,5 +22,4 @@ dependencies {
compileOnly libs.jakartaJsonB// , optional
testImplementation libs.test
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}

2
json-path/src/test/java/com/jayway/jsonpath/DeepScanTest.java

@ -1,6 +1,6 @@
package com.jayway.jsonpath;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.HashMap;

10
json-path/src/test/java/com/jayway/jsonpath/EscapeTest.java

@ -2,9 +2,9 @@ package com.jayway.jsonpath;
import net.minidev.json.JSONStyle;
import net.minidev.json.JSONValue;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@ -12,13 +12,13 @@ public class EscapeTest extends BaseTest {
private static JSONStyle style;
@BeforeClass
@BeforeAll
public static void before(){
style = JSONValue.COMPRESSION;
JSONValue.COMPRESSION = JSONStyle.LT_COMPRESS;
}
@AfterClass
@AfterAll
public static void after(){
JSONValue.COMPRESSION = style;
}

2
json-path/src/test/java/com/jayway/jsonpath/EvaluationListenerTest.java

@ -1,6 +1,6 @@
package com.jayway.jsonpath;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;

14
json-path/src/test/java/com/jayway/jsonpath/FilterCompilerTest.java

@ -1,9 +1,10 @@
package com.jayway.jsonpath;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static com.jayway.jsonpath.internal.filter.FilterCompiler.compile;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class FilterCompilerTest {
@ -60,9 +61,9 @@ public class FilterCompilerTest {
assertThat(compile("[?(@[\")]@$)]\"] == \")]@$)]\")]").toString()).isEqualTo("[?(@[\")]@$)]\"] == \")]@$)]\")]");
}
@Test(expected = InvalidPathException.class)
@Test
public void invalid_path_when_string_literal_is_unquoted() {
compile("[?(@.foo == x)]");
assertThrows(InvalidPathException.class, () -> compile("[?(@.foo == x)]"));
}
@Test
@ -86,19 +87,18 @@ public class FilterCompilerTest {
@Test
// issue #178
public void compile_and_serialize_not_exists_filter(){
public void compile_and_serialize_not_exists_filter() {
Filter compiled = compile("[?(!@.foo)]");
String serialized = compiled.toString();
assertThat(serialized).isEqualTo("[?(!@['foo'])]");
}
private void assertInvalidPathException(String filter){
private void assertInvalidPathException(String filter) {
try {
compile(filter);
throw new AssertionError("Expected " + filter + " to throw InvalidPathException");
} catch (InvalidPathException e){
} catch (InvalidPathException e) {
//e.printStackTrace();
}
}

2
json-path/src/test/java/com/jayway/jsonpath/FilterParseTest.java

@ -1,7 +1,7 @@
package com.jayway.jsonpath;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import java.util.regex.Pattern;

2
json-path/src/test/java/com/jayway/jsonpath/FilterTest.java

@ -1,7 +1,7 @@
package com.jayway.jsonpath;
import org.assertj.core.util.Lists;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.List;

113
json-path/src/test/java/com/jayway/jsonpath/GsonJsonProviderTest.java

@ -6,7 +6,7 @@ import com.google.gson.JsonObject;
import com.jayway.jsonpath.spi.json.GsonJsonProvider;
import com.jayway.jsonpath.spi.mapper.GsonMappingProvider;
import com.jayway.jsonpath.spi.mapper.MappingException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.math.BigDecimal;
@ -16,41 +16,42 @@ import java.util.List;
import static com.jayway.jsonpath.JsonPath.using;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class GsonJsonProviderTest extends BaseTest {
private static final String JSON =
"[" +
"{\n" +
" \"foo\" : \"foo0\",\n" +
" \"bar\" : 0,\n" +
" \"baz\" : true,\n" +
" \"gen\" : {\"eric\" : \"yepp\"}" +
"}," +
"{\n" +
" \"foo\" : \"foo1\",\n" +
" \"bar\" : 1,\n" +
" \"baz\" : true,\n" +
" \"gen\" : {\"eric\" : \"yepp\"}" +
"}," +
"{\n" +
" \"foo\" : \"foo2\",\n" +
" \"bar\" : 2,\n" +
" \"baz\" : true,\n" +
" \"gen\" : {\"eric\" : \"yepp\"}" +
"}" +
"]";
"{\n" +
" \"foo\" : \"foo0\",\n" +
" \"bar\" : 0,\n" +
" \"baz\" : true,\n" +
" \"gen\" : {\"eric\" : \"yepp\"}" +
"}," +
"{\n" +
" \"foo\" : \"foo1\",\n" +
" \"bar\" : 1,\n" +
" \"baz\" : true,\n" +
" \"gen\" : {\"eric\" : \"yepp\"}" +
"}," +
"{\n" +
" \"foo\" : \"foo2\",\n" +
" \"bar\" : 2,\n" +
" \"baz\" : true,\n" +
" \"gen\" : {\"eric\" : \"yepp\"}" +
"}" +
"]";
@Test
public void json_can_be_parsed() {
JsonObject node = using(GSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$");
JsonObject node = using(GSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$");
assertThat(node.get("string-property").getAsString()).isEqualTo("string-value");
}
@Test
public void strings_are_unwrapped() {
JsonElement node = using(GSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.string-property");
String unwrapped = using(GSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.string-property", String.class);
JsonElement node = using(GSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.string-property");
String unwrapped = using(GSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.string-property", String.class);
assertThat(unwrapped).isEqualTo("string-value");
assertThat(unwrapped).isEqualTo(node.getAsString());
@ -58,8 +59,8 @@ public class GsonJsonProviderTest extends BaseTest {
@Test
public void ints_are_unwrapped() {
JsonElement node = using(GSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.int-max-property");
int unwrapped = using(GSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.int-max-property", int.class);
JsonElement node = using(GSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.int-max-property");
int unwrapped = using(GSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.int-max-property", int.class);
assertThat(unwrapped).isEqualTo(Integer.MAX_VALUE);
assertThat(unwrapped).isEqualTo(node.getAsInt());
@ -67,8 +68,8 @@ public class GsonJsonProviderTest extends BaseTest {
@Test
public void longs_are_unwrapped() {
JsonElement node = using(GSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.long-max-property");
long val = using(GSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.long-max-property", Long.class);
JsonElement node = using(GSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.long-max-property");
long val = using(GSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.long-max-property", Long.class);
assertThat(val).isEqualTo(Long.MAX_VALUE);
assertThat(val).isEqualTo(node.getAsLong());
@ -78,8 +79,8 @@ public class GsonJsonProviderTest extends BaseTest {
public void doubles_are_unwrapped() {
final String json = "{double-property = 56.78}";
JsonElement node = using(GSON_CONFIGURATION).parse(json).read("$.double-property");
Double val = using(GSON_CONFIGURATION).parse(json).read("$.double-property", Double.class);
JsonElement node = using(GSON_CONFIGURATION).parse(json).read("$.double-property");
Double val = using(GSON_CONFIGURATION).parse(json).read("$.double-property", Double.class);
assertThat(val).isEqualTo(56.78);
assertThat(val).isEqualTo(node.getAsDouble());
@ -90,8 +91,8 @@ public class GsonJsonProviderTest extends BaseTest {
final BigDecimal bd = BigDecimal.valueOf(Long.MAX_VALUE).add(BigDecimal.valueOf(10.5));
final String json = "{bd-property = " + bd.toString() + "}";
JsonElement node = using(GSON_CONFIGURATION).parse(json).read("$.bd-property");
BigDecimal val = using(GSON_CONFIGURATION).parse(json).read("$.bd-property", BigDecimal.class);
JsonElement node = using(GSON_CONFIGURATION).parse(json).read("$.bd-property");
BigDecimal val = using(GSON_CONFIGURATION).parse(json).read("$.bd-property", BigDecimal.class);
assertThat(val).isEqualTo(bd);
assertThat(val).isEqualTo(node.getAsBigDecimal());
@ -102,8 +103,8 @@ public class GsonJsonProviderTest extends BaseTest {
final BigDecimal bd = BigDecimal.valueOf(10.5);
final String json = "{bd-property = " + bd.toString() + "}";
JsonElement node = using(GSON_CONFIGURATION).parse(json).read("$.bd-property");
BigDecimal val = using(GSON_CONFIGURATION).parse(json).read("$.bd-property", BigDecimal.class);
JsonElement node = using(GSON_CONFIGURATION).parse(json).read("$.bd-property");
BigDecimal val = using(GSON_CONFIGURATION).parse(json).read("$.bd-property", BigDecimal.class);
assertThat(val).isEqualTo(bd);
assertThat(val).isEqualTo(node.getAsBigDecimal());
@ -114,8 +115,8 @@ public class GsonJsonProviderTest extends BaseTest {
final BigInteger bi = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.TEN);
final String json = "{bi-property = " + bi.toString() + "}";
JsonElement node = using(GSON_CONFIGURATION).parse(json).read("$.bi-property");
BigInteger val = using(GSON_CONFIGURATION).parse(json).read("$.bi-property", BigInteger.class);
JsonElement node = using(GSON_CONFIGURATION).parse(json).read("$.bi-property");
BigInteger val = using(GSON_CONFIGURATION).parse(json).read("$.bi-property", BigInteger.class);
assertThat(val).isEqualTo(bi);
assertThat(val).isEqualTo(node.getAsBigInteger());
@ -126,8 +127,8 @@ public class GsonJsonProviderTest extends BaseTest {
final BigInteger bi = BigInteger.valueOf(Long.MAX_VALUE);
final String json = "{bi-property = " + bi.toString() + "}";
JsonElement node = using(GSON_CONFIGURATION).parse(json).read("$.bi-property");
BigInteger val = using(GSON_CONFIGURATION).parse(json).read("$.bi-property", BigInteger.class);
JsonElement node = using(GSON_CONFIGURATION).parse(json).read("$.bi-property");
BigInteger val = using(GSON_CONFIGURATION).parse(json).read("$.bi-property", BigInteger.class);
assertThat(val).isEqualTo(bi);
assertThat(val).isEqualTo(node.getAsBigInteger());
@ -145,7 +146,7 @@ public class GsonJsonProviderTest extends BaseTest {
@Test
public void list_of_numbers() {
JsonArray objs = using(GSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.store.book[*].display-price");
JsonArray objs = using(GSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.store.book[*].display-price");
List<Double> actual = new ArrayList<>();
for (JsonElement obj : objs) {
actual.add(obj.getAsDouble());
@ -173,36 +174,38 @@ public class GsonJsonProviderTest extends BaseTest {
@Test
public void test_type_ref() throws IOException {
TypeRef<List<FooBarBaz<Gen>>> typeRef = new TypeRef<List<FooBarBaz<Gen>>>() {};
TypeRef<List<FooBarBaz<Gen>>> typeRef = new TypeRef<List<FooBarBaz<Gen>>>() {
};
List<FooBarBaz<Gen>> list = JsonPath.using(GSON_CONFIGURATION).parse(JSON).read("$", typeRef);
assertThat(list.get(0).gen.eric).isEqualTo("yepp");
}
@Test(expected = MappingException.class)
@Test
public void test_type_ref_fail() throws IOException {
TypeRef<List<FooBarBaz<Integer>>> typeRef = new TypeRef<List<FooBarBaz<Integer>>>() {};
TypeRef<List<FooBarBaz<Integer>>> typeRef = new TypeRef<List<FooBarBaz<Integer>>>() {
};
using(GSON_CONFIGURATION).parse(JSON).read("$", typeRef);
assertThrows(MappingException.class, () -> using(GSON_CONFIGURATION).parse(JSON).read("$", typeRef));
}
@Test
// https://github.com/json-path/JsonPath/issues/351
public void no_error_when_mapping_null() throws IOException {
Configuration configuration = Configuration
.builder()
.mappingProvider(new GsonMappingProvider())
.jsonProvider(new GsonJsonProvider())
.options(Option.DEFAULT_PATH_LEAF_TO_NULL, Option.SUPPRESS_EXCEPTIONS)
.build();
String json = "{\"M\":[]}";
String result = JsonPath.using(configuration).parse(json).read("$.M[0].A[0]", String.class);
Configuration configuration = Configuration
.builder()
.mappingProvider(new GsonMappingProvider())
.jsonProvider(new GsonJsonProvider())
.options(Option.DEFAULT_PATH_LEAF_TO_NULL, Option.SUPPRESS_EXCEPTIONS)
.build();
String json = "{\"M\":[]}";
assertThat(result).isNull();
String result = JsonPath.using(configuration).parse(json).read("$.M[0].A[0]", String.class);
assertThat(result).isNull();
}
@ -225,6 +228,4 @@ public class GsonJsonProviderTest extends BaseTest {
}
}

163
json-path/src/test/java/com/jayway/jsonpath/InlineFilterTest.java

@ -1,8 +1,8 @@
package com.jayway.jsonpath;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.math.BigDecimal;
import java.util.ArrayList;
@ -14,66 +14,61 @@ import static com.jayway.jsonpath.TestUtils.assertHasOneResult;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(Parameterized.class)
public class InlineFilterTest extends BaseTest {
private static int bookCount = 4;
public static final String MULTI_STORE_JSON_DOCUMENT = "{\n" +
" \"store\" : [{\n" +
" \"name\": \"First\"," +
" \"book\" : [\n" +
" {\n" +
" \"category\" : \"reference\",\n" +
" \"author\" : \"Nigel Rees\",\n" +
" \"title\" : \"Sayings of the Century\",\n" +
" \"display-price\" : 8.95\n" +
" },\n" +
" {\n" +
" \"category\" : \"fiction\",\n" +
" \"author\" : \"Evelyn Waugh\",\n" +
" \"title\" : \"Sword of Honour\",\n" +
" \"display-price\" : 12.99\n" +
" },\n" +
" {\n" +
" \"category\" : \"fiction\",\n" +
" \"author\" : \"Herman Melville\",\n" +
" \"title\" : \"Moby Dick\",\n" +
" \"isbn\" : \"0-553-21311-3\",\n" +
" \"display-price\" : 8.99\n" +
" },\n" +
" {\n" +
" \"category\" : \"fiction\",\n" +
" \"author\" : \"J. R. R. Tolkien\",\n" +
" \"title\" : \"The Lord of the Rings\",\n" +
" \"isbn\" : \"0-395-19395-8\",\n" +
" \"display-price\" : 22.99\n" +
" }]\n" +
" },\n" +
" {\n" +
" \"name\": \"Second\",\n" +
" \"book\": [\n" +
" {\n" +
" \"category\" : \"fiction\",\n" +
" \"author\" : \"Ernest Hemmingway\",\n" +
" \"title\" : \"The Old Man and the Sea\",\n" +
" \"display-price\" : 12.99\n" +
" }]\n" +
" }]}";
private Configuration conf = Configurations.GSON_CONFIGURATION;
public InlineFilterTest(Configuration conf) {
this.conf = conf;
}
" \"store\" : [{\n" +
" \"name\": \"First\"," +
" \"book\" : [\n" +
" {\n" +
" \"category\" : \"reference\",\n" +
" \"author\" : \"Nigel Rees\",\n" +
" \"title\" : \"Sayings of the Century\",\n" +
" \"display-price\" : 8.95\n" +
" },\n" +
" {\n" +
" \"category\" : \"fiction\",\n" +
" \"author\" : \"Evelyn Waugh\",\n" +
" \"title\" : \"Sword of Honour\",\n" +
" \"display-price\" : 12.99\n" +
" },\n" +
" {\n" +
" \"category\" : \"fiction\",\n" +
" \"author\" : \"Herman Melville\",\n" +
" \"title\" : \"Moby Dick\",\n" +
" \"isbn\" : \"0-553-21311-3\",\n" +
" \"display-price\" : 8.99\n" +
" },\n" +
" {\n" +
" \"category\" : \"fiction\",\n" +
" \"author\" : \"J. R. R. Tolkien\",\n" +
" \"title\" : \"The Lord of the Rings\",\n" +
" \"isbn\" : \"0-395-19395-8\",\n" +
" \"display-price\" : 22.99\n" +
" }]\n" +
" },\n" +
" {\n" +
" \"name\": \"Second\",\n" +
" \"book\": [\n" +
" {\n" +
" \"category\" : \"fiction\",\n" +
" \"author\" : \"Ernest Hemmingway\",\n" +
" \"title\" : \"The Old Man and the Sea\",\n" +
" \"display-price\" : 12.99\n" +
" }]\n" +
" }]}";
@Parameterized.Parameters
public static Iterable<Configuration> configurations() {
return Configurations.configurations();
}
@Test
public void root_context_can_be_referred_in_predicate() {
@ParameterizedTest
@MethodSource("configurations")
public void root_context_can_be_referred_in_predicate(Configuration conf) {
List<?> prices = using(conf).parse(JSON_DOCUMENT).read("store.book[?(@.display-price <= $.max-price)].display-price", List.class);
assertThat(prices.stream().map(this::asDouble)).containsAll(asList(8.95D, 8.99D));
@ -84,8 +79,9 @@ public class InlineFilterTest extends BaseTest {
return object instanceof BigDecimal ? ((BigDecimal) object).doubleValue() : (Double) object;
}
@Test
public void multiple_context_object_can_be_refered() {
@ParameterizedTest
@MethodSource("configurations")
public void multiple_context_object_can_be_refered(Configuration conf) {
List all = using(conf).parse(JSON_DOCUMENT).read("store.book[ ?(@.category == @.category) ]", List.class);
assertThat(all.size()).isEqualTo(bookCount);
@ -104,8 +100,9 @@ public class InlineFilterTest extends BaseTest {
}
@Test
public void simple_inline_or_statement_evaluates() {
@ParameterizedTest
@MethodSource("configurations")
public void simple_inline_or_statement_evaluates(Configuration conf) {
List a = using(conf).parse(JSON_DOCUMENT).read("store.book[ ?(@.author == 'Nigel Rees' || @.author == 'Evelyn Waugh') ].author", List.class);
assertThat(a).containsExactly("Nigel Rees", "Evelyn Waugh");
@ -120,7 +117,7 @@ public class InlineFilterTest extends BaseTest {
assertThat(d).containsExactly("Nigel Rees");
}
@Test
public void no_path_ref_in_filter_hit_all() {
List<String> res = JsonPath.parse(JSON_DOCUMENT).read("$.store.book[?('a' == 'a')].author");
@ -199,18 +196,19 @@ public class InlineFilterTest extends BaseTest {
List<Integer> hits = JsonPath.parse(ints).read("$[?(@)]");
assertThat(hits).containsExactly(0,1,null,2,3);
assertThat(hits).containsExactly(0, 1, null, 2, 3);
hits = JsonPath.parse(ints).read("$[?(@ != null)]");
assertThat(hits).containsExactly(0,1,2,3);
assertThat(hits).containsExactly(0, 1, 2, 3);
List<Integer> isNull = JsonPath.parse(ints).read("$[?(!@)]");
assertThat(isNull).containsExactly(new Integer[]{});
assertThat(isNull).containsExactly(new Integer[]{});
}
@Test
public void equality_check_does_not_break_evaluation() {
@ParameterizedTest
@MethodSource("configurations")
public void equality_check_does_not_break_evaluation(Configuration conf) {
assertHasOneResult("[{\"value\":\"5\"}]", "$[?(@.value=='5')]", conf);
assertHasOneResult("[{\"value\":5}]", "$[?(@.value==5)]", conf);
@ -225,8 +223,9 @@ public class InlineFilterTest extends BaseTest {
assertHasNoResults("[{\"value\":\"5.1.26\"}]", "$[?(@.value==5.1)]", conf);
}
@Test
public void lt_check_does_not_break_evaluation() {
@ParameterizedTest
@MethodSource("configurations")
public void lt_check_does_not_break_evaluation(Configuration conf) {
assertHasOneResult("[{\"value\":\"5\"}]", "$[?(@.value<'7')]", conf);
assertHasNoResults("[{\"value\":\"7\"}]", "$[?(@.value<'5')]", conf);
@ -241,44 +240,50 @@ public class InlineFilterTest extends BaseTest {
assertHasNoResults("[{\"value\":7.1}]", "$[?(@.value<5)]", conf);
}
@Test
public void escaped_literals() {
if(conf.jsonProvider().getClass().getSimpleName().startsWith("Jackson")){
@ParameterizedTest
@MethodSource("configurations")
public void escaped_literals(Configuration conf) {
if (conf.jsonProvider().getClass().getSimpleName().startsWith("Jackson")) {
return;
}
if(conf.jsonProvider().getClass().getSimpleName().startsWith("Jakarta")){
if (conf.jsonProvider().getClass().getSimpleName().startsWith("Jakarta")) {
// single quotes are not valid in JSON; see json.org
return;
}
assertHasOneResult("[\"\\'foo\"]", "$[?(@ == '\\'foo')]", conf);
}
@Test
public void escaped_literals2() {
if(conf.jsonProvider().getClass().getSimpleName().startsWith("Jackson")){
@ParameterizedTest
@MethodSource("configurations")
public void escaped_literals2(Configuration conf) {
if (conf.jsonProvider().getClass().getSimpleName().startsWith("Jackson")) {
return;
}
assertHasOneResult("[\"\\\\'foo\"]", "$[?(@ == \"\\\\'foo\")]", conf);
}
@Test
public void escape_pattern() {
@ParameterizedTest
@MethodSource("configurations")
public void escape_pattern(Configuration conf) {
assertHasOneResult("[\"x\"]", "$[?(@ =~ /\\/|x/)]", conf);
}
@Test
public void escape_pattern_after_literal() {
@ParameterizedTest
@MethodSource("configurations")
public void escape_pattern_after_literal(Configuration conf) {
assertHasOneResult("[\"x\"]", "$[?(@ == \"abc\" || @ =~ /\\/|x/)]", conf);
}
@Test
public void escape_pattern_before_literal() {
@ParameterizedTest
@MethodSource("configurations")
public void escape_pattern_before_literal(Configuration conf) {
assertHasOneResult("[\"x\"]", "$[?(@ =~ /\\/|x/ || @ == \"abc\")]", conf);
}
@Test
public void filter_evaluation_does_not_break_path_evaluation() {
@ParameterizedTest
@MethodSource("configurations")
public void filter_evaluation_does_not_break_path_evaluation(Configuration conf) {
assertHasOneResult("[{\"s\": \"fo\", \"expected_size\": \"m\"}, {\"s\": \"lo\", \"expected_size\": 2}]", "$[?(@.s size @.expected_size)]", conf);
}
}

2
json-path/src/test/java/com/jayway/jsonpath/Issue_487.java

@ -1,6 +1,6 @@
package com.jayway.jsonpath;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class Issue_487 {

2
json-path/src/test/java/com/jayway/jsonpath/Issue_537.java

@ -1,6 +1,6 @@
package com.jayway.jsonpath;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;

6
json-path/src/test/java/com/jayway/jsonpath/Issue_721.java

@ -1,10 +1,6 @@
package com.jayway.jsonpath;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Option;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class Issue_721 {

4
json-path/src/test/java/com/jayway/jsonpath/Issue_762.java

@ -1,8 +1,6 @@
package com.jayway.jsonpath;
import org.junit.Test;
import static com.jayway.jsonpath.BaseTest.JSON_DOCUMENT;
import org.junit.jupiter.api.Test;
/**

2
json-path/src/test/java/com/jayway/jsonpath/Issue_786.java

@ -1,6 +1,6 @@
package com.jayway.jsonpath;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

2
json-path/src/test/java/com/jayway/jsonpath/Issue_970.java

@ -1,6 +1,6 @@
package com.jayway.jsonpath;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThatNoException;

2
json-path/src/test/java/com/jayway/jsonpath/Issue_973.java

@ -1,6 +1,6 @@
package com.jayway.jsonpath;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.*;

35
json-path/src/test/java/com/jayway/jsonpath/JacksonJsonNodeJsonProviderMapperSupportTest.java

@ -1,28 +1,23 @@
package com.jayway.jsonpath;
import static org.assertj.core.api.Assertions.assertThat;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.TextNode;
import com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider;
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
public class JacksonJsonNodeJsonProviderMapperSupportTest {
import static org.assertj.core.api.Assertions.assertThat;
private final TestData testData;
public class JacksonJsonNodeJsonProviderMapperSupportTest {
public JacksonJsonNodeJsonProviderMapperSupportTest(final TestData testData) {
this.testData = testData;
}
@Test
public void mapMethod_withJacksonJsonNodeJsonProvider_shouldUsingJsonNodeForMappingValues() {
@ParameterizedTest
@MethodSource("testDataSource")
public void mapMethod_withJacksonJsonNodeJsonProvider_shouldUsingJsonNodeForMappingValues(TestData testData) {
DocumentContext testJsonDocumentContext = cloneDocumentContext(testData.jsonDocumentContext);
testJsonDocumentContext.map(testData.jsonPath, (value, config) -> {
@ -33,16 +28,20 @@ public class JacksonJsonNodeJsonProviderMapperSupportTest {
.isEqualTo(testData.expectedUpdatedJsonDocument);
}
@Test
public void readMethod_withJacksonJsonNodeJsonProvider_shouldReturnJsonNode() {
@ParameterizedTest
@MethodSource("testDataSource")
public void readMethod_withJacksonJsonNodeJsonProvider_shouldReturnJsonNode(TestData testData) {
DocumentContext testJsonDocumentContext = cloneDocumentContext(testData.jsonDocumentContext);
final JsonNode actualJsonValue = testJsonDocumentContext.read(testData.jsonPath);
assertThat(actualJsonValue).isEqualTo(testData.expectedJsonValue);
}
@Test
public void setMethod_withJacksonJsonNodeJsonProvider_shouldAcceptJsonNode() {
@ParameterizedTest
@MethodSource("testDataSource")
public void setMethod_withJacksonJsonNodeJsonProvider_shouldAcceptJsonNode(TestData testData) {
DocumentContext testJsonDocumentContext = cloneDocumentContext(testData.jsonDocumentContext);
testJsonDocumentContext.set(testData.jsonPath, testData.newJsonValue);
@ -75,7 +74,7 @@ public class JacksonJsonNodeJsonProviderMapperSupportTest {
}
}
@Parameterized.Parameters
public static List<TestData> testDataSource() throws Exception {
final Configuration configuration = Configuration.builder()
.jsonProvider(new JacksonJsonNodeJsonProvider())

8
json-path/src/test/java/com/jayway/jsonpath/JacksonJsonNodeJsonProviderTest.java

@ -13,7 +13,9 @@ import com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider;
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
import com.jayway.jsonpath.spi.mapper.MappingException;
import java.nio.charset.StandardCharsets;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.math.BigDecimal;
@ -186,11 +188,11 @@ public class JacksonJsonNodeJsonProviderTest extends BaseTest {
assertThat(list.get(0).gen.eric).isEqualTo("yepp");
}
@Test(expected = MappingException.class)
@Test
public void test_type_ref_fail() throws IOException {
TypeRef<List<FooBarBaz<Integer>>> typeRef = new TypeRef<List<FooBarBaz<Integer>>>() {};
using(JACKSON_JSON_NODE_CONFIGURATION).parse(JSON).read("$", typeRef);
Assertions.assertThrows(MappingException.class, () -> using(JACKSON_JSON_NODE_CONFIGURATION).parse(JSON).read("$", typeRef));
}
@Test

3
json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java

@ -1,7 +1,8 @@
package com.jayway.jsonpath;
import org.junit.jupiter.api.Test;
import java.util.Date;
import org.junit.Test;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Collections.singletonMap;

547
json-path/src/test/java/com/jayway/jsonpath/JakartaJsonProviderTest.java

@ -2,204 +2,211 @@ package com.jayway.jsonpath;
import jakarta.json.JsonObject;
import jakarta.json.JsonString;
import org.junit.jupiter.api.Test;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import static com.jayway.jsonpath.JsonPath.parse;
import static com.jayway.jsonpath.JsonPath.using;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Collections.emptyMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class JakartaJsonProviderTest extends BaseTest {
private static final Map<String, Object> EMPTY_MAP = emptyMap();
@Test
public void an_object_can_be_read() {
JsonObject book = using(JAKARTA_JSON_CONFIGURATION)
.parse(JSON_DOCUMENT)
.read("$.store.book[0]");
assertThat(((JsonString) book.get("author")).getChars()).isEqualTo("Nigel Rees");
}
@Test
public void an_object_can_be_read_from_bytes() {
JsonObject book = using(JAKARTA_JSON_CONFIGURATION)
.parseUtf8(JSON_DOCUMENT.getBytes(UTF_8))
.read("$.store.book[0]");
assertThat(((JsonString) book.get("author")).getChars()).isEqualTo("Nigel Rees");
}
@Test
public void a_property_can_be_read() {
JsonString category = using(JAKARTA_JSON_CONFIGURATION)
.parse(JSON_DOCUMENT)
.read("$.store.book[0].category");
assertThat(category.getString()).isEqualTo("reference");
}
@Test
public void a_filter_can_be_applied() {
List<Object> fictionBooks = using(JAKARTA_JSON_CONFIGURATION)
.parse(JSON_DOCUMENT)
.read("$.store.book[?(@.category == 'fiction')]");
assertThat(fictionBooks.size()).isEqualTo(3);
}
@Test
public void result_can_be_mapped_to_object() {
@SuppressWarnings("unchecked")
List<Map<String, Object>> books = using(JAKARTA_JSON_CONFIGURATION)
.parse(JSON_DOCUMENT)
.read("$.store.book", List.class);
assertThat(books.size()).isEqualTo(4);
}
@Test
public void read_books_with_isbn() {
List<Object> books = using(JAKARTA_JSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$..book[?(@.isbn)]");
assertThat(books.size()).isEqualTo(2);
}
/**
* Functions take parameters, the length parameter for example takes an entire document which we anticipate
* will compute to a document that is an array of elements which can determine its length.
*
* Since we translate this query from $..books.length() to length($..books) verify that this particular translation
* works as anticipated.
*/
@Test
public void read_book_length_using_translated_query() {
Integer result = using(JAKARTA_JSON_CONFIGURATION)
.parse(JSON_BOOK_STORE_DOCUMENT)
.read("$..book.length()");
assertThat(result).isEqualTo(4);
}
@Test
public void read_book_length() {
Object result = using(JAKARTA_JSON_CONFIGURATION)
.parse(JSON_BOOK_STORE_DOCUMENT)
.read("$.length($..book)");
assertThat(result).isEqualTo(4);
}
@Test
public void issue_97() {
String json = "{ \"books\": [ " +
"{ \"category\": \"fiction\" }, " +
"{ \"category\": \"reference\" }, " +
"{ \"category\": \"fiction\" }, " +
"{ \"category\": \"fiction\" }, " +
"{ \"category\": \"reference\" }, " +
"{ \"category\": \"fiction\" }, " +
"{ \"category\": \"reference\" }, " +
"{ \"category\": \"reference\" }, " +
"{ \"category\": \"reference\" }, " +
"{ \"category\": \"reference\" }, " +
"{ \"category\": \"reference\" } ] }";
DocumentContext dc = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(json)
.delete("$.books[?(@.category == 'reference')]");
//System.out.println((Object) dc.read("$"));
@SuppressWarnings("unchecked")
List<String> categories = dc.read("$..category", List.class);
assertThat(categories).containsOnly("fiction");
}
@Test
public void test_delete_2() {
DocumentContext dc = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse("[" +
"{\"top\": {\"middle\": null}}," +
"{\"top\": {\"middle\": {} }}," +
"{\"top\": {\"middle\": {\"bottom\": 2} }}" +
"]")
.delete(JsonPath.compile("$[*].top.middle.bottom"));
Object ans = dc.read("$");
//System.out.println(ans);
assert(ans.toString().equals("[{\"top\":{\"middle\":null}},{\"top\":{\"middle\":{}}},{\"top\":{\"middle\":{}}}]"));
}
@Test
public void an_object_can_be_read() {
JsonObject book = using(JAKARTA_JSON_CONFIGURATION)
.parse(JSON_DOCUMENT)
.read("$.store.book[0]");
assertThat(((JsonString) book.get("author")).getChars()).isEqualTo("Nigel Rees");
}
@Test
public void an_object_can_be_read_from_bytes() {
JsonObject book = using(JAKARTA_JSON_CONFIGURATION)
.parseUtf8(JSON_DOCUMENT.getBytes(UTF_8))
.read("$.store.book[0]");
assertThat(((JsonString) book.get("author")).getChars()).isEqualTo("Nigel Rees");
}
@Test
public void a_property_can_be_read() {
JsonString category = using(JAKARTA_JSON_CONFIGURATION)
.parse(JSON_DOCUMENT)
.read("$.store.book[0].category");
assertThat(category.getString()).isEqualTo("reference");
}
@Test
public void a_filter_can_be_applied() {
List<Object> fictionBooks = using(JAKARTA_JSON_CONFIGURATION)
.parse(JSON_DOCUMENT)
.read("$.store.book[?(@.category == 'fiction')]");
assertThat(fictionBooks.size()).isEqualTo(3);
}
@Test
public void result_can_be_mapped_to_object() {
@SuppressWarnings("unchecked")
List<Map<String, Object>> books = using(JAKARTA_JSON_CONFIGURATION)
.parse(JSON_DOCUMENT)
.read("$.store.book", List.class);
assertThat(books.size()).isEqualTo(4);
}
@Test
public void read_books_with_isbn() {
List<Object> books = using(JAKARTA_JSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$..book[?(@.isbn)]");
assertThat(books.size()).isEqualTo(2);
}
/**
* Functions take parameters, the length parameter for example takes an entire document which we anticipate
* will compute to a document that is an array of elements which can determine its length.
* <p>
* Since we translate this query from $..books.length() to length($..books) verify that this particular translation
* works as anticipated.
*/
@Test
public void read_book_length_using_translated_query() {
Integer result = using(JAKARTA_JSON_CONFIGURATION)
.parse(JSON_BOOK_STORE_DOCUMENT)
.read("$..book.length()");
assertThat(result).isEqualTo(4);
}
@Test
public void read_book_length() {
Object result = using(JAKARTA_JSON_CONFIGURATION)
.parse(JSON_BOOK_STORE_DOCUMENT)
.read("$.length($..book)");
assertThat(result).isEqualTo(4);
}
@Test
public void issue_97() {
String json = "{ \"books\": [ " +
"{ \"category\": \"fiction\" }, " +
"{ \"category\": \"reference\" }, " +
"{ \"category\": \"fiction\" }, " +
"{ \"category\": \"fiction\" }, " +
"{ \"category\": \"reference\" }, " +
"{ \"category\": \"fiction\" }, " +
"{ \"category\": \"reference\" }, " +
"{ \"category\": \"reference\" }, " +
"{ \"category\": \"reference\" }, " +
"{ \"category\": \"reference\" }, " +
"{ \"category\": \"reference\" } ] }";
DocumentContext dc = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(json)
.delete("$.books[?(@.category == 'reference')]");
//System.out.println((Object) dc.read("$"));
@SuppressWarnings("unchecked")
List<String> categories = dc.read("$..category", List.class);
assertThat(categories).containsOnly("fiction");
}
@Test
public void test_delete_2() {
DocumentContext dc = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse("[" +
"{\"top\": {\"middle\": null}}," +
"{\"top\": {\"middle\": {} }}," +
"{\"top\": {\"middle\": {\"bottom\": 2} }}" +
"]")
.delete(JsonPath.compile("$[*].top.middle.bottom"));
Object ans = dc.read("$");
//System.out.println(ans);
assert (ans.toString().equals("[{\"top\":{\"middle\":null}},{\"top\":{\"middle\":{}}},{\"top\":{\"middle\":{}}}]"));
}
@Test
public void an_root_property_can_be_updated() {
Object o = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.set("$.int-max-property", 1)
.json();
.parse(JSON_DOCUMENT)
.set("$.int-max-property", 1)
.json();
Integer result = using(JAKARTA_JSON_RW_CONFIGURATION).parse(o)
.read("$.int-max-property", Integer.class);
.read("$.int-max-property", Integer.class);
assertThat(result).isEqualTo(1);
}
@Test
public void an_deep_scan_can_update() {
Object o = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.set("$..display-price", 1)
.json();
Object o = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.set("$..display-price", 1)
.json();
List<Integer> result = using(JAKARTA_JSON_RW_CONFIGURATION).parse(o)
.read("$..display-price", new TypeRef<List<Integer>>() {});
.read("$..display-price", new TypeRef<List<Integer>>() {
});
assertThat(result).containsExactly(1, 1, 1, 1, 1);
}
@Test
public void an_filter_can_update() {
final String updatePathFunction = "$.store.book[?(@.display-price)].display-price";
Object o = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.set(updatePathFunction, 1)
.json();
final String updatePathFunction = "$.store.book[?(@.display-price)].display-price";
Object o = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.set(updatePathFunction, 1)
.json();
List<Integer> result = using(JAKARTA_JSON_RW_CONFIGURATION).parse(o)
.read(updatePathFunction, new TypeRef<List<Integer>>() {});
.read(updatePathFunction, new TypeRef<List<Integer>>() {
});
assertThat(result).containsExactly(1, 1, 1, 1);
}
@Test
public void a_path_can_be_deleted() {
final String deletePath = "$.store.book[*].display-price";
Object o = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.delete(deletePath)
.json();
final String deletePath = "$.store.book[*].display-price";
Object o = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.delete(deletePath)
.json();
List<Integer> result = using(JAKARTA_JSON_RW_CONFIGURATION).parse(o)
.read(deletePath, new TypeRef<List<Integer>>() {});
.read(deletePath, new TypeRef<List<Integer>>() {
});
assertThat(result).isEmpty();
}
@Test
public void operations_can_chained() {
Object o = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
Object o = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.delete("$.store.book[*].display-price")
.set("$.store.book[*].category", "A")
.json();
List<Integer> prices = using(JAKARTA_JSON_RW_CONFIGURATION).parse(o)
.read("$.store.book[*].display-price", new TypeRef<List<Integer>>() {});
.read("$.store.book[*].display-price", new TypeRef<List<Integer>>() {
});
List<String> categories = using(JAKARTA_JSON_RW_CONFIGURATION).parse(o)
.read("$.store.book[*].category", new TypeRef<List<String>>() {});
.read("$.store.book[*].category", new TypeRef<List<String>>() {
});
assertThat(prices).isEmpty();
assertThat(categories).containsExactly("A", "A", "A", "A");
@ -208,9 +215,9 @@ public class JakartaJsonProviderTest extends BaseTest {
@Test
public void an_array_index_can_be_updated() {
String res = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.set("$.store.book[0]", "a")
.read("$.store.book[0]", String.class);
.parse(JSON_DOCUMENT)
.set("$.store.book[0]", "a")
.read("$.store.book[0]", String.class);
assertThat(res).isEqualTo("a");
}
@ -218,9 +225,10 @@ public class JakartaJsonProviderTest extends BaseTest {
@Test
public void an_array_slice_can_be_updated() {
List<String> res = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.set("$.store.book[0:2]", "a")
.read("$.store.book[0:2]", new TypeRef<List<String>>() {});
.parse(JSON_DOCUMENT)
.set("$.store.book[0:2]", "a")
.read("$.store.book[0:2]", new TypeRef<List<String>>() {
});
assertThat(res).containsExactly("a", "a");
}
@ -228,9 +236,10 @@ public class JakartaJsonProviderTest extends BaseTest {
@Test
public void an_array_criteria_can_be_updated() {
List<String> res = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.parse(JSON_DOCUMENT)
.set("$.store.book[?(@.category == 'fiction')]", "a")
.read("$.store.book[?(@ == 'a')]", new TypeRef<List<String>>() {});
.read("$.store.book[?(@ == 'a')]", new TypeRef<List<String>>() {
});
assertThat(res).containsExactly("a", "a", "a");
}
@ -238,15 +247,16 @@ public class JakartaJsonProviderTest extends BaseTest {
@Test
public void an_array_criteria_can_be_deleted() {
List<String> res = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.parse(JSON_DOCUMENT)
.delete("$.store.book[?(@.category == 'fiction')]")
.read("$.store.book[*].category", new TypeRef<List<String>>() {});
.read("$.store.book[*].category", new TypeRef<List<String>>() {
});
assertThat(res).containsExactly("reference");
}
@Test
public void an_array_criteria_with_multiple_results_can_be_deleted(){
public void an_array_criteria_with_multiple_results_can_be_deleted() {
InputStream stream = this.getClass().getResourceAsStream("/json_array_multiple_delete.json");
String deletePath = "$._embedded.mandates[?(@.count=~/0/)]";
DocumentContext dc = using(JAKARTA_JSON_RW_CONFIGURATION).parse(stream).delete(deletePath);
@ -257,9 +267,10 @@ public class JakartaJsonProviderTest extends BaseTest {
@Test
public void multi_prop_delete() {
List<Map<String, Object>> res = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.delete("$.store.book[*]['author', 'category']")
.read("$.store.book[*]['author', 'category']", new TypeRef<List<Map<String, Object>>>() {});
.parse(JSON_DOCUMENT)
.delete("$.store.book[*]['author', 'category']")
.read("$.store.book[*]['author', 'category']", new TypeRef<List<Map<String, Object>>>() {
});
assertThat(res).containsExactly(EMPTY_MAP, EMPTY_MAP, EMPTY_MAP, EMPTY_MAP);
}
@ -267,124 +278,128 @@ public class JakartaJsonProviderTest extends BaseTest {
@Test
public void multi_prop_update() {
@SuppressWarnings("serial")
Map<String, Object> expected = new HashMap<String, Object>(){{
Map<String, Object> expected = new HashMap<String, Object>() {{
put("author", "a");
put("category", "a");
}};
List<Map<String, Object>> res = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.set("$.store.book[*]['author', 'category']", "a")
.read("$.store.book[*]['author', 'category']", new TypeRef<List<Map<String, Object>>>() {});
.parse(JSON_DOCUMENT)
.set("$.store.book[*]['author', 'category']", "a")
.read("$.store.book[*]['author', 'category']", new TypeRef<List<Map<String, Object>>>() {
});
assertThat(res).containsExactly(expected, expected, expected, expected);
}
@Test
public void add_to_array() {
Object res = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.add("$.store.book", 1)
.read("$.store.book[4]");
res = JAKARTA_JSON_RW_CONFIGURATION.jsonProvider().unwrap(res);
assertThat(res).isEqualTo(1);
}
@Test
public void add_to_object() {
Object res = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.put("$.store.book[0]", "new-key", "new-value")
.read("$.store.book[0].new-key");
res = JAKARTA_JSON_RW_CONFIGURATION.jsonProvider().unwrap(res);
assertThat(res).isEqualTo("new-value");
}
@Test(expected = InvalidModificationException.class)
public void add_to_object_on_array() {
using(JAKARTA_JSON_RW_CONFIGURATION).parse(JSON_DOCUMENT).put("$.store.book", "new-key", "new-value");
}
@Test(expected = InvalidModificationException.class)
public void add_to_array_on_object() {
using(JAKARTA_JSON_RW_CONFIGURATION).parse(JSON_DOCUMENT).add("$.store.book[0]", "new-value");
}
@Test
public void a_path_can_be_renamed(){
Object o = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.renameKey("$.store", "book", "updated-book")
.json();
List<Object> result = parse(o).read("$.store.updated-book");
assertThat(result).isNotEmpty();
}
@Test
public void map_array_items_can_be_renamed(){
Object o = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.renameKey("$.store.book[*]", "category", "renamed-category")
.json();
List<Object> result = parse(o).read("$.store.book[*].renamed-category");
assertThat(result).isNotEmpty();
}
@Test(expected = PathNotFoundException.class)
public void non_existent_key_rename_not_allowed() {
using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.renameKey("$", "fake", "new-fake")
.json();
}
@Test
public void single_match_value_can_be_mapped() {
MapFunction mapFunction = new ToStringMapFunction();
String stringResult = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.map("$.string-property", mapFunction)
.read("$.string-property", String.class);
assertThat(stringResult.endsWith("converted")).isTrue();
}
@Test
public void object_can_be_mapped() {
TypeRef<List<String>> typeRef = new TypeRef<List<String>>() {};
MapFunction mapFunction = new ToStringMapFunction();
DocumentContext dc = using(JAKARTA_JSON_RW_CONFIGURATION).parse(JSON_DOCUMENT);
Object list = dc.read("$..book");
assertThat(list).isInstanceOf(List.class);
Object res = dc.map("$..book", mapFunction).read("$..book", typeRef).get(0);
assertThat(res).isInstanceOf(String.class);
assertThat((String) res).endsWith("converted");
}
@Test
public void multi_match_path_can_be_mapped() {
MapFunction mapFunction = new ToStringMapFunction();
List<Double> doubleResult = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.read("$..display-price", new TypeRef<List<Double>>() {});
for (Double dRes : doubleResult){
assertThat(dRes).isInstanceOf(Double.class);
}
List<String> stringResult = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.map("$..display-price", mapFunction)
.read("$..display-price", new TypeRef<List<String>>() {});
for (String sRes : stringResult){
assertThat(sRes).isInstanceOf(String.class);
assertThat(sRes.endsWith("converted")).isTrue();
}
}
// Helper converter implementation for test cases.
private class ToStringMapFunction implements MapFunction {
@Override
public Object map(Object currentValue, Configuration configuration) {
return currentValue.toString()+"converted";
}
}
@Test
public void add_to_array() {
Object res = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.add("$.store.book", 1)
.read("$.store.book[4]");
res = JAKARTA_JSON_RW_CONFIGURATION.jsonProvider().unwrap(res);
assertThat(res).isEqualTo(1);
}
@Test
public void add_to_object() {
Object res = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.put("$.store.book[0]", "new-key", "new-value")
.read("$.store.book[0].new-key");
res = JAKARTA_JSON_RW_CONFIGURATION.jsonProvider().unwrap(res);
assertThat(res).isEqualTo("new-value");
}
@Test
public void add_to_object_on_array() {
assertThrows(InvalidModificationException.class, () -> using(JAKARTA_JSON_RW_CONFIGURATION).parse(JSON_DOCUMENT).put("$.store.book", "new-key", "new-value"));
}
@Test
public void add_to_array_on_object() {
assertThrows(InvalidModificationException.class, () -> using(JAKARTA_JSON_RW_CONFIGURATION).parse(JSON_DOCUMENT).add("$.store.book[0]", "new-value"));
}
@Test
public void a_path_can_be_renamed() {
Object o = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.renameKey("$.store", "book", "updated-book")
.json();
List<Object> result = parse(o).read("$.store.updated-book");
assertThat(result).isNotEmpty();
}
@Test
public void map_array_items_can_be_renamed() {
Object o = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.renameKey("$.store.book[*]", "category", "renamed-category")
.json();
List<Object> result = parse(o).read("$.store.book[*].renamed-category");
assertThat(result).isNotEmpty();
}
@Test
public void non_existent_key_rename_not_allowed() {
assertThrows(PathNotFoundException.class, () -> using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.renameKey("$", "fake", "new-fake")
.json());
}
@Test
public void single_match_value_can_be_mapped() {
MapFunction mapFunction = new ToStringMapFunction();
String stringResult = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.map("$.string-property", mapFunction)
.read("$.string-property", String.class);
assertThat(stringResult.endsWith("converted")).isTrue();
}
@Test
public void object_can_be_mapped() {
TypeRef<List<String>> typeRef = new TypeRef<List<String>>() {
};
MapFunction mapFunction = new ToStringMapFunction();
DocumentContext dc = using(JAKARTA_JSON_RW_CONFIGURATION).parse(JSON_DOCUMENT);
Object list = dc.read("$..book");
assertThat(list).isInstanceOf(List.class);
Object res = dc.map("$..book", mapFunction).read("$..book", typeRef).get(0);
assertThat(res).isInstanceOf(String.class);
assertThat((String) res).endsWith("converted");
}
@Test
public void multi_match_path_can_be_mapped() {
MapFunction mapFunction = new ToStringMapFunction();
List<Double> doubleResult = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.read("$..display-price", new TypeRef<List<Double>>() {
});
for (Double dRes : doubleResult) {
assertThat(dRes).isInstanceOf(Double.class);
}
List<String> stringResult = using(JAKARTA_JSON_RW_CONFIGURATION)
.parse(JSON_DOCUMENT)
.map("$..display-price", mapFunction)
.read("$..display-price", new TypeRef<List<String>>() {
});
for (String sRes : stringResult) {
assertThat(sRes).isInstanceOf(String.class);
assertThat(sRes.endsWith("converted")).isTrue();
}
}
// Helper converter implementation for test cases.
private class ToStringMapFunction implements MapFunction {
@Override
public Object map(Object currentValue, Configuration configuration) {
return currentValue.toString() + "converted";
}
}
}

2
json-path/src/test/java/com/jayway/jsonpath/JsonOrgJsonProviderTest.java

@ -4,7 +4,7 @@ import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider;
import com.jayway.jsonpath.spi.mapper.JsonOrgMappingProvider;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;

37
json-path/src/test/java/com/jayway/jsonpath/JsonProviderTest.java

@ -1,44 +1,35 @@
package com.jayway.jsonpath;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import static com.jayway.jsonpath.JsonPath.using;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(Parameterized.class)
public class JsonProviderTest extends BaseTest {
private final Configuration conf;
public JsonProviderTest(Configuration conf) {
this.conf = conf;
}
@Parameterized.Parameters
public static Iterable<Configuration> configurations() {
return Configurations.configurations();
}
@Test
public void strings_are_unwrapped() {
@ParameterizedTest
@MethodSource("configurations")
public void strings_are_unwrapped(Configuration conf) {
assertThat(using(conf).parse(JSON_DOCUMENT).read("$.string-property", String.class)).isEqualTo("string-value");
}
@Test
public void integers_are_unwrapped() {
@ParameterizedTest
@MethodSource("configurations")
public void integers_are_unwrapped(Configuration conf) {
assertThat(using(conf).parse(JSON_DOCUMENT).read("$.int-max-property", Integer.class)).isEqualTo(Integer.MAX_VALUE);
}
@Test
public void ints_are_unwrapped() {
@ParameterizedTest
@MethodSource("configurations")
public void ints_are_unwrapped(Configuration conf) {
assertThat(using(conf).parse(JSON_DOCUMENT).read("$.int-max-property", int.class)).isEqualTo(Integer.MAX_VALUE);
}
}

69
json-path/src/test/java/com/jayway/jsonpath/JsonProviderTestObjectMapping.java

@ -1,8 +1,7 @@
package com.jayway.jsonpath;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.io.IOException;
import java.util.List;
@ -10,53 +9,51 @@ import java.util.List;
import static com.jayway.jsonpath.JsonPath.using;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(Parameterized.class)
public class JsonProviderTestObjectMapping extends BaseTest {
private static final String JSON =
"[" +
"{\n" +
" \"foo\" : \"foo0\",\n" +
" \"bar\" : 0,\n" +
" \"baz\" : true,\n" +
" \"gen\" : {\"prop\" : \"yepp0\"}" +
"}," +
"{\n" +
" \"foo\" : \"foo1\",\n" +
" \"bar\" : 1,\n" +
" \"baz\" : true,\n" +
" \"gen\" : {\"prop\" : \"yepp1\"}" +
"}," +
"{\n" +
" \"foo\" : \"foo2\",\n" +
" \"bar\" : 2,\n" +
" \"baz\" : true,\n" +
" \"gen\" : {\"prop\" : \"yepp2\"}" +
"}" +
"]";
private final Configuration conf;
public JsonProviderTestObjectMapping(Configuration conf) {
this.conf = conf;
}
"{\n" +
" \"foo\" : \"foo0\",\n" +
" \"bar\" : 0,\n" +
" \"baz\" : true,\n" +
" \"gen\" : {\"prop\" : \"yepp0\"}" +
"}," +
"{\n" +
" \"foo\" : \"foo1\",\n" +
" \"bar\" : 1,\n" +
" \"baz\" : true,\n" +
" \"gen\" : {\"prop\" : \"yepp1\"}" +
"}," +
"{\n" +
" \"foo\" : \"foo2\",\n" +
" \"bar\" : 2,\n" +
" \"baz\" : true,\n" +
" \"gen\" : {\"prop\" : \"yepp2\"}" +
"}" +
"]";
@Parameterized.Parameters
public static Iterable<Configuration> configurations() {
return Configurations.objectMappingConfigurations();
}
@Test
public void list_of_numbers() {
TypeRef<List<Double>> typeRef = new TypeRef<List<Double>>() {};
@ParameterizedTest
@MethodSource("configurations")
public void list_of_numbers(Configuration conf) {
TypeRef<List<Double>> typeRef = new TypeRef<List<Double>>() {
};
assertThat(using(conf).parse(JSON_DOCUMENT).read("$.store.book[*].display-price", typeRef)).containsExactly(8.95D, 12.99D, 8.99D, 22.99D);
}
@Test
public void test_type_ref() throws IOException {
TypeRef<List<FooBarBaz<Sub>>> typeRef = new TypeRef<List<FooBarBaz<Sub>>>() {};
@ParameterizedTest
@MethodSource("configurations")
public void test_type_ref(Configuration conf) throws IOException {
TypeRef<List<FooBarBaz<Sub>>> typeRef = new TypeRef<List<FooBarBaz<Sub>>>() {
};
assertThat(using(conf).parse(JSON).read("$", typeRef)).extracting("foo").containsExactly("foo0", "foo1", "foo2");
}

2
json-path/src/test/java/com/jayway/jsonpath/MapperTest.java

@ -1,6 +1,6 @@
package com.jayway.jsonpath;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import java.math.BigInteger;

7
json-path/src/test/java/com/jayway/jsonpath/MultiPropTest.java

@ -1,6 +1,7 @@
package com.jayway.jsonpath;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.List;
@ -48,7 +49,7 @@ public class MultiPropTest {
.containsEntry("d", null);
}
@Test(expected = PathNotFoundException.class)
@Test
public void multi_props_can_be_required() {
Map<String, Object> model = new HashMap<String, Object>(){{
@ -59,7 +60,7 @@ public class MultiPropTest {
Configuration conf = Configuration.defaultConfiguration().addOptions(Option.REQUIRE_PROPERTIES);
using(conf).parse(model).read("$['a', 'x']", Map.class);
Assertions.assertThrows(PathNotFoundException.class, () -> using(conf).parse(model).read("$['a', 'x']", Map.class));
}
@Test

43
json-path/src/test/java/com/jayway/jsonpath/OptionsTest.java

@ -1,6 +1,6 @@
package com.jayway.jsonpath;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.HashMap;
@ -13,15 +13,16 @@ import static java.util.Arrays.asList;
import static java.util.Collections.singletonMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class OptionsTest extends BaseTest {
@Test(expected = PathNotFoundException.class)
@Test
public void a_leafs_is_not_defaulted_to_null() {
Configuration conf = Configuration.defaultConfiguration();
assertThat((String)using(conf).parse("{\"foo\" : \"bar\"}").read("$.baz")).isNull();
assertThrows(PathNotFoundException.class, () -> using(conf).parse("{\"foo\" : \"bar\"}").read("$.baz"));
}
@Test
@ -37,7 +38,7 @@ public class OptionsTest extends BaseTest {
Configuration conf = Configuration.defaultConfiguration();
assertThat((String)using(conf).parse("{\"foo\" : \"bar\"}").read("$.foo")).isInstanceOf(String.class);
assertThat((String) using(conf).parse("{\"foo\" : \"bar\"}").read("$.foo")).isInstanceOf(String.class);
}
@Test
@ -45,11 +46,11 @@ public class OptionsTest extends BaseTest {
Configuration conf = Configuration.builder().options(ALWAYS_RETURN_LIST).build();
assertThat((List)using(conf).parse("{\"foo\" : \"bar\"}").read("$.foo")).isInstanceOf(List.class);
assertThat((List) using(conf).parse("{\"foo\" : \"bar\"}").read("$.foo")).isInstanceOf(List.class);
assertThat((List)using(conf).parse("{\"foo\": null}").read("$.foo")).isInstanceOf(List.class);
assertThat((List) using(conf).parse("{\"foo\": null}").read("$.foo")).isInstanceOf(List.class);
assertThat((List)using(conf).parse("{\"foo\": [1, 4, 8]}").read("$.foo")).asList()
assertThat((List) using(conf).parse("{\"foo\": [1, 4, 8]}").read("$.foo")).asList()
.containsExactly(Arrays.asList(1, 4, 8));
}
@ -61,7 +62,7 @@ public class OptionsTest extends BaseTest {
assertThat(result).hasSize(1);
assertThat(result.get(0)).isNull();
assertThat((List)using(conf).parse("{\"bar\": {\"foo\": [1, 4, 8]}}").read("$..foo")).asList()
assertThat((List) using(conf).parse("{\"bar\": {\"foo\": [1, 4, 8]}}").read("$..foo")).asList()
.containsExactly(Arrays.asList(1, 4, 8));
}
@ -69,7 +70,7 @@ public class OptionsTest extends BaseTest {
public void a_path_evaluation_is_returned_as_VALUE_by_default() {
Configuration conf = Configuration.defaultConfiguration();
assertThat((String)using(conf).parse("{\"foo\" : \"bar\"}").read("$.foo")).isEqualTo("bar");
assertThat((String) using(conf).parse("{\"foo\" : \"bar\"}").read("$.foo")).isEqualTo("bar");
}
@Test
@ -103,7 +104,7 @@ public class OptionsTest extends BaseTest {
@Test
public void when_property_is_required_exception_is_thrown() {
List<Map<String, String>> model = asList(singletonMap("a", "a-val"),singletonMap("b", "b-val"));
List<Map<String, String>> model = asList(singletonMap("a", "a-val"), singletonMap("b", "b-val"));
Configuration conf = Configuration.defaultConfiguration();
@ -112,10 +113,11 @@ public class OptionsTest extends BaseTest {
conf = conf.addOptions(Option.REQUIRE_PROPERTIES);
try{
try {
using(conf).parse(model).read("$[*].a", List.class);
fail("Should throw PathNotFoundException");
} catch (PathNotFoundException pnf){}
} catch (PathNotFoundException pnf) {
}
}
@Test
@ -131,10 +133,11 @@ public class OptionsTest extends BaseTest {
conf = conf.addOptions(Option.REQUIRE_PROPERTIES);
try{
try {
using(conf).parse(model).read("$.*.a-key", List.class);
fail("Should throw PathNotFoundException");
} catch (PathNotFoundException pnf){}
} catch (PathNotFoundException pnf) {
}
}
@ -142,20 +145,20 @@ public class OptionsTest extends BaseTest {
public void issue_suppress_exceptions_does_not_break_indefinite_evaluation() {
Configuration conf = Configuration.builder().options(SUPPRESS_EXCEPTIONS).build();
assertThat((List)using(conf).parse("{\"foo2\": [5]}").read("$..foo2[0]")).asList().containsOnly(5);
assertThat((List)using(conf).parse("{\"foo\" : {\"foo2\": [5]}}").read("$..foo2[0]")).asList().containsOnly(5);
assertThat((List)using(conf).parse("[null, [{\"foo\" : {\"foo2\": [5]}}]]").read("$..foo2[0]")).asList().containsOnly(5);
assertThat((List) using(conf).parse("{\"foo2\": [5]}").read("$..foo2[0]")).asList().containsOnly(5);
assertThat((List) using(conf).parse("{\"foo\" : {\"foo2\": [5]}}").read("$..foo2[0]")).asList().containsOnly(5);
assertThat((List) using(conf).parse("[null, [{\"foo\" : {\"foo2\": [5]}}]]").read("$..foo2[0]")).asList().containsOnly(5);
assertThat((List)using(conf).parse("[null, [{\"foo\" : {\"foo2\": [5]}}]]").read("$..foo.foo2[0]")).asList().containsOnly(5);
assertThat((List) using(conf).parse("[null, [{\"foo\" : {\"foo2\": [5]}}]]").read("$..foo.foo2[0]")).asList().containsOnly(5);
assertThat((List)using(conf).parse("{\"aoo\" : {}, \"foo\" : {\"foo2\": [5]}, \"zoo\" : {}}").read("$[*].foo2[0]")).asList().containsOnly(5);
assertThat((List) using(conf).parse("{\"aoo\" : {}, \"foo\" : {\"foo2\": [5]}, \"zoo\" : {}}").read("$[*].foo2[0]")).asList().containsOnly(5);
}
@Test
public void isbn_is_defaulted_when_option_is_provided() {
List<String> result1 = JsonPath.using(JSON_SMART_CONFIGURATION).parse(JSON_DOCUMENT).read("$.store.book.*.isbn");
assertThat(result1).containsExactly("0-553-21311-3","0-395-19395-8");
assertThat(result1).containsExactly("0-553-21311-3", "0-395-19395-8");
List<String> result2 = JsonPath.using(JSON_SMART_CONFIGURATION.addOptions(Option.DEFAULT_PATH_LEAF_TO_NULL)).parse(JSON_DOCUMENT).read("$.store.book.*.isbn");

64
json-path/src/test/java/com/jayway/jsonpath/PathCompilerTest.java

@ -1,32 +1,32 @@
package com.jayway.jsonpath;
import com.jayway.jsonpath.internal.ParseContextImpl;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.List;
import static com.jayway.jsonpath.internal.path.PathCompiler.compile;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class PathCompilerTest {
@Ignore("Backward compatibility <= 2.0.0")
@Test(expected = InvalidPathException.class)
@Disabled("Backward compatibility <= 2.0.0")
@Test
public void a_path_must_start_with_$_or_at() {
compile("x");
assertThrows(InvalidPathException.class, () -> compile("x"));
}
@Ignore("Backward compatibility <= 2.0.0")
@Test(expected = InvalidPathException.class)
@Disabled("Backward compatibility <= 2.0.0")
@Test
public void a_square_bracket_may_not_follow_a_period() {
compile("$.[");
assertThrows(InvalidPathException.class, () -> compile("$.["));
}
@Test(expected = InvalidPathException.class)
@Test
public void a_root_path_must_be_followed_by_period_or_bracket() {
compile("$X");
assertThrows(InvalidPathException.class, () -> compile("$X"));
}
@Test
@ -35,24 +35,24 @@ public class PathCompilerTest {
assertThat(compile("@").toString()).isEqualTo("@");
}
@Test(expected = InvalidPathException.class)
@Test
public void a_path_may_not_end_with_period() {
compile("$.");
assertThrows(InvalidPathException.class, () -> compile("$."));
}
@Test(expected = InvalidPathException.class)
@Test
public void a_path_may_not_end_with_period_2() {
compile("$.prop.");
assertThrows(InvalidPathException.class, () -> compile("$.prop."));
}
@Test(expected = InvalidPathException.class)
@Test
public void a_path_may_not_end_with_scan() {
compile("$..");
assertThrows(InvalidPathException.class, () -> compile("$.."));
}
@Test(expected = InvalidPathException.class)
@Test
public void a_path_may_not_end_with_scan_2() {
compile("$.prop..");
assertThrows(InvalidPathException.class, () -> compile("$.prop.."));
}
@Test
@ -84,9 +84,9 @@ public class PathCompilerTest {
assertThat(compile("$.aaa.bbb.ccc").toString()).isEqualTo("$['aaa']['bbb']['ccc']");
}
@Test(expected = InvalidPathException.class)
@Test
public void a_property_may_not_contain_blanks() {
assertThat(compile("$.foo bar").toString());
assertThrows(InvalidPathException.class, () -> compile("$.foo bar"));
}
@Test
@ -242,7 +242,7 @@ public class PathCompilerTest {
String json = "{\n"
+ " \"logs\": [\n"
+ " {\n"
+ " \"message\": \"\\\"it\\\"\",\n"
+ " \"message\": \"\\\"it\\\"\"\n"
+ " }\n"
+ " ]\n"
+ "}";
@ -255,7 +255,7 @@ public class PathCompilerTest {
String json = "{\n"
+ " \"logs\": [\n"
+ " {\n"
+ " \"message\": \"'it'\",\n"
+ " \"message\": \"'it'\"\n"
+ " }\n"
+ " ]\n"
+ "}";
@ -270,7 +270,7 @@ public class PathCompilerTest {
String json = "{\n"
+ " \"logs\": [\n"
+ " {\n"
+ " \"message\": \"'it'\",\n"
+ " \"message\": \"'it'\"\n"
+ " }\n"
+ " ]\n"
+ "}";
@ -304,24 +304,24 @@ public class PathCompilerTest {
assertThat(compile("$.aaa.foo(5,10,15)").toString()).isEqualTo("$['aaa'].foo(...)");
}
@Test(expected = InvalidPathException.class)
@Test
public void array_indexes_must_be_separated_by_commas() {
compile("$[0, 1, 2 4]");
assertThrows(InvalidPathException.class, () -> compile("$[0, 1, 2 4]"));
}
@Test(expected = InvalidPathException.class)
@Test
public void trailing_comma_after_list_is_not_accepted() {
compile("$['1','2',]");
assertThrows(InvalidPathException.class, () -> compile("$['1','2',]"));
}
@Test(expected = InvalidPathException.class)
@Test
public void accept_only_a_single_comma_between_indexes() {
compile("$['1', ,'3']");
assertThrows(InvalidPathException.class, () -> compile("$['1', ,'3']"));
}
@Test(expected = InvalidPathException.class)
@Test
public void property_must_be_separated_by_commas() {
compile("$['aaa'}'bbb']");
assertThrows(InvalidPathException.class, () -> compile("$['aaa'}'bbb']"));
}
@Test

2
json-path/src/test/java/com/jayway/jsonpath/PredicateTest.java

@ -1,6 +1,6 @@
package com.jayway.jsonpath;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;

29
json-path/src/test/java/com/jayway/jsonpath/ProviderInTest.java

@ -2,23 +2,14 @@ package com.jayway.jsonpath;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.gson.JsonArray;
import com.jayway.jsonpath.spi.json.GsonJsonProvider;
import com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider;
import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
import com.jayway.jsonpath.spi.json.JakartaJsonProvider;
import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider;
import com.jayway.jsonpath.spi.json.JsonSmartJsonProvider;
import com.jayway.jsonpath.spi.mapper.GsonMappingProvider;
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
import com.jayway.jsonpath.spi.mapper.JakartaMappingProvider;
import com.jayway.jsonpath.spi.mapper.JsonOrgMappingProvider;
import com.jayway.jsonpath.spi.mapper.JsonSmartMappingProvider;
import com.jayway.jsonpath.spi.json.*;
import com.jayway.jsonpath.spi.mapper.*;
import org.assertj.core.util.Lists;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ProviderInTest {
private final String JSON = "[{\"foo\": \"bar\"}, {\"foo\": \"baz\"}]";
@ -33,7 +24,7 @@ public class ProviderInTest {
@Test
public void testJsonPathQuotesJackson() throws Exception {
public void testJsonPathQuotesJackson() {
final Configuration jackson = Configuration.builder().jsonProvider(new JacksonJsonProvider()).mappingProvider(new JacksonMappingProvider()).build();
final DocumentContext ctx = JsonPath.using(jackson).parse(JSON);
@ -52,7 +43,7 @@ public class ProviderInTest {
@Test
public void testJsonPathQuotesJacksonJsonNode() throws Exception {
public void testJsonPathQuotesJacksonJsonNode() {
final Configuration jacksonJsonNode = Configuration.builder().jsonProvider(new JacksonJsonNodeJsonProvider()).mappingProvider(new JacksonMappingProvider()).build();
final DocumentContext ctx = JsonPath.using(jacksonJsonNode).parse(JSON);
@ -70,7 +61,7 @@ public class ProviderInTest {
}
@Test
public void testJsonPathQuotesGson() throws Exception {
public void testJsonPathQuotesGson() {
final Configuration gson = Configuration.builder().jsonProvider(new GsonJsonProvider()).mappingProvider(new GsonMappingProvider()).build();
final DocumentContext ctx = JsonPath.using(gson).parse(JSON);
@ -88,7 +79,7 @@ public class ProviderInTest {
}
@Test
public void testJsonPathQuotesJsonOrg() throws Exception {
public void testJsonPathQuotesJsonOrg() {
final Configuration jsonOrg = Configuration.builder().jsonProvider(new JsonOrgJsonProvider()).mappingProvider(new JsonOrgMappingProvider()).build();
final DocumentContext ctx = JsonPath.using(jsonOrg).parse(JSON);
@ -106,7 +97,7 @@ public class ProviderInTest {
}
@Test
public void testJsonPathQuotesJsonSmart() throws Exception {
public void testJsonPathQuotesJsonSmart() {
final Configuration jsonSmart = Configuration.builder().jsonProvider(new JsonSmartJsonProvider()).mappingProvider(new JsonSmartMappingProvider()).build();
final DocumentContext ctx = JsonPath.using(jsonSmart).parse(JSON);
@ -124,7 +115,7 @@ public class ProviderInTest {
}
@Test
public void testJsonPathQuotesJakarta() throws Exception {
public void testJsonPathQuotesJakarta() {
final Configuration gson = Configuration.builder().jsonProvider(new JakartaJsonProvider()).mappingProvider(new JakartaMappingProvider()).build();
final DocumentContext ctx = JsonPath.using(gson).parse(JSON);

2
json-path/src/test/java/com/jayway/jsonpath/ReadContextTest.java

@ -1,7 +1,7 @@
package com.jayway.jsonpath;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static com.jayway.jsonpath.JsonPath.using;

17
json-path/src/test/java/com/jayway/jsonpath/ReturnTypeTest.java

@ -1,6 +1,6 @@
package com.jayway.jsonpath;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;
@ -9,6 +9,7 @@ import static com.jayway.jsonpath.JsonPath.parse;
import static com.jayway.jsonpath.JsonPath.using;
import static com.jayway.jsonpath.Option.AS_PATH_LIST;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
@SuppressWarnings("ALL")
public class ReturnTypeTest extends BaseTest {
@ -18,7 +19,7 @@ public class ReturnTypeTest extends BaseTest {
@Test
public void assert_strings_can_be_read() {
assertThat((String)reader.read("$.string-property")).isEqualTo("string-value");
assertThat((String) reader.read("$.string-property")).isEqualTo("string-value");
}
@Test
@ -28,17 +29,17 @@ public class ReturnTypeTest extends BaseTest {
@Test
public void assert_longs_can_be_read() {
assertThat((Long)reader.read("$.long-max-property")).isEqualTo(Long.MAX_VALUE);
assertThat((Long) reader.read("$.long-max-property")).isEqualTo(Long.MAX_VALUE);
}
@Test
public void assert_boolean_values_can_be_read() {
assertThat((Boolean)reader.read("$.boolean-property")).isEqualTo(true);
assertThat((Boolean) reader.read("$.boolean-property")).isEqualTo(true);
}
@Test
public void assert_null_values_can_be_read() {
assertThat((String)reader.read("$.null-property")).isNull();
assertThat((String) reader.read("$.null-property")).isNull();
}
@Test
@ -78,8 +79,10 @@ public class ReturnTypeTest extends BaseTest {
}
@Test(expected = ClassCastException.class)
@Test
public void class_cast_exception_is_thrown_when_return_type_is_not_expected() {
List<String> list = reader.read("$.store.book[0].author");
assertThrows(ClassCastException.class, () -> {
List<String> list = reader.read("$.store.book[0].author");
});
}
}

2
json-path/src/test/java/com/jayway/jsonpath/ScientificNotationTest.java

@ -1,7 +1,7 @@
package com.jayway.jsonpath;
import com.google.gson.JsonArray;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;

2
json-path/src/test/java/com/jayway/jsonpath/TapestryJsonProviderTest.java

@ -8,7 +8,7 @@ import java.util.Map;
import org.apache.tapestry5.json.JSONArray;
import org.apache.tapestry5.json.JSONObject;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class TapestryJsonProviderTest extends BaseTest {

47
json-path/src/test/java/com/jayway/jsonpath/TestSuppressExceptions.java

@ -2,36 +2,35 @@ package com.jayway.jsonpath;
import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertNull;
public class TestSuppressExceptions {
@Test
public void testSuppressExceptionsIsRespected() {
ParseContext parseContext = JsonPath.using(
new Configuration.ConfigurationBuilder().jsonProvider(new JacksonJsonProvider())
.mappingProvider(new JacksonMappingProvider()).options(Option.SUPPRESS_EXCEPTIONS)
.build());
String json = "{}";
assertNull(parseContext.parse(json).read(JsonPath.compile("$.missing")));
}
@Test
public void testSuppressExceptionsIsRespectedPath() {
ParseContext parseContext = JsonPath.using(
new Configuration.ConfigurationBuilder().jsonProvider(new JacksonJsonProvider())
.mappingProvider(new JacksonMappingProvider()).options(Option.SUPPRESS_EXCEPTIONS, Option.AS_PATH_LIST)
.build());
String json = "{}";
List<String> result = parseContext.parse(json).read(JsonPath.compile("$.missing"));
assertThat(result).isEmpty();
}
@Test
public void testSuppressExceptionsIsRespected() {
ParseContext parseContext = JsonPath.using(
new Configuration.ConfigurationBuilder().jsonProvider(new JacksonJsonProvider())
.mappingProvider(new JacksonMappingProvider()).options(Option.SUPPRESS_EXCEPTIONS)
.build());
String json = "{}";
assertNull(parseContext.parse(json).read(JsonPath.compile("$.missing")));
}
@Test
public void testSuppressExceptionsIsRespectedPath() {
ParseContext parseContext = JsonPath.using(
new Configuration.ConfigurationBuilder().jsonProvider(new JacksonJsonProvider())
.mappingProvider(new JacksonMappingProvider()).options(Option.SUPPRESS_EXCEPTIONS, Option.AS_PATH_LIST)
.build());
String json = "{}";
List<String> result = parseContext.parse(json).read(JsonPath.compile("$.missing"));
assertThat(result).isEmpty();
}
}

35
json-path/src/test/java/com/jayway/jsonpath/WriteTest.java

@ -1,6 +1,6 @@
package com.jayway.jsonpath;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.InputStream;
import java.util.HashMap;
@ -11,6 +11,7 @@ import java.util.Map;
import static com.jayway.jsonpath.JsonPath.parse;
import static java.util.Collections.emptyMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class WriteTest extends BaseTest {
@ -187,7 +188,7 @@ public class WriteTest extends BaseTest {
@Test
public void item_can_be_added_to_root_array() {
List<Integer> model = new LinkedList<Integer>();
List<Integer> model = new LinkedList<>();
model.add(1);
model.add(2);
@ -206,23 +207,23 @@ public class WriteTest extends BaseTest {
assertThat(newVal).isEqualTo("new-val");
}
@Test(expected = InvalidModificationException.class)
@Test
public void add_to_object_on_array() {
parse(JSON_DOCUMENT).put("$.store.book", "new-key", "new-value");
assertThrows(InvalidModificationException.class, () -> parse(JSON_DOCUMENT).put("$.store.book", "new-key", "new-value"));
}
@Test(expected = InvalidModificationException.class)
@Test
public void add_to_array_on_object() {
parse(JSON_DOCUMENT).add("$.store.book[0]", "new-value");
assertThrows(InvalidModificationException.class, () -> parse(JSON_DOCUMENT).add("$.store.book[0]", "new-value"));
}
@Test(expected = InvalidModificationException.class)
@Test
public void root_object_can_not_be_updated() {
Map model = new HashMap();
model.put("a", "a-val");
parse(model).set("$[?(@.a == 'a-val')]", 1);
assertThrows(InvalidModificationException.class, () -> parse(model).set("$[?(@.a == 'a-val')]", 1));
}
@Test
@ -247,25 +248,25 @@ public class WriteTest extends BaseTest {
assertThat(result).isNotEmpty();
}
@Test(expected = InvalidModificationException.class)
@Test
public void non_map_array_items_cannot_be_renamed(){
List<Integer> model = new LinkedList<Integer>();
List<Integer> model = new LinkedList<>();
model.add(1);
model.add(2);
parse(model).renameKey("$[*]", "oldKey", "newKey");
assertThrows(InvalidModificationException.class, () -> parse(model).renameKey("$[*]", "oldKey", "newKey"));
}
@Test(expected = InvalidModificationException.class)
@Test
public void multiple_properties_cannot_be_renamed(){
parse(JSON_DOCUMENT).renameKey("$.store.book[*]['author', 'category']", "old-key", "new-key");
assertThrows(InvalidModificationException.class, () ->parse(JSON_DOCUMENT).renameKey("$.store.book[*]['author', 'category']", "old-key", "new-key"));
}
@Test(expected = PathNotFoundException.class)
@Test
public void non_existent_key_rename_not_allowed(){
Object o = parse(JSON_DOCUMENT).renameKey("$", "fake", "new-fake").json();
assertThrows(PathNotFoundException.class, () -> parse(JSON_DOCUMENT).renameKey("$", "fake", "new-fake").json());
}
@Test(expected = InvalidModificationException.class)
@Test
public void rootCannotBeMapped(){
MapFunction mapFunction = new MapFunction() {
@Override
@ -273,7 +274,7 @@ public class WriteTest extends BaseTest {
return currentValue.toString()+"converted";
}
};
Object o = parse(JSON_DOCUMENT).map("$", mapFunction).json();
assertThrows(InvalidModificationException.class, () -> parse(JSON_DOCUMENT).map("$", mapFunction).json());
}
@Test

2
json-path/src/test/java/com/jayway/jsonpath/internal/JsonContextTest.java

@ -6,7 +6,7 @@ import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.Filter;
import com.jayway.jsonpath.JsonPath;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;

126
json-path/src/test/java/com/jayway/jsonpath/internal/UtilsTest.java

@ -1,16 +1,13 @@
package com.jayway.jsonpath.internal;
import com.jayway.jsonpath.JsonPathException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
public class UtilsTest {
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Test
public void testJoin() {
@ -19,92 +16,87 @@ public class UtilsTest {
strings.add("bar");
strings.add("baz");
Assert.assertEquals("foo,bar,baz", Utils.join(",", strings));
Assert.assertEquals("", Utils.join(",", new ArrayList<String>()));
Assertions.assertEquals("foo,bar,baz", Utils.join(",", strings));
Assertions.assertEquals("", Utils.join(",", new ArrayList<String>()));
}
@Test
public void testConcat() {
Assert.assertEquals("", Utils.concat());
Assert.assertEquals("", Utils.concat(""));
Assert.assertEquals("", Utils.concat("", ""));
Assert.assertEquals("a", Utils.concat("a"));
Assert.assertEquals("a", Utils.concat("", "a", ""));
Assert.assertEquals("abc", Utils.concat("a", "b", "c"));
Assertions.assertEquals("", Utils.concat());
Assertions.assertEquals("", Utils.concat(""));
Assertions.assertEquals("", Utils.concat("", ""));
Assertions.assertEquals("a", Utils.concat("a"));
Assertions.assertEquals("a", Utils.concat("", "a", ""));
Assertions.assertEquals("abc", Utils.concat("a", "b", "c"));
}
@Test
public void testEscape() {
Assert.assertNull(Utils.escape(null, true));
Assertions.assertNull(Utils.escape(null, true));
Assert.assertEquals("\\\\f\\'o\\\"o\\rb\\fa\\t\\nr\\bb\\/a",
Utils.escape("\\f\'o\"o\rb\fa\t\nr\bb/a", true));
Assert.assertEquals("\\uFFFF\\u0FFF\\u00FF\\u000F\\u0010",
Utils.escape("\uffff\u0fff\u00ff\u000f\u0010", true));
Assertions.assertEquals("\\\\f\\'o\\\"o\\rb\\fa\\t\\nr\\bb\\/a", Utils.escape("\\f\'o\"o\rb\fa\t\nr\bb/a", true));
Assertions.assertEquals("\\uFFFF\\u0FFF\\u00FF\\u000F\\u0010", Utils.escape("\uffff\u0fff\u00ff\u000f\u0010", true));
}
@Test
public void testUnescape() {
Assert.assertNull(Utils.unescape(null));
Assertions.assertNull(Utils.unescape(null));
Assert.assertEquals("foo", Utils.unescape("foo"));
Assert.assertEquals("\\", Utils.unescape("\\"));
Assert.assertEquals("\\", Utils.unescape("\\\\"));
Assert.assertEquals("\'", Utils.unescape("\\\'"));
Assert.assertEquals("\"", Utils.unescape("\\\""));
Assert.assertEquals("\r", Utils.unescape("\\r"));
Assert.assertEquals("\f", Utils.unescape("\\f"));
Assert.assertEquals("\t", Utils.unescape("\\t"));
Assert.assertEquals("\n", Utils.unescape("\\n"));
Assert.assertEquals("\b", Utils.unescape("\\b"));
Assert.assertEquals("a", Utils.unescape("\\a"));
Assert.assertEquals("\uffff", Utils.unescape("\\uffff"));
Assertions.assertEquals("foo", Utils.unescape("foo"));
Assertions.assertEquals("\\", Utils.unescape("\\"));
Assertions.assertEquals("\\", Utils.unescape("\\\\"));
Assertions.assertEquals("\'", Utils.unescape("\\\'"));
Assertions.assertEquals("\"", Utils.unescape("\\\""));
Assertions.assertEquals("\r", Utils.unescape("\\r"));
Assertions.assertEquals("\f", Utils.unescape("\\f"));
Assertions.assertEquals("\t", Utils.unescape("\\t"));
Assertions.assertEquals("\n", Utils.unescape("\\n"));
Assertions.assertEquals("\b", Utils.unescape("\\b"));
Assertions.assertEquals("a", Utils.unescape("\\a"));
Assertions.assertEquals("\uffff", Utils.unescape("\\uffff"));
}
@Test
public void testUnescapeThrow() {
thrown.expect(JsonPathException.class);
Utils.unescape("\\uuuuu");
Assertions.assertThrows(JsonPathException.class, () -> Utils.unescape("\\uuuuu"));
}
@Test
public void testHex() {
Assert.assertEquals("61", Utils.hex('a'));
Assert.assertEquals("24", Utils.hex('$'));
Assertions.assertEquals("61", Utils.hex('a'));
Assertions.assertEquals("24", Utils.hex('$'));
}
@Test
public void testIsEmpty() {
Assert.assertTrue(Utils.isEmpty(null));
Assert.assertTrue(Utils.isEmpty(""));
Assertions.assertTrue(Utils.isEmpty(null));
Assertions.assertTrue(Utils.isEmpty(""));
Assert.assertFalse(Utils.isEmpty("foo"));
Assertions.assertFalse(Utils.isEmpty("foo"));
}
@Test
public void testIndexOf() {
Assert.assertEquals(-1, Utils.indexOf("bar", "foo", 0));
Assert.assertEquals(-1, Utils.indexOf("bar", "a", 2));
Assert.assertEquals(1, Utils.indexOf("bar", "a", 0));
Assert.assertEquals(1, Utils.indexOf("bar", "a", 1));
Assertions.assertEquals(-1, Utils.indexOf("bar", "foo", 0));
Assertions.assertEquals(-1, Utils.indexOf("bar", "a", 2));
Assertions.assertEquals(1, Utils.indexOf("bar", "a", 0));
Assertions.assertEquals(1, Utils.indexOf("bar", "a", 1));
}
@Test
public void testNotNull() {
Assert.assertEquals("", Utils.notNull("", "bar", "a", "b", "c"));
Assert.assertEquals("foo", Utils.notNull("foo", "bar", "a", "b", "c"));
Assertions.assertEquals("", Utils.notNull("", "bar", "a", "b", "c"));
Assertions.assertEquals("foo", Utils.notNull("foo", "bar", "a", "b", "c"));
}
@Test
public void testNotNullThrow() {
thrown.expect(IllegalArgumentException.class);
Utils.notNull(null, "bar", "a", "b", "c");
Assertions.assertThrows(IllegalArgumentException.class, () -> Utils.notNull(null, "bar", "a", "b", "c"));
}
@Test
public void testCloseQuietly() throws IllegalArgumentException {
thrown.expect(IllegalArgumentException.class);
Utils.notNull(null, "bar", "a", "b", "c");
Assertions.assertThrows(IllegalArgumentException.class, () -> Utils.notNull(null, "bar", "a", "b", "c"));
}
@Test
@ -114,56 +106,50 @@ public class UtilsTest {
@Test
public void testIsTrueThrow() {
thrown.expect(IllegalArgumentException.class);
Utils.isTrue(false, "foo");
Assertions.assertThrows(IllegalArgumentException.class, () -> Utils.isTrue(false, "foo"));
}
@Test
public void testOnlyOneIsTrueThrow1() {
thrown.expect(IllegalArgumentException.class);
Utils.onlyOneIsTrue("foo", false, false);
Assertions.assertThrows(IllegalArgumentException.class, () -> Utils.onlyOneIsTrue("foo", false, false));
}
@Test
public void testOnlyOneIsTrueThrow2() {
thrown.expect(IllegalArgumentException.class);
Utils.onlyOneIsTrue("foo", true, true);
Assertions.assertThrows(IllegalArgumentException.class, () -> Utils.onlyOneIsTrue("foo", true, true));
}
@Test
public void testOnlyOneIsTrueNonThrow() {
Assert.assertTrue(Utils.onlyOneIsTrueNonThrow(true));
Assertions.assertTrue(Utils.onlyOneIsTrueNonThrow(true));
Assert.assertFalse(Utils.onlyOneIsTrueNonThrow(true, true, true));
Assert.assertFalse(Utils.onlyOneIsTrueNonThrow(true, true, false));
Assert.assertFalse(Utils.onlyOneIsTrueNonThrow(false, false, false));
Assertions.assertFalse(Utils.onlyOneIsTrueNonThrow(true, true, true));
Assertions.assertFalse(Utils.onlyOneIsTrueNonThrow(true, true, false));
Assertions.assertFalse(Utils.onlyOneIsTrueNonThrow(false, false, false));
}
@Test
public void testNotEmpty() {
Assert.assertEquals("bar", Utils.notEmpty("bar", "foo", 1, 2, 3));
Assert.assertEquals("baz",
Utils.notEmpty("baz", "bar", "b", "a", "r"));
Assertions.assertEquals("bar", Utils.notEmpty("bar", "foo", 1, 2, 3));
Assertions.assertEquals("baz", Utils.notEmpty("baz", "bar", "b", "a", "r"));
}
@Test
public void testNotEmptyThrowNull() {
thrown.expect(IllegalArgumentException.class);
Utils.notEmpty(null, "foo", 1, 2, 3);
Assertions.assertThrows(IllegalArgumentException.class, () -> Utils.notEmpty(null, "foo", 1, 2, 3));
}
@Test
public void testNotEmptyThrowLength0() {
thrown.expect(IllegalArgumentException.class);
Utils.notEmpty("", "foo", 1, 2, 3);
Assertions.assertThrows(IllegalArgumentException.class, () -> Utils.notEmpty("", "foo", 1, 2, 3));
}
@Test
public void testToString() {
Assert.assertNull(Utils.toString(null));
Assertions.assertNull(Utils.toString(null));
Assert.assertEquals("", Utils.toString(""));
Assert.assertEquals("foo", Utils.toString("foo"));
Assert.assertEquals("123", Utils.toString(123));
Assertions.assertEquals("", Utils.toString(""));
Assertions.assertEquals("foo", Utils.toString("foo"));
Assertions.assertEquals("123", Utils.toString(123));
}
}

56
json-path/src/test/java/com/jayway/jsonpath/internal/filter/PatternFlagTest.java

@ -1,47 +1,37 @@
package com.jayway.jsonpath.internal.filter;
import com.jayway.jsonpath.BaseTest;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.stream.Stream;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.assertEquals;
@RunWith(Parameterized.class)
public class PatternFlagTest extends BaseTest {
private final int flags;
private final String expectedFlags;
public PatternFlagTest(int flags, String expectedFlags) {
this.flags = flags;
this.expectedFlags = expectedFlags;
@ParameterizedTest
@MethodSource("testData")
public void testParseFlags(int flags, String expectedFlags) {
assertEquals(expectedFlags, PatternFlag.parseFlags(flags));
}
@Test
public void testParseFlags() {
Assert.assertEquals(expectedFlags, PatternFlag.parseFlags(flags));
}
@Parameterized.Parameters
public static Iterable data() {
return Arrays.asList(
new Object[][]{
{ 1, "d" },
{ 2, "i" },
{ 4, "x" },
{ 8, "m" },
{ 32, "s" },
{ 64, "u" },
{ 256, "U" },
{ 300, "xmsU" },
{ 13, "dxm" },
{ 7, "dix" },
{ 100, "xsu" },
{ 367, "dixmsuU" }
}
public static Stream<Arguments> testData() {
return Stream.of(
Arguments.arguments(1, "d"),
Arguments.arguments(2, "i"),
Arguments.arguments(4, "x"),
Arguments.arguments(8, "m"),
Arguments.arguments(32, "s"),
Arguments.arguments(64, "u"),
Arguments.arguments(256, "U"),
Arguments.arguments(300, "xmsU"),
Arguments.arguments(13, "dxm"),
Arguments.arguments(7, "dix"),
Arguments.arguments(100, "xsu"),
Arguments.arguments(367, "dixmsuU")
);
}
}

79
json-path/src/test/java/com/jayway/jsonpath/internal/filter/RegexpEvaluatorTest.java

@ -5,35 +5,24 @@ import com.jayway.jsonpath.Predicate;
import com.jayway.jsonpath.internal.Path;
import com.jayway.jsonpath.internal.path.CompiledPath;
import com.jayway.jsonpath.internal.path.PathTokenFactory;
import org.assertj.core.util.Maps;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.stream.Stream;
import static com.jayway.jsonpath.internal.filter.ValueNode.*;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static com.jayway.jsonpath.internal.filter.ValueNode.*;
import static org.hamcrest.MatcherAssert.assertThat;
@RunWith(Parameterized.class)
public class RegexpEvaluatorTest extends BaseTest {
private String regexp;
private ValueNode valueNode;
private boolean expectedResult;
public RegexpEvaluatorTest(String regexp, ValueNode valueNode, boolean expectedResult) {
this.regexp = regexp;
this.valueNode = valueNode;
this.expectedResult = expectedResult;
}
@Test
public void should_evaluate_regular_expression() {
@ParameterizedTest
@MethodSource("testData")
public void should_evaluate_regular_expression(String regexp, ValueNode valueNode, boolean expectedResult) {
//given
Evaluator evaluator = EvaluatorFactory.createEvaluator(RelationalOperator.REGEX);
ValueNode patternNode = createPatternNode(regexp);
@ -46,33 +35,29 @@ public class RegexpEvaluatorTest extends BaseTest {
assertThat(result, is(equalTo(expectedResult)));
}
@Parameterized.Parameters(name="Regexp {0} for {1} node should evaluate to {2}")
public static Iterable data() {
return Arrays.asList(
new Object[][]{
{ "/true|false/", createStringNode("true", true), true },
{ "/9.*9/", createNumberNode("9979"), true },
{ "/fa.*se/", createBooleanNode("false"), true },
{ "/Eval.*or/", createClassNode(String.class), false },
{ "/JsonNode/", createJsonNode(json()), false },
{ "/PathNode/", createPathNode(path()), false },
{ "/Undefined/", createUndefinedNode(), false },
{ "/NullNode/", createNullNode(), false },
{ "/test/i", createStringNode("tEsT", true), true },
{ "/test/", createStringNode("tEsT", true), false },
{ "/\u00de/ui", createStringNode("\u00fe", true), true },
{ "/\u00de/", createStringNode("\u00fe", true), false },
{ "/\u00de/i", createStringNode("\u00fe", true), false },
{ "/test# code/", createStringNode("test", true), false },
{ "/test# code/x", createStringNode("test", true), true },
{ "/.*test.*/d", createStringNode("my\rtest", true), true },
{ "/.*test.*/", createStringNode("my\rtest", true), false },
{ "/.*tEst.*/is", createStringNode("test\ntest", true), true },
{ "/.*tEst.*/i", createStringNode("test\ntest", true), false },
{ "/^\\w+$/U", createStringNode("\u00fe", true), true },
{ "/^\\w+$/", createStringNode("\u00fe", true), false },
{ "/^test$\\ntest$/m", createStringNode("test\ntest", true), true }
}
public static Stream<Arguments> testData() {
return Stream.of(
Arguments.arguments("/true|false/", createStringNode("true", true), true),
Arguments.arguments("/9.*9/", createNumberNode("9979"), true),
Arguments.arguments("/fa.*se/", createBooleanNode("false"), true),
Arguments.arguments("/Eval.*or/", createClassNode(String.class), false),
Arguments.arguments("/JsonNode/", createJsonNode(json()), false),
Arguments.arguments("/PathNode/", createPathNode(path()), false),
Arguments.arguments("/Undefined/", createUndefinedNode(), false),
Arguments.arguments("/NullNode/", createNullNode(), false),
Arguments.arguments("/test/i", createStringNode("tEsT", true), true),
Arguments.arguments("/test/", createStringNode("tEsT", true), false),
Arguments.arguments("/\u00de/ui", createStringNode("\u00fe", true), true),
Arguments.arguments("/\u00de/", createStringNode("\u00fe", true), false),
Arguments.arguments("/\u00de/i", createStringNode("\u00fe", true), false),
Arguments.arguments("/test# code/", createStringNode("test", true), false),
Arguments.arguments("/test# code/x", createStringNode("test", true), true),
Arguments.arguments("/.*test.*/d", createStringNode("my\rtest", true), true),
Arguments.arguments("/.*test.*/", createStringNode("my\rtest", true), false),
Arguments.arguments("/.*tEst.*/is", createStringNode("test\ntest", true), true),
Arguments.arguments("/.*tEst.*/i", createStringNode("test\ntest", true), false),
Arguments.arguments("/^\\w+$/U", createStringNode("\u00fe", true), true),
Arguments.arguments("/^\\w+$/", createStringNode("\u00fe", true), false)
);
}

14
json-path/src/test/java/com/jayway/jsonpath/internal/filter/RelationalOperatorTest.java

@ -1,23 +1,23 @@
package com.jayway.jsonpath.internal.filter;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Locale;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class RelationalOperatorTest {
Locale locale;
@Before
@BeforeEach
public void saveDefaultLocale() {
locale = Locale.getDefault();
}
@After
@AfterEach
public void restoreDefaultLocale() {
Locale.setDefault(locale);
}

23
json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue191.java

@ -3,17 +3,16 @@ package com.jayway.jsonpath.internal.function;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.Configurations;
import com.jayway.jsonpath.JsonPath;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.InputStream;
import static org.junit.Assert.assertEquals;
/**
* TDD for Issue 191
*
* <p>
* Shows aggregation across fields rather than within a single entity.
*
*/
public class Issue191 {
@ -23,45 +22,41 @@ public class Issue191 {
public void testResultSetNumericComputation() {
InputStream stream = ClassLoader.getSystemResourceAsStream("issue_191.json");
Long value = JsonPath.parse(stream).read("$.sum($..timestamp)", Long.class);
assertEquals("Expected the max function to consume the aggregation parameters and calculate the max over the result set",
Long.valueOf(35679716813L), value);
Assertions.assertEquals(Long.valueOf(35679716813L), value, "Expected the max function to consume the aggregation parameters and calculate the max over the result set");
}
@Test
public void testResultSetNumericComputationTail() {
InputStream stream = ClassLoader.getSystemResourceAsStream("issue_191.json");
Long value = JsonPath.parse(stream).read("$..timestamp.sum()", Long.class);
assertEquals("Expected the max function to consume the aggregation parameters and calculate the max over the result set",
Long.valueOf(35679716813L), value);
Assertions.assertEquals(Long.valueOf(35679716813L), value, "Expected the max function to consume the aggregation parameters and calculate the max over the result set");
}
@Test
public void testResultSetNumericComputationRecursiveReplacement() {
InputStream stream = ClassLoader.getSystemResourceAsStream("issue_191.json");
Long value = JsonPath.parse(stream).read("$.max($..timestamp.avg(), $..timestamp.stddev())", Long.class);
assertEquals("Expected the max function to consume the aggregation parameters and calculate the max over the result set",
Long.valueOf(1427188672L), value);
Assertions.assertEquals(Long.valueOf(1427188672L), value, "Expected the max function to consume the aggregation parameters and calculate the max over the result set");
}
@Test
public void testMultipleResultSetSums() {
InputStream stream = ClassLoader.getSystemResourceAsStream("issue_191.json");
Long value = JsonPath.parse(stream).read("$.sum($..timestamp, $..cpus)", Long.class);
assertEquals("Expected the max function to consume the aggregation parameters and calculate the max over the result set",
Long.valueOf(35679716835L), value);
Assertions.assertEquals(Long.valueOf(35679716835L), value, "Expected the max function to consume the aggregation parameters and calculate the max over the result set");
}
@Test
public void testConcatResultSet() {
InputStream stream = ClassLoader.getSystemResourceAsStream("issue_191.json");
String concatResult = JsonPath.parse(stream).read("$.concat($..state)", String.class);
assertEquals("Expected a string length to be a concat of all of the states", concatResult.length(), 806);
Assertions.assertEquals(concatResult.length(), 806, "Expected a string length to be a concat of all of the states");
}
@Test
public void testConcatWithNumericValueAsString() {
InputStream stream = ClassLoader.getSystemResourceAsStream("issue_191.json");
String concatResult = JsonPath.parse(stream).read("$.concat($..cpus)", String.class);
assertEquals("Expected a string length to be a concat of all of the cpus", concatResult.length(), 489);
Assertions.assertEquals(concatResult.length(), 489, "Expected a string length to be a concat of all of the cpus");
}
}

2
json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue234.java

@ -1,7 +1,7 @@
package com.jayway.jsonpath.internal.function;
import com.jayway.jsonpath.JsonPath;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;

20
json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue273.java

@ -1,15 +1,13 @@
package com.jayway.jsonpath.internal.function;
import net.minidev.json.JSONArray;
import com.jayway.jsonpath.JsonPath;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import net.minidev.json.JSONArray;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class Issue273 {
@Test
public void testGetPropertyFromArray(){
public void testGetPropertyFromArray() {
String json = "[\n" +
" [\n" +
" {\n" +
@ -45,12 +43,12 @@ public class Issue273 {
" }\n" +
"]\n";
JSONArray arr = JsonPath.read(json,"$..[2].author");
assertEquals(arr.get(0), "Herman Melville");
JSONArray arr = JsonPath.read(json, "$..[2].author");
Assertions.assertEquals(arr.get(0), "Herman Melville");
}
@Test
public void testGetPropertyFromObject(){
public void testGetPropertyFromObject() {
String json = "{\n" +
" \"store\": {\n" +
" \"book\": [\n" +
@ -89,7 +87,7 @@ public class Issue273 {
" \"expensive\": 10\n" +
"}\n" +
" ";
JSONArray arr = JsonPath.read(json,"$..[2].author");
assertEquals(arr.get(0), "Herman Melville");
JSONArray arr = JsonPath.read(json, "$..[2].author");
Assertions.assertEquals(arr.get(0), "Herman Melville");
}
}

28
json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue612.java

@ -1,17 +1,11 @@
package com.jayway.jsonpath.internal.function;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.jayway.jsonpath.*;
import com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider;
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
import org.junit.Assert;
import org.junit.Test;
import static com.jayway.jsonpath.JsonPath.using;
import static com.jayway.jsonpath.internal.path.PathCompiler.fail;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Option;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class Issue612 {
@Test
@ -22,16 +16,18 @@ public class Issue612 {
String json = "{\"1\":{\"2\":null}}";
DocumentContext documentContext = JsonPath.using(config).parse(json);
JsonPath query = JsonPath.compile("$.1.2.a.b.c");
Assert.assertNull(documentContext.read(query));
Assert.assertNull(documentContext.map(query, (object, configuration) -> object));
Assertions.assertNull(documentContext.read(query));
Assertions.assertNull(documentContext.map(query, (object, configuration) -> object));
}
@Test(expected = Exception.class)
@Test
public void test2() {
Configuration config = Configuration.builder()
.build();
String json = "{\"1\":{\"2\":null}}";
DocumentContext documentContext = JsonPath.using(config).parse(json);
JsonPath query = JsonPath.compile("$.1.2.a.b.c");
documentContext.map(query, (object, configuration) -> object);
Assertions.assertThrows(Exception.class, () -> documentContext.map(query, (object, configuration) -> object));
}
}

12
json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue629.java

@ -1,12 +1,12 @@
package com.jayway.jsonpath.internal.function;
import com.jayway.jsonpath.JsonPath;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class Issue629 {
@ -15,8 +15,7 @@ public class Issue629 {
try {
JsonPath jsonPath = JsonPath.compile("$.A.B.C.D(");
fail("accepted jsonpath with unclosed parentheses");
}
catch (Exception e) {
} catch (Exception e) {
assertTrue(e.getMessage().startsWith("Arguments to function:"));
}
}
@ -26,8 +25,7 @@ public class Issue629 {
try {
JsonPath jsonPath = JsonPath.compile("$.A.B.C.sum(D()");
fail("accepted jsonpath with unclosed parentheses");
}
catch (Exception e) {
} catch (Exception e) {
assertTrue(e.getMessage().startsWith("Arguments to function:"));
}
}

5
json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue680.java

@ -1,10 +1,7 @@
package com.jayway.jsonpath.internal.function;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.spi.json.JsonSmartJsonProvider;
import com.jayway.jsonpath.spi.mapper.JsonSmartMappingProvider;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;

2
json-path/src/test/java/com/jayway/jsonpath/internal/function/JSONEntityPathFunctionTest.java

@ -3,7 +3,7 @@ package com.jayway.jsonpath.internal.function;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.Configurations;
import net.minidev.json.JSONArray;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* Verifies methods that are helper implementations of functions for manipulating JSON entities, i.e.

2
json-path/src/test/java/com/jayway/jsonpath/internal/function/KeySetFunctionTest.java

@ -3,7 +3,7 @@ package com.jayway.jsonpath.internal.function;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.Configurations;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.HashSet;

112
json-path/src/test/java/com/jayway/jsonpath/internal/function/NestedFunctionTest.java

@ -2,125 +2,139 @@ package com.jayway.jsonpath.internal.function;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.Configurations;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static com.jayway.jsonpath.JsonPath.using;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Created by matt@mjgreenwood.net on 12/10/15.
*/
@RunWith(Parameterized.class)
public class NestedFunctionTest extends BaseFunctionTest {
private static final Logger logger = LoggerFactory.getLogger(NumericPathFunctionTest.class);
private Configuration conf = Configurations.GSON_CONFIGURATION;
public NestedFunctionTest(Configuration conf) {
logger.debug("Testing with configuration {}", conf.getClass().getName());
this.conf = conf;
}
@Parameterized.Parameters
public static Iterable<Configuration> configurations() {
return Configurations.configurations();
}
@Test
public void testParameterAverageFunctionCall() {
@ParameterizedTest
@MethodSource("configurations")
public void testParameterAverageFunctionCall(Configuration conf) {
verifyMathFunction(conf, "$.avg($.numbers.min(), $.numbers.max())", 5.5);
}
@Test
public void testArrayAverageFunctionCall() {
@ParameterizedTest
@MethodSource("configurations")
public void testArrayAverageFunctionCall(Configuration conf) {
verifyMathFunction(conf, "$.numbers.avg()", 5.5);
}
/**
* This test calculates the following:
*
* <p>
* For each number in $.numbers 1 -> 10 add each number up,
* then add 1 (min), 10 (max)
*
* <p>
* Alternatively 1+2+3+4+5+6+7+8+9+10+1+10 == 66
*/
@Test
public void testArrayAverageFunctionCallWithParameters() {
@ParameterizedTest
@MethodSource("configurations")
public void testArrayAverageFunctionCallWithParameters(Configuration conf) {
verifyMathFunction(conf, "$.numbers.sum($.numbers.min(), $.numbers.max())", 66.0);
}
@Test
public void testJsonInnerArgumentArray() {
@ParameterizedTest
@MethodSource("configurations")
public void testJsonInnerArgumentArray(Configuration conf) {
verifyMathFunction(conf, "$.sum(5, 3, $.numbers.max(), 2)", 20.0);
}
@Test
public void testSimpleLiteralArgument() {
@ParameterizedTest
@MethodSource("configurations")
public void testSimpleLiteralArgument(Configuration conf) {
verifyMathFunction(conf, "$.sum(5)", 5.0);
verifyMathFunction(conf, "$.sum(50)", 50.0);
}
@Test
public void testStringConcat() {
@ParameterizedTest
@MethodSource("configurations")
public void testStringConcat(Configuration conf) {
verifyTextFunction(conf, "$.text.concat()", "abcdef");
}
@Test
public void testStringAndNumberConcat() {
@ParameterizedTest
@MethodSource("configurations")
public void testStringAndNumberConcat(Configuration conf) {
verifyTextAndNumberFunction(conf, "$.concat($.text[0], $.numbers[0])", "a1");
}
@Test
public void testStringConcatWithJSONParameter() {
@ParameterizedTest
@MethodSource("configurations")
public void testStringConcatWithJSONParameter(Configuration conf) {
verifyTextFunction(conf, "$.text.concat(\"-\", \"ghijk\")", "abcdef-ghijk");
}
@Test
public void testAppendNumber() {
@ParameterizedTest
@MethodSource("configurations")
public void testAppendNumber(Configuration conf) {
verifyMathFunction(conf, "$.numbers.append(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 0).avg()", 10.0);
}
/**
* Aggregation function should ignore text values
*/
@Test
public void testAppendTextAndNumberThenSum() {
@ParameterizedTest
@MethodSource("configurations")
public void testAppendTextAndNumberThenSum(Configuration conf) {
verifyMathFunction(conf, "$.numbers.append(\"0\", \"11\").sum()", 55.0);
}
@Test
public void testErrantCloseBraceNegative() {
@ParameterizedTest
@MethodSource("configurations")
public void testErrantCloseBraceNegative(Configuration conf) {
try {
using(conf).parse(this.NUMBER_SERIES).read("$.numbers.append(0, 1, 2}).avg()");
assert(false);
}
catch (Exception e) {
assert (false);
} catch (Exception e) {
assertTrue(e.getMessage().startsWith("Unexpected close brace"));
}
}
@Test
public void testErrantCloseBracketNegative() {
@ParameterizedTest
@MethodSource("configurations")
public void testErrantCloseBracketNegative(Configuration conf) {
try {
using(conf).parse(this.NUMBER_SERIES).read("$.numbers.append(0, 1, 2]).avg()");
assert(false);
}
catch (Exception e) {
assert (false);
} catch (Exception e) {
assertTrue(e.getMessage().startsWith("Unexpected close bracket"));
}
}
@Test
public void testUnclosedFunctionCallNegative() {
@ParameterizedTest
@MethodSource("configurations")
public void testUnclosedFunctionCallNegative(Configuration conf) {
try {
using(conf).parse(this.NUMBER_SERIES).read("$.numbers.append(0, 1, 2");
assert(false);
}
catch (Exception e) {
assert (false);
} catch (Exception e) {
assertTrue(e.getMessage().startsWith("Arguments to function: 'append'"));
}
}

78
json-path/src/test/java/com/jayway/jsonpath/internal/function/NumericPathFunctionTest.java

@ -3,52 +3,40 @@ package com.jayway.jsonpath.internal.function;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.Configurations;
import com.jayway.jsonpath.JsonPathException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.runners.Parameterized.Parameters;
/**
* Defines functional tests around executing:
*
* <p>
* - sum
* - avg
* - stddev
*
* <p>
* for each of the above, executes the test and verifies that the results are as expected based on a static input
* and static output.
*
* <p>
* Created by mattg on 6/26/15.
*/
@RunWith(Parameterized.class)
public class NumericPathFunctionTest extends BaseFunctionTest {
private static final Logger logger = LoggerFactory.getLogger(NumericPathFunctionTest.class);
private Configuration conf = Configurations.GSON_CONFIGURATION;
public NumericPathFunctionTest(Configuration conf) {
logger.debug("Testing with configuration {}", conf.getClass().getName());
this.conf = conf;
}
@Parameters
public static Iterable<Configuration> configurations() {
return Configurations.configurations();
}
@Test
public void testAverageOfDoubles() {
@ParameterizedTest
@MethodSource("configurations")
public void testAverageOfDoubles(Configuration conf) {
verifyMathFunction(conf, "$.numbers.avg()", 5.5);
}
@Test
public void testAverageOfEmptyListNegative() {
@ParameterizedTest
@MethodSource("configurations")
public void testAverageOfEmptyListNegative(Configuration conf) {
try {
verifyMathFunction(conf, "$.empty.avg()", null);
} catch (JsonPathException e) {
@ -56,13 +44,15 @@ public class NumericPathFunctionTest extends BaseFunctionTest {
}
}
@Test
public void testSumOfDouble() {
@ParameterizedTest
@MethodSource("configurations")
public void testSumOfDouble(Configuration conf) {
verifyMathFunction(conf, "$.numbers.sum()", (10d * (10d + 1d)) / 2d);
}
@Test
public void testSumOfEmptyListNegative() {
@ParameterizedTest
@MethodSource("configurations")
public void testSumOfEmptyListNegative(Configuration conf) {
try {
verifyMathFunction(conf, "$.empty.sum()", null);
} catch (JsonPathException e) {
@ -70,13 +60,15 @@ public class NumericPathFunctionTest extends BaseFunctionTest {
}
}
@Test
public void testMaxOfDouble() {
@ParameterizedTest
@MethodSource("configurations")
public void testMaxOfDouble(Configuration conf) {
verifyMathFunction(conf, "$.numbers.max()", 10d);
}
@Test
public void testMaxOfEmptyListNegative() {
@ParameterizedTest
@MethodSource("configurations")
public void testMaxOfEmptyListNegative(Configuration conf) {
try {
verifyMathFunction(conf, "$.empty.max()", null);
} catch (JsonPathException e) {
@ -84,13 +76,15 @@ public class NumericPathFunctionTest extends BaseFunctionTest {
}
}
@Test
public void testMinOfDouble() {
@ParameterizedTest
@MethodSource("configurations")
public void testMinOfDouble(Configuration conf) {
verifyMathFunction(conf, "$.numbers.min()", 1d);
}
@Test
public void testMinOfEmptyListNegative() {
@ParameterizedTest
@MethodSource("configurations")
public void testMinOfEmptyListNegative(Configuration conf) {
try {
verifyMathFunction(conf, "$.empty.min()", null);
} catch (JsonPathException e) {
@ -99,13 +93,15 @@ public class NumericPathFunctionTest extends BaseFunctionTest {
}
@Test
public void testStdDevOfDouble() {
@ParameterizedTest
@MethodSource("configurations")
public void testStdDevOfDouble(Configuration conf) {
verifyMathFunction(conf, "$.numbers.stddev()", 2.8722813232690143d);
}
@Test
public void testStddevOfEmptyListNegative() {
@ParameterizedTest
@MethodSource("configurations")
public void testStddevOfEmptyListNegative(Configuration conf) {
try {
verifyMathFunction(conf, "$.empty.stddev()", null);
} catch (JsonPathException e) {

2
json-path/src/test/java/com/jayway/jsonpath/internal/function/SequentialPathFunctionTest.java

@ -2,7 +2,7 @@ package com.jayway.jsonpath.internal.function;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.Configurations;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* Test cases for functions

2
json-path/src/test/java/com/jayway/jsonpath/internal/path/PathTokenTest.java

@ -1,7 +1,7 @@
package com.jayway.jsonpath.internal.path;
import com.jayway.jsonpath.BaseTest;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Arrays;

2
json-path/src/test/java/com/jayway/jsonpath/issue_613.java

@ -1,6 +1,6 @@
package com.jayway.jsonpath;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;

41
json-path/src/test/java/com/jayway/jsonpath/old/ArraySlicingTest.java

@ -2,91 +2,88 @@ package com.jayway.jsonpath.old;
import com.jayway.jsonpath.JsonPath;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
*
* If you have a list
* nums = [1, 3, 5, 7, 8, 13, 20]
* then it is possible to slice by using a notation similar to element retrieval:
*
* <p>
* nums[3] #equals 7, no slicing
* nums[:3] #equals [1, 3, 5], from index 0 (inclusive) until index 3 (exclusive)
* nums[1:5] #equals [3, 5, 7, 8]
* nums[-3:] #equals [8, 13, 20]
* nums[3:] #equals [8, 13, 20]
*
* <p>
* Note that Python allows negative list indices. The index -1 represents the last element, -2 the penultimate element, etc.
* Python also allows a step property by appending an extra colon and a value. For example:
*
* <p>
* nums[3::] #equals [7, 8, 13, 20], same as nums[3:]
* nums[::3] #equals [1, 7, 20] (starting at index 0 and getting every third element)
* nums[1:5:2] #equals [3, 7] (from index 1 until index 5 and getting every second element)
*
*/
public class ArraySlicingTest {
public static final String JSON_ARRAY = "[1, 3, 5, 7, 8, 13, 20]";
@Test
public void get_by_position(){
public void get_by_position() {
Integer result = JsonPath.read(JSON_ARRAY, "$[3]");
assertEquals(7, result.intValue());
}
@Test
public void get_from_index(){
public void get_from_index() {
List<Integer> result = JsonPath.read(JSON_ARRAY, "$[:3]");
assertThat(result, Matchers.contains(1,3,5));
assertThat(result, Matchers.contains(1, 3, 5));
}
@Test
public void get_between_index(){
public void get_between_index() {
List<Integer> result = JsonPath.read(JSON_ARRAY, "$[1:5]");
assertThat(result, Matchers.contains(3, 5, 7, 8));
}
@Test
public void get_between_index_2(){
public void get_between_index_2() {
List<Integer> result = JsonPath.read(JSON_ARRAY, "$[0:1]");
assertThat(result, Matchers.contains(1));
}
@Test
public void get_between_index_3(){
public void get_between_index_3() {
List<Integer> result = JsonPath.read(JSON_ARRAY, "$[0:2]");
assertThat(result, Matchers.contains(1,3));
assertThat(result, Matchers.contains(1, 3));
}
@Test
public void get_between_index_out_of_bounds(){
public void get_between_index_out_of_bounds() {
List<Integer> result = JsonPath.read(JSON_ARRAY, "$[1:15]");
assertThat(result, Matchers.contains(3, 5, 7, 8, 13, 20));
}
@Test
public void get_from_tail_index(){
public void get_from_tail_index() {
List<Integer> result = JsonPath.read(JSON_ARRAY, "$[-3:]");
assertThat(result, Matchers.contains(8, 13, 20));
}
@Test
public void get_from_tail(){
List<Integer> result = JsonPath.read(JSON_ARRAY, "$[3:]");
public void get_from_tail() {
List<Integer> result = JsonPath.read(JSON_ARRAY, "$[3:]");
assertThat(result, Matchers.contains(7, 8, 13, 20));
}
@Test
public void get_indexes(){
public void get_indexes() {
List<Integer> result = JsonPath.read(JSON_ARRAY, "$[0,1,2]");
assertThat(result, Matchers.contains(1,3,5));
assertThat(result, Matchers.contains(1, 3, 5));
}
}

10
json-path/src/test/java/com/jayway/jsonpath/old/ComplianceTest.java

@ -2,14 +2,14 @@ package com.jayway.jsonpath.old;
import com.jayway.jsonpath.JsonPath;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* test defined in http://jsonpath.googlecode.com/svn/trunk/tests/jsonpath-test-js.html
@ -31,7 +31,7 @@ public class ComplianceTest {
assertThat(JsonPath.<String>read(json, "$.['c d']"), is(equalTo("e")));
assertThat(JsonPath.<List<String>>read(json, "$[*]"), hasItems("a", "b", "e"));
}
@Test
public void test_two() throws Exception {
String json = "[ 1, \"2\", 3.14, true, null ]";
@ -43,7 +43,7 @@ public class ComplianceTest {
new String("2"),
new Double(3.14),
new Boolean(true),
(Comparable)null));
(Comparable) null));
List<Object> res = JsonPath.read(json, "$[-1:]");

29
json-path/src/test/java/com/jayway/jsonpath/old/FilterTest.java

@ -1,13 +1,9 @@
package com.jayway.jsonpath.old;
import com.jayway.jsonpath.BaseTest;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.Filter;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Predicate;
import com.jayway.jsonpath.*;
import com.jayway.jsonpath.spi.json.JsonProvider;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import java.util.HashMap;
@ -18,9 +14,9 @@ import java.util.regex.Pattern;
import static com.jayway.jsonpath.Criteria.where;
import static com.jayway.jsonpath.Filter.filter;
import static java.util.Arrays.asList;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.*;
public class FilterTest extends BaseTest {
@ -75,7 +71,6 @@ public class FilterTest extends BaseTest {
}
@Test
public void ne_filters_evaluates() throws Exception {
final Map<String, Object> check = new HashMap<String, Object>();
@ -270,17 +265,17 @@ public class FilterTest extends BaseTest {
Filter filter = filter(
where("first-name").is("Jock")
.and("address.state").is("Texas"));
.and("address.state").is("Texas"));
List<Map<String, Object>> jocksInTexas1 = JsonPath.read(json, "$[?]", filter);
List<Map<String, Object>> jocksInTexas2 = JsonPath.read(json, "$[?(@.first-name == 'Jock' && @.address.state == 'Texas')]");
List<Map<String, Object>> jocksInTexas2 = JsonPath.read(json, "$[?(@.first-name == 'Jock' && @.address.state == 'Texas')]");
JsonPath.parse(json).json();
assertThat((String)JsonPath.read(jocksInTexas1, "$[0].address.state"), is("Texas"));
assertThat((String)JsonPath.read(jocksInTexas1, "$[0].first-name"), is("Jock"));
assertThat((String)JsonPath.read(jocksInTexas1, "$[0].last-name"), is("Ewing"));
assertThat((String) JsonPath.read(jocksInTexas1, "$[0].address.state"), is("Texas"));
assertThat((String) JsonPath.read(jocksInTexas1, "$[0].first-name"), is("Jock"));
assertThat((String) JsonPath.read(jocksInTexas1, "$[0].last-name"), is("Ewing"));
}
@ -308,8 +303,6 @@ public class FilterTest extends BaseTest {
}
@Test
public void arrays_of_maps_can_be_filtered() throws Exception {
@ -340,7 +333,7 @@ public class FilterTest extends BaseTest {
root.put("children", asList(rootChild_A, rootChild_B, rootChild_C));
Predicate customFilter = new Predicate () {
Predicate customFilter = new Predicate() {
@Override
public boolean apply(PredicateContext ctx) {
if (ctx.configuration().jsonProvider().getMapValue(ctx.item(), "name").equals("rootGrandChild_A")) {
@ -366,7 +359,7 @@ public class FilterTest extends BaseTest {
Predicate customFilter = new Predicate() {
@Override
public boolean apply(PredicateContext ctx) {
return 1 == (Integer)ctx.item();
return 1 == (Integer) ctx.item();
}
};

100
json-path/src/test/java/com/jayway/jsonpath/old/IssuesTest.java

@ -2,14 +2,7 @@ package com.jayway.jsonpath.old;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.gson.JsonObject;
import com.jayway.jsonpath.BaseTest;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.Filter;
import com.jayway.jsonpath.InvalidPathException;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Option;
import com.jayway.jsonpath.PathNotFoundException;
import com.jayway.jsonpath.*;
import com.jayway.jsonpath.internal.Utils;
import com.jayway.jsonpath.spi.cache.LRUCache;
import com.jayway.jsonpath.spi.json.GsonJsonProvider;
@ -22,7 +15,7 @@ import net.minidev.json.JSONAware;
import net.minidev.json.parser.JSONParser;
import org.assertj.core.api.Assertions;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.InputStream;
import java.util.Collections;
@ -35,13 +28,11 @@ import static com.jayway.jsonpath.Criteria.where;
import static com.jayway.jsonpath.Filter.filter;
import static com.jayway.jsonpath.JsonPath.read;
import static com.jayway.jsonpath.JsonPath.using;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.jupiter.api.Assertions.*;
public class IssuesTest extends BaseTest {
@ -51,7 +42,7 @@ public class IssuesTest extends BaseTest {
public void issue_143() {
String json = "{ \"foo\": { \"bar\" : \"val\" }, \"moo\": { \"cow\" : \"val\" } }";
Configuration configuration = Configuration.builder().options( Option.AS_PATH_LIST ).build();
Configuration configuration = Configuration.builder().options(Option.AS_PATH_LIST).build();
List<String> pathList = JsonPath.using(configuration).parse(json).read(JsonPath.compile("$.*.bar"));
@ -67,7 +58,7 @@ public class IssuesTest extends BaseTest {
"}}";
List<String> result = read(json, "$.p.['s', 't'].u");
assertThat(result).containsExactly("su","tu");
assertThat(result).containsExactly("su", "tu");
}
@Test
@ -86,9 +77,9 @@ public class IssuesTest extends BaseTest {
assertThat(result).isEmpty();
}
@Test(expected = InvalidPathException.class)
@Test
public void issue_114_d() {
read(JSON_BOOK_DOCUMENT, "$..book[(@.length-1)] ");
assertThrows(InvalidPathException.class, () -> read(JSON_BOOK_DOCUMENT, "$..book[(@.length-1)] "));
}
@ -121,7 +112,7 @@ public class IssuesTest extends BaseTest {
List<Integer> result = read(json, "$.datas.selling['3','206'].*");
assertThat(result).containsExactly(26452067,31625950,32381852,32489262);
assertThat(result).containsExactly(26452067, 31625950, 32381852, 32489262);
}
@Test
@ -161,10 +152,10 @@ public class IssuesTest extends BaseTest {
assertTrue(result.isEmpty());
}
@Test(expected = PathNotFoundException.class)
@Test
public void issue_11b() throws Exception {
String json = "{ \"foo\" : [] }";
read(json, "$.foo[0].uri");
assertThrows(PathNotFoundException.class, () -> read(json, "$.foo[0].uri"));
}
@Test
@ -318,13 +309,13 @@ public class IssuesTest extends BaseTest {
}
@Test(expected = PathNotFoundException.class)
@Test
public void issue_22() throws Exception {
Configuration configuration = Configuration.defaultConfiguration();
String json = "{\"a\":{\"b\":1,\"c\":2}}";
JsonPath.parse(json, configuration).read("a.d");
assertThrows(PathNotFoundException.class, () -> JsonPath.parse(json, configuration).read("a.d"));
}
@Test
@ -344,10 +335,10 @@ public class IssuesTest extends BaseTest {
assertThat(res).hasSize(1).containsNull();
}
@Test(expected = PathNotFoundException.class)
@Test
public void issue_26() throws Exception {
String json = "[{\"a\":[{\"b\":1,\"c\":2}]}]";
Object o = read(json, "$.a");
assertThrows(PathNotFoundException.class, () -> read(json, "$.a"));
}
@Test
@ -434,7 +425,7 @@ public class IssuesTest extends BaseTest {
assertEquals(Integer.valueOf(1), read(json, "$[0].a"));
}
@Test(expected = PathNotFoundException.class)
@Test
public void a_test() {
String json = "{\n" +
@ -448,7 +439,7 @@ public class IssuesTest extends BaseTest {
" \"version\": 1371160528774\n" +
"}";
Object read = read(json, "$.data.passes[0].id");
assertThrows(PathNotFoundException.class, () -> read(json, "$.data.passes[0].id"));
}
@ -471,9 +462,9 @@ public class IssuesTest extends BaseTest {
String json = "{\"test\":null}";
assertThat((String)read(json, "test")).isNull();
assertThat((String) read(json, "test")).isNull();
assertThat((String)JsonPath.using(Configuration.defaultConfiguration().setOptions(Option.SUPPRESS_EXCEPTIONS)).parse(json).read("nonExistingProperty")).isNull();
assertThat((String) JsonPath.using(Configuration.defaultConfiguration().setOptions(Option.SUPPRESS_EXCEPTIONS)).parse(json).read("nonExistingProperty")).isNull();
try {
read(json, "nonExistingProperty");
@ -498,7 +489,7 @@ public class IssuesTest extends BaseTest {
public void issue_45() {
String json = "{\"rootkey\":{\"sub.key\":\"value\"}}";
assertThat((String)read(json, "rootkey['sub.key']")).isEqualTo("value");
assertThat((String) read(json, "rootkey['sub.key']")).isEqualTo("value");
}
@Test
@ -508,7 +499,7 @@ public class IssuesTest extends BaseTest {
String json = "{\"a\": {}}";
Configuration configuration = Configuration.defaultConfiguration().setOptions(Option.SUPPRESS_EXCEPTIONS);
assertThat((String)JsonPath.using(configuration).parse(json).read("a.x")).isNull();
assertThat((String) JsonPath.using(configuration).parse(json).read("a.x")).isNull();
try {
read(json, "a.x");
@ -818,7 +809,7 @@ public class IssuesTest extends BaseTest {
assertThat(parsed.apply(createPredicateContext(noMatch))).isFalse();
}
private PredicateContext createPredicateContext(final Map<String, Integer> map){
private PredicateContext createPredicateContext(final Map<String, Integer> map) {
return new PredicateContext() {
@Override
public Object item() {
@ -827,7 +818,7 @@ public class IssuesTest extends BaseTest {
@Override
public <T> T item(Class<T> clazz) throws MappingException {
return (T)map;
return (T) map;
}
@Override
@ -951,14 +942,14 @@ public class IssuesTest extends BaseTest {
assertThat(numbers).containsExactly(8.95D, 12.99D, 8.99D, 22.99D);
}
@Test(expected = PathNotFoundException.class)
@Test
public void github_89() {
com.google.gson.JsonObject json = new JsonObject();
json.addProperty("foo", "bar");
JsonPath path = JsonPath.compile("$.foo");
String object = path.read(json);
assertThrows(PathNotFoundException.class, () -> path.read(json));
}
@ -1003,7 +994,7 @@ public class IssuesTest extends BaseTest {
}
@Test
public void issue_309(){
public void issue_309() {
String json = "{\n" +
"\"jsonArr\": [\n" +
@ -1018,27 +1009,27 @@ public class IssuesTest extends BaseTest {
DocumentContext doc = JsonPath.parse(json).set("$.jsonArr[1].name", "Jayway");
assertThat((String)doc.read("$.jsonArr[0].name")).isEqualTo("nOne");
assertThat((String)doc.read("$.jsonArr[1].name")).isEqualTo("Jayway");
assertThat((String) doc.read("$.jsonArr[0].name")).isEqualTo("nOne");
assertThat((String) doc.read("$.jsonArr[1].name")).isEqualTo("Jayway");
}
@Test
public void issue_378(){
public void issue_378() {
String json = "{\n" +
" \"nodes\": {\n" +
" \"unnamed1\": {\n" +
" \"ntpServers\": [\n" +
" \"1.2.3.4\"\n" +
" ]\n" +
" }\n" +
" }\n" +
"}";
" \"nodes\": {\n" +
" \"unnamed1\": {\n" +
" \"ntpServers\": [\n" +
" \"1.2.3.4\"\n" +
" ]\n" +
" }\n" +
" }\n" +
"}";
Configuration configuration = Configuration.builder()
.jsonProvider(new JacksonJsonNodeJsonProvider())
.mappingProvider(new JacksonMappingProvider())
.build();
.jsonProvider(new JacksonJsonNodeJsonProvider())
.mappingProvider(new JacksonMappingProvider())
.build();
DocumentContext ctx = JsonPath.using(configuration).parse(json);
@ -1050,7 +1041,7 @@ public class IssuesTest extends BaseTest {
//CS304 (manually written) Issue link: https://github.com/json-path/JsonPath/issues/620
@Test
public void issue_620_1(){
public void issue_620_1() {
String json = "{\n" +
" \"complexText\": {\n" +
" \"nestedFields\": [\n" +
@ -1077,12 +1068,13 @@ public class IssuesTest extends BaseTest {
"$.complexText.nestedFields[1].name," +
"$.complexText.nestedFields[0].name)";
assertThat((String)JsonPath.read(json,path1)).isEqualTo("CBA");
assertThat((String)JsonPath.read(json,path2)).isEqualTo("CBA");
assertThat((String) JsonPath.read(json, path1)).isEqualTo("CBA");
assertThat((String) JsonPath.read(json, path2)).isEqualTo("CBA");
}
//CS304 (manually written) Issue link: https://github.com/json-path/JsonPath/issues/620
@Test
public void issue_620_2(){
public void issue_620_2() {
String json = "{\n" +
" \"complexText\": {\n" +
" \"nestedFields\": [\n" +
@ -1109,7 +1101,7 @@ public class IssuesTest extends BaseTest {
boolean thrown = false;
try {
Object result = (Object) JsonPath.read(json,path1);
Object result = (Object) JsonPath.read(json, path1);
} catch (Exception e) {
thrown = true;
}

44
json-path/src/test/java/com/jayway/jsonpath/old/JsonPathTest.java

@ -1,21 +1,17 @@
package com.jayway.jsonpath.old;
import com.jayway.jsonpath.BaseTest;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.InvalidPathException;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Option;
import com.jayway.jsonpath.PathNotFoundException;
import com.jayway.jsonpath.*;
import com.jayway.jsonpath.internal.path.PathCompiler;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
public class JsonPathTest extends BaseTest {
@ -81,12 +77,10 @@ public class JsonPathTest extends BaseTest {
private final static String ARRAY_EXPAND = "[{\"parent\": \"ONE\", \"child\": {\"name\": \"NAME_ONE\"}}, [{\"parent\": \"TWO\", \"child\": {\"name\": \"NAME_TWO\"}}]]";
@Test(expected = PathNotFoundException.class)
@Test
public void missing_prop() {
//Object read = JsonPath.using(Configuration.defaultConfiguration().setOptions(Option.THROW_ON_MISSING_PROPERTY)).parse(DOCUMENT).read("$.store.book[*].fooBar");
//Object read = JsonPath.using(Configuration.defaultConfiguration()).parse(DOCUMENT).read("$.store.book[*].fooBar");
Object read2 = JsonPath.using(Configuration.defaultConfiguration().addOptions(Option.REQUIRE_PROPERTIES)).parse(DOCUMENT).read("$.store.book[*].fooBar.not");
assertThrows(PathNotFoundException.class, () -> JsonPath.using(Configuration.defaultConfiguration().addOptions(Option.REQUIRE_PROPERTIES)).parse(DOCUMENT).read("$.store.book[*].fooBar.not"));
}
@ -133,7 +127,7 @@ public class JsonPathTest extends BaseTest {
Assertions.fail("Expected PathNotFoundException");
} catch (PathNotFoundException e) {
}
Assertions.assertThat((String)JsonPath.read(json, "$.data2.passes[0].id")).isEqualTo("1");
Assertions.assertThat((String) JsonPath.read(json, "$.data2.passes[0].id")).isEqualTo("1");
}
@Test
@ -296,9 +290,9 @@ public class JsonPathTest extends BaseTest {
List<String> all = JsonPath.read(DOCUMENT, "$..*");
}
@Test(expected = PathNotFoundException.class)
@Test
public void access_index_out_of_bounds_does_not_throw_exception() throws Exception {
JsonPath.read(DOCUMENT, "$.store.book[100].author");
assertThrows(PathNotFoundException.class, () -> JsonPath.read(DOCUMENT, "$.store.book[100].author"));
}
@Test
@ -311,21 +305,21 @@ public class JsonPathTest extends BaseTest {
@Test
// see https://code.google.com/p/json-path/issues/detail?id=58
public void invalid_paths_throw_invalid_path_exception() throws Exception {
for (String path : new String[]{"$.", "$.results[?"}){
try{
JsonPath.compile(path);
} catch (InvalidPathException e){
// that's expected
} catch (Exception e){
fail("Expected an InvalidPathException trying to compile '"+path+"', but got a "+e.getClass().getName());
}
for (String path : new String[]{"$.", "$.results[?"}) {
try {
JsonPath.compile(path);
} catch (InvalidPathException e) {
// that's expected
} catch (Exception e) {
fail("Expected an InvalidPathException trying to compile '" + path + "', but got a " + e.getClass().getName());
}
}
}
@Test(expected = InvalidPathException.class)
@Test
//see https://github.com/json-path/JsonPath/issues/428
public void prevent_stack_overflow_error_when_unclosed_property() {
JsonPath.compile("$['boo','foo][?(@ =~ /bar/)]");
assertThrows(InvalidPathException.class, () -> JsonPath.compile("$['boo','foo][?(@ =~ /bar/)]"));
}
}

2
json-path/src/test/java/com/jayway/jsonpath/old/JsonProviderTest.java

@ -1,7 +1,7 @@
package com.jayway.jsonpath.old;
import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class JsonProviderTest {

12
json-path/src/test/java/com/jayway/jsonpath/old/NullHandlingTest.java

@ -5,12 +5,12 @@ import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Option;
import com.jayway.jsonpath.PathNotFoundException;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class NullHandlingTest {
@ -36,9 +36,9 @@ public class NullHandlingTest {
"}";
@Test(expected = PathNotFoundException.class)
@Test
public void not_defined_property_throws_PathNotFoundException() {
JsonPath.read(DOCUMENT, "$.children[0].child.age");
assertThrows(PathNotFoundException.class, () -> JsonPath.read(DOCUMENT, "$.children[0].child.age"));
}
@ -53,7 +53,7 @@ public class NullHandlingTest {
@Test
public void null_property_returns_null() {
Integer age = JsonPath.read(DOCUMENT, "$.children[1].age");
assertEquals(null, age);
assertNull(age);
}
@Test

10
json-path/src/test/java/com/jayway/jsonpath/old/internal/ArrayIndexFilterTest.java

@ -1,19 +1,17 @@
package com.jayway.jsonpath.old.internal;
import com.jayway.jsonpath.JsonPath;
import org.junit.Assert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ArrayIndexFilterTest {
private static final String JSON = "[1, 3, 5, 7, 8, 13, 20]";
private static final String JSON = "[1, 3, 5, 7, 8, 13, 20]";
@Test
public void tail_does_not_throw_when_index_out_of_bounds() {
@ -49,7 +47,7 @@ public class ArrayIndexFilterTest {
@Test
public void can_access_items_from_end_with_negative_index() {
int result = JsonPath.parse(JSON).read("$[-3]");
Assert.assertEquals(8, result);
assertEquals(8, result);
}
}

2
json-path/src/test/java/com/jayway/jsonpath/old/internal/ArrayPathTokenTest.java

@ -1,6 +1,6 @@
package com.jayway.jsonpath.old.internal;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;

2
json-path/src/test/java/com/jayway/jsonpath/old/internal/PredicatePathTokenTest.java

@ -2,7 +2,7 @@ package com.jayway.jsonpath.old.internal;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;

20
json-path/src/test/java/com/jayway/jsonpath/old/internal/PropertyPathTokenTest.java

@ -4,14 +4,15 @@ import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Option;
import com.jayway.jsonpath.PathNotFoundException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class PropertyPathTokenTest {
@ -52,21 +53,14 @@ public class PropertyPathTokenTest {
}
@Test(expected = PathNotFoundException.class)
@Test
public void property_not_found_deep() {
String result = JsonPath.read(SIMPLE_MAP, "$.foo.not-found");
assertThat(result).isNull();
assertThrows(PathNotFoundException.class, () -> JsonPath.read(SIMPLE_MAP, "$.foo.not-found"));
}
@Test(expected = PathNotFoundException.class)
@Test
public void property_not_found_option_throw() {
//String result = JsonPath.using(Configuration.defaultConfiguration().setOptions(Option.THROW_ON_MISSING_PROPERTY)).parse(SIMPLE_MAP).read("$.not-found");
String result = JsonPath.using(Configuration.defaultConfiguration()).parse(SIMPLE_MAP).read("$.not-found");
assertThat(result).isNull();
assertThrows(PathNotFoundException.class, () -> JsonPath.using(Configuration.defaultConfiguration()).parse(SIMPLE_MAP).read("$.not-found"));
}
@Test

2
json-path/src/test/java/com/jayway/jsonpath/old/internal/ScanPathTokenTest.java

@ -2,7 +2,7 @@ package com.jayway.jsonpath.old.internal;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.internal.path.PathCompiler;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;

2
json-path/src/test/java/com/jayway/jsonpath/old/internal/TestInternal3.java

@ -1,6 +1,6 @@
package com.jayway.jsonpath.old.internal;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;

4
settings.gradle

@ -1,2 +1,2 @@
rootProject.name='json-path-parent'
include ':json-path', ':json-path-assert', ':json-path-web-test'
rootProject.name = 'json-path-parent'
include ':json-path', ':json-path-assert'
Loading…
Cancel
Save