-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add unit test for kneighborApi, KoutApi, MultiNodeShortestPathA…
…pi, NeighborRankApi, PathsApi, PersonalRankApi, RaysApi, RingsApi, SameNeighborsApi
- Loading branch information
Showing
21 changed files
with
894 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KneighborAPITest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.baidu.hugegraph.api.traversers; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
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; | ||
import com.google.common.collect.ImmutableMap; | ||
|
||
public class KneighborApiTest extends BaseApiTest { | ||
|
||
final static String path = "graphs/hugegraph/traversers/kneighbor"; | ||
|
||
@Before | ||
public void prepareSchema() { | ||
BaseApiTest.initPropertyKey(); | ||
BaseApiTest.initVertexLabel(); | ||
BaseApiTest.initEdgeLabel(); | ||
BaseApiTest.initVertex(); | ||
BaseApiTest.initEdge(); | ||
} | ||
|
||
@Test | ||
public void testGet() { | ||
Map<String, String> name2Ids = listAllVertexName2Ids(); | ||
String markoId = name2Ids.get("marko"); | ||
Response r = client().get(path, | ||
ImmutableMap.of("source", id2Json(markoId), | ||
"max_depth", 2)); | ||
String respBody = assertResponseStatus(200, r); | ||
List<String> vertices = assertJsonContains(respBody, "vertices"); | ||
assertEquals(3, vertices.size()); | ||
} | ||
|
||
@Test | ||
public void testPost() { | ||
Map<String, String> name2Ids = listAllVertexName2Ids(); | ||
String markoId = name2Ids.get("marko"); | ||
String reqBody = String.format("{ " | ||
+ "\"source\": \"%s\", " | ||
+ "\"step\": { " | ||
+ " \"direction\": \"BOTH\", " | ||
+ | ||
" \"labels\": [\"knows\", " + | ||
"\"created\"], " | ||
+ " \"properties\": { " | ||
+ " \"weight\": \"P.gt(0.1)\"}, " | ||
+ " \"degree\": 10000, " | ||
+ " \"skip_degree\": 100000}, " | ||
+ "\"max_depth\": 3, " | ||
+ "\"limit\": 10000, " | ||
+ "\"with_vertex\": true, " | ||
+ "\"with_path\": true}", markoId); | ||
Response r = client().post(path, reqBody); | ||
String content = assertResponseStatus(200, r); | ||
Map<String, Object> entity = parseMap(content); | ||
assertNotNull(entity); | ||
assertMapContains(entity, "kneighbor"); | ||
assertMapContains(entity, "paths"); | ||
assertMapContains(entity, "vertices"); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KneighborApiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.baidu.hugegraph.api.traversers; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
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; | ||
import com.google.common.collect.ImmutableMap; | ||
|
||
public class KneighborApiTest extends BaseApiTest { | ||
|
||
final static String path = "graphs/hugegraph/traversers/kneighbor"; | ||
|
||
@Before | ||
public void prepareSchema() { | ||
BaseApiTest.initPropertyKey(); | ||
BaseApiTest.initVertexLabel(); | ||
BaseApiTest.initEdgeLabel(); | ||
BaseApiTest.initVertex(); | ||
BaseApiTest.initEdge(); | ||
} | ||
|
||
@Test | ||
public void testGet() { | ||
Map<String, String> name2Ids = listAllVertexName2Ids(); | ||
String markoId = name2Ids.get("marko"); | ||
Response r = client().get(path, | ||
ImmutableMap.of("source", id2Json(markoId), | ||
"max_depth", 2)); | ||
String respBody = assertResponseStatus(200, r); | ||
List<String> vertices = assertJsonContains(respBody, "vertices"); | ||
assertEquals(3, vertices.size()); | ||
} | ||
|
||
@Test | ||
public void testPost() { | ||
Map<String, String> name2Ids = listAllVertexName2Ids(); | ||
String markoId = name2Ids.get("marko"); | ||
String reqBody = String.format("{ " | ||
+ "\"source\": \"%s\", " | ||
+ "\"step\": { " | ||
+ " \"direction\": \"BOTH\", " | ||
+ | ||
" \"labels\": [\"knows\", " + | ||
"\"created\"], " | ||
+ " \"properties\": { " | ||
+ " \"weight\": \"P.gt(0.1)\"}, " | ||
+ " \"degree\": 10000, " | ||
+ " \"skip_degree\": 100000}, " | ||
+ "\"max_depth\": 3, " | ||
+ "\"limit\": 10000, " | ||
+ "\"with_vertex\": true, " | ||
+ "\"with_path\": true}", markoId); | ||
Response r = client().post(path, reqBody); | ||
String content = assertResponseStatus(200, r); | ||
Map<String, Object> entity = parseMap(content); | ||
assertNotNull(entity); | ||
assertMapContains(entity, "kneighbor"); | ||
assertMapContains(entity, "paths"); | ||
assertMapContains(entity, "vertices"); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KoutAPITest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.baidu.hugegraph.api.traversers; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
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; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
|
||
public class KoutApiTest extends BaseApiTest { | ||
|
||
final static String path = "graphs/hugegraph/traversers/kout"; | ||
|
||
@Before | ||
public void prepareSchema() { | ||
BaseApiTest.initPropertyKey(); | ||
BaseApiTest.initVertexLabel(); | ||
BaseApiTest.initEdgeLabel(); | ||
BaseApiTest.initVertex(); | ||
BaseApiTest.initEdge(); | ||
} | ||
|
||
@Test | ||
public void testGet() { | ||
Map<String, String> name2Ids = listAllVertexName2Ids(); | ||
String markoId = name2Ids.get("marko"); | ||
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<String> vertices = assertJsonContains(respBody, "vertices"); | ||
assertEquals(1, vertices.size()); | ||
assertTrue(vertices.containsAll(ImmutableList.of(peterId, joshId))); | ||
} | ||
|
||
@Test | ||
public void testPost() { | ||
Map<String, String> name2Ids = listAllVertexName2Ids(); | ||
String markoId = name2Ids.get("marko"); | ||
String reqBody = String.format("{ " | ||
+ "\"source\": \"%s\", " | ||
+ "\"step\": { " | ||
+ " \"direction\": \"BOTH\", " | ||
+ | ||
" \"labels\": [\"knows\", " + | ||
"\"created\"], " | ||
+ " \"properties\": { " | ||
+ " \"weight\": \"P.gt(0.1)\"}, " | ||
+ " \"degree\": 10000, " | ||
+ " \"skip_degree\": 100000}, " | ||
+ "\"max_depth\": 1, " | ||
+ "\"nearest\": true, " | ||
+ "\"limit\": 10000, " | ||
+ "\"with_vertex\": true, " | ||
+ "\"with_path\": true}", markoId); | ||
Response resp = client().post(path, reqBody); | ||
String respBody = assertResponseStatus(200, resp); | ||
Map<String, Object> entity = parseMap(respBody); | ||
assertMapContains(entity, "size"); | ||
assertMapContains(entity, "kout"); | ||
assertMapContains(entity, "paths"); | ||
assertMapContains(entity, "vertices"); | ||
assertEquals(2, entity.get("size")); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KoutApiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.baidu.hugegraph.api.traversers; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
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; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
|
||
public class KoutApiTest extends BaseApiTest { | ||
|
||
final static String path = "graphs/hugegraph/traversers/kout"; | ||
|
||
@Before | ||
public void prepareSchema() { | ||
BaseApiTest.initPropertyKey(); | ||
BaseApiTest.initVertexLabel(); | ||
BaseApiTest.initEdgeLabel(); | ||
BaseApiTest.initVertex(); | ||
BaseApiTest.initEdge(); | ||
} | ||
|
||
@Test | ||
public void testGet() { | ||
Map<String, String> name2Ids = listAllVertexName2Ids(); | ||
String markoId = name2Ids.get("marko"); | ||
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<String> vertices = assertJsonContains(respBody, "vertices"); | ||
assertEquals(1, vertices.size()); | ||
assertTrue(vertices.containsAll(ImmutableList.of(peterId, joshId))); | ||
} | ||
|
||
@Test | ||
public void testPost() { | ||
Map<String, String> name2Ids = listAllVertexName2Ids(); | ||
String markoId = name2Ids.get("marko"); | ||
String reqBody = String.format("{ " | ||
+ "\"source\": \"%s\", " | ||
+ "\"step\": { " | ||
+ " \"direction\": \"BOTH\", " | ||
+ | ||
" \"labels\": [\"knows\", " + | ||
"\"created\"], " | ||
+ " \"properties\": { " | ||
+ " \"weight\": \"P.gt(0.1)\"}, " | ||
+ " \"degree\": 10000, " | ||
+ " \"skip_degree\": 100000}, " | ||
+ "\"max_depth\": 1, " | ||
+ "\"nearest\": true, " | ||
+ "\"limit\": 10000, " | ||
+ "\"with_vertex\": true, " | ||
+ "\"with_path\": true}", markoId); | ||
Response resp = client().post(path, reqBody); | ||
String respBody = assertResponseStatus(200, resp); | ||
Map<String, Object> entity = parseMap(respBody); | ||
assertMapContains(entity, "size"); | ||
assertMapContains(entity, "kout"); | ||
assertMapContains(entity, "paths"); | ||
assertMapContains(entity, "vertices"); | ||
assertEquals(2, entity.get("size")); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...h-test/src/main/java/com/baidu/hugegraph/api/traversers/MultiNodeShortestPathAPITest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.baidu.hugegraph.api.traversers; | ||
|
||
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 MultiNodeShortestPathApiTest extends BaseApiTest { | ||
|
||
final String path = "graphs/hugegraph/traversers/multinodeshortestpath"; | ||
|
||
@Before | ||
public void prepareSchema() { | ||
BaseApiTest.initPropertyKey(); | ||
BaseApiTest.initVertexLabel(); | ||
BaseApiTest.initEdgeLabel(); | ||
BaseApiTest.initVertex(); | ||
BaseApiTest.initEdge(); | ||
} | ||
|
||
@Test | ||
public void testPost() { | ||
Map<String, String> name2Ids = listAllVertexName2Ids(); | ||
String markoId = name2Ids.get("marko"); | ||
String peterId = name2Ids.get("peter"); | ||
String joshId = name2Ids.get("josh"); | ||
String vadasId = name2Ids.get("vadas"); | ||
String reqBody = String.format("{ " | ||
+ "\"vertices\": { " | ||
+ " \"ids\": [\"%s\", \"%s\", \"%s\", " | ||
+ " \"%s\"]}, " | ||
+ "\"step\": { " | ||
+ " \"direction\": \"BOTH\", " | ||
+ " \"properties\": {}}, " | ||
+ "\"max_depth\": 10, " | ||
+ "\"capacity\": 100000000, " | ||
+ "\"with_vertex\": true}", | ||
markoId, peterId, joshId, vadasId); | ||
Response r = client().post(path, reqBody); | ||
String respJosn = assertResponseStatus(200, r); | ||
Map<String, Object> entity = parseMap(respJosn); | ||
assertMapContains(entity, "paths"); | ||
assertMapContains(entity, "vertices"); | ||
} | ||
} |
Oops, something went wrong.