Changeset View
Changeset View
Standalone View
Standalone View
java/server/src/test/java/org/softwareheritage/graph/VisitTest.java
package org.softwareheritage.graph; | package org.softwareheritage.graph; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Set; | import java.util.Set; | ||||
import java.util.HashSet; | import java.util.HashSet; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
import org.softwareheritage.graph.Endpoint; | import org.softwareheritage.graph.Endpoint; | ||||
import org.softwareheritage.graph.Graph; | import org.softwareheritage.graph.Graph; | ||||
import org.softwareheritage.graph.GraphTest; | import org.softwareheritage.graph.GraphTest; | ||||
import org.softwareheritage.graph.SwhId; | import org.softwareheritage.graph.SwhPID; | ||||
import org.softwareheritage.graph.SwhPath; | import org.softwareheritage.graph.SwhPath; | ||||
// Avoid warnings concerning Endpoint.Output.result manual cast | // Avoid warnings concerning Endpoint.Output.result manual cast | ||||
@SuppressWarnings("unchecked") | @SuppressWarnings("unchecked") | ||||
public class VisitTest extends GraphTest { | public class VisitTest extends GraphTest { | ||||
private void assertSameNodesFromPaths(ArrayList<SwhPath> paths, ArrayList<SwhId> nodes) { | private void assertSameNodesFromPaths(ArrayList<SwhPath> paths, ArrayList<SwhPID> nodes) { | ||||
Set<SwhId> expectedNodes = new HashSet<SwhId>(); | Set<SwhPID> expectedNodes = new HashSet<SwhPID>(); | ||||
for (SwhPath path : paths) { | for (SwhPath path : paths) { | ||||
for (SwhId node : path.getPath()) { | for (SwhPID node : path.getPath()) { | ||||
expectedNodes.add(node); | expectedNodes.add(node); | ||||
} | } | ||||
} | } | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); | GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardFromRoot() { | public void forwardFromRoot() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SwhId swhId = new SwhId("swh:1:ori:0000000000000000000000000000000000000021"); | SwhPID swhPID = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); | ||||
Endpoint endpoint = new Endpoint(graph, "forward", "*"); | Endpoint endpoint = new Endpoint(graph, "forward", "*"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhId).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhPID).result; | ||||
ArrayList<SwhId> nodes = (ArrayList) endpoint.visitNodes(swhId).result; | ArrayList<SwhPID> nodes = (ArrayList) endpoint.visitNodes(swhPID).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:ori:0000000000000000000000000000000000000021", | "swh:1:ori:0000000000000000000000000000000000000021", | ||||
"swh:1:snp:0000000000000000000000000000000000000020", | "swh:1:snp:0000000000000000000000000000000000000020", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:dir:0000000000000000000000000000000000000008", | "swh:1:dir:0000000000000000000000000000000000000008", | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | public void forwardFromRoot() { | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardFromMiddle() { | public void forwardFromMiddle() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SwhId swhId = new SwhId("swh:1:dir:0000000000000000000000000000000000000012"); | SwhPID swhPID = new SwhPID("swh:1:dir:0000000000000000000000000000000000000012"); | ||||
Endpoint endpoint = new Endpoint(graph, "forward", "*"); | Endpoint endpoint = new Endpoint(graph, "forward", "*"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhId).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhPID).result; | ||||
ArrayList<SwhId> nodes = (ArrayList) endpoint.visitNodes(swhId).result; | ArrayList<SwhPID> nodes = (ArrayList) endpoint.visitNodes(swhPID).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:dir:0000000000000000000000000000000000000012", | "swh:1:dir:0000000000000000000000000000000000000012", | ||||
"swh:1:dir:0000000000000000000000000000000000000008", | "swh:1:dir:0000000000000000000000000000000000000008", | ||||
"swh:1:cnt:0000000000000000000000000000000000000007" | "swh:1:cnt:0000000000000000000000000000000000000007" | ||||
)); | )); | ||||
Show All 25 Lines | public void forwardFromMiddle() { | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardFromLeaf() { | public void forwardFromLeaf() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SwhId swhId = new SwhId("swh:1:cnt:0000000000000000000000000000000000000004"); | SwhPID swhPID = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); | ||||
Endpoint endpoint = new Endpoint(graph, "forward", "*"); | Endpoint endpoint = new Endpoint(graph, "forward", "*"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhId).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhPID).result; | ||||
ArrayList<SwhId> nodes = (ArrayList) endpoint.visitNodes(swhId).result; | ArrayList<SwhPID> nodes = (ArrayList) endpoint.visitNodes(swhPID).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:cnt:0000000000000000000000000000000000000004" | "swh:1:cnt:0000000000000000000000000000000000000004" | ||||
)); | )); | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void backwardFromRoot() { | public void backwardFromRoot() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SwhId swhId = new SwhId("swh:1:ori:0000000000000000000000000000000000000021"); | SwhPID swhPID = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); | ||||
Endpoint endpoint = new Endpoint(graph, "backward", "*"); | Endpoint endpoint = new Endpoint(graph, "backward", "*"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhId).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhPID).result; | ||||
ArrayList<SwhId> nodes = (ArrayList) endpoint.visitNodes(swhId).result; | ArrayList<SwhPID> nodes = (ArrayList) endpoint.visitNodes(swhPID).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:ori:0000000000000000000000000000000000000021" | "swh:1:ori:0000000000000000000000000000000000000021" | ||||
)); | )); | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void backwardFromMiddle() { | public void backwardFromMiddle() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SwhId swhId = new SwhId("swh:1:dir:0000000000000000000000000000000000000012"); | SwhPID swhPID = new SwhPID("swh:1:dir:0000000000000000000000000000000000000012"); | ||||
Endpoint endpoint = new Endpoint(graph, "backward", "*"); | Endpoint endpoint = new Endpoint(graph, "backward", "*"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhId).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhPID).result; | ||||
ArrayList<SwhId> nodes = (ArrayList) endpoint.visitNodes(swhId).result; | ArrayList<SwhPID> nodes = (ArrayList) endpoint.visitNodes(swhPID).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:dir:0000000000000000000000000000000000000012", | "swh:1:dir:0000000000000000000000000000000000000012", | ||||
"swh:1:rev:0000000000000000000000000000000000000013", | "swh:1:rev:0000000000000000000000000000000000000013", | ||||
"swh:1:rev:0000000000000000000000000000000000000018", | "swh:1:rev:0000000000000000000000000000000000000018", | ||||
"swh:1:rel:0000000000000000000000000000000000000019" | "swh:1:rel:0000000000000000000000000000000000000019" | ||||
)); | )); | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void backwardFromLeaf() { | public void backwardFromLeaf() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SwhId swhId = new SwhId("swh:1:cnt:0000000000000000000000000000000000000004"); | SwhPID swhPID = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); | ||||
Endpoint endpoint = new Endpoint(graph, "backward", "*"); | Endpoint endpoint = new Endpoint(graph, "backward", "*"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhId).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhPID).result; | ||||
ArrayList<SwhId> nodes = (ArrayList) endpoint.visitNodes(swhId).result; | ArrayList<SwhPID> nodes = (ArrayList) endpoint.visitNodes(swhPID).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:cnt:0000000000000000000000000000000000000004", | "swh:1:cnt:0000000000000000000000000000000000000004", | ||||
"swh:1:dir:0000000000000000000000000000000000000006", | "swh:1:dir:0000000000000000000000000000000000000006", | ||||
"swh:1:dir:0000000000000000000000000000000000000008", | "swh:1:dir:0000000000000000000000000000000000000008", | ||||
"swh:1:dir:0000000000000000000000000000000000000012", | "swh:1:dir:0000000000000000000000000000000000000012", | ||||
Show All 33 Lines | public void backwardFromLeaf() { | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardSnpToRev() { | public void forwardSnpToRev() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SwhId swhId = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); | SwhPID swhPID = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); | ||||
Endpoint endpoint = new Endpoint(graph, "forward", "snp:rev"); | Endpoint endpoint = new Endpoint(graph, "forward", "snp:rev"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhId).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhPID).result; | ||||
ArrayList<SwhId> nodes = (ArrayList) endpoint.visitNodes(swhId).result; | ArrayList<SwhPID> nodes = (ArrayList) endpoint.visitNodes(swhPID).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:snp:0000000000000000000000000000000000000020", | "swh:1:snp:0000000000000000000000000000000000000020", | ||||
"swh:1:rev:0000000000000000000000000000000000000009" | "swh:1:rev:0000000000000000000000000000000000000009" | ||||
)); | )); | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardRelToRevRevToRev() { | public void forwardRelToRevRevToRev() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SwhId swhId = new SwhId("swh:1:rel:0000000000000000000000000000000000000010"); | SwhPID swhPID = new SwhPID("swh:1:rel:0000000000000000000000000000000000000010"); | ||||
Endpoint endpoint = new Endpoint(graph, "forward", "rel:rev,rev:rev"); | Endpoint endpoint = new Endpoint(graph, "forward", "rel:rev,rev:rev"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhId).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhPID).result; | ||||
ArrayList<SwhId> nodes = (ArrayList) endpoint.visitNodes(swhId).result; | ArrayList<SwhPID> nodes = (ArrayList) endpoint.visitNodes(swhPID).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:rel:0000000000000000000000000000000000000010", | "swh:1:rel:0000000000000000000000000000000000000010", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:rev:0000000000000000000000000000000000000003" | "swh:1:rev:0000000000000000000000000000000000000003" | ||||
)); | )); | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardRevToAllDirToAll() { | public void forwardRevToAllDirToAll() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SwhId swhId = new SwhId("swh:1:rev:0000000000000000000000000000000000000013"); | SwhPID swhPID = new SwhPID("swh:1:rev:0000000000000000000000000000000000000013"); | ||||
Endpoint endpoint = new Endpoint(graph, "forward", "rev:*,dir:*"); | Endpoint endpoint = new Endpoint(graph, "forward", "rev:*,dir:*"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhId).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhPID).result; | ||||
ArrayList<SwhId> nodes = (ArrayList) endpoint.visitNodes(swhId).result; | ArrayList<SwhPID> nodes = (ArrayList) endpoint.visitNodes(swhPID).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:rev:0000000000000000000000000000000000000013", | "swh:1:rev:0000000000000000000000000000000000000013", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:dir:0000000000000000000000000000000000000008", | "swh:1:dir:0000000000000000000000000000000000000008", | ||||
"swh:1:dir:0000000000000000000000000000000000000006", | "swh:1:dir:0000000000000000000000000000000000000006", | ||||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | public void forwardRevToAllDirToAll() { | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardSnpToAllRevToAll() { | public void forwardSnpToAllRevToAll() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SwhId swhId = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); | SwhPID swhPID = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); | ||||
Endpoint endpoint = new Endpoint(graph, "forward", "snp:*,rev:*"); | Endpoint endpoint = new Endpoint(graph, "forward", "snp:*,rev:*"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhId).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhPID).result; | ||||
ArrayList<SwhId> nodes = (ArrayList) endpoint.visitNodes(swhId).result; | ArrayList<SwhPID> nodes = (ArrayList) endpoint.visitNodes(swhPID).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:snp:0000000000000000000000000000000000000020", | "swh:1:snp:0000000000000000000000000000000000000020", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:rev:0000000000000000000000000000000000000003", | "swh:1:rev:0000000000000000000000000000000000000003", | ||||
"swh:1:dir:0000000000000000000000000000000000000002" | "swh:1:dir:0000000000000000000000000000000000000002" | ||||
Show All 12 Lines | public void forwardSnpToAllRevToAll() { | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardNoEdges() { | public void forwardNoEdges() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SwhId swhId = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); | SwhPID swhPID = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); | ||||
Endpoint endpoint = new Endpoint(graph, "forward", ""); | Endpoint endpoint = new Endpoint(graph, "forward", ""); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhId).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhPID).result; | ||||
ArrayList<SwhId> nodes = (ArrayList) endpoint.visitNodes(swhId).result; | ArrayList<SwhPID> nodes = (ArrayList) endpoint.visitNodes(swhPID).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:snp:0000000000000000000000000000000000000020" | "swh:1:snp:0000000000000000000000000000000000000020" | ||||
)); | )); | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void backwardRevToRevRevToRel() { | public void backwardRevToRevRevToRel() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SwhId swhId = new SwhId("swh:1:rev:0000000000000000000000000000000000000003"); | SwhPID swhPID = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); | ||||
Endpoint endpoint = new Endpoint(graph, "backward", "rev:rev,rev:rel"); | Endpoint endpoint = new Endpoint(graph, "backward", "rev:rev,rev:rel"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhId).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint.visitPaths(swhPID).result; | ||||
ArrayList<SwhId> nodes = (ArrayList) endpoint.visitNodes(swhId).result; | ArrayList<SwhPID> nodes = (ArrayList) endpoint.visitNodes(swhPID).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:rev:0000000000000000000000000000000000000003", | "swh:1:rev:0000000000000000000000000000000000000003", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:rev:0000000000000000000000000000000000000013", | "swh:1:rev:0000000000000000000000000000000000000013", | ||||
"swh:1:rev:0000000000000000000000000000000000000018", | "swh:1:rev:0000000000000000000000000000000000000018", | ||||
"swh:1:rel:0000000000000000000000000000000000000019" | "swh:1:rel:0000000000000000000000000000000000000019" | ||||
)); | )); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:rev:0000000000000000000000000000000000000003", | "swh:1:rev:0000000000000000000000000000000000000003", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:rel:0000000000000000000000000000000000000010" | "swh:1:rel:0000000000000000000000000000000000000010" | ||||
)); | )); | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardFromRootNodesOnly() { | public void forwardFromRootNodesOnly() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SwhId swhId = new SwhId("swh:1:ori:0000000000000000000000000000000000000021"); | SwhPID swhPID = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); | ||||
Endpoint endpoint = new Endpoint(graph, "forward", "*"); | Endpoint endpoint = new Endpoint(graph, "forward", "*"); | ||||
ArrayList<SwhId> nodes = (ArrayList) endpoint.visitNodes(swhId).result; | ArrayList<SwhPID> nodes = (ArrayList) endpoint.visitNodes(swhPID).result; | ||||
ArrayList<SwhId> expectedNodes = new ArrayList<SwhId>(); | ArrayList<SwhPID> expectedNodes = new ArrayList<SwhPID>(); | ||||
expectedNodes.add(new SwhId("swh:1:ori:0000000000000000000000000000000000000021")); | expectedNodes.add(new SwhPID("swh:1:ori:0000000000000000000000000000000000000021")); | ||||
expectedNodes.add(new SwhId("swh:1:snp:0000000000000000000000000000000000000020")); | expectedNodes.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); | ||||
expectedNodes.add(new SwhId("swh:1:rel:0000000000000000000000000000000000000010")); | expectedNodes.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); | ||||
expectedNodes.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000009")); | expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000009")); | ||||
expectedNodes.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000003")); | expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000003")); | ||||
expectedNodes.add(new SwhId("swh:1:dir:0000000000000000000000000000000000000002")); | expectedNodes.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000002")); | ||||
expectedNodes.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000001")); | expectedNodes.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); | ||||
expectedNodes.add(new SwhId("swh:1:dir:0000000000000000000000000000000000000008")); | expectedNodes.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000008")); | ||||
expectedNodes.add(new SwhId("swh:1:dir:0000000000000000000000000000000000000006")); | expectedNodes.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000006")); | ||||
expectedNodes.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000004")); | expectedNodes.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004")); | ||||
expectedNodes.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000005")); | expectedNodes.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005")); | ||||
expectedNodes.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000007")); | expectedNodes.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); | GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void backwardRevToAllNodesOnly() { | public void backwardRevToAllNodesOnly() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SwhId swhId = new SwhId("swh:1:rev:0000000000000000000000000000000000000003"); | SwhPID swhPID = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); | ||||
Endpoint endpoint = new Endpoint(graph, "backward", "rev:*"); | Endpoint endpoint = new Endpoint(graph, "backward", "rev:*"); | ||||
ArrayList<SwhId> nodes = (ArrayList) endpoint.visitNodes(swhId).result; | ArrayList<SwhPID> nodes = (ArrayList) endpoint.visitNodes(swhPID).result; | ||||
ArrayList<SwhId> expectedNodes = new ArrayList<SwhId>(); | ArrayList<SwhPID> expectedNodes = new ArrayList<SwhPID>(); | ||||
expectedNodes.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000003")); | expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000003")); | ||||
expectedNodes.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000009")); | expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000009")); | ||||
expectedNodes.add(new SwhId("swh:1:snp:0000000000000000000000000000000000000020")); | expectedNodes.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); | ||||
expectedNodes.add(new SwhId("swh:1:rel:0000000000000000000000000000000000000010")); | expectedNodes.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); | ||||
expectedNodes.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000013")); | expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); | ||||
expectedNodes.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000018")); | expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000018")); | ||||
expectedNodes.add(new SwhId("swh:1:rel:0000000000000000000000000000000000000019")); | expectedNodes.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000019")); | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); | GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); | ||||
} | } | ||||
} | } |