use of org.jnosql.diana.api.TypeReference 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));
}
use of org.jnosql.diana.api.TypeReference in project jnosql-artemis by eclipse.
the class DefaultDocumentEntityConverterTest method shouldConvertEntityFromDocumentEntity2.
@Test
public void shouldConvertEntityFromDocumentEntity2() {
Movie movie = new Movie("Matriz", 2012, singleton("Actor"));
Director director = Director.builderDiretor().withAge(12).withId(12).withName("Otavio").withPhones(Arrays.asList("234", "2342")).withMovie(movie).build();
DocumentEntity entity = converter.toDocument(director);
assertEquals(5, entity.size());
assertEquals(getValue(entity.find("name")), director.getName());
assertEquals(getValue(entity.find("age")), director.getAge());
assertEquals(getValue(entity.find("_id")), director.getId());
assertEquals(getValue(entity.find("phones")), director.getPhones());
Document subdocument = entity.find("movie").get();
List<Document> documents = subdocument.get(new TypeReference<List<Document>>() {
});
assertEquals(3, documents.size());
assertEquals("movie", subdocument.getName());
assertEquals(movie.getTitle(), getValue(documents.stream().filter(d -> "title".equals(d.getName())).findFirst()));
assertEquals(movie.getYear(), getValue(documents.stream().filter(d -> "year".equals(d.getName())).findFirst()));
assertEquals(movie.getActors(), getValue(documents.stream().filter(d -> "actors".equals(d.getName())).findFirst()));
}
Aggregations