|
18 | 18 | import org.apache.tinkerpop.gremlin.structure.Graph; |
19 | 19 | import org.assertj.core.api.Assertions; |
20 | 20 | import org.assertj.core.api.SoftAssertions; |
| 21 | +import org.eclipse.jnosql.communication.graph.CommunicationEdge; |
21 | 22 | import org.eclipse.jnosql.communication.semistructured.CommunicationEntity; |
22 | 23 | import org.eclipse.jnosql.communication.semistructured.DeleteQuery; |
23 | 24 | import org.eclipse.jnosql.communication.semistructured.Element; |
@@ -427,8 +428,66 @@ void shouldFindAllByFields() { |
427 | 428 | }); |
428 | 429 | } |
429 | 430 |
|
| 431 | + @Test |
| 432 | + void shouldCreateEdge() { |
| 433 | + var person1 = entityManager.insert(getEntity()); |
| 434 | + var person2 = entityManager.insert(getEntity()); |
| 435 | + |
| 436 | + String label = "FRIEND"; |
| 437 | + Map<String, Object> properties = Map.of("since", 2023); |
| 438 | + |
| 439 | + var edge = entityManager.edge(person1, label, person2, properties); |
| 440 | + |
| 441 | + assertNotNull(edge); |
| 442 | + assertEquals(label, edge.label()); |
| 443 | + assertEquals(person1.find("_id").orElseThrow().get(), edge.source().find("_id").orElseThrow().get()); |
| 444 | + assertEquals(person2.find("_id").orElseThrow().get(), edge.target().find("_id").orElseThrow().get()); |
| 445 | + assertEquals(properties, edge.properties()); |
| 446 | + } |
| 447 | + |
| 448 | + @Test |
| 449 | + void shouldRemoveEdge() { |
| 450 | + var person1 = entityManager.insert(getEntity()); |
| 451 | + var person2 = entityManager.insert(getEntity()); |
| 452 | + |
| 453 | + entityManager.edge(person1, "FRIEND", person2, Map.of()); |
| 454 | + |
| 455 | + entityManager.remove(person1, "FRIEND", person2); |
| 456 | + |
| 457 | + var edgesQuery = select().from(COLLECTION_NAME).where("_id").eq(person1.find("_id").orElseThrow().get()).build(); |
| 458 | + var edges = entityManager.select(edgesQuery).toList(); |
| 459 | + |
| 460 | + assertThat(edges).isEmpty(); |
| 461 | + } |
| 462 | + |
| 463 | + @Test |
| 464 | + void shouldDeleteEdgeById() { |
| 465 | + var person1 = entityManager.insert(getEntity()); |
| 466 | + var person2 = entityManager.insert(getEntity()); |
430 | 467 |
|
| 468 | + var edge = entityManager.edge(person1, "FRIEND", person2, Map.of()); |
| 469 | + |
| 470 | + entityManager.deleteEdge(edge.id()); |
| 471 | + |
| 472 | + Optional<CommunicationEdge> foundEdge = entityManager.findEdgeById(edge.id()); |
| 473 | + assertFalse(foundEdge.isPresent()); |
| 474 | + } |
431 | 475 |
|
| 476 | + @Test |
| 477 | + void shouldFindEdgeById() { |
| 478 | + var person1 = entityManager.insert(getEntity()); |
| 479 | + var person2 = entityManager.insert(getEntity()); |
| 480 | + |
| 481 | + var edge = entityManager.edge(person1, "FRIEND", person2, Map.of("since", 2023)); |
| 482 | + |
| 483 | + Optional<CommunicationEdge> foundEdge = entityManager.findEdgeById(edge.id()); |
| 484 | + |
| 485 | + assertTrue(foundEdge.isPresent()); |
| 486 | + assertEquals(edge.id(), foundEdge.get().id()); |
| 487 | + assertEquals(edge.label(), foundEdge.get().label()); |
| 488 | + assertEquals(edge.source().find("_id").orElseThrow().get(), foundEdge.get().source().find("_id").orElseThrow().get()); |
| 489 | + assertEquals(edge.target().find("_id").orElseThrow().get(), foundEdge.get().target().find("_id").orElseThrow().get()); |
| 490 | + } |
432 | 491 |
|
433 | 492 | private CommunicationEntity getEntity() { |
434 | 493 | CommunicationEntity entity = CommunicationEntity.of(COLLECTION_NAME); |
|
0 commit comments