Search in sources :

Example 76 with Document

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

the class DefaultDeleteQueryBuilderTest method shouldDeleteNegate.

@Test
public void shouldDeleteNegate() {
    String columnFamily = "columnFamily";
    DocumentDeleteQuery query = delete().from(columnFamily).where("city").not().eq("Assis").and("name").not().eq("Lucas").build();
    DocumentCondition condition = query.getCondition().orElseThrow(RuntimeException::new);
    assertEquals(columnFamily, query.getDocumentCollection());
    Document column = condition.getDocument();
    List<DocumentCondition> conditions = column.get(new TypeReference<List<DocumentCondition>>() {
    });
    assertEquals(Condition.AND, condition.getCondition());
    assertThat(conditions, containsInAnyOrder(eq(Document.of("city", "Assis")).negate(), eq(Document.of("name", "Lucas")).negate()));
}
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 77 with Document

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

the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameNot.

@Test
public void shouldSelectWhereNameNot() {
    String documentCollection = "documentCollection";
    String name = "Ada Lovelace";
    DocumentDeleteQuery query = delete().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 : 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 78 with Document

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

the class DefaultSelectQueryBuilderTest method shouldSelectNegate.

@Test
public void shouldSelectNegate() {
    String columnFamily = "columnFamily";
    DocumentQuery query = select().from(columnFamily).where("city").not().eq("Assis").and("name").not().eq("Lucas").build();
    DocumentCondition condition = query.getCondition().orElseThrow(RuntimeException::new);
    assertEquals(columnFamily, query.getDocumentCollection());
    Document column = condition.getDocument();
    List<DocumentCondition> conditions = column.get(new TypeReference<List<DocumentCondition>>() {
    });
    assertEquals(Condition.AND, condition.getCondition());
    assertThat(conditions, containsInAnyOrder(eq(Document.of("city", "Assis")).negate(), eq(Document.of("name", "Lucas")).negate()));
}
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 79 with Document

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

the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameBetween.

@Test
public void shouldSelectWhereNameBetween() {
    String documentCollection = "documentCollection";
    Number valueA = 10;
    Number valueB = 20;
    DocumentQuery query = select().from(documentCollection).where("name").between(valueA, valueB).build();
    DocumentCondition condition = query.getCondition().get();
    Document document = condition.getDocument();
    assertTrue(query.getDocuments().isEmpty());
    assertEquals(documentCollection, query.getDocumentCollection());
    assertEquals(Condition.BETWEEN, condition.getCondition());
    assertEquals("name", document.getName());
    assertThat(document.get(new TypeReference<List<Number>>() {
    }), Matchers.contains(10, 20));
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) TypeReference(org.jnosql.diana.api.TypeReference) Document(org.jnosql.diana.api.document.Document) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 80 with Document

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

the class MongoDBDocumentCollectionManagerTest method shouldFindDocument.

@Test
public void shouldFindDocument() {
    DocumentEntity entity = entityManager.insert(getEntity());
    Optional<Document> id = entity.find("_id");
    DocumentQuery query = select().from(COLLECTION_NAME).where("_id").eq(id.get().get()).build();
    List<DocumentEntity> entities = entityManager.select(query);
    assertFalse(entities.isEmpty());
    assertThat(entities, contains(entity));
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Document(org.jnosql.diana.api.document.Document) 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