diff --git a/java/pom.xml b/java/pom.xml
index c0ec690..bed537c 100644
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -1,225 +1,235 @@
4.0.0
org.softwareheritage.graph
swh-graph
${git.closest.tag.name}
swh-graph
https://forge.softwareheritage.org/source/swh-graph/
UTF-8
11
ch.qos.logback
logback-classic
1.2.3
- junit
- junit
- 4.11
+ org.junit.jupiter
+ junit-jupiter-api
+ 5.7.0
test
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.7.0
+ test
+
org.hamcrest
hamcrest
2.1
test
io.javalin
javalin
3.0.0
org.slf4j
slf4j-simple
1.7.26
com.fasterxml.jackson.core
jackson-databind
2.9.8
it.unimi.dsi
webgraph-big
3.6.0
it.unimi.dsi
fastutil
8.4.1
it.unimi.dsi
law
2.6.2
org.apache.hadoop
hadoop-common
org.umlgraph
umlgraph
org.eclipse.jetty.aggregate
jetty-all
it.unimi.di
mg4j
it.unimi.di
mg4j-big
com.martiansoftware
jsap
2.1
net.sf.py4j
py4j
0.10.8.1
commons-codec
commons-codec
1.11
maven-clean-plugin
3.1.0
maven-resources-plugin
3.0.2
maven-compiler-plugin
3.8.0
11
-verbose
-Xlint:all
maven-surefire-plugin
- 2.22.1
+ 2.22.2
+
+
+ maven-failsafe-plugin
+ 2.22.2
maven-jar-plugin
3.0.2
maven-install-plugin
2.5.2
maven-deploy-plugin
2.8.2
maven-site-plugin
3.7.1
maven-project-info-reports-plugin
3.0.0
maven-assembly-plugin
3.3.0
org.softwareheritage.graph.server.App
jar-with-dependencies
false
make-assembly
package
single
pl.project13.maven
git-commit-id-plugin
3.0.1
get-the-git-infos
revision
initialize
true
true
true
true
v*
git.closest.tag.name
^v
true
org.apache.maven.plugins
maven-javadoc-plugin
3.1.1
diff --git a/java/src/test/java/org/softwareheritage/graph/AllowedEdgesTest.java b/java/src/test/java/org/softwareheritage/graph/AllowedEdgesTest.java
index 506a519..7edb19d 100644
--- a/java/src/test/java/org/softwareheritage/graph/AllowedEdgesTest.java
+++ b/java/src/test/java/org/softwareheritage/graph/AllowedEdgesTest.java
@@ -1,112 +1,112 @@
package org.softwareheritage.graph;
-import java.util.ArrayList;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
-import org.junit.Test;
-import org.junit.Assert;
+import java.util.ArrayList;
public class AllowedEdgesTest extends GraphTest {
static class EdgeType {
Node.Type src;
Node.Type dst;
public EdgeType(Node.Type src, Node.Type dst) {
this.src = src;
this.dst = dst;
}
@Override
public boolean equals(Object otherObj) {
if (otherObj == this) return true;
if (!(otherObj instanceof EdgeType)) return false;
EdgeType other = (EdgeType) otherObj;
return src == other.src && dst == other.dst;
}
}
void assertEdgeRestriction(AllowedEdges edges, ArrayList expectedAllowed) {
Node.Type[] nodeTypes = Node.Type.values();
for (Node.Type src : nodeTypes) {
for (Node.Type dst : nodeTypes) {
EdgeType edge = new EdgeType(src, dst);
boolean isAllowed = edges.isAllowed(src, dst);
boolean isExpected = false;
for (EdgeType expected : expectedAllowed) {
if (expected.equals(edge)) {
isExpected = true;
break;
}
}
- Assert.assertEquals("Edge type: " + src + " -> " + dst, isAllowed, isExpected);
+ Assertions.assertEquals(isAllowed, isExpected, "Edge type: " + src + " -> " + dst);
}
}
}
@Test
public void dirToDirDirToCntEdges() {
AllowedEdges edges = new AllowedEdges("dir:dir,dir:cnt");
ArrayList expected = new ArrayList<>();
expected.add(new EdgeType(Node.Type.DIR, Node.Type.DIR));
expected.add(new EdgeType(Node.Type.DIR, Node.Type.CNT));
assertEdgeRestriction(edges, expected);
}
@Test
public void relToRevRevToRevRevToDirEdges() {
AllowedEdges edges = new AllowedEdges("rel:rev,rev:rev,rev:dir");
ArrayList expected = new ArrayList<>();
expected.add(new EdgeType(Node.Type.REL, Node.Type.REV));
expected.add(new EdgeType(Node.Type.REV, Node.Type.REV));
expected.add(new EdgeType(Node.Type.REV, Node.Type.DIR));
assertEdgeRestriction(edges, expected);
}
@Test
public void revToAllDirToDirEdges() {
AllowedEdges edges = new AllowedEdges("rev:*,dir:dir");
ArrayList expected = new ArrayList<>();
for (Node.Type dst : Node.Type.values()) {
expected.add(new EdgeType(Node.Type.REV, dst));
}
expected.add(new EdgeType(Node.Type.DIR, Node.Type.DIR));
assertEdgeRestriction(edges, expected);
}
@Test
public void allToCntEdges() {
AllowedEdges edges = new AllowedEdges("*:cnt");
ArrayList expected = new ArrayList<>();
for (Node.Type src : Node.Type.values()) {
expected.add(new EdgeType(src, Node.Type.CNT));
}
assertEdgeRestriction(edges, expected);
}
@Test
public void allEdges() {
AllowedEdges edges = new AllowedEdges("*:*");
ArrayList expected = new ArrayList<>();
for (Node.Type src : Node.Type.values()) {
for (Node.Type dst : Node.Type.values()) {
expected.add(new EdgeType(src, dst));
}
}
assertEdgeRestriction(edges, expected);
// Special null value used to quickly bypass edge check when no restriction
AllowedEdges edges2 = new AllowedEdges("*");
- Assert.assertNull(edges2.restrictedTo);
+ Assertions.assertNull(edges2.restrictedTo);
}
@Test
public void noEdges() {
AllowedEdges edges = new AllowedEdges("");
AllowedEdges edges2 = new AllowedEdges(null);
ArrayList expected = new ArrayList<>();
assertEdgeRestriction(edges, expected);
assertEdgeRestriction(edges2, expected);
}
}
diff --git a/java/src/test/java/org/softwareheritage/graph/GraphTest.java b/java/src/test/java/org/softwareheritage/graph/GraphTest.java
index 43f207d..df1afb7 100644
--- a/java/src/test/java/org/softwareheritage/graph/GraphTest.java
+++ b/java/src/test/java/org/softwareheritage/graph/GraphTest.java
@@ -1,30 +1,44 @@
package org.softwareheritage.graph;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Iterator;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
+import it.unimi.dsi.big.webgraph.LazyLongIterator;
+import it.unimi.dsi.big.webgraph.LazyLongIterators;
+import org.hamcrest.MatcherAssert;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
-import org.softwareheritage.graph.Graph;
+import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
public class GraphTest {
static Graph graph;
public static void assertEqualsAnyOrder(Collection expecteds, Collection actuals) {
- Assert.assertThat(expecteds, containsInAnyOrder(actuals.toArray()));
+ MatcherAssert.assertThat(expecteds, containsInAnyOrder(actuals.toArray()));
+ }
+
+ public static void assertLazyLongIteratorsEqual(LazyLongIterator expected, LazyLongIterator actual) {
+ ArrayList expectedList = new ArrayList<>();
+ ArrayList actualList = new ArrayList<>();
+ Iterator expectedIt = LazyLongIterators.eager(expected);
+ Iterator actualIt = LazyLongIterators.eager(actual);
+ expectedIt.forEachRemaining(expectedList::add);
+ actualIt.forEachRemaining(actualList::add);
+ Assertions.assertArrayEquals(expectedList.toArray(), actualList.toArray());
}
- @BeforeClass
+ @BeforeAll
public static void setUp() throws IOException {
Path graphPath = Paths.get("..", "swh", "graph", "tests", "dataset", "output", "example");
graph = new Graph(graphPath.toString());
}
public Graph getGraph() {
return graph;
}
}
diff --git a/java/src/test/java/org/softwareheritage/graph/LeavesTest.java b/java/src/test/java/org/softwareheritage/graph/LeavesTest.java
index a24cb61..a288d03 100644
--- a/java/src/test/java/org/softwareheritage/graph/LeavesTest.java
+++ b/java/src/test/java/org/softwareheritage/graph/LeavesTest.java
@@ -1,108 +1,107 @@
package org.softwareheritage.graph;
import java.util.ArrayList;
-import org.junit.Test;
-
+import org.junit.jupiter.api.Test;
import org.softwareheritage.graph.server.Endpoint;
// Avoid warnings concerning Endpoint.Output.result manual cast
@SuppressWarnings("unchecked")
public class LeavesTest extends GraphTest {
@Test
public void forwardFromSnp() {
Graph graph = getGraph();
SWHID src = new SWHID("swh:1:snp:0000000000000000000000000000000000000020");
Endpoint endpoint = new Endpoint(graph, "forward", "*");
ArrayList expectedLeaves = new ArrayList<>();
expectedLeaves.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000001"));
expectedLeaves.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000004"));
expectedLeaves.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000005"));
expectedLeaves.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000007"));
ArrayList actualLeaves = (ArrayList) endpoint.leaves(new Endpoint.Input(src)).result;
GraphTest.assertEqualsAnyOrder(expectedLeaves, actualLeaves);
}
@Test
public void forwardFromRel() {
Graph graph = getGraph();
SWHID src = new SWHID("swh:1:rel:0000000000000000000000000000000000000019");
Endpoint endpoint = new Endpoint(graph, "forward", "*");
ArrayList expectedLeaves = new ArrayList<>();
expectedLeaves.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000015"));
expectedLeaves.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000014"));
expectedLeaves.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000001"));
expectedLeaves.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000004"));
expectedLeaves.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000005"));
expectedLeaves.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000007"));
expectedLeaves.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000011"));
ArrayList actualLeaves = (ArrayList) endpoint.leaves(new Endpoint.Input(src)).result;
GraphTest.assertEqualsAnyOrder(expectedLeaves, actualLeaves);
}
@Test
public void backwardFromLeaf() {
Graph graph = getGraph();
Endpoint endpoint1 = new Endpoint(graph, "backward", "*");
SWHID src1 = new SWHID("swh:1:cnt:0000000000000000000000000000000000000015");
ArrayList expectedLeaves1 = new ArrayList<>();
expectedLeaves1.add(new SWHID("swh:1:rel:0000000000000000000000000000000000000019"));
ArrayList actualLeaves1 = (ArrayList) endpoint1.leaves(new Endpoint.Input(src1)).result;
GraphTest.assertEqualsAnyOrder(expectedLeaves1, actualLeaves1);
Endpoint endpoint2 = new Endpoint(graph, "backward", "*");
SWHID src2 = new SWHID("swh:1:cnt:0000000000000000000000000000000000000004");
ArrayList expectedLeaves2 = new ArrayList<>();
expectedLeaves2.add(new SWHID("swh:1:ori:0000000000000000000000000000000000000021"));
expectedLeaves2.add(new SWHID("swh:1:rel:0000000000000000000000000000000000000019"));
ArrayList actualLeaves2 = (ArrayList) endpoint2.leaves(new Endpoint.Input(src2)).result;
GraphTest.assertEqualsAnyOrder(expectedLeaves2, actualLeaves2);
}
@Test
public void forwardRevToRevOnly() {
Graph graph = getGraph();
SWHID src = new SWHID("swh:1:rev:0000000000000000000000000000000000000018");
Endpoint endpoint = new Endpoint(graph, "forward", "rev:rev");
ArrayList expectedLeaves = new ArrayList<>();
expectedLeaves.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000003"));
ArrayList actualLeaves = (ArrayList) endpoint.leaves(new Endpoint.Input(src)).result;
GraphTest.assertEqualsAnyOrder(expectedLeaves, actualLeaves);
}
@Test
public void forwardDirToAll() {
Graph graph = getGraph();
SWHID src = new SWHID("swh:1:dir:0000000000000000000000000000000000000008");
Endpoint endpoint = new Endpoint(graph, "forward", "dir:*");
ArrayList expectedLeaves = new ArrayList<>();
expectedLeaves.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000004"));
expectedLeaves.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000005"));
expectedLeaves.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000001"));
expectedLeaves.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000007"));
ArrayList actualLeaves = (ArrayList) endpoint.leaves(new Endpoint.Input(src)).result;
GraphTest.assertEqualsAnyOrder(expectedLeaves, actualLeaves);
}
@Test
public void backwardCntToDirDirToDir() {
Graph graph = getGraph();
SWHID src = new SWHID("swh:1:cnt:0000000000000000000000000000000000000005");
Endpoint endpoint = new Endpoint(graph, "backward", "cnt:dir,dir:dir");
ArrayList expectedLeaves = new ArrayList<>();
expectedLeaves.add(new SWHID("swh:1:dir:0000000000000000000000000000000000000012"));
ArrayList actualLeaves = (ArrayList) endpoint.leaves(new Endpoint.Input(src)).result;
GraphTest.assertEqualsAnyOrder(expectedLeaves, actualLeaves);
}
}
diff --git a/java/src/test/java/org/softwareheritage/graph/NeighborsTest.java b/java/src/test/java/org/softwareheritage/graph/NeighborsTest.java
index b20bcb6..cf41aa4 100644
--- a/java/src/test/java/org/softwareheritage/graph/NeighborsTest.java
+++ b/java/src/test/java/org/softwareheritage/graph/NeighborsTest.java
@@ -1,142 +1,141 @@
package org.softwareheritage.graph;
import java.util.ArrayList;
-import org.junit.Test;
-
+import org.junit.jupiter.api.Test;
import org.softwareheritage.graph.server.Endpoint;
// Avoid warnings concerning Endpoint.Output.result manual cast
@SuppressWarnings("unchecked")
public class NeighborsTest extends GraphTest {
@Test
public void zeroNeighbor() {
Graph graph = getGraph();
ArrayList expectedNodes = new ArrayList<>();
SWHID src1 = new SWHID("swh:1:ori:0000000000000000000000000000000000000021");
Endpoint endpoint1 = new Endpoint(graph, "backward", "*");
ArrayList actuals1 = (ArrayList) endpoint1.neighbors(new Endpoint.Input(src1)).result;
GraphTest.assertEqualsAnyOrder(expectedNodes, actuals1);
SWHID src2 = new SWHID("swh:1:cnt:0000000000000000000000000000000000000004");
Endpoint endpoint2 = new Endpoint(graph, "forward", "*");
ArrayList actuals2 = (ArrayList) endpoint2.neighbors(new Endpoint.Input(src2)).result;
GraphTest.assertEqualsAnyOrder(expectedNodes, actuals2);
SWHID src3 = new SWHID("swh:1:cnt:0000000000000000000000000000000000000015");
Endpoint endpoint3 = new Endpoint(graph, "forward", "*");
ArrayList actuals3 = (ArrayList) endpoint3.neighbors(new Endpoint.Input(src3)).result;
GraphTest.assertEqualsAnyOrder(expectedNodes, actuals3);
SWHID src4 = new SWHID("swh:1:rel:0000000000000000000000000000000000000019");
Endpoint endpoint4 = new Endpoint(graph, "backward", "*");
ArrayList actuals4 = (ArrayList) endpoint4.neighbors(new Endpoint.Input(src4)).result;
GraphTest.assertEqualsAnyOrder(expectedNodes, actuals4);
SWHID src5 = new SWHID("swh:1:dir:0000000000000000000000000000000000000008");
Endpoint endpoint5 = new Endpoint(graph, "forward", "snp:*,rev:*,rel:*");
ArrayList actuals5 = (ArrayList) endpoint5.neighbors(new Endpoint.Input(src5)).result;
GraphTest.assertEqualsAnyOrder(expectedNodes, actuals5);
}
@Test
public void oneNeighbor() {
Graph graph = getGraph();
SWHID src1 = new SWHID("swh:1:rev:0000000000000000000000000000000000000003");
Endpoint endpoint1 = new Endpoint(graph, "forward", "*");
ArrayList expectedNodes1 = new ArrayList<>();
expectedNodes1.add(new SWHID("swh:1:dir:0000000000000000000000000000000000000002"));
ArrayList actuals1 = (ArrayList) endpoint1.neighbors(new Endpoint.Input(src1)).result;
GraphTest.assertEqualsAnyOrder(expectedNodes1, actuals1);
SWHID src2 = new SWHID("swh:1:dir:0000000000000000000000000000000000000017");
Endpoint endpoint2 = new Endpoint(graph, "forward", "dir:cnt");
ArrayList expectedNodes2 = new ArrayList<>();
expectedNodes2.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000014"));
ArrayList actuals2 = (ArrayList) endpoint2.neighbors(new Endpoint.Input(src2)).result;
GraphTest.assertEqualsAnyOrder(expectedNodes2, actuals2);
SWHID src3 = new SWHID("swh:1:dir:0000000000000000000000000000000000000012");
Endpoint endpoint3 = new Endpoint(graph, "backward", "*");
ArrayList expectedNodes3 = new ArrayList<>();
expectedNodes3.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000013"));
ArrayList actuals3 = (ArrayList) endpoint3.neighbors(new Endpoint.Input(src3)).result;
GraphTest.assertEqualsAnyOrder(expectedNodes3, actuals3);
SWHID src4 = new SWHID("swh:1:rev:0000000000000000000000000000000000000009");
Endpoint endpoint4 = new Endpoint(graph, "backward", "rev:rev");
ArrayList expectedNodes4 = new ArrayList<>();
expectedNodes4.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000013"));
ArrayList actuals4 = (ArrayList) endpoint4.neighbors(new Endpoint.Input(src4)).result;
GraphTest.assertEqualsAnyOrder(expectedNodes4, actuals4);
SWHID src5 = new SWHID("swh:1:snp:0000000000000000000000000000000000000020");
Endpoint endpoint5 = new Endpoint(graph, "backward", "*");
ArrayList expectedNodes5 = new ArrayList<>();
expectedNodes5.add(new SWHID("swh:1:ori:0000000000000000000000000000000000000021"));
ArrayList actuals5 = (ArrayList) endpoint5.neighbors(new Endpoint.Input(src5)).result;
GraphTest.assertEqualsAnyOrder(expectedNodes5, actuals5);
}
@Test
public void twoNeighbors() {
Graph graph = getGraph();
SWHID src1 = new SWHID("swh:1:snp:0000000000000000000000000000000000000020");
Endpoint endpoint1 = new Endpoint(graph, "forward", "*");
ArrayList expectedNodes1 = new ArrayList<>();
expectedNodes1.add(new SWHID("swh:1:rel:0000000000000000000000000000000000000010"));
expectedNodes1.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000009"));
ArrayList actuals1 = (ArrayList) endpoint1.neighbors(new Endpoint.Input(src1)).result;
GraphTest.assertEqualsAnyOrder(expectedNodes1, actuals1);
SWHID src2 = new SWHID("swh:1:dir:0000000000000000000000000000000000000008");
Endpoint endpoint2 = new Endpoint(graph, "forward", "dir:cnt");
ArrayList expectedNodes2 = new ArrayList<>();
expectedNodes2.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000001"));
expectedNodes2.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000007"));
ArrayList actuals2 = (ArrayList) endpoint2.neighbors(new Endpoint.Input(src2)).result;
GraphTest.assertEqualsAnyOrder(expectedNodes2, actuals2);
SWHID src3 = new SWHID("swh:1:cnt:0000000000000000000000000000000000000001");
Endpoint endpoint3 = new Endpoint(graph, "backward", "*");
ArrayList expectedNodes3 = new ArrayList<>();
expectedNodes3.add(new SWHID("swh:1:dir:0000000000000000000000000000000000000008"));
expectedNodes3.add(new SWHID("swh:1:dir:0000000000000000000000000000000000000002"));
ArrayList actuals3 = (ArrayList) endpoint3.neighbors(new Endpoint.Input(src3)).result;
GraphTest.assertEqualsAnyOrder(expectedNodes3, actuals3);
SWHID src4 = new SWHID("swh:1:rev:0000000000000000000000000000000000000009");
Endpoint endpoint4 = new Endpoint(graph, "backward", "rev:snp,rev:rel");
ArrayList expectedNodes4 = new ArrayList<>();
expectedNodes4.add(new SWHID("swh:1:snp:0000000000000000000000000000000000000020"));
expectedNodes4.add(new SWHID("swh:1:rel:0000000000000000000000000000000000000010"));
ArrayList actuals4 = (ArrayList) endpoint4.neighbors(new Endpoint.Input(src4)).result;
GraphTest.assertEqualsAnyOrder(expectedNodes4, actuals4);
}
@Test
public void threeNeighbors() {
Graph graph = getGraph();
SWHID src1 = new SWHID("swh:1:dir:0000000000000000000000000000000000000008");
Endpoint endpoint1 = new Endpoint(graph, "forward", "*");
ArrayList expectedNodes1 = new ArrayList<>();
expectedNodes1.add(new SWHID("swh:1:dir:0000000000000000000000000000000000000006"));
expectedNodes1.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000001"));
expectedNodes1.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000007"));
ArrayList actuals1 = (ArrayList) endpoint1.neighbors(new Endpoint.Input(src1)).result;
GraphTest.assertEqualsAnyOrder(expectedNodes1, actuals1);
SWHID src2 = new SWHID("swh:1:rev:0000000000000000000000000000000000000009");
Endpoint endpoint2 = new Endpoint(graph, "backward", "*");
ArrayList expectedNodes2 = new ArrayList<>();
expectedNodes2.add(new SWHID("swh:1:snp:0000000000000000000000000000000000000020"));
expectedNodes2.add(new SWHID("swh:1:rel:0000000000000000000000000000000000000010"));
expectedNodes2.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000013"));
ArrayList actuals2 = (ArrayList) endpoint2.neighbors(new Endpoint.Input(src2)).result;
GraphTest.assertEqualsAnyOrder(expectedNodes2, actuals2);
}
}
diff --git a/java/src/test/java/org/softwareheritage/graph/VisitTest.java b/java/src/test/java/org/softwareheritage/graph/VisitTest.java
index 11fc97c..9cce68d 100644
--- a/java/src/test/java/org/softwareheritage/graph/VisitTest.java
+++ b/java/src/test/java/org/softwareheritage/graph/VisitTest.java
@@ -1,543 +1,540 @@
package org.softwareheritage.graph;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;
-import org.junit.Test;
-
+import org.junit.jupiter.api.Test;
import org.softwareheritage.graph.server.Endpoint;
// Avoid warnings concerning Endpoint.Output.result manual cast
@SuppressWarnings("unchecked")
public class VisitTest extends GraphTest {
private void assertSameNodesFromPaths(ArrayList paths, ArrayList nodes) {
Set expectedNodes = new HashSet();
for (SwhPath path : paths) {
- for (SWHID node : path.getPath()) {
- expectedNodes.add(node);
- }
+ expectedNodes.addAll(path.getPath());
}
GraphTest.assertEqualsAnyOrder(expectedNodes, nodes);
}
@Test
public void forwardFromRoot() {
Graph graph = getGraph();
SWHID swhid = new SWHID("swh:1:ori:0000000000000000000000000000000000000021");
Endpoint endpoint1 = new Endpoint(graph, "forward", "*");
ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result;
Endpoint endpoint2 = new Endpoint(graph, "forward", "*");
ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result;
ArrayList expectedPaths = new ArrayList();
expectedPaths.add(
new SwhPath(
"swh:1:ori:0000000000000000000000000000000000000021",
"swh:1:snp:0000000000000000000000000000000000000020",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:cnt:0000000000000000000000000000000000000007"
));
expectedPaths.add(
new SwhPath(
"swh:1:ori:0000000000000000000000000000000000000021",
"swh:1:snp:0000000000000000000000000000000000000020",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:cnt:0000000000000000000000000000000000000001"
));
expectedPaths.add(
new SwhPath(
"swh:1:ori:0000000000000000000000000000000000000021",
"swh:1:snp:0000000000000000000000000000000000000020",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:dir:0000000000000000000000000000000000000006",
"swh:1:cnt:0000000000000000000000000000000000000004"
));
expectedPaths.add(
new SwhPath(
"swh:1:ori:0000000000000000000000000000000000000021",
"swh:1:snp:0000000000000000000000000000000000000020",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:dir:0000000000000000000000000000000000000006",
"swh:1:cnt:0000000000000000000000000000000000000005"
));
expectedPaths.add(
new SwhPath(
"swh:1:ori:0000000000000000000000000000000000000021",
"swh:1:snp:0000000000000000000000000000000000000020",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:rev:0000000000000000000000000000000000000003",
"swh:1:dir:0000000000000000000000000000000000000002",
"swh:1:cnt:0000000000000000000000000000000000000001"
));
expectedPaths.add(
new SwhPath(
"swh:1:ori:0000000000000000000000000000000000000021",
"swh:1:snp:0000000000000000000000000000000000000020",
"swh:1:rel:0000000000000000000000000000000000000010",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:cnt:0000000000000000000000000000000000000007"
));
expectedPaths.add(
new SwhPath(
"swh:1:ori:0000000000000000000000000000000000000021",
"swh:1:snp:0000000000000000000000000000000000000020",
"swh:1:rel:0000000000000000000000000000000000000010",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:cnt:0000000000000000000000000000000000000001"
));
expectedPaths.add(
new SwhPath(
"swh:1:ori:0000000000000000000000000000000000000021",
"swh:1:snp:0000000000000000000000000000000000000020",
"swh:1:rel:0000000000000000000000000000000000000010",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:dir:0000000000000000000000000000000000000006",
"swh:1:cnt:0000000000000000000000000000000000000004"
));
expectedPaths.add(
new SwhPath(
"swh:1:ori:0000000000000000000000000000000000000021",
"swh:1:snp:0000000000000000000000000000000000000020",
"swh:1:rel:0000000000000000000000000000000000000010",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:dir:0000000000000000000000000000000000000006",
"swh:1:cnt:0000000000000000000000000000000000000005"
));
expectedPaths.add(
new SwhPath(
"swh:1:ori:0000000000000000000000000000000000000021",
"swh:1:snp:0000000000000000000000000000000000000020",
"swh:1:rel:0000000000000000000000000000000000000010",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:rev:0000000000000000000000000000000000000003",
"swh:1:dir:0000000000000000000000000000000000000002",
"swh:1:cnt:0000000000000000000000000000000000000001"
));
GraphTest.assertEqualsAnyOrder(expectedPaths, paths);
assertSameNodesFromPaths(expectedPaths, nodes);
}
@Test
public void forwardFromMiddle() {
Graph graph = getGraph();
SWHID swhid = new SWHID("swh:1:dir:0000000000000000000000000000000000000012");
Endpoint endpoint1 = new Endpoint(graph, "forward", "*");
ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result;
Endpoint endpoint2 = new Endpoint(graph, "forward", "*");
ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result;
ArrayList expectedPaths = new ArrayList();
expectedPaths.add(
new SwhPath(
"swh:1:dir:0000000000000000000000000000000000000012",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:cnt:0000000000000000000000000000000000000007"
));
expectedPaths.add(
new SwhPath(
"swh:1:dir:0000000000000000000000000000000000000012",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:cnt:0000000000000000000000000000000000000001"
));
expectedPaths.add(
new SwhPath(
"swh:1:dir:0000000000000000000000000000000000000012",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:dir:0000000000000000000000000000000000000006",
"swh:1:cnt:0000000000000000000000000000000000000004"
));
expectedPaths.add(
new SwhPath(
"swh:1:dir:0000000000000000000000000000000000000012",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:dir:0000000000000000000000000000000000000006",
"swh:1:cnt:0000000000000000000000000000000000000005"
));
expectedPaths.add(
new SwhPath(
"swh:1:dir:0000000000000000000000000000000000000012",
"swh:1:cnt:0000000000000000000000000000000000000011"
));
GraphTest.assertEqualsAnyOrder(expectedPaths, paths);
assertSameNodesFromPaths(expectedPaths, nodes);
}
@Test
public void forwardFromLeaf() {
Graph graph = getGraph();
SWHID swhid = new SWHID("swh:1:cnt:0000000000000000000000000000000000000004");
Endpoint endpoint1 = new Endpoint(graph, "forward", "*");
ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result;
Endpoint endpoint2 = new Endpoint(graph, "forward", "*");
ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result;
ArrayList expectedPaths = new ArrayList();
expectedPaths.add(
new SwhPath(
"swh:1:cnt:0000000000000000000000000000000000000004"
));
GraphTest.assertEqualsAnyOrder(expectedPaths, paths);
assertSameNodesFromPaths(expectedPaths, nodes);
}
@Test
public void backwardFromRoot() {
Graph graph = getGraph();
SWHID swhid = new SWHID("swh:1:ori:0000000000000000000000000000000000000021");
Endpoint endpoint1 = new Endpoint(graph, "backward", "*");
ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result;
Endpoint endpoint2 = new Endpoint(graph, "backward", "*");
ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result;
ArrayList expectedPaths = new ArrayList();
expectedPaths.add(
new SwhPath(
"swh:1:ori:0000000000000000000000000000000000000021"
));
GraphTest.assertEqualsAnyOrder(expectedPaths, paths);
assertSameNodesFromPaths(expectedPaths, nodes);
}
@Test
public void backwardFromMiddle() {
Graph graph = getGraph();
SWHID swhid = new SWHID("swh:1:dir:0000000000000000000000000000000000000012");
Endpoint endpoint1 = new Endpoint(graph, "backward", "*");
ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result;
Endpoint endpoint2 = new Endpoint(graph, "backward", "*");
ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result;
ArrayList expectedPaths = new ArrayList();
expectedPaths.add(
new SwhPath(
"swh:1:dir:0000000000000000000000000000000000000012",
"swh:1:rev:0000000000000000000000000000000000000013",
"swh:1:rev:0000000000000000000000000000000000000018",
"swh:1:rel:0000000000000000000000000000000000000019"
));
GraphTest.assertEqualsAnyOrder(expectedPaths, paths);
assertSameNodesFromPaths(expectedPaths, nodes);
}
@Test
public void backwardFromLeaf() {
Graph graph = getGraph();
SWHID swhid = new SWHID("swh:1:cnt:0000000000000000000000000000000000000004");
Endpoint endpoint1 = new Endpoint(graph, "backward", "*");
ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result;
Endpoint endpoint2 = new Endpoint(graph, "backward", "*");
ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result;
ArrayList expectedPaths = new ArrayList();
expectedPaths.add(
new SwhPath(
"swh:1:cnt:0000000000000000000000000000000000000004",
"swh:1:dir:0000000000000000000000000000000000000006",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:dir:0000000000000000000000000000000000000012",
"swh:1:rev:0000000000000000000000000000000000000013",
"swh:1:rev:0000000000000000000000000000000000000018",
"swh:1:rel:0000000000000000000000000000000000000019"
));
expectedPaths.add(
new SwhPath(
"swh:1:cnt:0000000000000000000000000000000000000004",
"swh:1:dir:0000000000000000000000000000000000000006",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:rev:0000000000000000000000000000000000000013",
"swh:1:rev:0000000000000000000000000000000000000018",
"swh:1:rel:0000000000000000000000000000000000000019"
));
expectedPaths.add(
new SwhPath(
"swh:1:cnt:0000000000000000000000000000000000000004",
"swh:1:dir:0000000000000000000000000000000000000006",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:snp:0000000000000000000000000000000000000020",
"swh:1:ori:0000000000000000000000000000000000000021"
));
expectedPaths.add(
new SwhPath(
"swh:1:cnt:0000000000000000000000000000000000000004",
"swh:1:dir:0000000000000000000000000000000000000006",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:rel:0000000000000000000000000000000000000010",
"swh:1:snp:0000000000000000000000000000000000000020",
"swh:1:ori:0000000000000000000000000000000000000021"
));
GraphTest.assertEqualsAnyOrder(expectedPaths, paths);
assertSameNodesFromPaths(expectedPaths, nodes);
}
@Test
public void forwardSnpToRev() {
Graph graph = getGraph();
SWHID swhid = new SWHID("swh:1:snp:0000000000000000000000000000000000000020");
Endpoint endpoint1 = new Endpoint(graph, "forward", "snp:rev");
ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result;
Endpoint endpoint2 = new Endpoint(graph, "forward", "snp:rev");
ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result;
ArrayList expectedPaths = new ArrayList();
expectedPaths.add(
new SwhPath(
"swh:1:snp:0000000000000000000000000000000000000020",
"swh:1:rev:0000000000000000000000000000000000000009"
));
GraphTest.assertEqualsAnyOrder(expectedPaths, paths);
assertSameNodesFromPaths(expectedPaths, nodes);
}
@Test
public void forwardRelToRevRevToRev() {
Graph graph = getGraph();
SWHID swhid = new SWHID("swh:1:rel:0000000000000000000000000000000000000010");
Endpoint endpoint1 = new Endpoint(graph, "forward", "rel:rev,rev:rev");
ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result;
Endpoint endpoint2 = new Endpoint(graph, "forward", "rel:rev,rev:rev");
ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result;
ArrayList expectedPaths = new ArrayList();
expectedPaths.add(
new SwhPath(
"swh:1:rel:0000000000000000000000000000000000000010",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:rev:0000000000000000000000000000000000000003"
));
GraphTest.assertEqualsAnyOrder(expectedPaths, paths);
assertSameNodesFromPaths(expectedPaths, nodes);
}
@Test
public void forwardRevToAllDirToAll() {
Graph graph = getGraph();
SWHID swhid = new SWHID("swh:1:rev:0000000000000000000000000000000000000013");
Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:*,dir:*");
ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result;
Endpoint endpoint2 = new Endpoint(graph, "forward", "rev:*,dir:*");
ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result;
ArrayList expectedPaths = new ArrayList();
expectedPaths.add(
new SwhPath(
"swh:1:rev:0000000000000000000000000000000000000013",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:dir:0000000000000000000000000000000000000006",
"swh:1:cnt:0000000000000000000000000000000000000005"
));
expectedPaths.add(
new SwhPath(
"swh:1:rev:0000000000000000000000000000000000000013",
"swh:1:dir:0000000000000000000000000000000000000012",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:dir:0000000000000000000000000000000000000006",
"swh:1:cnt:0000000000000000000000000000000000000005"
));
expectedPaths.add(
new SwhPath(
"swh:1:rev:0000000000000000000000000000000000000013",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:dir:0000000000000000000000000000000000000006",
"swh:1:cnt:0000000000000000000000000000000000000004"
));
expectedPaths.add(
new SwhPath(
"swh:1:rev:0000000000000000000000000000000000000013",
"swh:1:dir:0000000000000000000000000000000000000012",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:dir:0000000000000000000000000000000000000006",
"swh:1:cnt:0000000000000000000000000000000000000004"
));
expectedPaths.add(
new SwhPath(
"swh:1:rev:0000000000000000000000000000000000000013",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:cnt:0000000000000000000000000000000000000007"
));
expectedPaths.add(
new SwhPath(
"swh:1:rev:0000000000000000000000000000000000000013",
"swh:1:dir:0000000000000000000000000000000000000012",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:cnt:0000000000000000000000000000000000000007"
));
expectedPaths.add(
new SwhPath(
"swh:1:rev:0000000000000000000000000000000000000013",
"swh:1:dir:0000000000000000000000000000000000000012",
"swh:1:cnt:0000000000000000000000000000000000000011"
));
expectedPaths.add(
new SwhPath(
"swh:1:rev:0000000000000000000000000000000000000013",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:rev:0000000000000000000000000000000000000003",
"swh:1:dir:0000000000000000000000000000000000000002",
"swh:1:cnt:0000000000000000000000000000000000000001"
));
expectedPaths.add(
new SwhPath(
"swh:1:rev:0000000000000000000000000000000000000013",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:cnt:0000000000000000000000000000000000000001"
));
expectedPaths.add(
new SwhPath(
"swh:1:rev:0000000000000000000000000000000000000013",
"swh:1:dir:0000000000000000000000000000000000000012",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:cnt:0000000000000000000000000000000000000001"
));
GraphTest.assertEqualsAnyOrder(expectedPaths, paths);
assertSameNodesFromPaths(expectedPaths, nodes);
}
@Test
public void forwardSnpToAllRevToAll() {
Graph graph = getGraph();
SWHID swhid = new SWHID("swh:1:snp:0000000000000000000000000000000000000020");
Endpoint endpoint1 = new Endpoint(graph, "forward", "snp:*,rev:*");
ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result;
Endpoint endpoint2 = new Endpoint(graph, "forward", "snp:*,rev:*");
ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result;
ArrayList expectedPaths = new ArrayList();
expectedPaths.add(
new SwhPath(
"swh:1:snp:0000000000000000000000000000000000000020",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:rev:0000000000000000000000000000000000000003",
"swh:1:dir:0000000000000000000000000000000000000002"
));
expectedPaths.add(
new SwhPath(
"swh:1:snp:0000000000000000000000000000000000000020",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:dir:0000000000000000000000000000000000000008"
));
expectedPaths.add(
new SwhPath(
"swh:1:snp:0000000000000000000000000000000000000020",
"swh:1:rel:0000000000000000000000000000000000000010"
));
GraphTest.assertEqualsAnyOrder(expectedPaths, paths);
assertSameNodesFromPaths(expectedPaths, nodes);
}
@Test
public void forwardNoEdges() {
Graph graph = getGraph();
SWHID swhid = new SWHID("swh:1:snp:0000000000000000000000000000000000000020");
Endpoint endpoint1 = new Endpoint(graph, "forward", "");
ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result;
Endpoint endpoint2 = new Endpoint(graph, "forward", "");
ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result;
ArrayList expectedPaths = new ArrayList();
expectedPaths.add(
new SwhPath(
"swh:1:snp:0000000000000000000000000000000000000020"
));
GraphTest.assertEqualsAnyOrder(expectedPaths, paths);
assertSameNodesFromPaths(expectedPaths, nodes);
}
@Test
public void backwardRevToRevRevToRel() {
Graph graph = getGraph();
SWHID swhid = new SWHID("swh:1:rev:0000000000000000000000000000000000000003");
Endpoint endpoint1 = new Endpoint(graph, "backward", "rev:rev,rev:rel");
ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result;
Endpoint endpoint2 = new Endpoint(graph, "backward", "rev:rev,rev:rel");
ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result;
ArrayList expectedPaths = new ArrayList();
expectedPaths.add(
new SwhPath(
"swh:1:rev:0000000000000000000000000000000000000003",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:rev:0000000000000000000000000000000000000013",
"swh:1:rev:0000000000000000000000000000000000000018",
"swh:1:rel:0000000000000000000000000000000000000019"
));
expectedPaths.add(
new SwhPath(
"swh:1:rev:0000000000000000000000000000000000000003",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:rel:0000000000000000000000000000000000000010"
));
GraphTest.assertEqualsAnyOrder(expectedPaths, paths);
assertSameNodesFromPaths(expectedPaths, nodes);
}
@Test
public void forwardFromRootNodesOnly() {
Graph graph = getGraph();
SWHID swhid = new SWHID("swh:1:ori:0000000000000000000000000000000000000021");
Endpoint endpoint = new Endpoint(graph, "forward", "*");
ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhid)).result;
ArrayList expectedNodes = new ArrayList();
expectedNodes.add(new SWHID("swh:1:ori:0000000000000000000000000000000000000021"));
expectedNodes.add(new SWHID("swh:1:snp:0000000000000000000000000000000000000020"));
expectedNodes.add(new SWHID("swh:1:rel:0000000000000000000000000000000000000010"));
expectedNodes.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000009"));
expectedNodes.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000003"));
expectedNodes.add(new SWHID("swh:1:dir:0000000000000000000000000000000000000002"));
expectedNodes.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000001"));
expectedNodes.add(new SWHID("swh:1:dir:0000000000000000000000000000000000000008"));
expectedNodes.add(new SWHID("swh:1:dir:0000000000000000000000000000000000000006"));
expectedNodes.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000004"));
expectedNodes.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000005"));
expectedNodes.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000007"));
GraphTest.assertEqualsAnyOrder(expectedNodes, nodes);
}
@Test
public void backwardRevToAllNodesOnly() {
Graph graph = getGraph();
SWHID swhid = new SWHID("swh:1:rev:0000000000000000000000000000000000000003");
Endpoint endpoint = new Endpoint(graph, "backward", "rev:*");
ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhid)).result;
ArrayList expectedNodes = new ArrayList();
expectedNodes.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000003"));
expectedNodes.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000009"));
expectedNodes.add(new SWHID("swh:1:snp:0000000000000000000000000000000000000020"));
expectedNodes.add(new SWHID("swh:1:rel:0000000000000000000000000000000000000010"));
expectedNodes.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000013"));
expectedNodes.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000018"));
expectedNodes.add(new SWHID("swh:1:rel:0000000000000000000000000000000000000019"));
GraphTest.assertEqualsAnyOrder(expectedNodes, nodes);
}
}
diff --git a/java/src/test/java/org/softwareheritage/graph/WalkTest.java b/java/src/test/java/org/softwareheritage/graph/WalkTest.java
index f575a66..fe463d2 100644
--- a/java/src/test/java/org/softwareheritage/graph/WalkTest.java
+++ b/java/src/test/java/org/softwareheritage/graph/WalkTest.java
@@ -1,234 +1,233 @@
package org.softwareheritage.graph;
import java.util.Arrays;
import java.util.List;
-import org.junit.Assert;
-import org.junit.Test;
-
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
import org.softwareheritage.graph.server.Endpoint;
public class WalkTest extends GraphTest {
@Test
public void forwardRootToLeaf() {
Graph graph = getGraph();
SWHID src = new SWHID("swh:1:snp:0000000000000000000000000000000000000020");
String dstFmt = "swh:1:cnt:0000000000000000000000000000000000000005";
SwhPath solution1 =
new SwhPath(
"swh:1:snp:0000000000000000000000000000000000000020",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:dir:0000000000000000000000000000000000000006",
"swh:1:cnt:0000000000000000000000000000000000000005"
);
SwhPath solution2 =
new SwhPath(
"swh:1:snp:0000000000000000000000000000000000000020",
"swh:1:rel:0000000000000000000000000000000000000010",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:dir:0000000000000000000000000000000000000006",
"swh:1:cnt:0000000000000000000000000000000000000005"
);
Endpoint endpoint1 = new Endpoint(graph, "forward", "*");
SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result;
Endpoint endpoint2 = new Endpoint(graph, "forward", "*");
SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result;
List possibleSolutions = Arrays.asList(solution1, solution2);
- Assert.assertTrue(possibleSolutions.contains(dfsPath));
- Assert.assertTrue(possibleSolutions.contains(bfsPath));
+ Assertions.assertTrue(possibleSolutions.contains(dfsPath));
+ Assertions.assertTrue(possibleSolutions.contains(bfsPath));
}
@Test
public void forwardLeafToLeaf() {
Graph graph = getGraph();
SWHID src = new SWHID("swh:1:cnt:0000000000000000000000000000000000000007");
String dstFmt = "cnt";
SwhPath expectedPath =
new SwhPath(
"swh:1:cnt:0000000000000000000000000000000000000007"
);
Endpoint endpoint1 = new Endpoint(graph, "forward", "*");
SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result;
Endpoint endpoint2 = new Endpoint(graph, "forward", "*");
SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result;
- Assert.assertEquals(dfsPath, expectedPath);
- Assert.assertEquals(bfsPath, expectedPath);
+ Assertions.assertEquals(dfsPath, expectedPath);
+ Assertions.assertEquals(bfsPath, expectedPath);
}
@Test
public void forwardRevToRev() {
Graph graph = getGraph();
SWHID src = new SWHID("swh:1:rev:0000000000000000000000000000000000000018");
String dstFmt = "swh:1:rev:0000000000000000000000000000000000000003";
SwhPath expectedPath =
new SwhPath(
"swh:1:rev:0000000000000000000000000000000000000018",
"swh:1:rev:0000000000000000000000000000000000000013",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:rev:0000000000000000000000000000000000000003"
);
Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:rev");
SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result;
Endpoint endpoint2 = new Endpoint(graph, "forward", "rev:rev");
SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result;
- Assert.assertEquals(dfsPath, expectedPath);
- Assert.assertEquals(bfsPath, expectedPath);
+ Assertions.assertEquals(dfsPath, expectedPath);
+ Assertions.assertEquals(bfsPath, expectedPath);
}
@Test
public void backwardRevToRev() {
Graph graph = getGraph();
SWHID src = new SWHID("swh:1:rev:0000000000000000000000000000000000000003");
String dstFmt = "swh:1:rev:0000000000000000000000000000000000000018";
SwhPath expectedPath =
new SwhPath(
"swh:1:rev:0000000000000000000000000000000000000003",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:rev:0000000000000000000000000000000000000013",
"swh:1:rev:0000000000000000000000000000000000000018"
);
Endpoint endpoint1 = new Endpoint(graph, "backward", "rev:rev");
SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result;
Endpoint endpoint2 = new Endpoint(graph, "backward", "rev:rev");
SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result;
- Assert.assertEquals(dfsPath, expectedPath);
- Assert.assertEquals(bfsPath, expectedPath);
+ Assertions.assertEquals(dfsPath, expectedPath);
+ Assertions.assertEquals(bfsPath, expectedPath);
}
@Test
public void backwardCntToFirstSnp() {
Graph graph = getGraph();
SWHID src = new SWHID("swh:1:cnt:0000000000000000000000000000000000000001");
String dstFmt = "snp";
SwhPath solution1 =
new SwhPath(
"swh:1:cnt:0000000000000000000000000000000000000001",
"swh:1:dir:0000000000000000000000000000000000000002",
"swh:1:rev:0000000000000000000000000000000000000003",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:snp:0000000000000000000000000000000000000020"
);
SwhPath solution2 =
new SwhPath(
"swh:1:cnt:0000000000000000000000000000000000000001",
"swh:1:dir:0000000000000000000000000000000000000002",
"swh:1:rev:0000000000000000000000000000000000000003",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:rel:0000000000000000000000000000000000000010",
"swh:1:snp:0000000000000000000000000000000000000020"
);
SwhPath solution3 =
new SwhPath(
"swh:1:cnt:0000000000000000000000000000000000000001",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:snp:0000000000000000000000000000000000000020"
);
SwhPath solution4 =
new SwhPath(
"swh:1:cnt:0000000000000000000000000000000000000001",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:rel:0000000000000000000000000000000000000010",
"swh:1:snp:0000000000000000000000000000000000000020"
);
Endpoint endpoint1 = new Endpoint(graph, "backward", "*");
SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result;
Endpoint endpoint2 = new Endpoint(graph, "backward", "*");
SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result;
List possibleSolutions = Arrays.asList(solution1, solution2, solution3, solution4);
- Assert.assertTrue(possibleSolutions.contains(dfsPath));
- Assert.assertTrue(possibleSolutions.contains(bfsPath));
+ Assertions.assertTrue(possibleSolutions.contains(dfsPath));
+ Assertions.assertTrue(possibleSolutions.contains(bfsPath));
}
@Test
public void forwardRevToFirstCnt() {
Graph graph = getGraph();
SWHID src = new SWHID("swh:1:rev:0000000000000000000000000000000000000009");
String dstFmt = "cnt";
SwhPath solution1 =
new SwhPath(
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:cnt:0000000000000000000000000000000000000007"
);
SwhPath solution2 =
new SwhPath(
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:dir:0000000000000000000000000000000000000006",
"swh:1:cnt:0000000000000000000000000000000000000005"
);
SwhPath solution3 =
new SwhPath(
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:dir:0000000000000000000000000000000000000006",
"swh:1:cnt:0000000000000000000000000000000000000004"
);
SwhPath solution4 =
new SwhPath(
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:cnt:0000000000000000000000000000000000000001"
);
SwhPath solution5 =
new SwhPath(
"swh:1:rev:0000000000000000000000000000000000000009",
"swh:1:rev:0000000000000000000000000000000000000003",
"swh:1:dir:0000000000000000000000000000000000000002",
"swh:1:cnt:0000000000000000000000000000000000000001"
);
Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:*,dir:*");
SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result;
Endpoint endpoint2 = new Endpoint(graph, "forward", "rev:*,dir:*");
SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result;
List possibleSolutions =
Arrays.asList(solution1, solution2, solution3, solution4, solution5);
- Assert.assertTrue(possibleSolutions.contains(dfsPath));
- Assert.assertTrue(possibleSolutions.contains(bfsPath));
+ Assertions.assertTrue(possibleSolutions.contains(dfsPath));
+ Assertions.assertTrue(possibleSolutions.contains(bfsPath));
}
@Test
public void backwardDirToFirstRel() {
Graph graph = getGraph();
SWHID src = new SWHID("swh:1:dir:0000000000000000000000000000000000000016");
String dstFmt = "rel";
SwhPath expectedPath =
new SwhPath(
"swh:1:dir:0000000000000000000000000000000000000016",
"swh:1:dir:0000000000000000000000000000000000000017",
"swh:1:rev:0000000000000000000000000000000000000018",
"swh:1:rel:0000000000000000000000000000000000000019"
);
Endpoint endpoint1 = new Endpoint(graph, "backward", "dir:dir,dir:rev,rev:*");
SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result;
Endpoint endpoint2 = new Endpoint(graph, "backward", "dir:dir,dir:rev,rev:*");
SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result;
- Assert.assertEquals(dfsPath, expectedPath);
- Assert.assertEquals(bfsPath, expectedPath);
+ Assertions.assertEquals(dfsPath, expectedPath);
+ Assertions.assertEquals(bfsPath, expectedPath);
}
}