use of jakarta.nosql.TypeReference in project jnosql-diana by eclipse.
the class DefaultValueTest method shouldConvertToList.
@Test
public void shouldConvertToList() {
Value value = Value.of(Arrays.asList(10, 20, 30));
assertThat(value.get(new TypeReference<List<String>>() {
}), containsInAnyOrder("10", "20", "30"));
assertThat(value.get(new TypeReference<List<BigInteger>>() {
}), containsInAnyOrder(BigInteger.TEN, BigInteger.valueOf(20L), BigInteger.valueOf(30L)));
}
use of jakarta.nosql.TypeReference in project jnosql-diana by eclipse.
the class DocumentTest method shouldReturnGetType.
@Test
public void shouldReturnGetType() {
Value value = Value.of("text");
Document document = Document.of("name", value);
TypeReference<List<String>> typeReference = new TypeReference<List<String>>() {
};
assertEquals(value.get(typeReference), document.get(typeReference));
}
use of jakarta.nosql.TypeReference in project jnosql-diana by eclipse.
the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameBetween.
@Test
public void shouldSelectWhereNameBetween() {
String documentCollection = "documentCollection";
Number valueA = 10;
Number valueB = 20;
DocumentDeleteQuery query = delete().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));
}
use of jakarta.nosql.TypeReference 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.TypeReference 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