Skip to content

Commit 1fd83f0

Browse files
committed
test: generate entity with tinkerpop
Signed-off-by: Otavio Santana <[email protected]>
1 parent 3b34c2b commit 1fd83f0

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

jnosql-tinkerpop/src/test/java/org/eclipse/jnosql/databases/tinkerpop/communication/DefaultTinkerpopGraphDatabaseManagerTest.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.apache.tinkerpop.gremlin.structure.Graph;
1919
import org.assertj.core.api.Assertions;
2020
import org.assertj.core.api.SoftAssertions;
21+
import org.eclipse.jnosql.communication.graph.CommunicationEdge;
2122
import org.eclipse.jnosql.communication.semistructured.CommunicationEntity;
2223
import org.eclipse.jnosql.communication.semistructured.DeleteQuery;
2324
import org.eclipse.jnosql.communication.semistructured.Element;
@@ -427,8 +428,66 @@ void shouldFindAllByFields() {
427428
});
428429
}
429430

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());
430467

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+
}
431475

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+
}
432491

433492
private CommunicationEntity getEntity() {
434493
CommunicationEntity entity = CommunicationEntity.of(COLLECTION_NAME);

0 commit comments

Comments
 (0)