use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method createsRegexClauseCorrectly.
// DATAMONGO-338
@Test
void createsRegexClauseCorrectly() {
PartTree tree = new PartTree("findByFirstNameRegex", Person.class);
MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, ".*"), context);
Query query = query(where("firstName").regex(".*"));
assertThat(creator.createQuery()).isEqualTo(query);
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method shouldCreateInClauseWhenUsingContainsOnCollectionLikeProperty.
// DATAMONGO-1075
@Test
void shouldCreateInClauseWhenUsingContainsOnCollectionLikeProperty() {
PartTree tree = new PartTree("findByEmailAddressesContaining", User.class);
MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "dave"), context);
Query query = creator.createQuery();
assertThat(query).isEqualTo(query(where("emailAddresses").in("dave")));
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method createsQueryReferencingADBRefCorrectly.
// DATAMONGO-347
@Test
void createsQueryReferencingADBRefCorrectly() {
User user = new User();
user.id = new ObjectId();
PartTree tree = new PartTree("findByCreator", User.class);
MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, user), context);
Document queryObject = creator.createQuery().getQueryObject();
assertThat(queryObject.get("creator")).isEqualTo(user);
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method notLikeShouldEscapeSourceWhenUsedWithLeadingAndTrailingWildcard.
// DATAMONGO-1424
@Test
void notLikeShouldEscapeSourceWhenUsedWithLeadingAndTrailingWildcard() {
PartTree tree = new PartTree("findByUsernameNotLike", User.class);
ConvertingParameterAccessor accessor = getAccessor(converter, "*fire.fight+*");
Query query = new MongoQueryCreator(tree, accessor, context).createQuery();
assertThat(query.getQueryObject().toJson()).isEqualTo(query(where("username").not().regex(".*\\Qfire.fight+\\E.*")).getQueryObject().toJson());
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method notLikeShouldEscapeSourceWhenUsedWithLeadingWildcard.
// DATAMONGO-1424
@Test
void notLikeShouldEscapeSourceWhenUsedWithLeadingWildcard() {
PartTree tree = new PartTree("findByUsernameNotLike", User.class);
ConvertingParameterAccessor accessor = getAccessor(converter, "*steel.heart+");
Query query = new MongoQueryCreator(tree, accessor, context).createQuery();
assertThat(query.getQueryObject().toJson()).isEqualTo(query(where("username").not().regex(".*\\Qsteel.heart+\\E")).getQueryObject().toJson());
}
Aggregations