use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class EdgeTest method testLinkedVertex.
@Test
public void testLinkedVertex() {
Object peterId = getVertexId("person", "name", "peter");
Object lopId = getVertexId("software", "name", "lop");
Edge created = graph().addEdge(peterId, "created", lopId, "date", "2017-03-24");
Assert.assertTrue(created.linkedVertex(peterId));
Assert.assertTrue(created.linkedVertex(lopId));
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class EdgeTest method testGetEdgesByLabelAndPropertiesWithRangeCondition.
@Test
public void testGetEdgesByLabelAndPropertiesWithRangeCondition() throws ParseException {
schema().indexLabel("knowsByDate").range().onE("knows").by("date").create();
schema().indexLabel("createdByDate").range().onE("created").by("date").create();
BaseClientTest.initEdge();
Date expected = DateUtil.parse("2014-01-10");
Date expected2 = DateUtil.parse("2016-01-10");
Map<String, Object> properties = ImmutableMap.of("date", "P.eq(\"2014-1-10\")");
List<Edge> edges = graph().listEdges("created", properties);
Date time;
Assert.assertEquals(1, edges.size());
for (Edge e : edges) {
Assert.assertEquals("created", e.label());
time = DateUtil.parse((String) e.property("date"));
Assert.assertEquals(expected.getTime(), time.getTime());
}
properties = ImmutableMap.of("date", "P.gt(\"2014-1-10\")");
edges = graph().listEdges("created", properties);
Assert.assertEquals(3, edges.size());
for (Edge e : edges) {
Assert.assertEquals("created", e.label());
time = DateUtil.parse((String) e.property("date"));
Assert.assertGt(expected.getTime(), time.getTime());
}
properties = ImmutableMap.of("date", "P.gte(\"2014-1-10\")");
edges = graph().listEdges("created", properties);
Assert.assertEquals(4, edges.size());
for (Edge e : edges) {
Assert.assertEquals("created", e.label());
time = DateUtil.parse((String) e.property("date"));
Assert.assertGte(expected.getTime(), time.getTime());
}
properties = ImmutableMap.of("date", "P.lt(\"2014-1-10\")");
edges = graph().listEdges(null, properties);
Assert.assertEquals(2, edges.size());
for (Edge e : edges) {
Assert.assertEquals("knows", e.label());
time = DateUtil.parse((String) e.property("date"));
Assert.assertLt(expected.getTime(), time.getTime());
}
properties = ImmutableMap.of("date", "P.lte(\"2014-1-10\")");
edges = graph().listEdges(null, properties);
Assert.assertEquals(3, edges.size());
for (Edge e : edges) {
time = DateUtil.parse((String) e.property("date"));
Assert.assertLte(expected.getTime(), time.getTime());
}
properties = ImmutableMap.of("date", "P.between(\"2014-1-10\",\"2016-1-10\")");
edges = graph().listEdges(null, properties);
Assert.assertEquals(2, edges.size());
for (Edge e : edges) {
Assert.assertEquals("created", e.label());
time = DateUtil.parse((String) e.property("date"));
Assert.assertGte(expected.getTime(), time.getTime());
Assert.assertLt(expected2.getTime(), time.getTime());
}
properties = ImmutableMap.of("date", "P.inside(\"2014-1-10\",\"2016-1-10\")");
edges = graph().listEdges(null, properties);
Assert.assertEquals(1, edges.size());
for (Edge e : edges) {
Assert.assertEquals("created", e.label());
time = DateUtil.parse((String) e.property("date"));
Assert.assertGt(expected.getTime(), time.getTime());
Assert.assertLt(expected2.getTime(), time.getTime());
}
properties = ImmutableMap.of("date", "P.within(\"2014-1-10\",\"2016-1-10\")");
edges = graph().listEdges(null, properties);
Assert.assertEquals(2, edges.size());
for (Edge e : edges) {
Assert.assertEquals("created", e.label());
time = DateUtil.parse((String) e.property("date"));
Assert.assertGte(expected.getTime(), time.getTime());
Assert.assertLte(expected2.getTime(), time.getTime());
}
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class EdgeTest method testAddEdgePropertyValueSetWithSameValue.
@Test
public void testAddEdgePropertyValueSetWithSameValue() {
schema().propertyKey("time").asDate().valueSet().ifNotExist().create();
schema().edgeLabel("created").properties("time").nullableKeys("time").append();
Object peterId = getVertexId("person", "name", "peter");
Object lopId = getVertexId("software", "name", "lop");
Edge created = graph().addEdge(peterId, "created", lopId, "date", "2017-03-24", "time", "2012-10-10");
Map<String, Object> props = ImmutableMap.of("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")));
Assert.assertEquals(props, created.properties());
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class EdgeTest method testRemoveEdgePropertyNotExist.
@Test
public void testRemoveEdgePropertyNotExist() {
Object peterId = getVertexId("person", "name", "peter");
Object lopId = getVertexId("software", "name", "lop");
Edge created = graph().addEdge(peterId, "created", lopId, "date", "2017-03-24");
Map<String, Object> props = ImmutableMap.of("date", Utils.formatDate("2017-03-24"));
Assert.assertEquals(props, created.properties());
Assert.assertThrows(InvalidOperationException.class, () -> {
created.removeProperty("not-exist");
});
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class BatchUpdateElementApiTest method testEdgeBatchUpdateStrategyEliminate.
@Test
public void testEdgeBatchUpdateStrategyEliminate() {
BatchEdgeRequest req = batchEdgeRequest("list", "old", "old", UpdateStrategy.ELIMINATE);
List<Edge> edges = edgeAPI.update(req);
assertBatchResponse(edges, "list");
req = batchEdgeRequest("list", "old", "new", UpdateStrategy.ELIMINATE);
edges = edgeAPI.update(req);
assertBatchResponse(edges, "list", "old");
}
Aggregations