Search in sources :

Example 66 with Edge

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

the class EdgeTest method assertContains.

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));
}
Also used : Edge(com.baidu.hugegraph.structure.graph.Edge)

Example 67 with Edge

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

the class EdgeTest method testAddEdgePropertyValueListWithSameValue.

@Test
public void testAddEdgePropertyValueListWithSameValue() {
    schema().propertyKey("time").asDate().valueList().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"), Utils.formatDate("2012-10-10")));
    Assert.assertEquals(props, created.properties());
}
Also used : Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test) BaseClientTest(com.baidu.hugegraph.BaseClientTest)

Example 68 with Edge

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

the class EdgeTest method testAddEdgePropertyValueSet.

@Test
public void testAddEdgePropertyValueSet() {
    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", "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")));
    Assert.assertEquals(props, created.properties());
}
Also used : Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test) BaseClientTest(com.baidu.hugegraph.BaseClientTest)

Example 69 with Edge

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

the class EdgeApiTest method testBatchCreateWithInvalidVertexLabelAndCheck.

@Test
public void testBatchCreateWithInvalidVertexLabelAndCheck() {
    List<Edge> edges = new ArrayList<>(2);
    Edge edge1 = new Edge("created");
    edge1.sourceId("person:peter");
    edge1.targetId("software:lop");
    edge1.property("date", "2017-03-24");
    edge1.property("city", "Hongkong");
    edges.add(edge1);
    Edge edge2 = new Edge("knows");
    edge2.sourceLabel("undefined");
    edge2.targetLabel("undefined");
    edge2.sourceId("person:peter");
    edge2.targetId("person:marko");
    edge2.property("date", "2017-03-24");
    edges.add(edge2);
    Utils.assertResponseError(400, () -> {
        edgeAPI.create(edges, true);
    });
}
Also used : ArrayList(java.util.ArrayList) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Example 70 with Edge

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

the class EdgeApiTest method testCreateWithUndefinedLabel.

@Test
public void testCreateWithUndefinedLabel() {
    Object outVId = getVertexId("person", "name", "peter");
    Object inVId = getVertexId("software", "name", "lop");
    Edge edge = new Edge("undefined");
    edge.sourceLabel("person");
    edge.targetLabel("software");
    edge.sourceId(outVId);
    edge.targetId(inVId);
    edge.property("date", "2017-03-24");
    edge.property("city", "Hongkong");
    Utils.assertResponseError(400, () -> {
        edgeAPI.create(edge);
    });
}
Also used : Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Aggregations

Edge (com.baidu.hugegraph.structure.graph.Edge)103 Test (org.junit.Test)73 Vertex (com.baidu.hugegraph.structure.graph.Vertex)33 ArrayList (java.util.ArrayList)22 BaseClientTest (com.baidu.hugegraph.BaseClientTest)20 BatchEdgeRequest (com.baidu.hugegraph.structure.graph.BatchEdgeRequest)12 HugeClient (com.baidu.hugegraph.driver.HugeClient)10 Path (com.baidu.hugegraph.structure.graph.Path)9 Result (com.baidu.hugegraph.structure.gremlin.Result)8 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)7 RestResult (com.baidu.hugegraph.rest.RestResult)5 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)5 GraphManager (com.baidu.hugegraph.driver.GraphManager)4 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)4 GraphView (com.baidu.hugegraph.entity.query.GraphView)4 Edges (com.baidu.hugegraph.structure.graph.Edges)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 GremlinResult (com.baidu.hugegraph.entity.query.GremlinResult)3 TypedResult (com.baidu.hugegraph.entity.query.TypedResult)3