Search in sources :

Example 6 with Document

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

the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameEq.

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

Example 7 with Document

use of jakarta.nosql.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(jakarta.nosql.document.DocumentQuery) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 8 with Document

use of jakarta.nosql.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(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 9 with Document

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

the class DocumentParamsTest method shouldSetParameter.

@Test
public void shouldSetParameter() {
    Params params = Params.newParams();
    Value name = params.add("name");
    Document document = Document.of("name", name);
    params.bind("name", "Ada Lovelace");
    assertEquals("Ada Lovelace", document.get());
    params.bind("name", "Diana");
    assertEquals("Diana", document.get());
}
Also used : Value(jakarta.nosql.Value) Params(jakarta.nosql.Params) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 10 with Document

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

the class DocumentTest method shouldReturnGetObject.

@Test
public void shouldReturnGetObject() {
    Value value = Value.of("text");
    Document document = Document.of("name", value);
    assertEquals(value.get(), document.get());
}
Also used : Value(jakarta.nosql.Value) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Aggregations

Document (jakarta.nosql.document.Document)196 Test (org.junit.jupiter.api.Test)140 DocumentEntity (jakarta.nosql.document.DocumentEntity)115 DocumentQuery (jakarta.nosql.document.DocumentQuery)93 DocumentCondition (jakarta.nosql.document.DocumentCondition)60 List (java.util.List)60 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)44 Arrays.asList (java.util.Arrays.asList)33 ArrayList (java.util.ArrayList)31 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 ValueSource (org.junit.jupiter.params.provider.ValueSource)26 TypeReference (jakarta.nosql.TypeReference)21 HashMap (java.util.HashMap)20 Map (java.util.Map)17 Collectors (java.util.stream.Collectors)16 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)16 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)16 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)14 Matchers.contains (org.hamcrest.Matchers.contains)14 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)14