@@ -1132,136 +1132,87 @@ public void testRestrictedXPathUnanamedNodes()
11321132 assertEquals ( "40.72" , third .path ("nodes" ).path ("value" ).asText ());
11331133 }
11341134
1135- /*
1136- * Test Restricted xpath with predicate
1137- * SJS TEST 35
1138- *
1139- * Temporarily simplifying the plan in this test (it seems unnecessarily complex for what the assertions are trying
1140- * to do) while figuring out why it fails on ML 10 but not ML 11.
1141- */
1142- @ Test
1143- public void testRestrictedXPathPredicate ()
1144- {
1145- System .out .println ("In testRestrictedXPathPredicate method" );
1146-
1147- // Create a new Plan.
1148- RowManager rowMgr = client .newRowManager ();
1149- PlanBuilder p = rowMgr .newPlanBuilder ();
1150-
1151- Map <String , CtsReferenceExpr > index1 = new HashMap <String , CtsReferenceExpr >();
1152- index1 .put ("uri1" , p .cts .uriReference ());
1153- index1 .put ("city" , p .cts .jsonPropertyReference ("city" ));
1154- // index1.put("popularity", p.cts.jsonPropertyReference("popularity"));
1155- // index1.put("date", p.cts.jsonPropertyReference("date"));
1156- // index1.put("distance", p.cts.jsonPropertyReference("distance"));
1157- // index1.put("point", p.cts.jsonPropertyReference("latLonPoint"));
1158-
1159- Map <String , CtsReferenceExpr > index2 = new HashMap <String , CtsReferenceExpr >();
1160- index2 .put ("uri2" , p .cts .uriReference ());
1161- index2 .put ("cityName" , p .cts .jsonPropertyReference ("cityName" ));
1162- // index2.put("cityTeam", p.cts.jsonPropertyReference("cityTeam"));
1163-
1164- // plan1
1165- ModifyPlan plan1 = p .fromLexicons (index1 , "myCity" );
1166- ModifyPlan plan2 = p .fromLexicons (index2 , "myTeam" );
1167-
1168- PlanColumn uriCol1 = p .col ("uri1" );
1169- PlanColumn cityCol = p .col ("city" );
1170- PlanColumn popCol = p .col ("popularity" );
1171- PlanColumn dateCol = p .col ("date" );
1172- PlanColumn distCol = p .col ("distance" );
1173- PlanColumn pointCol = p .col ("point" );
1174- PlanColumn uriCol2 = p .col ("uri2" );
1175-
1176- PlanColumn cityNameCol = p .col ("cityName" );
1177- PlanColumn cityTeamCol = p .col ("cityTeam" );
1178-
1179- ModifyPlan finalPlan = plan1
1180- .joinInner (plan2 ,
1181- p .on (p .viewCol ("myCity" , "city" ), p .viewCol ("myTeam" , "cityName" ))
1182- )
1183- .joinDoc (p .col ("doc" ), p .col ("uri1" ))
1184- .select (
1185- cityCol ,
1186- // TODO This doesn't work with ML 10 any longer
1187- //p.as("nodes", p.xpath("doc", "/description[fn:matches(., 'disc*')]")),
1188- p .as (
1189- p .col ("nodes" ),
1190- p .xpath (p .col ("doc" ), p .xs .string ("/description[fn:matches(., 'disc*')]" ))
1191- )
1192- )
1193- .where (p .isDefined (p .col ("nodes" )));
1194-
1195- System .out .println (finalPlan .exportAs (ObjectNode .class ).toPrettyString ());
1196- JsonNode rows = rowMgr .resultDoc (finalPlan , new JacksonHandle ()).get ().path ("rows" );
1197- // Should have 1 node returned.
1198- assertEquals ( 1 , rows .size ());
1199- JsonNode first = rows .path (0 );
1200- assertEquals ( "london" , first .path ("myCity.city" ).path ("value" ).asText ());
1201- assertEquals ( "Two recent discoveries indicate probable very early settlements near the Thames" , first .path ("nodes" ).path ("value" ).asText ());
1202- }
1135+ /*
1136+ * Test Restricted xpath with predicate
1137+ * SJS TEST 35
1138+ */
1139+ @ Test
1140+ public void testRestrictedXPathPredicate () {
1141+ RowManager rowMgr = client .newRowManager ();
1142+ PlanBuilder p = rowMgr .newPlanBuilder ();
1143+
1144+ Map <String , CtsReferenceExpr > index1 = new HashMap <String , CtsReferenceExpr >();
1145+ index1 .put ("uri1" , p .cts .uriReference ());
1146+ index1 .put ("city" , p .cts .jsonPropertyReference ("city" ));
1147+
1148+ Map <String , CtsReferenceExpr > index2 = new HashMap <String , CtsReferenceExpr >();
1149+ index2 .put ("uri2" , p .cts .uriReference ());
1150+ index2 .put ("cityName" , p .cts .jsonPropertyReference ("cityName" ));
1151+
1152+ PlanColumn cityCol = p .col ("city" );
1153+ ModifyPlan plan = p .fromLexicons (index1 , "myCity" )
1154+ .joinInner (
1155+ p .fromLexicons (index2 , "myTeam" ),
1156+ p .on (p .viewCol ("myCity" , "city" ), p .viewCol ("myTeam" , "cityName" ))
1157+ )
1158+ .joinDoc (p .col ("doc" ), p .col ("uri1" ))
1159+ .select (cityCol ,
1160+ p .as (
1161+ p .col ("nodes" ),
1162+ p .xpath (p .col ("doc" ), p .xs .string ("/description[fn:matches(., 'disc*')]" ))
1163+ )
1164+ )
1165+ .where (p .isDefined (p .col ("nodes" )));
1166+
1167+ System .out .println ("PLAN: " + plan .exportAs (ObjectNode .class ).toPrettyString ());
1168+ JsonNode rows = rowMgr .resultDoc (plan , new JacksonHandle ()).get ().path ("rows" );
1169+ assertEquals (1 , rows .size (), "Expected only the London row since it's the only one with 'discoveries' in its description: " + rows .toPrettyString ());
1170+ JsonNode first = rows .path (0 );
1171+ assertEquals ("london" , first .path ("myCity.city" ).path ("value" ).asText ());
1172+ assertEquals ("Two recent discoveries indicate probable very early settlements near the Thames" , first .path ("nodes" ).path ("value" ).asText ());
1173+ }
12031174
12041175 /*
12051176 * Test Restricted xpath with predicate math:pow
12061177 * SJS TEST 40
12071178 */
12081179 @ Test
1209- public void testRestrictedXPathPredicateMath ()
1210- {
1211- System .out .println ("In testRestrictedXPathPredicateMath method" );
1212-
1213- // Create a new Plan.
1214- RowManager rowMgr = client .newRowManager ();
1215- PlanBuilder p = rowMgr .newPlanBuilder ();
1216-
1217- Map <String , CtsReferenceExpr > index1 = new HashMap <String , CtsReferenceExpr >();
1218- index1 .put ("uri1" , p .cts .uriReference ());
1219- index1 .put ("city" , p .cts .jsonPropertyReference ("city" ));
1220- index1 .put ("popularity" , p .cts .jsonPropertyReference ("popularity" ));
1221- index1 .put ("date" , p .cts .jsonPropertyReference ("date" ));
1222- index1 .put ("distance" , p .cts .jsonPropertyReference ("distance" ));
1223- index1 .put ("point" , p .cts .jsonPropertyReference ("latLonPoint" ));
1224-
1225- Map <String , CtsReferenceExpr > index2 = new HashMap <String , CtsReferenceExpr >();
1226- index2 .put ("uri2" , p .cts .uriReference ());
1227- index2 .put ("cityName" , p .cts .jsonPropertyReference ("cityName" ));
1228- index2 .put ("cityTeam" , p .cts .jsonPropertyReference ("cityTeam" ));
1229-
1230- // plan1
1231- ModifyPlan plan1 = p .fromLexicons (index1 , "myCity" );
1232- ModifyPlan plan2 = p .fromLexicons (index2 , "myTeam" );
1233-
1234- PlanColumn uriCol1 = p .col ("uri1" );
1235- PlanColumn cityCol = p .col ("city" );
1236- PlanColumn popCol = p .col ("popularity" );
1237- PlanColumn dateCol = p .col ("date" );
1238- PlanColumn distCol = p .col ("distance" );
1239- PlanColumn pointCol = p .col ("point" );
1240- PlanColumn uriCol2 = p .col ("uri2" );
1241-
1242- PlanColumn cityNameCol = p .col ("cityName" );
1243- PlanColumn cityTeamCol = p .col ("cityTeam" );
1244-
1245- ModifyPlan UnnamedNodes = plan1 .joinInner (plan2 ,
1246- p .on (p .viewCol ("myCity" , "city" ), p .viewCol ("myTeam" , "cityName" )),
1247- p .ne (p .col ("popularity" ), p .xs .intVal (3 )))
1248- .joinDoc (p .col ("doc" ), p .col ("uri1" ))
1249- .select (
1250- uriCol1 , cityCol , popCol , dateCol , distCol , pointCol ,
1251- p .as (p .col ("nodes" ), p .xpath (p .col ("doc" ), p .xs .string ("popularity[math:pow(., 2) eq 4]" ))),
1252- uriCol2 , cityNameCol , cityTeamCol
1253- )
1254- .where (p .isDefined (p .col ("nodes" )));
1255-
1256- JacksonHandle jacksonHandle = new JacksonHandle ();
1257- jacksonHandle .setMimetype ("application/json" );
1258-
1259- rowMgr .resultDoc (UnnamedNodes , jacksonHandle );
1260- JsonNode jsonResults = jacksonHandle .get ();
1261- JsonNode jsonBindingsNodes = jsonResults .path ("rows" );
1262- assertEquals (1 , jsonBindingsNodes .size (), "Expected 1 node: " + jsonBindingsNodes .toPrettyString ());
1263- JsonNode first = jsonBindingsNodes .path (0 );
1264- assertEquals ( "new jersey" , first .path ("myCity.city" ).path ("value" ).asText ());
1180+ public void testRestrictedXPathPredicateMath () {
1181+ RowManager rowMgr = client .newRowManager ();
1182+ PlanBuilder p = rowMgr .newPlanBuilder ();
1183+
1184+ Map <String , CtsReferenceExpr > index1 = new HashMap <>();
1185+ index1 .put ("uri1" , p .cts .uriReference ());
1186+ index1 .put ("city" , p .cts .jsonPropertyReference ("city" ));
1187+ index1 .put ("popularity" , p .cts .jsonPropertyReference ("popularity" ));
1188+
1189+ Map <String , CtsReferenceExpr > index2 = new HashMap <>();
1190+ index2 .put ("uri2" , p .cts .uriReference ());
1191+ index2 .put ("cityName" , p .cts .jsonPropertyReference ("cityName" ));
1192+ index2 .put ("cityTeam" , p .cts .jsonPropertyReference ("cityTeam" ));
1193+
1194+ ModifyPlan plan = p .fromLexicons (index1 , "myCity" ).joinInner (
1195+ p .fromLexicons (index2 , "myTeam" ),
1196+ p .on (p .viewCol ("myCity" , "city" ), p .viewCol ("myTeam" , "cityName" )),
1197+ p .ne (p .col ("popularity" ), p .xs .intVal (3 ))
1198+ )
1199+ .joinDoc (p .col ("doc" ), p .col ("uri1" ))
1200+ .select (
1201+ p .col ("uri1" ), p .col ("city" ), p .col ("popularity" ),
1202+ p .as (p .col ("nodes" ), p .xpath (p .col ("doc" ), p .xs .string ("popularity[math:pow(., 2) eq 4]" )))
1203+ )
1204+ .where (p .isDefined (p .col ("nodes" )));
1205+
1206+ JacksonHandle jacksonHandle = new JacksonHandle ();
1207+ jacksonHandle .setMimetype ("application/json" );
1208+
1209+ System .out .println ("PLAN: " + plan .exportAs (ObjectNode .class ).toPrettyString ());
1210+
1211+ rowMgr .resultDoc (plan , jacksonHandle );
1212+ JsonNode rows = jacksonHandle .get ().path ("rows" );
1213+ assertEquals (1 , rows .size (), "Expected only the New Jersey row, which has a popularity of 2: " + rows .toPrettyString ());
1214+ JsonNode first = rows .path (0 );
1215+ assertEquals ("new jersey" , first .path ("myCity.city" ).path ("value" ).asText ());
12651216 }
12661217
12671218}
0 commit comments