Search in sources :

Example 76 with DocumentCondition

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

the class DefaultDocumentConditionTest method shouldCreateNegationCondition.

@Test
public void shouldCreateNegationCondition() {
    Document age = Document.of("age", 26);
    DocumentCondition condition = DefaultDocumentCondition.of(age, Condition.GREATER_THAN);
    DocumentCondition negate = condition.negate();
    Document negateDocument = negate.getDocument();
    assertEquals(Condition.NOT, negate.getCondition());
    assertEquals(Condition.NOT.getNameField(), negateDocument.getName());
    assertEquals(DefaultDocumentCondition.of(age, Condition.GREATER_THAN), negateDocument.getValue().get());
}
Also used : Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 77 with DocumentCondition

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

the class DefaultDocumentConditionTest method shouldAppendOr.

@Test
public void shouldAppendOr() {
    DocumentCondition eq = DocumentCondition.eq(Document.of("name", "otavio"));
    DocumentCondition gt = DocumentCondition.gt(Document.of("age", 10));
    DocumentCondition and = DocumentCondition.or(eq, gt);
    assertEquals(Condition.OR, and.getCondition());
    List<DocumentCondition> conditions = and.getDocument().get(new TypeReference<List<DocumentCondition>>() {
    });
    assertThat(conditions, Matchers.containsInAnyOrder(eq, gt));
}
Also used : List(java.util.List) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 78 with DocumentCondition

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

the class DefaultDocumentConditionTest method shouldCreateAnInstance.

@Test
public void shouldCreateAnInstance() {
    Document name = Document.of("name", "Otavio");
    DocumentCondition condition = DefaultDocumentCondition.of(name, Condition.EQUALS);
    assertNotNull(condition);
    assertEquals(name, condition.getDocument());
    assertEquals(Condition.EQUALS, condition.getCondition());
}
Also used : Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 79 with DocumentCondition

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

the class DefaultDocumentConditionTest method shouldOr.

@Test
public void shouldOr() {
    DocumentCondition eq = DocumentCondition.eq(Document.of("name", "otavio"));
    DocumentCondition gt = DocumentCondition.gt(Document.of("age", 10));
    DocumentCondition lte = DocumentCondition.lte(Document.of("salary", 10_000.00));
    DocumentCondition or = eq.or(gt);
    List<DocumentCondition> conditions = or.getDocument().get(new TypeReference<List<DocumentCondition>>() {
    });
    assertEquals(Condition.OR, or.getCondition());
    assertThat(conditions, Matchers.containsInAnyOrder(eq, gt));
    DocumentCondition result = or.or(lte);
    assertEquals(Condition.OR, result.getCondition());
    assertThat(result.getDocument().get(new TypeReference<List<DocumentCondition>>() {
    }), Matchers.containsInAnyOrder(eq, gt, lte));
}
Also used : List(java.util.List) TypeReference(jakarta.nosql.TypeReference) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 80 with DocumentCondition

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

the class DefaultDocumentConditionTest method shouldCreateAndCondition.

@Test
public void shouldCreateAndCondition() {
    Document age = Document.of("age", 26);
    Document name = Document.of("name", "Otavio");
    DocumentCondition condition1 = DefaultDocumentCondition.of(name, Condition.EQUALS);
    DocumentCondition condition2 = DefaultDocumentCondition.of(age, Condition.GREATER_THAN);
    DocumentCondition and = condition1.and(condition2);
    Document andDocument = and.getDocument();
    assertEquals(Condition.AND, and.getCondition());
    assertEquals(Condition.AND.getNameField(), andDocument.getName());
    assertThat(andDocument.getValue().get(new TypeReference<List<DocumentCondition>>() {
    }), Matchers.containsInAnyOrder(condition1, condition2));
}
Also used : TypeReference(jakarta.nosql.TypeReference) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentCondition (jakarta.nosql.document.DocumentCondition)132 Test (org.junit.jupiter.api.Test)68 DocumentQuery (jakarta.nosql.document.DocumentQuery)64 Document (jakarta.nosql.document.Document)60 List (java.util.List)37 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)37 ValueSource (org.junit.jupiter.params.provider.ValueSource)37 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)33 Person (jakarta.nosql.tck.entities.Person)17 Pagination (jakarta.nosql.mapping.Pagination)13 DocumentPreparedStatement (jakarta.nosql.document.DocumentPreparedStatement)10 TypeReference (jakarta.nosql.TypeReference)7 Params (jakarta.nosql.Params)6 DocumentEntity (jakarta.nosql.document.DocumentEntity)6 DocumentObserverParser (jakarta.nosql.document.DocumentObserverParser)5 QueryException (jakarta.nosql.QueryException)4 ServiceLoaderProvider (jakarta.nosql.ServiceLoaderProvider)4 DocumentCollectionManager (jakarta.nosql.document.DocumentCollectionManager)4 DocumentQueryParams (jakarta.nosql.document.DocumentQueryParams)4 SelectQueryConverter (jakarta.nosql.document.SelectQueryConverter)4