Skip to content

Commit

Permalink
feat: add unit test for kneighborApi, KoutApi, MultiNodeShortestPathA…
Browse files Browse the repository at this point in the history
…pi, NeighborRankApi, PathsApi, PersonalRankApi, RaysApi, RingsApi, SameNeighborsApi
  • Loading branch information
zyxxoo committed Jun 25, 2021
1 parent fd41716 commit 4632218
Show file tree
Hide file tree
Showing 21 changed files with 894 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
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";

Expand Down
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");
}
}
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");
}
}
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"));
}
}
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"));
}
}
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");
}
}
Loading

0 comments on commit 4632218

Please sign in to comment.