use of com.baidu.hugegraph.structure.schema.EdgeLabel in project incubator-hugegraph-toolchain by apache.
the class VertexLabelService method getLinkEdgeLabels.
public List<String> getLinkEdgeLabels(String name, int connId) {
HugeClient client = this.client(connId);
List<EdgeLabel> edgeLabels = client.schema().getEdgeLabels();
List<String> results = new ArrayList<>();
for (EdgeLabel edgeLabel : edgeLabels) {
if (edgeLabel.linkedVertexLabel(name)) {
results.add(edgeLabel.name());
}
}
return results;
}
use of com.baidu.hugegraph.structure.schema.EdgeLabel in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadEdgeLabels.
@Test
public void testReadEdgeLabels() {
String json = "{\"edgelabels\": [" + "{" + "\"id\": 2," + "\"source_label\": \"person\"," + "\"index_labels\": [\"createdByDate\"]," + "\"name\": \"created\"," + "\"target_label\": \"software\"," + "\"sort_keys\": []," + "\"properties\": [\"date\"]," + "\"frequency\": \"SINGLE\"" + "}," + "{\"id\": 3," + "\"source_label\": \"person\"," + "\"index_labels\": []," + "\"name\": \"knows\"," + "\"target_label\": \"person\"," + "\"sort_keys\": []," + "\"properties\": [\"date\", \"city\"]," + "\"frequency\": \"SINGLE\"" + "}" + "]}";
Mockito.when(this.mockResponse.getStatus()).thenReturn(200);
Mockito.when(this.mockResponse.getHeaders()).thenReturn(null);
Mockito.when(this.mockResponse.readEntity(String.class)).thenReturn(json);
RestResult result = new RestResult(this.mockResponse);
Assert.assertEquals(200, result.status());
Assert.assertNull(result.headers());
List<EdgeLabel> edgeLabels = result.readList("edgelabels", EdgeLabel.class);
Assert.assertEquals(2, edgeLabels.size());
EdgeLabel edgeLabel1 = edgeLabels.get(0);
EdgeLabel edgeLabel2 = edgeLabels.get(1);
Assert.assertEquals("created", edgeLabel1.name());
Assert.assertEquals("person", edgeLabel1.sourceLabel());
Assert.assertEquals("software", edgeLabel1.targetLabel());
Assert.assertEquals(Frequency.SINGLE, edgeLabel1.frequency());
Assert.assertEquals(Collections.emptyList(), edgeLabel1.sortKeys());
Assert.assertEquals(ImmutableSet.of("date"), edgeLabel1.properties());
Assert.assertEquals("knows", edgeLabel2.name());
Assert.assertEquals("person", edgeLabel2.sourceLabel());
Assert.assertEquals("person", edgeLabel2.targetLabel());
Assert.assertEquals(Frequency.SINGLE, edgeLabel2.frequency());
Assert.assertEquals(Collections.emptyList(), edgeLabel2.sortKeys());
Assert.assertEquals(ImmutableSet.of("date", "city"), edgeLabel2.properties());
}
use of com.baidu.hugegraph.structure.schema.EdgeLabel in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadEdgeLabel.
@Test
public void testReadEdgeLabel() {
String json = "{" + "\"id\": 2," + "\"source_label\": \"person\"," + "\"index_labels\": [\"createdByDate\"]," + "\"name\": \"created\"," + "\"target_label\": \"software\"," + "\"sort_keys\": []," + "\"properties\": [\"date\"]," + "\"frequency\": \"SINGLE\"" + "}";
Mockito.when(this.mockResponse.getStatus()).thenReturn(200);
Mockito.when(this.mockResponse.getHeaders()).thenReturn(null);
Mockito.when(this.mockResponse.readEntity(String.class)).thenReturn(json);
RestResult result = new RestResult(this.mockResponse);
Assert.assertEquals(200, result.status());
Assert.assertNull(result.headers());
EdgeLabel edgeLabel = result.readObject(EdgeLabel.class);
Assert.assertEquals("created", edgeLabel.name());
Assert.assertEquals("person", edgeLabel.sourceLabel());
Assert.assertEquals("software", edgeLabel.targetLabel());
Assert.assertEquals(Frequency.SINGLE, edgeLabel.frequency());
Assert.assertEquals(Collections.emptyList(), edgeLabel.sortKeys());
Assert.assertEquals(ImmutableSet.of("date"), edgeLabel.properties());
}
use of com.baidu.hugegraph.structure.schema.EdgeLabel in project incubator-hugegraph-toolchain by apache.
the class EdgeLabelTest method testRemoveEdgeLabelAsync.
@Test
public void testRemoveEdgeLabelAsync() {
SchemaManager schema = schema();
EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("date", "weight").userdata("multiplicity", "one-to-many").userdata("icon", "picture2").create();
Assert.assertNotNull(write);
// Remove edge label async and wait
long taskId = schema.removeEdgeLabelAsync("write");
Task task = task().waitUntilTaskCompleted(taskId, 10);
Assert.assertTrue(task.completed());
}
use of com.baidu.hugegraph.structure.schema.EdgeLabel in project incubator-hugegraph-toolchain by apache.
the class EdgeLabelTest method testEliminateEdgeLabelWithUserData.
@Test
public void testEliminateEdgeLabelWithUserData() {
SchemaManager schema = schema();
EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("date", "weight").userdata("multiplicity", "one-to-many").userdata("icon", "picture2").create();
Assert.assertEquals(3, write.userdata().size());
Assert.assertEquals("one-to-many", write.userdata().get("multiplicity"));
Assert.assertEquals("picture2", write.userdata().get("icon"));
String time = (String) write.userdata().get("~create_time");
Date createTime = DateUtil.parse(time);
Assert.assertTrue(createTime.before(DateUtil.now()));
write = schema.edgeLabel("write").userdata("icon", "").eliminate();
Assert.assertEquals(2, write.userdata().size());
Assert.assertEquals("one-to-many", write.userdata().get("multiplicity"));
time = (String) write.userdata().get("~create_time");
Assert.assertEquals(createTime, DateUtil.parse(time));
}
Aggregations