Skip to content

Commit 4cac3d9

Browse files
Ajit GeorgeAjit George
authored andcommitted
No Task - Replaced test method which was causing a JS exception instead
of expected Optic exception. Previous method was of no test value.
1 parent e921a84 commit 4cac3d9

File tree

1 file changed

+47
-18
lines changed

1 file changed

+47
-18
lines changed

test-complete/src/test/java/com/marklogic/client/functionaltest/TestOpticOnLexicons.java

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -866,12 +866,12 @@ public void testPreparedPlanMultipleOrderBy() throws KeyManagementException, NoS
866866
}
867867

868868
/*
869-
* Test False entry in where clause
869+
* conditional from join doc - TEST31
870870
*/
871871
@Test
872-
public void testFalseWhereClause() throws KeyManagementException, NoSuchAlgorithmException, IOException, SAXException, ParserConfigurationException
872+
public void testConditionalFromJoinDoc() throws KeyManagementException, NoSuchAlgorithmException, IOException, SAXException, ParserConfigurationException
873873
{
874-
System.out.println("In testFalseWhereClause method");
874+
System.out.println("In testConditionalFromJoinDoc method");
875875

876876
// Create a new Plan.
877877
RowManager rowMgr = client.newRowManager();
@@ -880,31 +880,60 @@ public void testFalseWhereClause() throws KeyManagementException, NoSuchAlgorith
880880
PlanColumn dateCol = p.col("date");
881881

882882
Map<String, CtsReferenceExpr>index1 = new HashMap<String, CtsReferenceExpr>();
883-
index1.put("uri", p.cts.uriReference());
883+
index1.put("uri1", p.cts.uriReference());
884884
index1.put("city", p.cts.jsonPropertyReference("city"));
885885
index1.put("popularity", p.cts.jsonPropertyReference("popularity"));
886886
index1.put("date", p.cts.jsonPropertyReference("date"));
887887
index1.put("distance", p.cts.jsonPropertyReference("distance"));
888888
index1.put("point", p.cts.jsonPropertyReference("latLonPoint"));
889889

890+
Map<String, CtsReferenceExpr>index2 = new HashMap<String, CtsReferenceExpr>();
891+
index2.put("uri2", p.cts.uriReference());
892+
index2.put("cityName", p.cts.jsonPropertyReference("cityName"));
893+
index2.put("cityTeam", p.cts.jsonPropertyReference("cityTeam"));
894+
895+
PlanSystemColumn fragIdCol1 = p.fragmentIdCol("fragId1");
896+
PlanSystemColumn fragIdCol2 = p.fragmentIdCol("fragId2");
897+
890898
// plan1
891-
ModifyPlan plan1 = p.fromLexicons(index1, "myCity");
892-
PreparePlan output = plan1.where(p.gt(popCol, p.xs.string("blah")))
893-
.select(p.colSeq("city", "popularity", "date", "distance", "point"))
894-
.orderBy(p.asc("date"));
899+
ModifyPlan plan1 = p.fromLexicons(index1, "myCity", fragIdCol1);
900+
// plan2
901+
ModifyPlan plan2 = p.fromLexicons(index2, "myTeam", fragIdCol2);
902+
903+
// plan
904+
ModifyPlan output = plan1.joinInner(plan2)
905+
.joinDoc(p.col("doc"), p.fragmentIdCol("fragId2"))
906+
.select(p.col("uri1"),
907+
p.col("city"),
908+
p.col("popularity"),
909+
p.col("date"),
910+
p.col("distance"),
911+
p.col("point"),
912+
p.as("nodes", p.xpath("doc", "//cityName")),
913+
p.col("uri2"),
914+
p.col("cityName"),
915+
p.col("cityTeam"))
916+
.where(p.eq(p.viewCol("myCity", "city"), p.sql.collatedString(p.col("nodes"), "http://marklogic.com/collation/")))
917+
.orderBy(p.col("uri1"));
918+
895919
JacksonHandle jacksonHandle = new JacksonHandle();
896920
jacksonHandle.setMimetype("application/json");
897921

898-
StringBuilder str = new StringBuilder();
899-
try {
900-
rowMgr.resultDoc(output, jacksonHandle);
901-
}
902-
catch(Exception ex) {
903-
str.append(ex.getMessage());
904-
}
905-
// Should have XDMP-CAST exceptions.
906-
System.out.println("Exception in testFalseWhereClause method" + str.toString());
907-
assertTrue("Exceptions not found", str.toString().contains("XDMP-CAST: (err:FORG0001) \"blah\" cast as xs:int* -- Invalid cast: \"blah\" cast as xs:int"));
922+
rowMgr.resultDoc(output, jacksonHandle);
923+
JsonNode jsonResults = jacksonHandle.get();
924+
JsonNode jsonBindingsNodes = jsonResults.path("rows");
925+
// Should have 5 nodes returned.
926+
assertEquals("Five nodes not returned from testConditionalFromJoinDoc method ", 5, jsonBindingsNodes.size());
927+
928+
JsonNode node = jsonBindingsNodes.path(0);
929+
assertEquals("Row 1 myCity.city value incorrect", "london", node.path("myCity.city").path("value").asText());
930+
assertEquals("Row 1 myTeam.cityName value incorrect", "london", node.path("myTeam.cityName").path("value").asText());
931+
assertEquals("Row 1 myTeam.cityTeam value incorrect", "arsenal", node.path("myTeam.cityTeam").path("value").asText());
932+
933+
node = jsonBindingsNodes.path(4);
934+
assertEquals("Row 5 myCity.city value incorrect", "cape town", node.path("myCity.city").path("value").asText());
935+
assertEquals("Row 5 myTeam.cityName value incorrect", "cape town", node.path("myTeam.cityName").path("value").asText());
936+
assertEquals("Row 5 myTeam.cityTeam value incorrect", "pirates", node.path("myTeam.cityTeam").path("value").asText());
908937
}
909938

910939
/*

0 commit comments

Comments
 (0)