From 3677e56197afb34943d3077cd3a37c55715b02ea Mon Sep 17 00:00:00 2001 From: zyxxoo <1318247699@qq.com> Date: Tue, 8 Jun 2021 19:01:05 +0800 Subject: [PATCH] chore: code style --- .../com/baidu/hugegraph/api/ApiTestSuite.java | 30 ++-- .../com/baidu/hugegraph/api/BaseApiTest.java | 135 +++++++++--------- .../com/baidu/hugegraph/api/CountAPITest.java | 57 -------- .../api/CustomizedCrosspointsAPITest.java | 61 -------- .../baidu/hugegraph/api/KneighborAPITest.java | 4 - .../com/baidu/hugegraph/api/KoutAPITest.java | 4 - .../api/MultiNodeShortestPathAPITest.java | 4 - .../hugegraph/api/NeighborRankAPITest.java | 4 - .../com/baidu/hugegraph/api/PathsAPITest.java | 4 - .../hugegraph/api/PersonalRankAPITest.java | 4 - .../com/baidu/hugegraph/api/RaysAPITest.java | 4 - .../AllShortestPathsAPITest.java | 15 +- .../api/traversers/CountAPITest.java | 61 ++++++++ .../{ => traversers}/CrosspointsAPITest.java | 17 ++- .../CustomizedCrosspointsAPITest.java | 63 ++++++++ .../api/{ => traversers}/EdgesAPITest.java | 28 ++-- .../FusiformSimilarityAPITest.java | 11 +- .../JaccardSimilarityAPITest.java | 9 +- .../api/traversers/KneighborAPITest.java | 6 + .../hugegraph/api/traversers/KoutAPITest.java | 6 + .../MultiNodeShortestPathAPITest.java | 6 + .../api/traversers/NeighborRankAPITest.java | 6 + .../api/traversers/PathsAPITest.java | 6 + .../api/traversers/PersonalRankAPITest.java | 6 + .../hugegraph/api/traversers/RaysAPITest.java | 6 + .../traversers/TraversersAPITestSuite.java | 32 +++++ 26 files changed, 331 insertions(+), 258 deletions(-) delete mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/api/CountAPITest.java delete mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/api/CustomizedCrosspointsAPITest.java delete mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/api/KneighborAPITest.java delete mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/api/KoutAPITest.java delete mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/api/MultiNodeShortestPathAPITest.java delete mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/api/NeighborRankAPITest.java delete mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/api/PathsAPITest.java delete mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/api/PersonalRankAPITest.java delete mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/api/RaysAPITest.java rename hugegraph-test/src/main/java/com/baidu/hugegraph/api/{ => traversers}/AllShortestPathsAPITest.java (60%) create mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CountAPITest.java rename hugegraph-test/src/main/java/com/baidu/hugegraph/api/{ => traversers}/CrosspointsAPITest.java (69%) create mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedCrosspointsAPITest.java rename hugegraph-test/src/main/java/com/baidu/hugegraph/api/{ => traversers}/EdgesAPITest.java (77%) rename hugegraph-test/src/main/java/com/baidu/hugegraph/api/{ => traversers}/FusiformSimilarityAPITest.java (92%) rename hugegraph-test/src/main/java/com/baidu/hugegraph/api/{ => traversers}/JaccardSimilarityAPITest.java (75%) create mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KneighborAPITest.java create mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KoutAPITest.java create mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/MultiNodeShortestPathAPITest.java create mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/NeighborRankAPITest.java create mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/PathsAPITest.java create mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/PersonalRankAPITest.java create mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/RaysAPITest.java create mode 100644 hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/TraversersAPITestSuite.java diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/ApiTestSuite.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/ApiTestSuite.java index df56fd6843..aa487823e2 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/ApiTestSuite.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/ApiTestSuite.java @@ -23,10 +23,25 @@ import org.junit.runner.RunWith; import org.junit.runners.Suite; +import com.baidu.hugegraph.api.traversers.AllShortestPathsAPITest; +import com.baidu.hugegraph.api.traversers.CountAPITest; +import com.baidu.hugegraph.api.traversers.CrosspointsAPITest; +import com.baidu.hugegraph.api.traversers.CustomizedCrosspointsAPITest; +import com.baidu.hugegraph.api.traversers.EdgesAPITest; +import com.baidu.hugegraph.api.traversers.FusiformSimilarityAPITest; +import com.baidu.hugegraph.api.traversers.JaccardSimilarityAPITest; +import com.baidu.hugegraph.api.traversers.KneighborAPITest; +import com.baidu.hugegraph.api.traversers.KoutAPITest; +import com.baidu.hugegraph.api.traversers.MultiNodeShortestPathAPITest; +import com.baidu.hugegraph.api.traversers.NeighborRankAPITest; +import com.baidu.hugegraph.api.traversers.PathsAPITest; +import com.baidu.hugegraph.api.traversers.PersonalRankAPITest; +import com.baidu.hugegraph.api.traversers.RaysAPITest; import com.baidu.hugegraph.dist.RegisterUtil; @RunWith(Suite.class) @Suite.SuiteClasses({ + UserApiTest.class, PropertyKeyApiTest.class, VertexLabelApiTest.class, EdgeLabelApiTest.class, @@ -36,21 +51,6 @@ TaskApiTest.class, GremlinApiTest.class, MetricsApiTest.class, - UserApiTest.class, - AllShortestPathsAPITest.class, - CountAPITest.class, - CrosspointsAPITest.class, - CustomizedCrosspointsAPITest.class, - EdgesAPITest.class, - FusiformSimilarityAPITest.class, - JaccardSimilarityAPITest.class, - KneighborAPITest.class, - KoutAPITest.class, - MultiNodeShortestPathAPITest.class, - NeighborRankAPITest.class, - PathsAPITest.class, - PersonalRankAPITest.class, - RaysAPITest.class }) public class ApiTestSuite { 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 31916ed56f..cf7d63eb0f 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 @@ -98,7 +98,7 @@ public static RestClient newClient() { return new RestClient(BASE_URL); } - static class RestClient { + public static class RestClient { private Client client; private WebTarget target; @@ -134,15 +134,17 @@ public Response get(String path, String id) { public Response get(String path, Map params) { return this.get(path, - params.entrySet().stream() + params.entrySet() + .stream() .map(entry -> new Pair( - entry.getKey(), entry.getValue())) + entry.getKey(), entry.getValue())) .iterator()); } public Response get(String path, Iterator> params) { class WrapWebTarget { + WebTarget target; WrapWebTarget(WebTarget target) { @@ -323,65 +325,68 @@ protected static void initIndexLabel() { protected static void initEdge() { String path = URL_PREFIX + GRAPH_EDGE + BATCH; Map ret = getAllName2VertexIds(); - System.out.println(ret); String markoId = ret.get("marko"); String peterId = ret.get("peter"); String joshId = ret.get("josh"); String vadasId = ret.get("vadas"); String rippleId = ret.get("ripple"); - createAndAssert(path, "[" + - "{" + - "\"label\": \"knows\"," + - "\"outV\": \"" + markoId + "\"," + - "\"inV\": \"" + peterId + "\"," + - "\"outVLabel\": \"person\"," + - "\"inVLabel\": \"person\"," + - "\"properties\": {" + - "\"date\": \"2021-01-01\"," + - "\"weight\":0.5}" + - "}," + - "{" + - "\"label\": \"knows\"," + - "\"outV\": \"" + peterId + "\"," + - "\"inV\": \"" + joshId + "\"," + - "\"outVLabel\": \"person\"," + - "\"inVLabel\": \"person\"," + - "\"properties\": {" + - "\"date\": \"2021-01-01\"," + - "\"weight\":0.5}" + - "}," + - "{" + - "\"label\": \"knows\"," + - "\"outV\": \"" + joshId + "\"," + - "\"inV\": \"" + vadasId + "\"," + - "\"outVLabel\": \"person\"," + - "\"inVLabel\": \"person\"," + - "\"properties\": {" + - "\"date\": \"2021-01-01\"," + - "\"weight\":0.5}" + - "}," + - "{" + - "\"label\": \"created\"," + - "\"outV\": \"" + markoId + "\"," + - "\"inV\": \"" + rippleId + "\"," + - "\"outVLabel\": \"person\"," + - "\"inVLabel\": \"software\"," + - "\"properties\": {" + - "\"date\": \"2021-01-01\"," + - "\"weight\":0.5}" + - "}," + - "{" + - "\"label\": \"created\"," + - "\"outV\": \"" + peterId + "\"," + - "\"inV\": \"" + rippleId + "\"," + - "\"outVLabel\": \"person\"," + - "\"inVLabel\": \"software\"," + - "\"properties\": {" + - "\"date\": \"2021-01-01\"," + - "\"weight\":0.5}" + - "}" + - "]"); + String body = String.format("[" + + "{" + + "\"label\": \"knows\"," + + "\"outV\": \"%s\"," + + "\"inV\": \"%s\"," + + "\"outVLabel\": \"person\"," + + "\"inVLabel\": \"person\"," + + "\"properties\": {" + + "\"date\": \"2021-01-01\"," + + "\"weight\":0.5}" + + "}," + + "{" + + "\"label\": \"knows\"," + + "\"outV\": \"%s\"," + + "\"inV\": \"%s\"," + + "\"outVLabel\": \"person\"," + + "\"inVLabel\": \"person\"," + + "\"properties\": {" + + "\"date\": \"2021-01-01\"," + + "\"weight\":0.5}" + + "}," + + "{" + + "\"label\": \"knows\"," + + "\"outV\": \"%s\"," + + "\"inV\": \"%s\"," + + "\"outVLabel\": \"person\"," + + "\"inVLabel\": \"person\"," + + "\"properties\": {" + + "\"date\": \"2021-01-01\"," + + "\"weight\":0.5}" + + "}," + + "{" + + "\"label\": \"created\"," + + "\"outV\": \"%s\"," + + "\"inV\": \"%s\"," + + "\"outVLabel\": \"person\"," + + "\"inVLabel\": \"software\"," + + "\"properties\": {" + + "\"date\": \"2021-01-01\"," + + "\"weight\":0.5}" + + "}," + + "{" + + "\"label\": \"created\"," + + "\"outV\": \"%s\"," + + "\"inV\": \"%s\"," + + "\"outVLabel\": \"person\"," + + "\"inVLabel\": \"software\"," + + "\"properties\": {" + + "\"date\": \"2021-01-01\"," + + "\"weight\":0.5}" + + "}" + + "]", markoId, peterId, peterId, joshId, + joshId, vadasId, markoId, rippleId, + peterId, rippleId); + + createAndAssert(path, ); } @@ -453,20 +458,18 @@ protected static Response createAndAssert(String path, String body) { protected static Map getAllName2VertexIds() { Response r = client.get(URL_PREFIX + GRAPH_VERTEX); String content = r.readEntity(String.class); - if (r.getStatus() != 200) { - throw new HugeException("Failed to get vertex id: %s", content); - } + assertResponseStatus(200, r); @SuppressWarnings("rawtypes") List list = readList(content, "vertices", Map.class); - return list.stream().filter(map -> map.get("properties") != null && - ((Map) map.get("properties")) - .get("name") != null) + return list.stream() + .filter(map -> map.get("properties") != null && + ((Map) map.get("properties")) + .get("name") != null) .collect( Collectors.toMap(map -> ((Map) map.get("properties")) - .get( - "name").toString(), + .get("name").toString(), map -> map.get("id").toString())); } @@ -479,9 +482,7 @@ protected static String getVertexId(String label, String key, String value) ); Response r = client.get(URL_PREFIX + GRAPH_VERTEX, params); String content = r.readEntity(String.class); - if (r.getStatus() != 200) { - throw new HugeException("Failed to get vertex id: %s", content); - } + assertResponseStatus(200, r); @SuppressWarnings("rawtypes") List list = readList(content, "vertices", Map.class); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/CountAPITest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/CountAPITest.java deleted file mode 100644 index e5c8941b13..0000000000 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/CountAPITest.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.baidu.hugegraph.api; - -import static com.baidu.hugegraph.testutil.Assert.assertEquals; - -import java.util.Map; - -import javax.ws.rs.core.Response; - -import org.junit.Before; -import org.junit.Test; - -public class CountAPITest extends BaseApiTest { - public static String path = "graphs/hugegraph/traversers/count"; - @Before - public void prepareSchema() { - BaseApiTest.initPropertyKey(); - BaseApiTest.initVertexLabel(); - BaseApiTest.initEdgeLabel(); - BaseApiTest.initVertex(); - BaseApiTest.initEdge(); - } - - @Test - public void count() { - String markoId = getAllName2VertexIds().get("marko"); - Response r = client().post(path, "{\n" + - "\t\"source\": \""+markoId+"\",\n" + - "\t\"steps\": [\n" + - "\t\t{\n" + - "\t\t\t\"labels\": [\n" + - "\t\t\t ],\n" + - "\t\t\t \"degree\": 100,\n" + - "\t\t\t \"skip_degree\": 100\n" + - "\t\t},\n" + - "\t\t{\n" + - "\t\t\t\"labels\": [\n" + - "\t\t\t ],\n" + - "\t\t\t \"degree\": 100,\n" + - "\t\t\t \"skip_degree\": 100\n" + - "\t\t},\n" + - "\t\t\t{\n" + - "\t\t\t\"labels\": [\n" + - "\t\t\t ],\n" + - "\t\t\t \"degree\": 100,\n" + - "\t\t\t \"skip_degree\": 100\n" + - "\t\t}\t\n" + - "\t\t\n" + - "\t]\n" + - "\t\n" + - "}"); - - assertEquals(200, r.getStatus()); - Integer count = (Integer) r.readEntity(Map.class).get("count"); - assertEquals(3, count); - - } -} diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/CustomizedCrosspointsAPITest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/CustomizedCrosspointsAPITest.java deleted file mode 100644 index a2d8525749..0000000000 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/CustomizedCrosspointsAPITest.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.baidu.hugegraph.api; - -import static org.junit.Assert.assertEquals; - -import java.util.List; -import java.util.Map; - -import javax.ws.rs.core.Response; - -import org.junit.Before; -import org.junit.Test; - -import com.baidu.hugegraph.api.traversers.CustomizedCrosspointsAPI; - -public class CustomizedCrosspointsAPITest extends BaseApiTest{ - public static String path = "graphs/hugegraph/traversers/customizedcrosspoints"; - - @Before - public void prepareSchema() { - BaseApiTest.initPropertyKey(); - BaseApiTest.initVertexLabel(); - BaseApiTest.initEdgeLabel(); - BaseApiTest.initVertex(); - BaseApiTest.initEdge(); - } - @Test - public void post() { - Map name2Ids = getAllName2VertexIds(); - String markoId = name2Ids.get("marko"); - String rippleId = name2Ids.get("ripple"); - Response r = client().post(path, "{\n" + - " \"sources\":{\n" + - " \"ids\":[\n" + - " \"" + markoId + "\",\n" + - " \"" + rippleId + "\"\n" + - " ]\n" + - " },\n" + - " \"path_patterns\":[\n" + - " {\n" + - " \"steps\":[\n" + - " {\n" + - " \"direction\":\"BOTH\"," + - " \"labels\":[\n" + - " ],\n" + - " \"degree\":-1\n" + - " }\n" + - " ]\n" + - " }\n" + - " ],\n" + - " \"with_path\":true,\n" + - " \"with_vertex\":true,\n" + - " \"capacity\":-1,\n" + - " \"limit\":-1\n" + - "}"); - - assertEquals(200, r.getStatus()); - Map map = r.readEntity(Map.class); - List paths = (List) map.get("paths"); - assertEquals(2, paths.size()); - } -} diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/KneighborAPITest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/KneighborAPITest.java deleted file mode 100644 index 6966db3950..0000000000 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/KneighborAPITest.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.baidu.hugegraph.api; - -public class KneighborAPITest { -} diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/KoutAPITest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/KoutAPITest.java deleted file mode 100644 index ed184c35e9..0000000000 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/KoutAPITest.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.baidu.hugegraph.api; - -public class KoutAPITest { -} diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/MultiNodeShortestPathAPITest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/MultiNodeShortestPathAPITest.java deleted file mode 100644 index 6938b5c550..0000000000 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/MultiNodeShortestPathAPITest.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.baidu.hugegraph.api; - -public class MultiNodeShortestPathAPITest { -} diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/NeighborRankAPITest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/NeighborRankAPITest.java deleted file mode 100644 index 58214762a0..0000000000 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/NeighborRankAPITest.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.baidu.hugegraph.api; - -public class NeighborRankAPITest { -} diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/PathsAPITest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/PathsAPITest.java deleted file mode 100644 index 0bf738af1b..0000000000 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/PathsAPITest.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.baidu.hugegraph.api; - -public class PathsAPITest { -} diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/PersonalRankAPITest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/PersonalRankAPITest.java deleted file mode 100644 index 5dbc430ce9..0000000000 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/PersonalRankAPITest.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.baidu.hugegraph.api; - -public class PersonalRankAPITest { -} diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/RaysAPITest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/RaysAPITest.java deleted file mode 100644 index 7c3e69d101..0000000000 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/RaysAPITest.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.baidu.hugegraph.api; - -public class RaysAPITest { -} diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/AllShortestPathsAPITest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/AllShortestPathsAPITest.java similarity index 60% rename from hugegraph-test/src/main/java/com/baidu/hugegraph/api/AllShortestPathsAPITest.java rename to hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/AllShortestPathsAPITest.java index 84a2affbd1..74f30d21e8 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/AllShortestPathsAPITest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/AllShortestPathsAPITest.java @@ -1,15 +1,18 @@ -package com.baidu.hugegraph.api; +package com.baidu.hugegraph.api.traversers; import java.util.Map; import org.junit.Before; import org.junit.Test; +import com.baidu.hugegraph.api.BaseApiTest; import com.google.common.collect.ImmutableMap; public class AllShortestPathsAPITest extends BaseApiTest { + public static String path = "graphs/hugegraph/traversers/allshortestpaths"; + @Before public void prepareSchema() { BaseApiTest.initPropertyKey(); @@ -20,12 +23,16 @@ public void prepareSchema() { } @Test - public void get() { + public void testGet() { Map name2Ids = getAllName2VertexIds(); String markoId = name2Ids.get("marko"); String vadasId= name2Ids.get("vadas"); - Map map = ImmutableMap.of("source", "\""+ markoId+"\"", - "target", "\""+vadasId+"\"", + Map map = ImmutableMap.of("source", + String.format("\"%s\"", + markoId), + "target", + String.format("\"%s\"", + vadasId), "max_depth", 100); assertResponseStatus(200, client().get(path, map)); } 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 new file mode 100644 index 0000000000..0bb46c274f --- /dev/null +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CountAPITest.java @@ -0,0 +1,61 @@ +package com.baidu.hugegraph.api.traversers; + +import static com.baidu.hugegraph.testutil.Assert.assertEquals; + +import java.util.Map; + +import javax.ws.rs.core.Response; + +import org.junit.Before; +import org.junit.Test; + +import com.baidu.hugegraph.api.BaseApiTest; + +public class CountAPITest extends BaseApiTest { + + public static String path = "graphs/hugegraph/traversers/count"; + + @Before + public void prepareSchema() { + BaseApiTest.initPropertyKey(); + BaseApiTest.initVertexLabel(); + BaseApiTest.initEdgeLabel(); + BaseApiTest.initVertex(); + BaseApiTest.initEdge(); + } + + @Test + public void testCount() { + String markoId = getAllName2VertexIds().get("marko"); + String content = String.format("{\n" + + "\t\"source\": \"%s\",\n" + + "\t\"steps\": [\n" + + "\t\t{\n" + + "\t\t\t\"labels\": [\n" + + "\t\t\t ],\n" + + "\t\t\t \"degree\": 100,\n" + + "\t\t\t \"skip_degree\": 100\n" + + "\t\t},\n" + + "\t\t{\n" + + "\t\t\t\"labels\": [\n" + + "\t\t\t ],\n" + + "\t\t\t \"degree\": 100,\n" + + "\t\t\t \"skip_degree\": 100\n" + + "\t\t},\n" + + "\t\t\t{\n" + + "\t\t\t\"labels\": [\n" + + "\t\t\t ],\n" + + "\t\t\t \"degree\": 100,\n" + + "\t\t\t \"skip_degree\": 100\n" + + "\t\t}\t\n" + + "\t\t\n" + + "\t]\n" + + "\t\n" + + "}", markoId); + Response r = client().post(path, content); + + assertResponseStatus(200, r); + Integer count = (Integer) r.readEntity(Map.class).get("count"); + assertEquals(3, count); + } +} diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/CrosspointsAPITest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CrosspointsAPITest.java similarity index 69% rename from hugegraph-test/src/main/java/com/baidu/hugegraph/api/CrosspointsAPITest.java rename to hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CrosspointsAPITest.java index 3319c884f6..e8c5a09e43 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/CrosspointsAPITest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CrosspointsAPITest.java @@ -1,4 +1,4 @@ -package com.baidu.hugegraph.api; +package com.baidu.hugegraph.api.traversers; import static com.baidu.hugegraph.testutil.Assert.assertEquals; @@ -10,10 +10,13 @@ import org.junit.Before; import org.junit.Test; +import com.baidu.hugegraph.api.BaseApiTest; import com.google.common.collect.ImmutableMap; -public class CrosspointsAPITest extends BaseApiTest{ +public class CrosspointsAPITest extends BaseApiTest { + public static String path = "graphs/hugegraph/traversers/crosspoints"; + @Before public void prepareSchema() { BaseApiTest.initPropertyKey(); @@ -23,17 +26,19 @@ public void prepareSchema() { BaseApiTest.initEdge(); } @Test - public void get(){ + public void testGet(){ Map name2Ids = getAllName2VertexIds(); String markoId = name2Ids.get("marko"); String vadasId = name2Ids.get("vadas"); Map params = ImmutableMap.of("source", - "\"" + markoId + "\"", + String.format("\"%s\"", + markoId), "target", - "\"" + vadasId + "\"", + String.format("\"%s\"", + vadasId), "max_depth", 1000); Response r = client().get(path, params); - assertEquals(200, r.getStatus()); + assertResponseStatus(200, r); Map data = r.readEntity(Map.class); List> crosspoints = (List>) data.get("crosspoints"); 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 new file mode 100644 index 0000000000..02d5d526dc --- /dev/null +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedCrosspointsAPITest.java @@ -0,0 +1,63 @@ +package com.baidu.hugegraph.api.traversers; + +import static org.junit.Assert.assertEquals; + +import java.util.List; +import java.util.Map; + +import javax.ws.rs.core.Response; + +import org.junit.Before; +import org.junit.Test; + +import com.baidu.hugegraph.api.BaseApiTest; + +public class CustomizedCrosspointsAPITest extends BaseApiTest { + + public static String path = "graphs/hugegraph/traversers/customizedcrosspoints"; + + @Before + public void prepareSchema() { + BaseApiTest.initPropertyKey(); + BaseApiTest.initVertexLabel(); + BaseApiTest.initEdgeLabel(); + BaseApiTest.initVertex(); + BaseApiTest.initEdge(); + } + @Test + public void testPost() { + Map name2Ids = getAllName2VertexIds(); + String markoId = name2Ids.get("marko"); + String rippleId = name2Ids.get("ripple"); + String content = String.format("{\n" + + " \"sources\":{\n" + + " \"ids\":[\n" + + " \"%s\",\n" + + " \"%s\"\n" + + " ]\n" + + " },\n" + + " \"path_patterns\":[\n" + + " {\n" + + " \"steps\":[\n" + + " {\n" + + " \"direction\":\"BOTH\"," + + " \"labels\":[\n" + + " ],\n" + + " \"degree\":-1\n" + + " }\n" + + " ]\n" + + " }\n" + + " ],\n" + + " \"with_path\":true,\n" + + " \"with_vertex\":true,\n" + + " \"capacity\":-1,\n" + + " \"limit\":-1\n" + + "}", markoId, rippleId); + Response r = client().post(path, content); + + assertResponseStatus(200, r); + Map map = r.readEntity(Map.class); + List paths = (List) map.get("paths"); + assertEquals(2, paths.size()); + } +} diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/EdgesAPITest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/EdgesAPITest.java similarity index 77% rename from hugegraph-test/src/main/java/com/baidu/hugegraph/api/EdgesAPITest.java rename to hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/EdgesAPITest.java index d314f19e1c..3646b6950e 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/EdgesAPITest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/EdgesAPITest.java @@ -1,4 +1,4 @@ -package com.baidu.hugegraph.api; +package com.baidu.hugegraph.api.traversers; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -13,11 +13,13 @@ import org.junit.Before; import org.junit.Test; +import com.baidu.hugegraph.api.BaseApiTest; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; public class EdgesAPITest extends BaseApiTest { + public final static String EDGE_PATH = "graphs/hugegraph/traversers/edges"; public final static String SHARES_PATH = "graphs/hugegraph/traversers" + "/edges/shards"; @@ -33,14 +35,15 @@ public void prepareSchema() { } @Test - public void list() { + public void testList() { Map name2Ids = getAllName2VertexIds(); final String edgeGetPath = "graphs/hugegraph/graph/edges"; String vadasId = name2Ids.get("vadas"); - Response r = client().get(edgeGetPath, ImmutableMap.of("vertex_id", - "\"" + vadasId + "\"", - "direction", - "IN")); + Response r = client().get(edgeGetPath, + ImmutableMap.of("vertex_id", + String.format("\"%s\"", vadasId), + "direction", + "IN")); assertEquals(200, r.getStatus()); Map entity = r.readEntity(Map.class); List edges = (List) entity.get("edges"); @@ -52,15 +55,16 @@ public void list() { r = client().get(EDGE_PATH, ImmutableList.of(new Pair("ids", - edgeId)).iterator()); - assertEquals(200, r.getStatus()); + edgeId)) + .iterator()); + assertResponseStatus(200, r); } @Test - public void shareAndScan() { + public void testShareAndScan() { Response r = client().get(SHARES_PATH, ImmutableMap.of("split_size", 1048576)); - assertEquals(200, r.getStatus()); + assertResponseStatus(200, r); Map entity = r.readEntity(Map.class); assertNotNull(entity); @@ -71,8 +75,8 @@ public void shareAndScan() { String end = shards.get(0).get("end").toString(); r = client().get(SCAN_PATH, ImmutableMap.of("start", start, - "end", end)); - assertEquals(200, r.getStatus()); + "end", end)); + assertResponseStatus(200, r); Map entity2 = r.readEntity(Map.class); assertNotNull(entity2); assertEquals(false, entity2.isEmpty()); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/FusiformSimilarityAPITest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/FusiformSimilarityAPITest.java similarity index 92% rename from hugegraph-test/src/main/java/com/baidu/hugegraph/api/FusiformSimilarityAPITest.java rename to hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/FusiformSimilarityAPITest.java index fd6d640f36..0c22966301 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/FusiformSimilarityAPITest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/FusiformSimilarityAPITest.java @@ -1,7 +1,5 @@ -package com.baidu.hugegraph.api; +package com.baidu.hugegraph.api.traversers; - -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.util.Map; @@ -11,7 +9,10 @@ import org.junit.Before; import org.junit.Test; +import com.baidu.hugegraph.api.BaseApiTest; + public class FusiformSimilarityAPITest extends BaseApiTest { + final static String path = "graphs/hugegraph/traversers/fusiformsimilarity"; @Before @@ -24,7 +25,7 @@ public void prepareSchema() { } @Test - public void post() { + public void testPost() { Response r = client().post(path, "{\n" + " \"sources\":{\n" + " \"ids\":[],\n" + @@ -46,7 +47,7 @@ public void post() { " \"with_intermediary\": false,\n" + " \"with_vertex\":true\n" + "}"); - assertEquals(200, r.getStatus()); + assertResponseStatus(200, r); Map entity = r.readEntity(Map.class); assertNotNull(entity); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/JaccardSimilarityAPITest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/JaccardSimilarityAPITest.java similarity index 75% rename from hugegraph-test/src/main/java/com/baidu/hugegraph/api/JaccardSimilarityAPITest.java rename to hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/JaccardSimilarityAPITest.java index e427a0b0ac..d8148c6ab1 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/JaccardSimilarityAPITest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/JaccardSimilarityAPITest.java @@ -1,9 +1,12 @@ -package com.baidu.hugegraph.api; +package com.baidu.hugegraph.api.traversers; import org.junit.Before; import org.junit.Test; +import com.baidu.hugegraph.api.BaseApiTest; + public class JaccardSimilarityAPITest extends BaseApiTest { + final static String path = "graphs/hugegraph/traversers/jaccardsimilarity"; @Before @@ -16,10 +19,10 @@ public void prepareSchema() { } @Test - public void get() { + public void testGet() { } @Test - public void post() { + public void testPost() { } } 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 new file mode 100644 index 0000000000..c706736ec6 --- /dev/null +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KneighborAPITest.java @@ -0,0 +1,6 @@ +package com.baidu.hugegraph.api.traversers; + +import com.baidu.hugegraph.api.BaseApiTest; + +public class KneighborAPITest extends BaseApiTest { +} 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 new file mode 100644 index 0000000000..0a64dbf38e --- /dev/null +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KoutAPITest.java @@ -0,0 +1,6 @@ +package com.baidu.hugegraph.api.traversers; + +import com.baidu.hugegraph.api.BaseApiTest; + +public class KoutAPITest extends BaseApiTest { +} 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 new file mode 100644 index 0000000000..177f76d680 --- /dev/null +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/MultiNodeShortestPathAPITest.java @@ -0,0 +1,6 @@ +package com.baidu.hugegraph.api.traversers; + +import com.baidu.hugegraph.api.BaseApiTest; + +public class MultiNodeShortestPathAPITest extends BaseApiTest { +} 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 new file mode 100644 index 0000000000..a82fa3eeef --- /dev/null +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/NeighborRankAPITest.java @@ -0,0 +1,6 @@ +package com.baidu.hugegraph.api.traversers; + +import com.baidu.hugegraph.api.BaseApiTest; + +public class NeighborRankAPITest extends BaseApiTest { +} 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 new file mode 100644 index 0000000000..e84d9ad39e --- /dev/null +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/PathsAPITest.java @@ -0,0 +1,6 @@ +package com.baidu.hugegraph.api.traversers; + +import com.baidu.hugegraph.api.BaseApiTest; + +public class PathsAPITest extends BaseApiTest { +} 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 new file mode 100644 index 0000000000..9cdac32b30 --- /dev/null +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/PersonalRankAPITest.java @@ -0,0 +1,6 @@ +package com.baidu.hugegraph.api.traversers; + +import com.baidu.hugegraph.api.BaseApiTest; + +public class PersonalRankAPITest extends BaseApiTest { +} 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 new file mode 100644 index 0000000000..d3160dafa4 --- /dev/null +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/RaysAPITest.java @@ -0,0 +1,6 @@ +package com.baidu.hugegraph.api.traversers; + +import com.baidu.hugegraph.api.BaseApiTest; + +public class RaysAPITest extends BaseApiTest { +} diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/TraversersAPITestSuite.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/TraversersAPITestSuite.java new file mode 100644 index 0000000000..6c11659bd9 --- /dev/null +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/TraversersAPITestSuite.java @@ -0,0 +1,32 @@ +package com.baidu.hugegraph.api.traversers; + +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +import com.baidu.hugegraph.dist.RegisterUtil; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + AllShortestPathsAPITest.class, + CountAPITest.class, + CrosspointsAPITest.class, + CustomizedCrosspointsAPITest.class, + EdgesAPITest.class, + FusiformSimilarityAPITest.class, + JaccardSimilarityAPITest.class, + KneighborAPITest.class, + KoutAPITest.class, + MultiNodeShortestPathAPITest.class, + NeighborRankAPITest.class, + PathsAPITest.class, + PersonalRankAPITest.class, + RaysAPITest.class +}) +public class TraversersAPITestSuite { + + @BeforeClass + public static void initEnv() { + RegisterUtil.registerBackends(); + } +}