From e649d153d98c0edcc8a18acc2f7bee53d9f8980f Mon Sep 17 00:00:00 2001 From: zyxxoo <1318247699@qq.com> Date: Thu, 15 Jul 2021 19:05:29 +0800 Subject: [PATCH] feat: improve test result verify --- .../com/baidu/hugegraph/api/BaseApiTest.java | 2 ++ .../traversers/AllShortestPathsApiTest.java | 6 ++--- .../api/traversers/CountApiTest.java | 20 +++++++------- .../api/traversers/CrosspointsApiTest.java | 11 ++++---- .../CustomizedCrosspointsApiTest.java | 6 ++--- .../api/traversers/EdgesApiTest.java | 26 ++++++++++--------- .../traversers/FusiformSimilarityApiTest.java | 8 +++--- .../traversers/JaccardSimilarityApiTest.java | 10 +++---- .../api/traversers/KneighborApiTest.java | 13 +++++++--- .../hugegraph/api/traversers/KoutApiTest.java | 20 +++++++------- .../MultiNodeShortestPathApiTest.java | 10 ++++--- .../api/traversers/NeighborRankApiTest.java | 6 ++--- .../api/traversers/PathsApiTest.java | 14 +++++----- .../api/traversers/PersonalRankApiTest.java | 6 ++--- .../hugegraph/api/traversers/RaysApiTest.java | 6 ++--- .../api/traversers/RingsApiTest.java | 8 +++--- .../api/traversers/SameNeighborsApiTest.java | 6 ++--- .../api/traversers/ShortestPathApiTest.java | 12 +++++---- .../SingleSourceShortestPathApiTest.java | 9 +++---- .../api/traversers/TemplatePathsApiTest.java | 6 ++--- .../WeightedShortestPathApiTest.java | 7 +++-- 21 files changed, 112 insertions(+), 100 deletions(-) diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/BaseApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/BaseApiTest.java index bf4cd1b2eb..68e328237a 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/BaseApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/BaseApiTest.java @@ -69,6 +69,8 @@ public class BaseApiTest { private static final String GRAPH_EDGE = "/graph/edges"; private static final String BATCH = "/batch"; + protected static final String TRAVERSERS_API = URL_PREFIX + "/traversers"; + private static RestClient client; private static final ObjectMapper mapper = new ObjectMapper(); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/AllShortestPathsApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/AllShortestPathsApiTest.java index db13f01663..5c4cd3d11f 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/AllShortestPathsApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/AllShortestPathsApiTest.java @@ -32,7 +32,7 @@ public class AllShortestPathsApiTest extends BaseApiTest { - public static String path = "graphs/hugegraph/traversers/allshortestpaths"; + public static String path = TRAVERSERS_API + "/allshortestpaths"; @Before public void prepareSchema() { @@ -55,9 +55,9 @@ public void testGet() { "target", id2Json(vadasId), "max_depth", 100); - String respJson = assertResponseStatus(200, + String content = assertResponseStatus(200, client().get(path, entities)); - List paths = assertJsonContains(respJson, "paths"); + List paths = assertJsonContains(content, "paths"); Assert.assertEquals(1, paths.size()); List objects = assertMapContains((Map) paths.get(0), "objects"); Assert.assertEquals(ImmutableList.of(markoId, peterId, joshId, diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CountApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CountApiTest.java index 8c219fb26a..26e83f2e01 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CountApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CountApiTest.java @@ -29,7 +29,7 @@ public class CountApiTest extends BaseApiTest { - public static String path = "graphs/hugegraph/traversers/count"; + public static String path = TRAVERSERS_API + "/count"; @Before public void prepareSchema() { @@ -46,15 +46,15 @@ public void testCount() { String reqBody = String.format("{ " + "\"source\": \"%s\", " + "\"steps\": [{ " + - " \"labels\": []," + - " \"degree\": 100," + - " \"skip_degree\": 100},{ " + - " \"labels\": []," + - " \"degree\": 100," + - " \"skip_degree\": 100},{ " + - " \"labels\": []," + - " \"degree\": 100," + - " \"skip_degree\": 100}]}", markoId); + " \"labels\": []," + + " \"degree\": 100," + + " \"skip_degree\": 100},{ " + + " \"labels\": []," + + " \"degree\": 100," + + " \"skip_degree\": 100},{ " + + " \"labels\": []," + + " \"degree\": 100," + + " \"skip_degree\": 100}]}", markoId); Response r = client().post(path, reqBody); String content = assertResponseStatus(200, r); Integer count = assertJsonContains(content, "count"); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CrosspointsApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CrosspointsApiTest.java index 6adba86c81..e29bd46ddc 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CrosspointsApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CrosspointsApiTest.java @@ -19,8 +19,6 @@ package com.baidu.hugegraph.api.traversers; -import com.baidu.hugegraph.testutil.Assert; - import java.util.List; import java.util.Map; @@ -30,11 +28,12 @@ import org.junit.Test; import com.baidu.hugegraph.api.BaseApiTest; +import com.baidu.hugegraph.testutil.Assert; import com.google.common.collect.ImmutableMap; public class CrosspointsApiTest extends BaseApiTest { - public static String path = "graphs/hugegraph/traversers/crosspoints"; + public static String path = TRAVERSERS_API + "/crosspoints"; @Before public void prepareSchema() { @@ -56,9 +55,9 @@ public void testGet() { id2Json(vadasId), "max_depth", 10); Response r = client().get(path, params); - String respBody = assertResponseStatus(200, r); - List> crosspoints = assertJsonContains(respBody, - "crosspoints"); + String content = assertResponseStatus(200, r); + List> crosspoints = assertJsonContains( + content, "crosspoints"); Assert.assertEquals(2, crosspoints.size()); } } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedCrosspointsApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedCrosspointsApiTest.java index aec3abed75..27bd4de139 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedCrosspointsApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedCrosspointsApiTest.java @@ -32,7 +32,7 @@ public class CustomizedCrosspointsApiTest extends BaseApiTest { - public static String path = "graphs/hugegraph/traversers/customizedcrosspoints"; + public static String path = TRAVERSERS_API + "/customizedcrosspoints"; @Before public void prepareSchema() { @@ -60,8 +60,8 @@ public void testPost() { "\"capacity\":-1, " + "\"limit\":-1}", markoId, rippleId); Response r = client().post(path, reqBody); - String respBody = assertResponseStatus(200, r); - List paths = assertJsonContains(respBody, "paths"); + String content = assertResponseStatus(200, r); + List paths = assertJsonContains(content, "paths"); Assert.assertEquals(2, paths.size()); } } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/EdgesApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/EdgesApiTest.java index ac2ea6e81a..54316ef57b 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/EdgesApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/EdgesApiTest.java @@ -35,10 +35,9 @@ public class EdgesApiTest extends BaseApiTest { - final static String EDGE_PATH = "graphs/hugegraph/traversers/edges"; - final static String SHARES_PATH = "graphs/hugegraph/traversers" + - "/edges/shards"; - final static String SCAN_PATH = "graphs/hugegraph/traversers/edges/scan"; + final static String EDGE_PATH = TRAVERSERS_API + "/edges"; + final static String SHARES_PATH = TRAVERSERS_API + "/edges/shards"; + final static String SCAN_PATH = TRAVERSERS_API + "/edges/scan"; @Before public void prepareSchema() { @@ -57,31 +56,34 @@ public void testList() { Map params = ImmutableMap.of("vertex_id", id2Json(vadasId), "direction", "IN"); Response r = client().get(edgeGetPath, params); - String respBody = assertResponseStatus(200, r); - List edges = assertJsonContains(respBody, "edges"); + String content = assertResponseStatus(200, r); + List edges = assertJsonContains(content, "edges"); Assert.assertNotNull(edges); Assert.assertFalse(edges.isEmpty()); String edgeId = assertMapContains(edges.get(0), "id"); Assert.assertNotNull(edgeId); r = client().get(EDGE_PATH, ImmutableMultimap.of("ids", edgeId)); - assertResponseStatus(200, r); + content = assertResponseStatus(200, r); + List edges2 = assertJsonContains(content, "edges"); + Assert.assertEquals(1, edges.size()); + Assert.assertEquals(edges.get(0), edges2.get(0)); } @Test public void testShareAndScan() { Response r = client().get(SHARES_PATH, ImmutableMap.of("split_size", 1048576)); - String respBody = assertResponseStatus(200, r); - List shards = assertJsonContains(respBody, "shards"); + String content = assertResponseStatus(200, r); + List shards = assertJsonContains(content, "shards"); Assert.assertNotNull(shards); Assert.assertFalse(shards.isEmpty()); String start = assertMapContains(shards.get(0), "start"); String end = assertMapContains(shards.get(0), "end"); r = client().get(SCAN_PATH, ImmutableMap.of("start", start, "end", end)); - respBody = assertResponseStatus(200, r); - List edges = assertJsonContains(respBody, "edges"); - Assert.assertFalse(edges.isEmpty()); + content = assertResponseStatus(200, r); + List edges = assertJsonContains(content, "edges"); + Assert.assertEquals(5, edges.size()); } } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/FusiformSimilarityApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/FusiformSimilarityApiTest.java index fbff683fab..a29f991a19 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/FusiformSimilarityApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/FusiformSimilarityApiTest.java @@ -24,6 +24,7 @@ import javax.ws.rs.core.Response; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -31,7 +32,7 @@ public class FusiformSimilarityApiTest extends BaseApiTest { - final static String path = "graphs/hugegraph/traversers/fusiformsimilarity"; + final static String path = TRAVERSERS_API + "/fusiformsimilarity"; @Before public void prepareSchema() { @@ -62,11 +63,12 @@ public void testPost() { "\"limit\": -1, " + "\"with_intermediary\": false, " + "\"with_vertex\":true}"); - String respBody = assertResponseStatus(200, r); - Map similars = assertJsonContains(respBody, "similars"); + String content = assertResponseStatus(200, r); + Map similars = assertJsonContains(content, "similars"); Map name2Ids = listAllVertexName2Ids(); String markoId = name2Ids.get("marko"); String peterId = name2Ids.get("peter"); + Assert.assertEquals(2, similars.size()); assertMapContains(similars, markoId); assertMapContains(similars, peterId); } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/JaccardSimilarityApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/JaccardSimilarityApiTest.java index 294869fa45..e69f3ad738 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/JaccardSimilarityApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/JaccardSimilarityApiTest.java @@ -32,7 +32,7 @@ public class JaccardSimilarityApiTest extends BaseApiTest { - final static String path = "graphs/hugegraph/traversers/jaccardsimilarity"; + final static String path = TRAVERSERS_API + "/jaccardsimilarity"; @Before public void prepareSchema() { @@ -74,10 +74,10 @@ public void testPost() { " \"skip_degree\": 100000 }, " + "\"top\": 3}", markoId); Response r = client().post(path, reqBody); - String respBody = assertResponseStatus(200, r); - Double rippleJaccardSimilarity = assertJsonContains(respBody, rippleId); - Double peterJaccardSimilarity = assertJsonContains(respBody, peterId); - Double jsonJaccardSimilarity = assertJsonContains(respBody, jsonId); + String content = assertResponseStatus(200, r); + Double rippleJaccardSimilarity = assertJsonContains(content, rippleId); + Double peterJaccardSimilarity = assertJsonContains(content, peterId); + Double jsonJaccardSimilarity = assertJsonContains(content, jsonId); Assert.assertEquals(0.3333, rippleJaccardSimilarity.doubleValue(), 0.0001); Assert.assertEquals(0.25, peterJaccardSimilarity.doubleValue(), 0.0001); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KneighborApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KneighborApiTest.java index aba7b4f400..158d7c37ae 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KneighborApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KneighborApiTest.java @@ -30,10 +30,11 @@ import com.baidu.hugegraph.api.BaseApiTest; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; public class KneighborApiTest extends BaseApiTest { - final static String path = "graphs/hugegraph/traversers/kneighbor"; + final static String path = TRAVERSERS_API + "/kneighbor"; @Before public void prepareSchema() { @@ -48,12 +49,16 @@ public void prepareSchema() { public void testGet() { Map name2Ids = listAllVertexName2Ids(); String markoId = name2Ids.get("marko"); + String rippleId = name2Ids.get("ripple"); + String peterId = name2Ids.get("peter"); + String joshId = name2Ids.get("josh"); Response r = client().get(path, ImmutableMap.of("source", id2Json(markoId), "max_depth", 2)); - String respBody = assertResponseStatus(200, r); - List vertices = assertJsonContains(respBody, "vertices"); - Assert.assertEquals(3, vertices.size()); + String content = assertResponseStatus(200, r); + List vertices = assertJsonContains(content, "vertices"); + Assert.assertEquals(ImmutableSet.of(rippleId, joshId, peterId), + ImmutableSet.copyOf(vertices)); } @Test diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KoutApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KoutApiTest.java index b6b09ff4bb..00a43ba44d 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KoutApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KoutApiTest.java @@ -34,7 +34,7 @@ public class KoutApiTest extends BaseApiTest { - final static String path = "graphs/hugegraph/traversers/kout"; + final static String path = TRAVERSERS_API + "/kout"; @Before public void prepareSchema() { @@ -56,16 +56,16 @@ public void testGet() { Response r = client().get(path, ImmutableMap.of("source", id2Json(markoId), "max_depth", 2)); - String respBody = assertResponseStatus(200, r); - List vertices = assertJsonContains(respBody, "vertices"); + String content = assertResponseStatus(200, r); + List vertices = assertJsonContains(content, "vertices"); Assert.assertEquals(1, vertices.size()); Assert.assertTrue(vertices.contains(joshId)); // Test for nearest=false r = client().get(path, ImmutableMap.of("source", id2Json(markoId), "max_depth", 2, "nearest", "false")); - respBody = assertResponseStatus(200, r); - vertices = assertJsonContains(respBody, "vertices"); + content = assertResponseStatus(200, r); + vertices = assertJsonContains(content, "vertices"); Assert.assertEquals(3, vertices.size()); Assert.assertTrue(vertices.containsAll(ImmutableList.of(peterId, rippleId, @@ -92,11 +92,11 @@ public void testPost() { "\"with_vertex\": true, " + "\"with_path\": true}", markoId); Response resp = client().post(path, reqBody); - String respBody = assertResponseStatus(200, resp); - Object size = assertJsonContains(respBody, "size"); + String content = assertResponseStatus(200, resp); + Object size = assertJsonContains(content, "size"); Assert.assertEquals(2, size); - assertJsonContains(respBody, "kout"); - assertJsonContains(respBody, "paths"); - assertJsonContains(respBody, "vertices"); + assertJsonContains(content, "kout"); + assertJsonContains(content, "paths"); + assertJsonContains(content, "vertices"); } } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/MultiNodeShortestPathApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/MultiNodeShortestPathApiTest.java index 6bd69243c9..4a4342b024 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/MultiNodeShortestPathApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/MultiNodeShortestPathApiTest.java @@ -19,10 +19,12 @@ package com.baidu.hugegraph.api.traversers; +import java.util.List; import java.util.Map; import javax.ws.rs.core.Response; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -30,7 +32,7 @@ public class MultiNodeShortestPathApiTest extends BaseApiTest { - final String path = "graphs/hugegraph/traversers/multinodeshortestpath"; + final String path = TRAVERSERS_API + "/multinodeshortestpath"; @Before public void prepareSchema() { @@ -60,8 +62,8 @@ public void testPost() { "\"with_vertex\": true}", markoId, peterId, joshId, vadasId); Response r = client().post(path, reqBody); - String respJson = assertResponseStatus(200, r); - assertJsonContains(respJson, "paths"); - assertJsonContains(respJson, "vertices"); + String content = assertResponseStatus(200, r); + List paths = assertJsonContains(content, "paths"); + Assert.assertEquals(6, paths.size()); } } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/NeighborRankApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/NeighborRankApiTest.java index 574ea47284..a803dfd041 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/NeighborRankApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/NeighborRankApiTest.java @@ -32,7 +32,7 @@ public class NeighborRankApiTest extends BaseApiTest { - final static String path = "graphs/hugegraph/traversers/neighborrank"; + final static String path = TRAVERSERS_API + "/neighborrank"; @Before public void prepareSchema() { @@ -53,8 +53,8 @@ public void testNeighborRank() { " \"direction\": \"BOTH\"}]," + "\"alpha\":%s}", markoId, 1); Response r = client().post(path, reqBody); - String respBody = assertResponseStatus(200, r); - List ranks = assertJsonContains(respBody, "ranks"); + String content = assertResponseStatus(200, r); + List ranks = assertJsonContains(content, "ranks"); Assert.assertEquals(2, ranks.size()); } } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/PathsApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/PathsApiTest.java index c66a72a519..a9181d875d 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/PathsApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/PathsApiTest.java @@ -33,7 +33,7 @@ public class PathsApiTest extends BaseApiTest { - final static String path = "graphs/hugegraph/traversers/paths"; + final static String path = TRAVERSERS_API + "/paths"; @Before public void prepareSchema() { @@ -54,9 +54,9 @@ public void testGet() { "target", id2Json(vadasId), "max_depth", 3)); - String respBody = assertResponseStatus(200, r); - assertJsonContains(respBody, "paths"); - List> paths = assertJsonContains(respBody, "paths"); + String content = assertResponseStatus(200, r); + assertJsonContains(content, "paths"); + List> paths = assertJsonContains(content, "paths"); Assert.assertEquals(1, paths.size()); } @@ -80,8 +80,8 @@ public void testPost() { "\"with_vertex\": false}", markoId, joshId); Response r = client().post(path, reqBody); - String respBody = assertResponseStatus(200, r); - List> paths = assertJsonContains(respBody, "paths"); - Assert.assertFalse(paths.isEmpty()); + String content = assertResponseStatus(200, r); + List> paths = assertJsonContains(content, "paths"); + Assert.assertEquals(2, paths.size()); } } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/PersonalRankApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/PersonalRankApiTest.java index 1bd78731a6..3d81f64d8c 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/PersonalRankApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/PersonalRankApiTest.java @@ -30,7 +30,7 @@ public class PersonalRankApiTest extends BaseApiTest { - final static String path = "graphs/hugegraph/traversers/personalrank"; + final static String path = TRAVERSERS_API + "/personalrank"; @Before public void prepareSchema() { @@ -53,7 +53,7 @@ public void testPersonalRank() { "\"alpha\":\"%s\"}", markoId, 3, "created", 1); Response r = client().post(path, reqBody); - String respBody = assertResponseStatus(200, r); - assertJsonContains(respBody, peterId); + String content = assertResponseStatus(200, r); + assertJsonContains(content, peterId); } } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/RaysApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/RaysApiTest.java index 32d9bc70b0..bd2facd79d 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/RaysApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/RaysApiTest.java @@ -33,7 +33,7 @@ public class RaysApiTest extends BaseApiTest { - final static String path = "graphs/hugegraph/traversers/rays"; + final static String path = TRAVERSERS_API + "/rays"; @Before public void prepareSchema() { @@ -52,8 +52,8 @@ public void testGet() { Response r = client().get(path, ImmutableMap.of("source", id2Json(markoId), "max_depth", 10)); - String respBody = assertResponseStatus(200, r); - List>> rays = assertJsonContains(respBody, + String content = assertResponseStatus(200, r); + List>> rays = assertJsonContains(content, "rays"); Assert.assertNotNull(rays); Assert.assertEquals(2, rays.size()); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/RingsApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/RingsApiTest.java index 3a441f3902..468e1f0287 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/RingsApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/RingsApiTest.java @@ -33,7 +33,7 @@ public class RingsApiTest extends BaseApiTest { - final static String path = "graphs/hugegraph/traversers/rings"; + final static String path = TRAVERSERS_API + "/rings"; @Before public void prepareSchema() { @@ -52,9 +52,9 @@ public void testGet() { id2Json(markoId), "max_depth", 10); Response r = client().get(path, params); - String respJson = assertResponseStatus(200, r); - List>> rings = assertJsonContains(respJson, + String content = assertResponseStatus(200, r); + List>> rings = assertJsonContains(content, "rings"); - Assert.assertFalse(rings.isEmpty()); + Assert.assertEquals(1, rings.size()); } } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/SameNeighborsApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/SameNeighborsApiTest.java index 69f47bcc4d..8b0c8a9dd5 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/SameNeighborsApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/SameNeighborsApiTest.java @@ -33,7 +33,7 @@ public class SameNeighborsApiTest extends BaseApiTest { - final static String path = "graphs/hugegraph/traversers/sameneighbors"; + final static String path = TRAVERSERS_API + "/sameneighbors"; @Before public void prepareSchema() { @@ -54,8 +54,8 @@ public void testGet() { id2Json(markoId), "other", id2Json(joshId))); - String respBody = assertResponseStatus(200, r); - List sameNeighbors = assertJsonContains(respBody, + String content = assertResponseStatus(200, r); + List sameNeighbors = assertJsonContains(content, "same_neighbors"); Assert.assertFalse(sameNeighbors.isEmpty()); Assert.assertTrue(sameNeighbors.contains(peterId)); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/ShortestPathApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/ShortestPathApiTest.java index 0a5f12d932..e5d783dadf 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/ShortestPathApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/ShortestPathApiTest.java @@ -29,11 +29,12 @@ import org.junit.Test; import com.baidu.hugegraph.api.BaseApiTest; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; public class ShortestPathApiTest extends BaseApiTest { - final static String path = "graphs/hugegraph/traversers/shortestpath"; + final static String path = TRAVERSERS_API + "/shortestpath"; @Before public void prepareSchema() { @@ -48,15 +49,16 @@ public void prepareSchema() { public void testGet() { Map name2Ids = listAllVertexName2Ids(); String markoId = name2Ids.get("marko"); - String joshId = name2Ids.get("vadas"); + String joshId = name2Ids.get("josh"); + String peterId = name2Ids.get("peter"); Response r = client().get(path, ImmutableMap.of("source", id2Json(markoId), "target", id2Json(joshId), "max_depth", 100)); - String respBody = assertResponseStatus(200, r); - List paths = assertJsonContains(respBody, "path"); - Assert.assertFalse(paths.isEmpty()); + String content = assertResponseStatus(200, r); + List paths = assertJsonContains(content, "path"); + Assert.assertEquals(ImmutableList.of(markoId, peterId, joshId), paths); } } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/SingleSourceShortestPathApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/SingleSourceShortestPathApiTest.java index 7f160ec282..49ca9d0e6b 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/SingleSourceShortestPathApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/SingleSourceShortestPathApiTest.java @@ -32,8 +32,7 @@ public class SingleSourceShortestPathApiTest extends BaseApiTest { - final static String path = "graphs/hugegraph/traversers/" + - "singlesourceshortestpath"; + final static String path = TRAVERSERS_API + "/singlesourceshortestpath"; @Before public void prepareSchema() { @@ -52,8 +51,8 @@ public void testGet() { id2Json(markoId), "with_vertex", true)); - String respBody = assertResponseStatus(200, r); - Map paths = assertJsonContains(respBody,"paths"); - Assert.assertFalse(paths.isEmpty()); + String content = assertResponseStatus(200, r); + Map paths = assertJsonContains(content,"paths"); + Assert.assertEquals(4, paths.size()); } } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/TemplatePathsApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/TemplatePathsApiTest.java index a012e1d62b..af4c6609c1 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/TemplatePathsApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/TemplatePathsApiTest.java @@ -33,7 +33,7 @@ public class TemplatePathsApiTest extends BaseApiTest { - final static String path = "graphs/hugegraph/traversers/templatepaths"; + final static String path = TRAVERSERS_API + "/templatepaths"; @Before public void prepareSchema() { @@ -78,8 +78,8 @@ public void testPost() { " \"limit\": 10," + " \"with_vertex\": true}"; Response r = client().post(path, template); - String resp = assertResponseStatus(200, r); - List objects = assertJsonContains(resp, "paths"); + String content = assertResponseStatus(200, r); + List objects = assertJsonContains(content, "paths"); Assert.assertEquals(1, objects.size()); List paths = assertMapContains(objects.get(0), "objects"); Assert.assertEquals(ImmutableList.of(vadasId, joshId, peterId, rippleId), diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/WeightedShortestPathApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/WeightedShortestPathApiTest.java index f511d691cd..2a53670707 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/WeightedShortestPathApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/WeightedShortestPathApiTest.java @@ -34,8 +34,7 @@ public class WeightedShortestPathApiTest extends BaseApiTest { - final static String path = "graphs/hugegraph/traversers/" + - "weightedshortestpath"; + final static String path = TRAVERSERS_API + "/weightedshortestpath"; @Before public void prepareSchema() { @@ -59,8 +58,8 @@ public void testGet() { id2Json(joshId), "weight", "weight", "with_vertex", true)); - String respBody = assertResponseStatus(200, r); - Map paths = assertJsonContains(respBody,"path"); + String content = assertResponseStatus(200, r); + Map paths = assertJsonContains(content,"path"); Assert.assertFalse(paths.isEmpty()); List expectedVertices = ImmutableList.of(markoId, rippleId, peterId, joshId);