Search in sources :

Example 16 with EdgeLabel

use of com.baidu.hugegraph.structure.schema.EdgeLabel in project incubator-hugegraph-toolchain by apache.

the class EdgeLabelApiTest method testAddEdgeLabelWithUserData.

@Test
public void testAddEdgeLabelWithUserData() {
    EdgeLabel father = schema().edgeLabel("father").link("person", "person").properties("weight").userdata("multiplicity", "one-to-many").build();
    father = edgeLabelAPI.create(father);
    Assert.assertEquals(2, father.userdata().size());
    Assert.assertEquals("one-to-many", father.userdata().get("multiplicity"));
    String time = (String) father.userdata().get("~create_time");
    Date createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
    EdgeLabel write = schema().edgeLabel("write").link("person", "book").properties("date", "weight").userdata("multiplicity", "one-to-many").userdata("multiplicity", "many-to-many").build();
    write = edgeLabelAPI.create(write);
    // The same key user data will be overwritten
    Assert.assertEquals(2, write.userdata().size());
    Assert.assertEquals("many-to-many", write.userdata().get("multiplicity"));
    time = (String) write.userdata().get("~create_time");
    createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) Date(java.util.Date) Test(org.junit.Test)

Example 17 with EdgeLabel

use of com.baidu.hugegraph.structure.schema.EdgeLabel in project incubator-hugegraph-toolchain by apache.

the class EdgeLabelApiTest method testCreateWithEnableLabelIndexFalse.

@Test
public void testCreateWithEnableLabelIndexFalse() {
    EdgeLabel edgeLabel = schema().edgeLabel("created").sourceLabel("person").targetLabel("software").singleTime().properties("date", "city").enableLabelIndex(false).create();
    Assert.assertEquals("created", edgeLabel.name());
    Assert.assertEquals("person", edgeLabel.sourceLabel());
    Assert.assertEquals("software", edgeLabel.targetLabel());
    Assert.assertEquals(Frequency.SINGLE, edgeLabel.frequency());
    Assert.assertEquals(false, edgeLabel.enableLabelIndex());
    Set<String> props = ImmutableSet.of("date", "city");
    Assert.assertTrue(props.size() == edgeLabel.properties().size());
    Assert.assertTrue(props.containsAll(edgeLabel.properties()));
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) Test(org.junit.Test)

Example 18 with EdgeLabel

use of com.baidu.hugegraph.structure.schema.EdgeLabel in project incubator-hugegraph-toolchain by apache.

the class EdgeLabelApiTest method testCreateWithUndefinedSortKey.

@Test
public void testCreateWithUndefinedSortKey() {
    EdgeLabel edgeLabel = schema().edgeLabel("created").sourceLabel("person").targetLabel("software").multiTimes().properties("date", "city").sortKeys("undefined").build();
    Utils.assertResponseError(400, () -> {
        edgeLabelAPI.create(edgeLabel);
    });
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) Test(org.junit.Test)

Example 19 with EdgeLabel

use of com.baidu.hugegraph.structure.schema.EdgeLabel in project incubator-hugegraph-toolchain by apache.

the class EdgeLabelApiTest method testEliminate.

@Test
public void testEliminate() {
    EdgeLabel edgeLabel1 = schema().edgeLabel("created").sourceLabel("person").targetLabel("software").singleTime().properties("date").build();
    edgeLabel1 = edgeLabelAPI.create(edgeLabel1);
    Assert.assertEquals("created", edgeLabel1.name());
    Assert.assertEquals("person", edgeLabel1.sourceLabel());
    Assert.assertEquals("software", edgeLabel1.targetLabel());
    Assert.assertEquals(Frequency.SINGLE, edgeLabel1.frequency());
    Set<String> props = ImmutableSet.of("date");
    Assert.assertEquals(props, edgeLabel1.properties());
    EdgeLabel edgeLabel2 = schema().edgeLabel("created").properties("city").build();
    Utils.assertResponseError(400, () -> {
        edgeLabelAPI.eliminate(edgeLabel2);
    });
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) Test(org.junit.Test)

Example 20 with EdgeLabel

use of com.baidu.hugegraph.structure.schema.EdgeLabel in project incubator-hugegraph-toolchain by apache.

the class EdgeLabelApiTest method testGet.

@Test
public void testGet() {
    EdgeLabel edgeLabel1 = edgeLabelAPI.create(fillEdgeLabel.apply("created"));
    EdgeLabel edgeLabel2 = edgeLabelAPI.get("created");
    Assert.assertEquals(edgeLabel1.name(), edgeLabel2.name());
    Assert.assertEquals(edgeLabel1.sourceLabel(), edgeLabel2.sourceLabel());
    Assert.assertEquals(edgeLabel1.targetLabel(), edgeLabel2.targetLabel());
    Assert.assertEquals(edgeLabel1.frequency(), edgeLabel2.frequency());
    Assert.assertEquals(edgeLabel1.properties(), edgeLabel2.properties());
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) Test(org.junit.Test)

Aggregations

EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)44 Test (org.junit.Test)31 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)9 HugeClient (com.baidu.hugegraph.driver.HugeClient)8 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)6 ExternalException (com.baidu.hugegraph.exception.ExternalException)4 ServerException (com.baidu.hugegraph.exception.ServerException)4 Date (java.util.Date)4 RestResult (com.baidu.hugegraph.rest.RestResult)3 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)3 ArrayList (java.util.ArrayList)3 Task (com.baidu.hugegraph.structure.Task)2 BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)1 EdgeLabelEntity (com.baidu.hugegraph.entity.schema.EdgeLabelEntity)1 EdgeLabelStyle (com.baidu.hugegraph.entity.schema.EdgeLabelStyle)1 Edge (com.baidu.hugegraph.structure.graph.Edge)1 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)1 HashSet (java.util.HashSet)1