Skip to content

Commit 67ef67e

Browse files
committed
test: include query on tinkerpop
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
1 parent e65c520 commit 67ef67e

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@
2020
import org.assertj.core.api.SoftAssertions;
2121
import org.eclipse.jnosql.communication.graph.CommunicationEdge;
2222
import org.eclipse.jnosql.communication.semistructured.CommunicationEntity;
23+
import org.eclipse.jnosql.communication.semistructured.CriteriaCondition;
2324
import org.eclipse.jnosql.communication.semistructured.DeleteQuery;
2425
import org.eclipse.jnosql.communication.semistructured.Element;
2526
import org.eclipse.jnosql.communication.semistructured.Elements;
2627
import org.eclipse.jnosql.communication.semistructured.SelectQuery;
28+
import org.eclipse.jnosql.mapping.semistructured.MappingQuery;
2729
import org.junit.jupiter.api.BeforeEach;
2830
import org.junit.jupiter.api.Test;
2931

3032
import java.time.Duration;
33+
import java.util.Collections;
3134
import java.util.HashMap;
3235
import java.util.List;
3336
import java.util.Map;
@@ -488,6 +491,68 @@ void shouldFindEdgeById() {
488491
assertEquals(edge.target().find("_id").orElseThrow().get(), foundEdge.get().target().find("_id").orElseThrow().get());
489492
}
490493

494+
@Test
495+
void shouldFindContains() {
496+
var entity = getEntity();
497+
498+
entityManager.insert(entity);
499+
var query = new MappingQuery(Collections.emptyList(), 0L, 0L, CriteriaCondition.contains(Element.of("name",
500+
"lia")), COLLECTION_NAME, Collections.emptyList());
501+
502+
var result = entityManager.select(query).toList();
503+
SoftAssertions.assertSoftly(softly -> {
504+
softly.assertThat(result).hasSize(1);
505+
softly.assertThat(result.get(0).find("name").orElseThrow().get(String.class)).isEqualTo("Poliana");
506+
});
507+
}
508+
509+
@Test
510+
void shouldStartsWith() {
511+
var entity = getEntity();
512+
513+
entityManager.insert(entity);
514+
var query = new MappingQuery(Collections.emptyList(), 0L, 0L, CriteriaCondition.startsWith(Element.of("name",
515+
"Pol")), COLLECTION_NAME, Collections.emptyList());
516+
517+
var result = entityManager.select(query).toList();
518+
SoftAssertions.assertSoftly(softly -> {
519+
softly.assertThat(result).hasSize(1);
520+
softly.assertThat(result.get(0).find("name").orElseThrow().get(String.class)).isEqualTo("Poliana");
521+
});
522+
}
523+
524+
@Test
525+
void shouldEndsWith() {
526+
var entity = getEntity();
527+
528+
entityManager.insert(entity);
529+
var query = new MappingQuery(Collections.emptyList(), 0L, 0L, CriteriaCondition.endsWith(Element.of("name",
530+
"ana")), COLLECTION_NAME, Collections.emptyList());
531+
532+
var result = entityManager.select(query).toList();
533+
SoftAssertions.assertSoftly(softly -> {
534+
softly.assertThat(result).hasSize(1);
535+
softly.assertThat(result.get(0).find("name").orElseThrow().get(String.class)).isEqualTo("Poliana");
536+
});
537+
}
538+
539+
@Test
540+
void shouldFindDocumentLike() {
541+
DeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where("type").eq("V").build();
542+
entityManager.delete(deleteQuery);
543+
Iterable<CommunicationEntity> entitiesSaved = entityManager.insert(getEntitiesWithValues());
544+
List<CommunicationEntity> entities = StreamSupport.stream(entitiesSaved.spliterator(), false).toList();
545+
546+
var query = select().from(COLLECTION_NAME)
547+
.where("name").like("Lu%")
548+
.and("type").eq("V")
549+
.build();
550+
551+
List<CommunicationEntity> entitiesFound = entityManager.select(query).collect(Collectors.toList());
552+
assertEquals(2, entitiesFound.size());
553+
assertThat(entitiesFound).contains(entities.get(0), entities.get(2));
554+
}
555+
491556
private CommunicationEntity getEntity() {
492557
CommunicationEntity entity = CommunicationEntity.of(COLLECTION_NAME);
493558
Map<String, Object> map = new HashMap<>();

0 commit comments

Comments
 (0)