Skip to content

Commit 24921ae

Browse files
Ajit GeorgeAjit George
authored andcommitted
No Task - Added tests for Bug Track issue 45435
1 parent c4c0c65 commit 24921ae

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

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

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import com.marklogic.client.type.PlanSystemColumn;
5858
import com.marklogic.client.type.PlanTripleOption;
5959
import com.marklogic.client.type.PlanTriplePatternSeq;
60+
import com.marklogic.client.type.PlanTriplePositionSeq;
6061
import com.marklogic.client.type.SemIriSeqVal;
6162
import com.marklogic.client.type.SemStoreExpr;
6263

@@ -1461,6 +1462,133 @@ public void testFromTriplesWithbindParam() throws KeyManagementException, NoSuch
14611462
assertTrue("No data should have been returned", jsonResults == null);
14621463
}
14631464

1465+
/* This test checks union instead of join over pattern value permutations.
1466+
*
1467+
*/
1468+
@Test
1469+
public void testPatternValuePermutations() throws KeyManagementException, NoSuchAlgorithmException, IOException, SAXException, ParserConfigurationException
1470+
{
1471+
System.out.println("In testPatternValuePermutations method");
1472+
1473+
// Create a new Plan.
1474+
RowManager rowMgr = client.newRowManager();
1475+
PlanBuilder p = rowMgr.newPlanBuilder();
1476+
PlanPrefixer bb = p.prefixer("http://marklogic.com/baseball/players");
1477+
1478+
PlanColumn ageCol = p.col("age");
1479+
PlanColumn idCol = p.col("id");
1480+
PlanColumn nameCol = p.col("name");
1481+
1482+
PlanColumn posCol = p.col("position");
1483+
1484+
PlanTriplePositionSeq subjectSeq = p.subjectSeq(idCol);
1485+
PlanTriplePositionSeq predicateSeq = p.predicateSeq(bb.iri("/age"));
1486+
1487+
PlanTriplePositionSeq objectSeq = p.objectSeq(p.xs.intVal(23), p.xs.intVal(19));
1488+
1489+
PlanTriplePatternSeq patSeq = p.patternSeq(p.pattern(subjectSeq, predicateSeq, objectSeq),
1490+
p.pattern(idCol, bb.iri("name"), nameCol),
1491+
p.pattern(idCol, bb.iri("position"), posCol),
1492+
p.pattern(p.col("id"), p.sem.iri("http://marklogic.com/baseball/players/age"), p.col("age")));
1493+
ModifyPlan output = p.fromTriples(patSeq, "myPlayer")
1494+
.orderBy(p.desc(ageCol))
1495+
.select(
1496+
p.as("PlayerName", nameCol),
1497+
p.as("PlayerPosition", posCol),
1498+
p.as("PlayerAge", ageCol)
1499+
);
1500+
JacksonHandle jacksonHandle = new JacksonHandle();
1501+
jacksonHandle.setMimetype("application/json");
1502+
1503+
rowMgr.resultDoc(output, jacksonHandle);
1504+
JsonNode jsonResults = jacksonHandle.get();
1505+
JsonNode jsonBindingsNodes = jsonResults.path("rows");
1506+
JsonNode nodeVal = jsonBindingsNodes.path(0);
1507+
// Should have 2 nodes returned.
1508+
assertEquals("Two nodes not returned from testPatternValuePermutations method", 2, jsonBindingsNodes.size());
1509+
assertEquals("Row 1 PlayerName value incorrect", "Bob Brian", nodeVal.path("PlayerName").path("value").asText());
1510+
assertEquals("Row 1 PlayerAge value incorrect", "23", nodeVal.path("PlayerAge").path("value").asText());
1511+
assertEquals("Row 1 PlayerPosition value incorrect", "Outfielder", nodeVal.path("PlayerPosition").path("value").asText());
1512+
1513+
nodeVal = jsonBindingsNodes.path(1);
1514+
assertEquals("Row 2 PlayerName value incorrect", "Pedro Barrozo", nodeVal.path("PlayerName").path("value").asText());
1515+
assertEquals("Row 2 PlayerAge value incorrect", "19", nodeVal.path("PlayerAge").path("value").asText());
1516+
assertEquals("Row 2 PlayerPosition value incorrect", "Midfielder", nodeVal.path("PlayerPosition").path("value").asText());
1517+
1518+
// Test for verifying that value permutations do not appear in the result rows. They should not be part of results.
1519+
// In the above plan we explicitly made a pattern to recover the ages.
1520+
PlanTriplePatternSeq patSeq1 = p.patternSeq(p.pattern(subjectSeq, predicateSeq, objectSeq));
1521+
ModifyPlan output1 = p.fromTriples(patSeq1, "myPlayer");
1522+
JacksonHandle jacksonHandle1 = new JacksonHandle();
1523+
jacksonHandle1.setMimetype("application/json");
1524+
1525+
rowMgr.resultDoc(output1, jacksonHandle1);
1526+
JsonNode jsonResults1 = jacksonHandle1.get();
1527+
JsonNode jsonBindingsNodes1 = jsonResults1.path("rows");
1528+
JsonNode nodeVal1 = jsonBindingsNodes1.path(0);
1529+
// Should have 2 nodes returned.
1530+
assertEquals("Two nodes not returned from testPatternValuePermutations method", 2, jsonBindingsNodes1.size());
1531+
assertTrue("Node not returned from testPatternValuePermutations method",
1532+
jsonBindingsNodes1.path(0).get("myPlayer.id").get("value").asText().contains("http://marklogic.com/baseball/id#005") ||
1533+
jsonBindingsNodes1.path(0).get("myPlayer.id").get("value").asText().contains("http://marklogic.com/baseball/id#002"));
1534+
assertTrue("Node not returned from testPatternValuePermutations method",
1535+
jsonBindingsNodes1.path(1).get("myPlayer.id").get("value").asText().contains("http://marklogic.com/baseball/id#005") ||
1536+
jsonBindingsNodes1.path(1).get("myPlayer.id").get("value").asText().contains("http://marklogic.com/baseball/id#002"));
1537+
// Negative cases
1538+
PlanTriplePositionSeq objectSeqNeg = p.objectSeq(p.xs.intVal(123), p.xs.intVal(100));
1539+
1540+
PlanTriplePatternSeq patSeqNeg = p.patternSeq(p.pattern(subjectSeq, predicateSeq, objectSeqNeg),
1541+
p.pattern(idCol, bb.iri("name"), nameCol),
1542+
p.pattern(idCol, bb.iri("position"), posCol),
1543+
p.pattern(p.col("id"), p.sem.iri("http://marklogic.com/baseball/players/age"), p.col("age")));
1544+
ModifyPlan outputNeg = p.fromTriples(patSeqNeg, "myPlayer")
1545+
.orderBy(p.desc(ageCol))
1546+
.select(
1547+
p.as("PlayerName", nameCol),
1548+
p.as("PlayerPosition", posCol),
1549+
p.as("PlayerAge", ageCol)
1550+
);
1551+
jacksonHandle = new JacksonHandle();
1552+
jacksonHandle.setMimetype("application/json");
1553+
1554+
rowMgr.resultDoc(outputNeg, jacksonHandle);
1555+
JsonNode jsonResultsNeg = jacksonHandle.get();
1556+
1557+
// Should have 0 nodes returned.
1558+
assertTrue("Zero nodes not returned from testPatternValuePermutations method", jsonResultsNeg==null);
1559+
1560+
PlanTriplePositionSeq objectSeqNeg1 = p.objectSeq(p.xs.intVal(23), p.xs.intVal(19), p.xs.intVal(-1));
1561+
1562+
PlanTriplePatternSeq patSeqNeg1 = p.patternSeq(p.pattern(subjectSeq, predicateSeq, objectSeqNeg1),
1563+
p.pattern(idCol, bb.iri("name"), nameCol),
1564+
p.pattern(idCol, bb.iri("position"), posCol),
1565+
p.pattern(p.col("id"), p.sem.iri("http://marklogic.com/baseball/players/age"), p.col("age")));
1566+
ModifyPlan outputNeg1= p.fromTriples(patSeqNeg1, "myPlayer")
1567+
.orderBy(p.desc(ageCol))
1568+
.select(
1569+
p.as("PlayerName", nameCol),
1570+
p.as("PlayerPosition", posCol),
1571+
p.as("PlayerAge", ageCol)
1572+
);
1573+
jacksonHandle = new JacksonHandle();
1574+
jacksonHandle.setMimetype("application/json");
1575+
1576+
rowMgr.resultDoc(outputNeg1, jacksonHandle);
1577+
JsonNode jsonResultsNeg1 = jacksonHandle.get();
1578+
JsonNode jsonBindingsNodesNeg1 = jsonResultsNeg1.path("rows");
1579+
JsonNode nodeValNeg1 = jsonBindingsNodesNeg1.path(0);
1580+
// Should have 2 nodes returned.
1581+
assertEquals("Two nodes not returned from testPatternValuePermutations method", 2, jsonBindingsNodesNeg1.size());
1582+
assertEquals("Row 1 PlayerName value incorrect", "Bob Brian", nodeValNeg1.path("PlayerName").path("value").asText());
1583+
assertEquals("Row 1 PlayerAge value incorrect", "23", nodeValNeg1.path("PlayerAge").path("value").asText());
1584+
assertEquals("Row 1 PlayerPosition value incorrect", "Outfielder", nodeValNeg1.path("PlayerPosition").path("value").asText());
1585+
1586+
nodeValNeg1 = jsonBindingsNodesNeg1.path(1);
1587+
assertEquals("Row 2 PlayerName value incorrect", "Pedro Barrozo", nodeValNeg1.path("PlayerName").path("value").asText());
1588+
assertEquals("Row 2 PlayerAge value incorrect", "19", nodeValNeg1.path("PlayerAge").path("value").asText());
1589+
assertEquals("Row 2 PlayerPosition value incorrect", "Midfielder", nodeValNeg1.path("PlayerPosition").path("value").asText());
1590+
}
1591+
14641592
@AfterClass
14651593
public static void tearDownAfterClass() throws Exception {
14661594
System.out.println("In tear down");

0 commit comments

Comments
 (0)