|
20 | 20 | import org.assertj.core.api.SoftAssertions;
|
21 | 21 | import org.eclipse.jnosql.communication.graph.CommunicationEdge;
|
22 | 22 | import org.eclipse.jnosql.communication.semistructured.CommunicationEntity;
|
| 23 | +import org.eclipse.jnosql.communication.semistructured.CriteriaCondition; |
23 | 24 | import org.eclipse.jnosql.communication.semistructured.DeleteQuery;
|
24 | 25 | import org.eclipse.jnosql.communication.semistructured.Element;
|
25 | 26 | import org.eclipse.jnosql.communication.semistructured.Elements;
|
26 | 27 | import org.eclipse.jnosql.communication.semistructured.SelectQuery;
|
| 28 | +import org.eclipse.jnosql.mapping.semistructured.MappingQuery; |
27 | 29 | import org.junit.jupiter.api.BeforeEach;
|
28 | 30 | import org.junit.jupiter.api.Test;
|
29 | 31 |
|
30 | 32 | import java.time.Duration;
|
| 33 | +import java.util.Collections; |
31 | 34 | import java.util.HashMap;
|
32 | 35 | import java.util.List;
|
33 | 36 | import java.util.Map;
|
@@ -488,6 +491,68 @@ void shouldFindEdgeById() {
|
488 | 491 | assertEquals(edge.target().find("_id").orElseThrow().get(), foundEdge.get().target().find("_id").orElseThrow().get());
|
489 | 492 | }
|
490 | 493 |
|
| 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 | + |
491 | 556 | private CommunicationEntity getEntity() {
|
492 | 557 | CommunicationEntity entity = CommunicationEntity.of(COLLECTION_NAME);
|
493 | 558 | Map<String, Object> map = new HashMap<>();
|
|
0 commit comments