Skip to content

Commit

Permalink
add encode test case
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenyuT committed Nov 26, 2023
1 parent d9603c0 commit 0a09aac
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,6 @@ public static MetricsManager metrics() {
return client.metrics();
}

@Before
public void setup() {
// this.clearData();
}

@After
public void teardown() throws Exception {
// pass
}

protected static Object getVertexId(String label, String key,
String value) {
return getVertex(label, key, value).id();
Expand Down Expand Up @@ -185,6 +175,7 @@ protected static void initPropertyKey() {
schema.propertyKey("city").asText().ifNotExist().create();
schema.propertyKey("lang").asText().ifNotExist().create();
schema.propertyKey("date").asDate().ifNotExist().create();
schema.propertyKey("date 2&@").asDate().ifNotExist().create();
schema.propertyKey("price").asInt().ifNotExist().create();
schema.propertyKey("weight").asDouble().ifNotExist().create();
}
Expand Down Expand Up @@ -230,8 +221,8 @@ protected static void initEdgeLabel() {
schema.edgeLabel("created")
.sourceLabel("person")
.targetLabel("software")
.properties("date", "city")
.nullableKeys("city")
.properties("date", "date 2&@", "city")
.nullableKeys("city", "date 2&@")
.ifNotExist()
.create();
}
Expand Down Expand Up @@ -294,7 +285,7 @@ protected static void initEdge() {
graph().addEdge(markoId, "knows", vadasId, "date", "2012-01-10");
graph().addEdge(markoId, "knows", joshId, "date", "2013-01-10");
graph().addEdge(markoId, "created", lopId,
"date", "2014-01-10", "city", "Shanghai");
"date", "2014-01-10", "city", "Shanghai", "date 2&@", "2014-01-10");
graph().addEdge(joshId, "created", rippleId,
"date", "2015-01-10", "city", "Beijing");
graph().addEdge(joshId, "created", lopId,
Expand All @@ -303,6 +294,16 @@ protected static void initEdge() {
"date", "2017-01-10", "city", "Hongkong");
}

@Before
public void setup() {
// this.clearData();
}

@After
public void teardown() throws Exception {
// pass
}

protected List<Vertex> create100PersonBatch() {
List<Vertex> vertices = new ArrayList<>(100);
for (int i = 0; i < 100; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ public static void clear() {
}
}

protected static User createUser(String name, String password) {
User user = new User();
user.name(name);
user.password(password);
user.email("test@hugegraph.com");
user.phone("16812345678");
user.avatar("image.jpg");
return api.create(user);
}

@Override
@After
public void teardown() {
Expand Down Expand Up @@ -136,15 +146,19 @@ public void testGet() {
public void testGetUserRole() {
User user1 = createUser("test1", "psw1");
User user2 = createUser("test2", "psw2");
User user3 = createUser("test3 aaa", "psw3");

Assert.assertEquals("test1", user1.name());
Assert.assertEquals("test2", user2.name());
Assert.assertContains("test3 aaa", user3.name());//test special character

UserRole role1 = api.getUserRole(user1.id());
UserRole role2 = api.getUserRole(user2.id());
UserRole role3 = api.getUserRole(user3.id());

Assert.assertEquals("{\"roles\":{}}", role1.toString());
Assert.assertEquals("{\"roles\":{}}", role2.toString());
Assert.assertEquals("{\"roles\":{}}", role3.toString());
}

@Test
Expand Down Expand Up @@ -256,14 +270,4 @@ public void testDelete() {
Assert.assertContains("Invalid user id: fake-id", e.getMessage());
});
}

protected static User createUser(String name, String password) {
User user = new User();
user.name(name);
user.password(password);
user.email("test@hugegraph.com");
user.phone("16812345678");
user.avatar("image.jpg");
return api.create(user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@

public class EdgeTest extends BaseFuncTest {

private static void assertContains(List<Edge> edges, Object source,
String label, Object target,
Object... keyValues) {
Map<String, Object> properties = Utils.asMap(keyValues);

Edge edge = new Edge(label);
edge.sourceId(source);
edge.targetId(target);
for (String key : properties.keySet()) {
edge.property(key, properties.get(key));
}

Assert.assertTrue(Utils.contains(edges, edge));
}

@Override
@Before
public void setup() {
Expand Down Expand Up @@ -80,7 +95,7 @@ public void testAddEdgeProperty() {
Edge created = graph().addEdge(peterId, "created", lopId,
"date", "2017-03-24");
Map<String, Object> props = ImmutableMap.of(
"date", Utils.formatDate("2017-03-24"));
"date", Utils.formatDate("2017-03-24"));
Assert.assertEquals(props, created.properties());

created.property("city", "HongKong");
Expand All @@ -97,7 +112,7 @@ public void testUpdateEdgeProperty() {
Edge created = graph().addEdge(peterId, "created", lopId,
"date", "2017-03-24");
Map<String, Object> props = ImmutableMap.of(
"date", Utils.formatDate("2017-03-24"));
"date", Utils.formatDate("2017-03-24"));
Assert.assertEquals(props, created.properties());

created.property("date", "2017-08-08");
Expand Down Expand Up @@ -125,16 +140,16 @@ public void testAddEdgePropertyValueList() {
"time", "2012-10-10");

Map<String, Object> props = ImmutableMap.of(
"date", Utils.formatDate("2017-03-24"),
"time", ImmutableList.of(
Utils.formatDate("2012-10-10")));
"date", Utils.formatDate("2017-03-24"),
"time", ImmutableList.of(
Utils.formatDate("2012-10-10")));
Assert.assertEquals(props, created.properties());

created.property("time", "2014-02-14");
props = ImmutableMap.of("date", Utils.formatDate("2017-03-24"),
"time", ImmutableList.of(
Utils.formatDate("2012-10-10"),
Utils.formatDate("2014-02-14")));
Utils.formatDate("2012-10-10"),
Utils.formatDate("2014-02-14")));
Assert.assertEquals(props, created.properties());
}

Expand All @@ -158,16 +173,16 @@ public void testAddEdgePropertyValueSet() {
"time", "2012-10-10");

Map<String, Object> props = ImmutableMap.of(
"date", Utils.formatDate("2017-03-24"),
"time", ImmutableList.of(
Utils.formatDate("2012-10-10")));
"date", Utils.formatDate("2017-03-24"),
"time", ImmutableList.of(
Utils.formatDate("2012-10-10")));
Assert.assertEquals(props, created.properties());

created.property("time", "2014-02-14");
props = ImmutableMap.of("date", Utils.formatDate("2017-03-24"),
"time", ImmutableList.of(
Utils.formatDate("2012-10-10"),
Utils.formatDate("2014-02-14")));
Utils.formatDate("2012-10-10"),
Utils.formatDate("2014-02-14")));
Assert.assertEquals(props, created.properties());
}

