Skip to content

Commit

Permalink
feat: improve test result verify
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxxoo committed Jul 15, 2021
1 parent 6b60826 commit e649d15
Show file tree
Hide file tree
Showing 21 changed files with 112 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

package com.baidu.hugegraph.api.traversers;

import com.baidu.hugegraph.testutil.Assert;

import java.util.List;
import java.util.Map;

Expand All @@ -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() {
Expand All @@ -56,9 +55,9 @@ public void testGet() {
id2Json(vadasId),
"max_depth", 10);
Response r = client().get(path, params);
String respBody = assertResponseStatus(200, r);
List<Map<String, Object>> crosspoints = assertJsonContains(respBody,
"crosspoints");
String content = assertResponseStatus(200, r);
List<Map<String, Object>> crosspoints = assertJsonContains(
content, "crosspoints");
Assert.assertEquals(2, crosspoints.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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<Object> paths = assertJsonContains(respBody, "paths");
String content = assertResponseStatus(200, r);
List<Object> paths = assertJsonContains(content, "paths");
Assert.assertEquals(2, paths.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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<Map> edges = assertJsonContains(respBody, "edges");
String content = assertResponseStatus(200, r);
List<Map> 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<Map> shards = assertJsonContains(respBody, "shards");
String content = assertResponseStatus(200, r);
List<Map> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@

import javax.ws.rs.core.Response;

import org.junit.Assert;
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";
final static String path = TRAVERSERS_API + "/fusiformsimilarity";

@Before
public void prepareSchema() {
Expand Down Expand Up @@ -62,11 +63,12 @@ public void testPost() {
"\"limit\": -1, " +
"\"with_intermediary\": false, " +
"\"with_vertex\":true}");
String respBody = assertResponseStatus(200, r);
Map<String, List> similars = assertJsonContains(respBody, "similars");
String content = assertResponseStatus(200, r);
Map<String, List> similars = assertJsonContains(content, "similars");
Map<String, String> name2Ids = listAllVertexName2Ids();
String markoId = name2Ids.get("marko");
String peterId = name2Ids.get("peter");
Assert.assertEquals(2, similars.size());
assertMapContains(similars, markoId);
assertMapContains(similars, peterId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -48,12 +49,16 @@ public void prepareSchema() {
public void testGet() {
Map<String, String> 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<String> vertices = assertJsonContains(respBody, "vertices");
Assert.assertEquals(3, vertices.size());
String content = assertResponseStatus(200, r);
List<String> vertices = assertJsonContains(content, "vertices");
Assert.assertEquals(ImmutableSet.of(rippleId, joshId, peterId),
ImmutableSet.copyOf(vertices));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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<String> vertices = assertJsonContains(respBody, "vertices");
String content = assertResponseStatus(200, r);
List<String> 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,
Expand All @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@

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;

import com.baidu.hugegraph.api.BaseApiTest;

public class MultiNodeShortestPathApiTest extends BaseApiTest {

final String path = "graphs/hugegraph/traversers/multinodeshortestpath";
final String path = TRAVERSERS_API + "/multinodeshortestpath";

@Before
public void prepareSchema() {
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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<Double> ranks = assertJsonContains(respBody, "ranks");
String content = assertResponseStatus(200, r);
List<Double> ranks = assertJsonContains(content, "ranks");
Assert.assertEquals(2, ranks.size());
}
}
Loading

0 comments on commit e649d15

Please sign in to comment.