use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method shouldFindDocumentLesserEqualsThan.
@Test
public void shouldFindDocumentLesserEqualsThan() {
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where("type").eq("V").build();
entityManager.delete(deleteQuery);
Iterable<DocumentEntity> entitiesSaved = entityManager.insert(getEntitiesWithValues());
List<DocumentEntity> entities = StreamSupport.stream(entitiesSaved.spliterator(), false).collect(Collectors.toList());
DocumentQuery query = select().from(COLLECTION_NAME).where("age").lte(23).and("type").eq("V").build();
List<DocumentEntity> entitiesFound = entityManager.select(query);
assertTrue(entitiesFound.size() == 2);
assertThat(entitiesFound, contains(entities.get(0), entities.get(2)));
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method shouldFindDocument3.
@Test
public void shouldFindDocument3() {
DocumentEntity entity = entityManager.insert(getEntity());
Optional<Document> id = entity.find("_id");
DocumentQuery query = select().from(COLLECTION_NAME).where("name").eq("Poliana").or("city").eq("Salvador").and(id.get().getName()).eq(id.get().get()).build();
List<DocumentEntity> entities = entityManager.select(query);
assertFalse(entities.isEmpty());
assertThat(entities, contains(entity));
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method shouldFindDocumentLesserThan.
@Test
public void shouldFindDocumentLesserThan() {
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where("type").eq("V").build();
entityManager.delete(deleteQuery);
Iterable<DocumentEntity> entitiesSaved = entityManager.insert(getEntitiesWithValues());
List<DocumentEntity> entities = StreamSupport.stream(entitiesSaved.spliterator(), false).collect(Collectors.toList());
DocumentQuery query = select().from(COLLECTION_NAME).where("age").lt(23).and("type").eq("V").build();
List<DocumentEntity> entitiesFound = entityManager.select(query);
assertTrue(entitiesFound.size() == 1);
assertThat(entitiesFound, contains(entities.get(0)));
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method shouldFindDocumentGreaterEqualsThan.
@Test
public void shouldFindDocumentGreaterEqualsThan() {
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where("type").eq("V").build();
entityManager.delete(deleteQuery);
Iterable<DocumentEntity> entitiesSaved = entityManager.insert(getEntitiesWithValues());
List<DocumentEntity> entities = StreamSupport.stream(entitiesSaved.spliterator(), false).collect(Collectors.toList());
DocumentQuery query = select().from(COLLECTION_NAME).where("age").gte(23).and("type").eq("V").build();
List<DocumentEntity> entitiesFound = entityManager.select(query);
assertTrue(entitiesFound.size() == 2);
assertThat(entitiesFound, not(contains(entities.get(0))));
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method getEntitiesWithValues.
private List<DocumentEntity> getEntitiesWithValues() {
DocumentEntity lucas = DocumentEntity.of(COLLECTION_NAME);
lucas.add(Document.of("name", "Lucas"));
lucas.add(Document.of("age", 22));
lucas.add(Document.of("location", "BR"));
lucas.add(Document.of("type", "V"));
DocumentEntity otavio = DocumentEntity.of(COLLECTION_NAME);
otavio.add(Document.of("name", "Otavio"));
otavio.add(Document.of("age", 25));
otavio.add(Document.of("location", "BR"));
otavio.add(Document.of("type", "V"));
DocumentEntity luna = DocumentEntity.of(COLLECTION_NAME);
luna.add(Document.of("name", "Luna"));
luna.add(Document.of("age", 23));
luna.add(Document.of("location", "US"));
luna.add(Document.of("type", "V"));
return asList(lucas, otavio, luna);
}
Aggregations