Search in sources :

Example 31 with EdgeLabel

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

the class EdgeLabelTest method testSetCheckExist.

@Test
public void testSetCheckExist() {
    SchemaManager schema = schema();
    EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("date", "weight").userdata("multiplicity", "one-to-many").userdata("icon", "picture2").create();
    Assert.assertTrue(write.checkExist());
    write.checkExist(false);
    Assert.assertFalse(write.checkExist());
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Test(org.junit.Test)

Example 32 with EdgeLabel

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

the class EdgeLabelTest method testAppendEdgeLabelWithUserData.

@Test
public void testAppendEdgeLabelWithUserData() {
    SchemaManager schema = schema();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").nullableKeys("city").ifNotExist().create();
    EdgeLabel father = schema.edgeLabel("father").link("person", "person").properties("weight").create();
    Assert.assertEquals(1, father.userdata().size());
    String time = (String) father.userdata().get("~create_time");
    Date createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
    father = schema.edgeLabel("father").userdata("multiplicity", "one-to-many").append();
    Assert.assertEquals(2, father.userdata().size());
    Assert.assertEquals("one-to-many", father.userdata().get("multiplicity"));
    time = (String) father.userdata().get("~create_time");
    Assert.assertEquals(createTime, DateUtil.parse(time));
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Date(java.util.Date) Test(org.junit.Test)

Example 33 with EdgeLabel

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

the class EdgeLabelApiTest method testListByNames.

@Test
public void testListByNames() {
    EdgeLabel created = schema().edgeLabel("created").sourceLabel("person").targetLabel("software").singleTime().properties("date", "city").build();
    created = edgeLabelAPI.create(created);
    EdgeLabel knows = schema().edgeLabel("knows").sourceLabel("person").targetLabel("person").singleTime().properties("date").build();
    knows = edgeLabelAPI.create(knows);
    List<EdgeLabel> edgeLabels;
    edgeLabels = edgeLabelAPI.list(ImmutableList.of("created"));
    Assert.assertEquals(1, edgeLabels.size());
    assertContains(edgeLabels, created);
    edgeLabels = edgeLabelAPI.list(ImmutableList.of("knows"));
    Assert.assertEquals(1, edgeLabels.size());
    assertContains(edgeLabels, knows);
    edgeLabels = edgeLabelAPI.list(ImmutableList.of("created", "knows"));
    Assert.assertEquals(2, edgeLabels.size());
    assertContains(edgeLabels, created);
    assertContains(edgeLabels, knows);
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) Test(org.junit.Test)

Example 34 with EdgeLabel

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

the class EdgeLabelApiTest method testAppendWithUndefinedPropertyKey.

@Test
public void testAppendWithUndefinedPropertyKey() {
    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("undefined").build();
    Utils.assertResponseError(400, () -> {
        edgeLabelAPI.append(edgeLabel2);
    });
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) Test(org.junit.Test)

Example 35 with EdgeLabel

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

the class EdgeLabelApiTest method testAppendWithUndefinedNullableKeys.

@Test
public void testAppendWithUndefinedNullableKeys() {
    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").nullableKeys("undefined").build();
    Utils.assertResponseError(400, () -> {
        edgeLabelAPI.append(edgeLabel2);
    });
}
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