Search in sources :

Example 6 with DocumentQuery

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

the class DefaultSelectQueryBuilderTest method shouldSelectOrderAsc.

@Test
public void shouldSelectOrderAsc() {
    String documentCollection = "documentCollection";
    DocumentQuery query = select().from(documentCollection).orderBy("name").asc().build();
    assertTrue(query.getDocuments().isEmpty());
    assertFalse(query.getCondition().isPresent());
    assertEquals(documentCollection, query.getDocumentCollection());
    assertThat(query.getSorts(), Matchers.contains(Sort.of("name", SortType.ASC)));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Test(org.junit.jupiter.api.Test)

Example 7 with DocumentQuery

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

the class DefaultSelectQueryBuilderTest method shouldSelectOrderDesc.

@Test
public void shouldSelectOrderDesc() {
    String documentCollection = "documentCollection";
    DocumentQuery query = select().from(documentCollection).orderBy("name").desc().build();
    assertTrue(query.getDocuments().isEmpty());
    assertFalse(query.getCondition().isPresent());
    assertEquals(documentCollection, query.getDocumentCollection());
    assertThat(query.getSorts(), contains(Sort.of("name", SortType.DESC)));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Test(org.junit.jupiter.api.Test)

Example 8 with DocumentQuery

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

the class DefaultSelectQueryBuilderTest method shouldSelect.

@Test
public void shouldSelect() {
    String documentCollection = "documentCollection";
    DocumentQuery query = select().from(documentCollection).build();
    assertTrue(query.getDocuments().isEmpty());
    assertFalse(query.getCondition().isPresent());
    assertEquals(documentCollection, query.getDocumentCollection());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Test(org.junit.jupiter.api.Test)

Example 9 with DocumentQuery

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

the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameAnd.

@Test
public void shouldSelectWhereNameAnd() {
    String documentCollection = "documentCollection";
    String name = "Ada Lovelace";
    DocumentQuery query = select().from(documentCollection).where("name").eq(name).and("age").gt(10).build();
    DocumentCondition condition = query.getCondition().get();
    Document document = condition.getDocument();
    List<DocumentCondition> conditions = document.get(new TypeReference<List<DocumentCondition>>() {
    });
    assertEquals(Condition.AND, condition.getCondition());
    assertThat(conditions, Matchers.containsInAnyOrder(eq(Document.of("name", name)), DocumentCondition.gt(Document.of("age", 10))));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) List(java.util.List) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 10 with DocumentQuery

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

the class DefaultSelectQueryBuilderTest method shouldSelectLimit.

@Test
public void shouldSelectLimit() {
    String documentCollection = "documentCollection";
    DocumentQuery query = select().from(documentCollection).limit(10).build();
    assertTrue(query.getDocuments().isEmpty());
    assertFalse(query.getCondition().isPresent());
    assertEquals(documentCollection, query.getDocumentCollection());
    assertEquals(10L, query.getLimit());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentQuery (jakarta.nosql.document.DocumentQuery)292 Test (org.junit.jupiter.api.Test)234 DocumentEntity (jakarta.nosql.document.DocumentEntity)123 Document (jakarta.nosql.document.Document)98 DocumentCondition (jakarta.nosql.document.DocumentCondition)64 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)55 Person (jakarta.nosql.tck.entities.Person)50 List (java.util.List)50 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)44 Arrays.asList (java.util.Arrays.asList)34 ValueSource (org.junit.jupiter.params.provider.ValueSource)30 Pagination (jakarta.nosql.mapping.Pagination)27 ArrayList (java.util.ArrayList)26 Collectors (java.util.stream.Collectors)19 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)18 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)16 Matchers.contains (org.hamcrest.Matchers.contains)16 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)16 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)16 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)16