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());
}
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));
}
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());
}
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));
}
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));
}
Aggregations