use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class TemplatePathsApiTest method testTemplatePathsWithVertex.
@Test
public void testTemplatePathsWithVertex() {
TemplatePathsRequest.Builder builder = TemplatePathsRequest.builder();
builder.sources().ids(1);
builder.targets().ids(10);
builder.steps().direction(Direction.OUT).labels("relateTo").maxTimes(3);
builder.steps().direction(Direction.OUT).labels("relateTo").maxTimes(3);
builder.steps().direction(Direction.IN).labels("relateTo").maxTimes(3);
builder.withVertex(true);
TemplatePathsRequest request = builder.build();
PathsWithVertices pathsWithVertices = templatePathsAPI.post(request);
List<PathsWithVertices.Paths> paths = pathsWithVertices.paths();
Assert.assertEquals(1, paths.size());
List<Object> expectedIds = ImmutableList.of(1, 16, 17, 10);
List<List<Object>> expectedPath = ImmutableList.of(expectedIds);
for (PathsWithVertices.Paths path : paths) {
Assert.assertTrue(expectedPath.contains(path.objects()));
}
Set<Vertex> vertices = pathsWithVertices.vertices();
Assert.assertEquals(4, vertices.size());
for (Vertex v : vertices) {
Assert.assertTrue(expectedIds.contains(v.id()));
}
}
use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class CustomizedPathsApiTest method initEdgesWithWeights.
private static void initEdgesWithWeights() {
SchemaManager schema = schema();
schema.edgeLabel("knows1").sourceLabel("person").targetLabel("person").properties("date", "weight").nullableKeys("weight").ifNotExist().create();
schema.edgeLabel("created1").sourceLabel("person").targetLabel("software").properties("date", "weight").nullableKeys("weight").ifNotExist().create();
Vertex marko = getVertex("person", "name", "marko");
Vertex vadas = getVertex("person", "name", "vadas");
Vertex lop = getVertex("software", "name", "lop");
Vertex josh = getVertex("person", "name", "josh");
Vertex ripple = getVertex("software", "name", "ripple");
Vertex peter = getVertex("person", "name", "peter");
marko.addEdge("knows1", vadas, "date", "2016-01-10", "weight", 0.5);
marko.addEdge("knows1", josh, "date", "2013-02-20", "weight", 1.0);
marko.addEdge("created1", lop, "date", "2017-12-10", "weight", 0.4);
josh.addEdge("created1", lop, "date", "2009-11-11", "weight", 0.4);
josh.addEdge("created1", ripple, "date", "2017-12-10", "weight", 1.0);
peter.addEdge("created1", lop, "date", "2017-03-24", "weight", 0.2);
}
use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class VertexApiTest method testCreate.
@Test
public void testCreate() {
Vertex vertex = new Vertex("person");
vertex.property("name", "James");
vertex.property("city", "Beijing");
vertex.property("age", 19);
vertex = vertexAPI.create(vertex);
Assert.assertEquals("person", vertex.label());
Map<String, Object> props = ImmutableMap.of("name", "James", "city", "Beijing", "age", 19);
Assert.assertEquals(props, vertex.properties());
}
use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class VertexApiTest method testCreateWithCustomizeNumberId.
@Test
public void testCreateWithCustomizeNumberId() {
Vertex person = new Vertex("person");
person.property(T.id, 123456);
person.property("name", "James");
person.property("city", "Beijing");
person.property("age", 19);
Utils.assertResponseError(400, () -> {
vertexAPI.create(person);
});
schema().vertexLabel("log").useCustomizeNumberId().properties("date").ifNotExist().create();
Vertex log = new Vertex("log");
log.id(123456);
log.property("date", "2018-01-01");
Vertex vertex = vertexAPI.create(log);
Assert.assertEquals("log", vertex.label());
Assert.assertEquals(123456, vertex.id());
String date = Utils.formatDate("2018-01-01");
Map<String, Object> props = ImmutableMap.of("date", date);
Assert.assertEquals(props, vertex.properties());
}
use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class VertexApiTest method testBatchCreate.
@Test
public void testBatchCreate() {
List<Vertex> vertices = super.create100PersonBatch();
vertexAPI.create(vertices);
List<Object> ids = vertexAPI.create(vertices);
Assert.assertEquals(100, ids.size());
for (int i = 0; i < 100; i++) {
Vertex person = vertexAPI.get(ids.get(i));
Assert.assertEquals("person", person.label());
Map<String, Object> props = ImmutableMap.of("name", "Person-" + i, "city", "Beijing", "age", 30);
Assert.assertEquals(props, person.properties());
}
}
Aggregations