Search in sources :

Example 1 with DocumentQuery

use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana by eclipse.

the class DefaultSelectQueryBuilderTest method shouldSelectStart.

@Test
public void shouldSelectStart() {
    String documentCollection = "documentCollection";
    DocumentQuery query = select().from(documentCollection).start(10).build();
    assertTrue(query.getDocuments().isEmpty());
    assertFalse(query.getCondition().isPresent());
    assertEquals(documentCollection, query.getDocumentCollection());
    assertEquals(10L, query.getFirstResult());
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Test(org.junit.jupiter.api.Test)

Example 2 with DocumentQuery

use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana by eclipse.

the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameOr.

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

Example 3 with DocumentQuery

use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana by eclipse.

the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameNot.

@Test
public void shouldSelectWhereNameNot() {
    String documentCollection = "documentCollection";
    String name = "Ada Lovelace";
    DocumentQuery query = select().from(documentCollection).where("name").not().eq(name).build();
    DocumentCondition condition = query.getCondition().get();
    Document column = condition.getDocument();
    DocumentCondition negate = column.get(DocumentCondition.class);
    assertTrue(query.getDocuments().isEmpty());
    assertEquals(documentCollection, query.getDocumentCollection());
    assertEquals(Condition.NOT, condition.getCondition());
    assertEquals(Condition.EQUALS, negate.getCondition());
    assertEquals("name", negate.getDocument().getName());
    assertEquals(name, negate.getDocument().get());
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Document(org.jnosql.diana.api.document.Document) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 4 with DocumentQuery

use of org.jnosql.diana.api.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(org.jnosql.diana.api.document.DocumentQuery) Test(org.junit.jupiter.api.Test)

Example 5 with DocumentQuery

use of org.jnosql.diana.api.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(), contains(Sort.of("name", ASC)));
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)201 Test (org.junit.jupiter.api.Test)186 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)95 Document (org.jnosql.diana.api.document.Document)84 List (java.util.List)50 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)46 Person (org.jnosql.artemis.model.Person)37 DocumentCondition (org.jnosql.diana.api.document.DocumentCondition)35 Arrays.asList (java.util.Arrays.asList)27 ArrayList (java.util.ArrayList)21 Duration (java.time.Duration)20 DocumentQueryBuilder.select (org.jnosql.diana.api.document.query.DocumentQueryBuilder.select)20 Optional (java.util.Optional)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)18 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)18 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)17 DocumentQueryBuilder.delete (org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete)17 BeforeEach (org.junit.jupiter.api.BeforeEach)17 Consumer (java.util.function.Consumer)16 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)16