Search in sources :

Example 51 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana-driver by eclipse.

the class DefaultSolrDocumentCollectionManagerTest method shouldFindDocumentLike.

@Test
public void shouldFindDocumentLike() {
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).build();
    entityManager.delete(deleteQuery);
    Iterable<DocumentEntity> entities = entityManager.insert(getEntitiesWithValues());
    DocumentQuery query = select().from(COLLECTION_NAME).where("name").like("Lu*").and("type").eq("V").build();
    List<DocumentEntity> entitiesFound = entityManager.select(query).collect(Collectors.toList());
    assertEquals(2, entitiesFound.size());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 52 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana-driver by eclipse.

the class DefaultSolrDocumentCollectionManagerTest method shouldFindDocumentIn.

@Test
public void shouldFindDocumentIn() {
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).build();
    entityManager.delete(deleteQuery);
    Iterable<DocumentEntity> entitiesSaved = entityManager.insert(getEntitiesWithValues());
    List<DocumentEntity> entities = StreamSupport.stream(entitiesSaved.spliterator(), false).collect(Collectors.toList());
    DocumentQuery query = select().from(COLLECTION_NAME).where("location").in(asList("BR", "US")).and("type").eq("V").build();
    assertEquals(3, entityManager.select(query).collect(Collectors.toList()).size());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 53 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana-driver by eclipse.

the class DefaultSolrDocumentCollectionManagerTest method shouldRemoveEntity.

@Test
public void shouldRemoveEntity() {
    DocumentEntity documentEntity = entityManager.insert(getEntity());
    Optional<Document> id = documentEntity.find(ID);
    DocumentQuery query = select().from(COLLECTION_NAME).where(ID).eq(id.get().get()).build();
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(ID).eq(id.get().get()).build();
    entityManager.delete(deleteQuery);
    assertTrue(entityManager.select(query).collect(Collectors.toList()).isEmpty());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) Document(jakarta.nosql.document.Document) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 54 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana-driver by eclipse.

the class DefaultSolrDocumentCollectionManagerTest method shouldFindDocumentSort.

@Test
public void shouldFindDocumentSort() {
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).build();
    entityManager.delete(deleteQuery);
    Iterable<DocumentEntity> entitiesSaved = entityManager.insert(getEntitiesWithValues());
    List<DocumentEntity> entities = StreamSupport.stream(entitiesSaved.spliterator(), false).collect(Collectors.toList());
    DocumentQuery query = select().from(COLLECTION_NAME).where("age").gt(22).and("type").eq("V").orderBy("age").asc().build();
    List<DocumentEntity> entitiesFound = entityManager.select(query).collect(Collectors.toList());
    List<Integer> ages = entitiesFound.stream().map(e -> e.find("age").get().get(Integer.class)).collect(Collectors.toList());
    assertThat(ages, contains(22, 23, 25));
    query = select().from(COLLECTION_NAME).where("age").gt(22).and("type").eq("V").orderBy("age").desc().build();
    entitiesFound = entityManager.select(query).collect(Collectors.toList());
    ages = entitiesFound.stream().map(e -> e.find("age").get().get(Integer.class)).collect(Collectors.toList());
    assertThat(ages, contains(25, 23, 22));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) DocumentQuery.select(jakarta.nosql.document.DocumentQuery.select) Date(java.util.Date) Matchers.not(org.hamcrest.Matchers.not) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) HashMap(java.util.HashMap) Random(java.util.Random) ArrayList(java.util.ArrayList) DocumentQuery(jakarta.nosql.document.DocumentQuery) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BeforeAll(org.junit.jupiter.api.BeforeAll) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) Map(java.util.Map) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) StreamSupport(java.util.stream.StreamSupport) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Documents(org.eclipse.jnosql.communication.document.Documents) Document(jakarta.nosql.document.Document) DocumentEntity(jakarta.nosql.document.DocumentEntity) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) DocumentDeleteQuery.delete(jakarta.nosql.document.DocumentDeleteQuery.delete) Matchers.contains(org.hamcrest.Matchers.contains) LocalDate(java.time.LocalDate) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 55 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana-driver by eclipse.

the class DefaultSolrDocumentCollectionManagerTest method shouldFindDocumentGreaterEqualsThan.

@Test
public void shouldFindDocumentGreaterEqualsThan() {
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).build();
    entityManager.delete(deleteQuery);
    Iterable<DocumentEntity> entitiesSaved = entityManager.insert(getEntitiesWithValues());
    List<DocumentEntity> entities = StreamSupport.stream(entitiesSaved.spliterator(), false).collect(Collectors.toList());
    DocumentQuery query = select().from(COLLECTION_NAME).where("age").gte(23).and("type").eq("V").build();
    List<DocumentEntity> entitiesFound = entityManager.select(query).collect(Collectors.toList());
    assertEquals(2, entitiesFound.size());
    assertThat(entitiesFound, not(contains(entities.get(0))));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)114 Test (org.junit.jupiter.api.Test)79 DocumentEntity (jakarta.nosql.document.DocumentEntity)45 DocumentQuery (jakarta.nosql.document.DocumentQuery)43 Document (jakarta.nosql.document.Document)37 DocumentCondition (jakarta.nosql.document.DocumentCondition)33 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 ValueSource (org.junit.jupiter.params.provider.ValueSource)20 List (java.util.List)15 Person (jakarta.nosql.tck.entities.Person)12 Collectors (java.util.stream.Collectors)7 Params (jakarta.nosql.Params)5 DocumentDeleteQueryParams (jakarta.nosql.document.DocumentDeleteQueryParams)5 Duration (java.time.Duration)5 HashMap (java.util.HashMap)5 Optional (java.util.Optional)5 StreamSupport (java.util.stream.StreamSupport)5 DocumentCollectionManager (jakarta.nosql.document.DocumentCollectionManager)4 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)4 Map (java.util.Map)4