Search in sources :

Example 6 with Document

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

the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameGt.

@Test
public void shouldSelectWhereNameGt() {
    String documentCollection = "documentCollection";
    Number value = 10;
    DocumentDeleteQuery query = delete().from(documentCollection).where("name").gt(value).build();
    DocumentCondition condition = query.getCondition().get();
    Document document = condition.getDocument();
    assertTrue(query.getDocuments().isEmpty());
    assertEquals(documentCollection, query.getDocumentCollection());
    assertEquals(Condition.GREATER_THAN, condition.getCondition());
    assertEquals("name", document.getName());
    assertEquals(value, document.get());
}
Also used : Document(org.jnosql.diana.api.document.Document) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 7 with Document

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

the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameAnd.

@Test
public void shouldSelectWhereNameAnd() {
    String documentCollection = "documentCollection";
    String name = "Ada Lovelace";
    DocumentDeleteQuery query = delete().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 : List(java.util.List) Document(org.jnosql.diana.api.document.Document) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 8 with Document

use of org.jnosql.diana.api.document.Document 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 9 with Document

use of org.jnosql.diana.api.document.Document 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 10 with Document

use of org.jnosql.diana.api.document.Document 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(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)

Aggregations

Document (org.jnosql.diana.api.document.Document)126 Test (org.junit.jupiter.api.Test)102 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)94 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)71 List (java.util.List)41 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)37 ArrayList (java.util.ArrayList)25 DocumentCondition (org.jnosql.diana.api.document.DocumentCondition)25 Arrays.asList (java.util.Arrays.asList)23 HashMap (java.util.HashMap)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 Map (java.util.Map)11 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)11 TypeReference (org.jnosql.diana.api.TypeReference)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 Matchers.contains (org.hamcrest.Matchers.contains)10 DocumentQueryBuilder.select (org.jnosql.diana.api.document.query.DocumentQueryBuilder.select)10 Arrays (java.util.Arrays)8 Optional (java.util.Optional)8 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)8