Expand All @@ -191,16 +206,16 @@ public void testAddEdgePropertyValueListWithSameValue() {
"time", "2012-10-10");

Map<String, Object> props = ImmutableMap.of(
"date", Utils.formatDate("2017-03-24"),
"time", ImmutableList.of(
Utils.formatDate("2012-10-10")));
"date", Utils.formatDate("2017-03-24"),
"time", ImmutableList.of(
Utils.formatDate("2012-10-10")));
Assert.assertEquals(props, created.properties());

created.property("time", "2012-10-10");
props = ImmutableMap.of("date", Utils.formatDate("2017-03-24"),
"time", ImmutableList.of(
Utils.formatDate("2012-10-10"),
Utils.formatDate("2012-10-10")));
Utils.formatDate("2012-10-10"),
Utils.formatDate("2012-10-10")));
Assert.assertEquals(props, created.properties());
}

Expand All @@ -224,15 +239,15 @@ public void testAddEdgePropertyValueSetWithSameValue() {
"time", "2012-10-10");

Map<String, Object> props = ImmutableMap.of(
"date", Utils.formatDate("2017-03-24"),
"time", ImmutableList.of(
Utils.formatDate("2012-10-10")));
"date", Utils.formatDate("2017-03-24"),
"time", ImmutableList.of(
Utils.formatDate("2012-10-10")));
Assert.assertEquals(props, created.properties());

created.property("time", "2012-10-10");
props = ImmutableMap.of("date", Utils.formatDate("2017-03-24"),
"time", ImmutableList.of(
Utils.formatDate("2012-10-10")));
Utils.formatDate("2012-10-10")));
Assert.assertEquals(props, created.properties());
}

Expand All @@ -245,8 +260,8 @@ public void testAddEdgeWithMapProperties() {
"city", "HongKong");
Edge created = graph().addEdge(peter, "created", lop, properties);
Map<String, Object> props = ImmutableMap.of(
"date", Utils.formatDate("2017-03-24"),
"city", "HongKong");
"date", Utils.formatDate("2017-03-24"),
"city", "HongKong");
Assert.assertEquals(props, created.properties());
}

