|
12 | 12 | import com.marklogic.client.io.JacksonHandle;
|
13 | 13 | import com.marklogic.client.io.StringHandle;
|
14 | 14 | import com.marklogic.client.row.RowManager;
|
| 15 | +import com.marklogic.client.row.RowRecord; |
| 16 | +import com.marklogic.client.row.RowTemplate; |
15 | 17 | import com.marklogic.client.type.*;
|
16 | 18 | import org.junit.jupiter.api.AfterAll;
|
17 | 19 | import org.junit.jupiter.api.BeforeAll;
|
18 |
| -import org.junit.jupiter.api.*; |
19 |
| -import static org.junit.jupiter.api.Assertions.*; |
| 20 | +import org.junit.jupiter.api.Test; |
20 | 21 |
|
21 | 22 | import java.util.Iterator;
|
22 | 23 |
|
| 24 | +import static org.junit.jupiter.api.Assertions.*; |
| 25 | + |
23 | 26 | public class TestOpticOnTriples extends AbstractFunctionalTest {
|
24 | 27 |
|
25 | 28 | @BeforeAll
|
@@ -1425,66 +1428,77 @@ public void testPatternValuePermutations()
|
1425 | 1428 | }
|
1426 | 1429 |
|
1427 | 1430 | @Test
|
1428 |
| - public void testShortestPathWithColumnInputs() |
1429 |
| - { |
1430 |
| - if(!isML12OrHigher){ |
| 1431 | + void shortestPathWithColumnInputs() { |
| 1432 | + if (!isML12OrHigher) { |
1431 | 1433 | return;
|
1432 | 1434 | }
|
1433 | 1435 |
|
1434 |
| - RowManager rowMgr = client.newRowManager(); |
1435 |
| - PlanBuilder p = rowMgr.newPlanBuilder(); |
1436 |
| - |
1437 |
| - PlanColumn teamIdCol = p.col("player_team"); |
1438 |
| - PlanColumn teamNameCol = p.col("team_name"); |
1439 |
| - PlanColumn teamCityCol = p.col("team_city"); |
1440 |
| - |
1441 |
| - PlanPrefixer team = p.prefixer("http://marklogic.com/mlb/team/"); |
1442 |
| - PlanBuilder.ModifyPlan team_plan = p.fromTriples( |
1443 |
| - p.pattern(teamIdCol, team.iri("name"), teamNameCol), |
1444 |
| - p.pattern(teamIdCol, team.iri("city"), teamCityCol) |
1445 |
| - ).shortestPath(p.col("team_name"), p.col("team_city"), p.col("path"), p.col("length")); |
1446 |
| - JacksonHandle jacksonHandle = new JacksonHandle().withMimetype("application/json"); |
1447 |
| - rowMgr.resultDoc(team_plan, jacksonHandle); |
1448 |
| - JsonNode jsonResults = jacksonHandle.get(); |
1449 |
| - JsonNode jsonBindingsNodes = jsonResults.path("rows"); |
1450 |
| - for (int i=0; i<jsonBindingsNodes.size(); i++){ |
1451 |
| - JsonNode path = jsonBindingsNodes.path(i); |
1452 |
| - assertNotNull(path.path("team_name")); |
1453 |
| - assertNotNull(path.path("team_city")); |
1454 |
| - assertNotNull(path.path("path")); |
1455 |
| - assertEquals("1",path.path("length").path("value").toString()); |
1456 |
| - } |
| 1436 | + new RowTemplate(client).query(op -> { |
| 1437 | + PlanPrefixer team = op.prefixer("http://marklogic.com/mlb/team/"); |
| 1438 | + return op.fromTriples( |
| 1439 | + op.pattern(op.col("player_team"), team.iri("name"), op.col("team_name")), |
| 1440 | + op.pattern(op.col("player_team"), team.iri("city"), op.col("team_city")) |
| 1441 | + ) |
| 1442 | + .where(op.eq(op.col("team_name"), op.xs.string("Giants"))) |
| 1443 | + .shortestPath(op.col("team_name"), op.col("team_city"), op.col("path"), op.col("length")); |
| 1444 | + }, |
| 1445 | + rows -> { |
| 1446 | + RowRecord row = rows.iterator().next(); |
| 1447 | + assertEquals("Giants", row.getString("team_name")); |
| 1448 | + assertEquals("San Francisco", row.getString("team_city")); |
| 1449 | + assertEquals(1, row.getInt("length")); |
| 1450 | + return null; |
| 1451 | + }); |
1457 | 1452 | }
|
1458 | 1453 |
|
1459 | 1454 | @Test
|
1460 |
| - public void testShortestPathWithStringInputs() |
1461 |
| - { |
1462 |
| - if(!isML12OrHigher){ |
| 1455 | + void shortestPathWithStringInputs() { |
| 1456 | + if (!isML12OrHigher) { |
1463 | 1457 | return;
|
1464 | 1458 | }
|
1465 | 1459 |
|
1466 |
| - RowManager rowMgr = client.newRowManager(); |
1467 |
| - PlanBuilder p = rowMgr.newPlanBuilder(); |
1468 |
| - |
1469 |
| - PlanColumn teamIdCol = p.col("player_team"); |
1470 |
| - PlanColumn teamNameCol = p.col("team_name"); |
1471 |
| - PlanColumn teamCityCol = p.col("team_city"); |
1472 |
| - |
1473 |
| - PlanPrefixer team = p.prefixer("http://marklogic.com/mlb/team/"); |
1474 |
| - PlanBuilder.ModifyPlan team_plan = p.fromTriples( |
1475 |
| - p.pattern(teamIdCol, team.iri("name"), teamNameCol), |
1476 |
| - p.pattern(teamIdCol, team.iri("city"), teamCityCol) |
1477 |
| - ).shortestPath("team_name", "team_city", "path", "length"); |
1478 |
| - JacksonHandle jacksonHandle = new JacksonHandle().withMimetype("application/json"); |
1479 |
| - rowMgr.resultDoc(team_plan, jacksonHandle); |
1480 |
| - JsonNode jsonResults = jacksonHandle.get(); |
1481 |
| - JsonNode jsonBindingsNodes = jsonResults.path("rows"); |
1482 |
| - for (int i=0; i<jsonBindingsNodes.size(); i++){ |
1483 |
| - JsonNode path = jsonBindingsNodes.path(i); |
1484 |
| - assertNotNull(path.path("team_name")); |
1485 |
| - assertNotNull(path.path("team_city")); |
1486 |
| - assertNotNull(path.path("path")); |
1487 |
| - assertEquals("1",path.path("length").path("value").toString()); |
| 1460 | + new RowTemplate(client).query(op -> { |
| 1461 | + PlanPrefixer team = op.prefixer("http://marklogic.com/mlb/team/"); |
| 1462 | + return op.fromTriples( |
| 1463 | + op.pattern(op.col("player_team"), team.iri("name"), op.col("team_name")), |
| 1464 | + op.pattern(op.col("player_team"), team.iri("city"), op.col("team_city")) |
| 1465 | + ).shortestPath("team_name", "team_city", "path", "length"); |
| 1466 | + }, |
| 1467 | + rows -> { |
| 1468 | + rows.iterator().forEachRemaining(row -> { |
| 1469 | + assertNotNull(row.get("team_name")); |
| 1470 | + assertNotNull(row.get("team_city")); |
| 1471 | + assertNotNull(row.get("path")); |
| 1472 | + assertEquals("1", row.get("length").toString()); |
| 1473 | + }); |
| 1474 | + return null; |
| 1475 | + }); |
| 1476 | + } |
| 1477 | + |
| 1478 | + @Test |
| 1479 | + void shortestPathWithWeight() { |
| 1480 | + if (!isML12OrHigher) { |
| 1481 | + return; |
1488 | 1482 | }
|
| 1483 | + |
| 1484 | + new RowTemplate(client).query(op -> { |
| 1485 | + PlanPrefixer team = op.prefixer("http://marklogic.com/mlb/team/"); |
| 1486 | + return op.fromTriples( |
| 1487 | + op.pattern(op.col("player_team"), team.iri("name"), op.col("team_name")), |
| 1488 | + op.pattern(op.col("player_team"), team.iri("city"), op.col("team_city")) |
| 1489 | + ) |
| 1490 | + .where(op.eq(op.col("team_name"), op.xs.string("Giants"))) |
| 1491 | + .bind(op.as("weight", op.xs.doubleVal(0.5))) |
| 1492 | + // The effect of the 'weight' column is not relevant to the test; we just want to make sure a |
| 1493 | + // value can be passed without causing an error. |
| 1494 | + .shortestPath("team_name", "team_city", "path", "length", "weight"); |
| 1495 | + }, |
| 1496 | + rows -> { |
| 1497 | + RowRecord row = rows.iterator().next(); |
| 1498 | + assertEquals("Giants", row.getString("team_name")); |
| 1499 | + assertEquals("San Francisco", row.getString("team_city")); |
| 1500 | + assertEquals(1, row.getInt("length")); |
| 1501 | + return null; |
| 1502 | + }); |
1489 | 1503 | }
|
1490 | 1504 | }
|
0 commit comments