Search in sources :

Example 51 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class EdgeTest method testAddEdgeWithMapProperties.

@Test
public void testAddEdgeWithMapProperties() {
    Vertex peter = getVertex("person", "name", "peter");
    Vertex lop = getVertex("software", "name", "lop");
    Map<String, Object> properties = ImmutableMap.of("date", "2017-03-24", "city", "HongKong");
    Edge created = graph().addEdge(peter, "created", lop, properties);
    Map<String, Object> props = ImmutableMap.of("date", Utils.formatDate("2017-03-24"), "city", "HongKong");
    Assert.assertEquals(props, created.properties());
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test) BaseClientTest(com.baidu.hugegraph.BaseClientTest)

Example 52 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class HugeClientHttpsTest method addVertexAndCheckPropertyValue.

private void addVertexAndCheckPropertyValue() {
    SchemaManager schema = client.schema();
    schema.propertyKey("name").asText().ifNotExist().create();
    schema.propertyKey("age").asInt().ifNotExist().create();
    schema.propertyKey("city").asText().ifNotExist().create();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").ifNotExist().create();
    GraphManager graph = client.graph();
    Vertex marko = graph.addVertex(T.label, "person", "name", "marko", "age", 29, "city", "Beijing");
    Map<String, Object> props = ImmutableMap.of("name", "marko", "age", 29, "city", "Beijing");
    Assert.assertEquals(props, marko.properties());
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) GraphManager(com.baidu.hugegraph.driver.GraphManager) SchemaManager(com.baidu.hugegraph.driver.SchemaManager)

Example 53 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class VertexTest method testAddVertexPropertyValueSet.

@Test
public void testAddVertexPropertyValueSet() {
    schema().propertyKey("time").asDate().valueSet().ifNotExist().create();
    schema().vertexLabel("person").properties("time").nullableKeys("time").append();
    Vertex vadas = graph().addVertex(T.label, "person", "name", "vadas", "age", 19, "time", "2012-10-10");
    Map<String, Object> props = ImmutableMap.of("name", "vadas", "age", 19, "time", ImmutableList.of(Utils.formatDate("2012-10-10")));
    Assert.assertEquals(props, vadas.properties());
    vadas.property("time", "2014-02-14");
    props = ImmutableMap.of("name", "vadas", "age", 19, "time", ImmutableList.of(Utils.formatDate("2012-10-10"), Utils.formatDate("2014-02-14")));
    Assert.assertEquals(props, vadas.properties());
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Test(org.junit.Test) BaseClientTest(com.baidu.hugegraph.BaseClientTest)

Example 54 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class VertexTest method testGetVerticesByLabelAndPropertiesWithRangeCondition.

@Test
public void testGetVerticesByLabelAndPropertiesWithRangeCondition() {
    schema().indexLabel("personByAge").range().onV("person").by("age").create();
    BaseClientTest.initVertex();
    Map<String, Object> properties = ImmutableMap.of("age", "P.eq(29)");
    List<Vertex> vertices = graph().listVertices("person", properties);
    Assert.assertEquals(2, vertices.size());
    for (Vertex v : vertices) {
        Assert.assertEquals("person", v.label());
        Assert.assertEquals(29, v.property("age"));
    }
    properties = ImmutableMap.of("age", "P.gt(29)");
    vertices = graph().listVertices("person", properties);
    Assert.assertEquals(1, vertices.size());
    for (Vertex v : vertices) {
        Assert.assertEquals("person", v.label());
        Assert.assertGt(29, v.property("age"));
    }
    properties = ImmutableMap.of("age", "P.gte(29)");
    vertices = graph().listVertices("person", properties);
    Assert.assertEquals(3, vertices.size());
    for (Vertex v : vertices) {
        Assert.assertEquals("person", v.label());
        Assert.assertGte(29, v.property("age"));
    }
    properties = ImmutableMap.of("age", "P.lt(29)");
    vertices = graph().listVertices("person", properties);
    Assert.assertEquals(1, vertices.size());
    for (Vertex v : vertices) {
        Assert.assertEquals("person", v.label());
        Assert.assertLt(29, v.property("age"));
    }
    properties = ImmutableMap.of("age", "P.lte(29)");
    vertices = graph().listVertices("person", properties);
    Assert.assertEquals(3, vertices.size());
    for (Vertex v : vertices) {
        Assert.assertEquals("person", v.label());
        Assert.assertLte(29, v.property("age"));
    }
    properties = ImmutableMap.of("age", "P.between(29,32)");
    vertices = graph().listVertices("person", properties);
    Assert.assertEquals(2, vertices.size());
    for (Vertex v : vertices) {
        Assert.assertEquals("person", v.label());
        Assert.assertGte(29, v.property("age"));
        Assert.assertLt(31, v.property("age"));
    }
    properties = ImmutableMap.of("age", "P.inside(27,32)");
    vertices = graph().listVertices("person", properties);
    Assert.assertEquals(2, vertices.size());
    for (Vertex v : vertices) {
        Assert.assertEquals("person", v.label());
        Assert.assertGt(27, v.property("age"));
        Assert.assertLt(32, v.property("age"));
    }
    properties = ImmutableMap.of("age", "P.within(27,32)");
    vertices = graph().listVertices("person", properties);
    Assert.assertEquals(2, vertices.size());
    for (Vertex v : vertices) {
        Assert.assertEquals("person", v.label());
        Assert.assertThat(v.property("age"), CoreMatchers.anyOf(CoreMatchers.is(27), CoreMatchers.is(32)));
    }
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Test(org.junit.Test) BaseClientTest(com.baidu.hugegraph.BaseClientTest)

Example 55 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class VertexTest method testRemoveVertexPropertyNotExist.

@Test
public void testRemoveVertexPropertyNotExist() {
    Vertex vadas = graph().addVertex(T.label, "person", "name", "vadas", "age", 19, "city", "Beijing");
    Map<String, Object> props = ImmutableMap.of("name", "vadas", "age", 19, "city", "Beijing");
    Assert.assertEquals(props, vadas.properties());
    Assert.assertThrows(InvalidOperationException.class, () -> {
        vadas.removeProperty("not-exist");
    });
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Test(org.junit.Test) BaseClientTest(com.baidu.hugegraph.BaseClientTest)

Aggregations

Vertex (com.baidu.hugegraph.structure.graph.Vertex)165 Test (org.junit.Test)110 Edge (com.baidu.hugegraph.structure.graph.Edge)33 HugeClient (com.baidu.hugegraph.driver.HugeClient)22 ArrayList (java.util.ArrayList)21 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)18 BaseClientTest (com.baidu.hugegraph.BaseClientTest)17 BeforeClass (org.junit.BeforeClass)17 GraphManager (com.baidu.hugegraph.driver.GraphManager)14 BatchVertexRequest (com.baidu.hugegraph.structure.graph.BatchVertexRequest)13 Path (com.baidu.hugegraph.structure.graph.Path)11 Result (com.baidu.hugegraph.structure.gremlin.Result)10 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)10 List (java.util.List)10 BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)9 ImmutableList (com.google.common.collect.ImmutableList)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 Map (java.util.Map)6 RestResult (com.baidu.hugegraph.rest.RestResult)5 PathsWithVertices (com.baidu.hugegraph.structure.traverser.PathsWithVertices)5