Expand All @@ -270,9 +285,9 @@ public void testRemoveEdgeProperty() {
"time", "2012-10-10");

Map<String, Object> props = ImmutableMap.of(
"date", Utils.formatDate("2017-03-24"),
"time", ImmutableList.of(
Utils.formatDate("2012-10-10")));
"date", Utils.formatDate("2017-03-24"),
"time", ImmutableList.of(
Utils.formatDate("2012-10-10")));
Assert.assertEquals(props, created.properties());

created.removeProperty("time");
Expand All @@ -288,7 +303,7 @@ public void testRemoveEdgePropertyNotExist() {
Edge created = graph().addEdge(peterId, "created", lopId,
"date", "2017-03-24");
Map<String, Object> props = ImmutableMap.of(
"date", Utils.formatDate("2017-03-24"));
"date", Utils.formatDate("2017-03-24"));
Assert.assertEquals(props, created.properties());

Assert.assertThrows(InvalidOperationException.class, () -> {
Expand Down Expand Up @@ -511,8 +526,8 @@ public void testGetEdgesByVertexIdDirectionLabelProperties() {
Object rippleId = getVertexId("software", "name", "ripple");

Map<String, Object> properties = ImmutableMap.of(
"date",
Utils.formatDate("2015-01-10"));
"date",
Utils.formatDate("2015-01-10"));
List<Edge> edges = graph().getEdges(joshId, Direction.OUT,
"created", properties);
Assert.assertEquals(1, edges.size());
Expand All @@ -534,8 +549,8 @@ public void testGetEdgesByVertexIdDirectionLabelPropertiesWithLimit1() {
Object joshId = getVertexId("person", "name", "josh");

Map<String, Object> properties = ImmutableMap.of(
"date",
Utils.formatDate("2015-01-10"));
"date",
Utils.formatDate("2015-01-10"));
List<Edge> edges = graph().getEdges(joshId, Direction.OUT,
"created", properties);
Assert.assertEquals(1, edges.size());
Expand All @@ -555,7 +570,7 @@ public void testGetEdgesByVertexIdDirectionLabelPropertiesWithLimit1() {

@Test
public void testGetEdgesByLabelAndPropertiesWithRangeCondition()
throws ParseException {
throws ParseException {
schema().indexLabel("knowsByDate").range()
.onE("knows").by("date").create();
schema().indexLabel("createdByDate").range()
Expand All @@ -567,7 +582,7 @@ public void testGetEdgesByLabelAndPropertiesWithRangeCondition()
Date expected2 = DateUtil.parse("2016-01-10");

Map<String, Object> properties = ImmutableMap.of(
"date", "P.eq(\"2014-1-10\")");
"date", "P.eq(\"2014-1-10\")");
List<Edge> edges = graph().listEdges("created", properties);

Date time;
Expand Down Expand Up @@ -649,19 +664,29 @@ public void testGetEdgesByLabelAndPropertiesWithRangeCondition()

@Test
public void testGetEdgesByLabelAndPropertiesWithKeepP()
throws ParseException {
throws ParseException {
schema().indexLabel("createdByCity").secondary()
.onE("created").by("city").create();
schema().indexLabel("createdByDate").secondary()
.onE("created").by("date").create();
.onE("created").by("date 2&@").create();

BaseClientTest.initEdge();

{
//test special character
Map<String, Object> properties = ImmutableMap.of(
"date 2&@", "P.eq(\"2014-1-10\")");
List<Edge> edges = graph().listEdges("created", properties, false);
Assert.assertEquals(1, edges.size());
}


Map<String, Object> properties = ImmutableMap.of(
"date", "P.eq(\"2014-1-10\")");
"date", "P.eq(\"2014-1-10\")");
List<Edge> edges = graph().listEdges("created", properties, false);
Assert.assertEquals(1, edges.size());


Assert.assertThrows(ServerException.class, () -> {
graph().listEdges("created", properties, true);
}, e -> {
Expand Down Expand Up @@ -779,19 +804,4 @@ public void testQueryByPagingAndFiltering() {
e.getMessage());
});
}

private static void assertContains(List<Edge> edges, Object source,
String label, Object target,
Object... keyValues) {
Map<String, Object> properties = Utils.asMap(keyValues);

Edge edge = new Edge(label);
edge.sourceId(source);
edge.targetId(target);
for (String key : properties.keySet()) {
edge.property(key, properties.get(key));
}

Assert.assertTrue(Utils.contains(edges, edge));
}
}

0 comments on commit 0a09aac

Please sign in to comment.