@@ -1021,7 +1021,7 @@ public void issue_309(){
10211021 assertThat ((String )doc .read ("$.jsonArr[0].name" )).isEqualTo ("nOne" );
10221022 assertThat ((String )doc .read ("$.jsonArr[1].name" )).isEqualTo ("Jayway" );
10231023 }
1024-
1024+
10251025 @ Test
10261026 public void issue_378 (){
10271027
@@ -1039,12 +1039,81 @@ public void issue_378(){
10391039 .jsonProvider (new JacksonJsonNodeJsonProvider ())
10401040 .mappingProvider (new JacksonMappingProvider ())
10411041 .build ();
1042-
1042+
10431043 DocumentContext ctx = JsonPath .using (configuration ).parse (json );
10441044
10451045 String path = "$.nodes[*][?(!([\" 1.2.3.4\" ] subsetof @.ntpServers))].ntpServers" ;
10461046 JsonPath jsonPath = JsonPath .compile (path );
10471047
10481048 ctx .read (jsonPath );
10491049 }
1050+
1051+ //CS304 (manually written) Issue link: https://github.com/json-path/JsonPath/issues/620
1052+ @ Test
1053+ public void issue_620_1 (){
1054+ String json = "{\n " +
1055+ " \" complexText\" : {\n " +
1056+ " \" nestedFields\" : [\n " +
1057+ " {\n " +
1058+ " \" index\" : \" 0\" ,\n " +
1059+ " \" name\" : \" A\" \n " +
1060+ " },\n " +
1061+ " {\n " +
1062+ " \" index\" : \" 1\" ,\n " +
1063+ " \" name\" : \" B\" \n " +
1064+ " },\n " +
1065+ " {\n " +
1066+ " \" index\" : \" 2\" ,\n " +
1067+ " \" name\" : \" C\" \n " +
1068+ " }\n " +
1069+ " ]\n " +
1070+ " }\n " +
1071+ "}" ;
1072+
1073+ String path1 = "$.concat($.complexText.nestedFields[?(@.index == '2')].name," +
1074+ "$.complexText.nestedFields[?(@.index == '1')].name," +
1075+ "$.complexText.nestedFields[?(@.index == '0')].name)" ;
1076+ String path2 = "$.concat($.complexText.nestedFields[2].name," +
1077+ "$.complexText.nestedFields[1].name," +
1078+ "$.complexText.nestedFields[0].name)" ;
1079+
1080+ assertThat ((String )JsonPath .read (json ,path1 )).isEqualTo ("CBA" );
1081+ assertThat ((String )JsonPath .read (json ,path2 )).isEqualTo ("CBA" );
1082+ }
1083+ //CS304 (manually written) Issue link: https://github.com/json-path/JsonPath/issues/620
1084+ @ Test
1085+ public void issue_620_2 (){
1086+ String json = "{\n " +
1087+ " \" complexText\" : {\n " +
1088+ " \" nestedFields\" : [\n " +
1089+ " {\n " +
1090+ " \" index\" : \" 0\" ,\n " +
1091+ " \" name\" : \" A\" \n " +
1092+ " },\n " +
1093+ " {\n " +
1094+ " \" index\" : \" 1\" ,\n " +
1095+ " \" name\" : \" B\" \n " +
1096+ " },\n " +
1097+ " {\n " +
1098+ " \" index\" : \" 2\" ,\n " +
1099+ " \" name\" : \" C\" \n " +
1100+ " }\n " +
1101+ " ]\n " +
1102+ " }\n " +
1103+ "}" ;
1104+
1105+ String path1 = "$.concat($.complexText.nestedFields[?(@.index == '2')].name," +
1106+ "$.complexText.nestedFields[?((@.index == '1')].name," +
1107+ "$.complexText.nestedFields[?(@.index == '0')].name)" ;
1108+
1109+ boolean thrown = false ;
1110+
1111+ try {
1112+ Object result = (Object ) JsonPath .read (json ,path1 );
1113+ } catch (Exception e ) {
1114+ thrown = true ;
1115+ }
1116+
1117+ assertTrue (thrown );
1118+ }
10501119}
0 commit comments