use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method shouldCreateRegexWhenUsingNotContainsOnStringProperty.
// DATAMONGO-1075, DATAMONGO-1425
@Test
void shouldCreateRegexWhenUsingNotContainsOnStringProperty() {
PartTree tree = new PartTree("findByUsernameNotContaining", User.class);
MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "thew"), context);
Query query = creator.createQuery();
assertThat(query.getQueryObject().toJson()).isEqualTo(query(where("username").not().regex(".*thew.*")).getQueryObject().toJson());
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method createsExistsClauseCorrectly.
// DATAMONGO-338
@Test
void createsExistsClauseCorrectly() {
PartTree tree = new PartTree("findByAgeExists", Person.class);
MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, true), context);
Query query = query(where("age").exists(true));
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 createsRegexQueryForPatternCorrectly.
// DATAMONGO-2003
@Test
void createsRegexQueryForPatternCorrectly() {
PartTree tree = new PartTree("findByFirstNameRegex", Person.class);
MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, Pattern.compile(".*")), context);
assertThat(creator.createQuery()).isEqualTo(query(where("firstName").regex(".*")));
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method likeShouldBeTreatedCorrectlyWhenUsedWithWildcardOnly.
// DATAMONGO-1232
@Test
void likeShouldBeTreatedCorrectlyWhenUsedWithWildcardOnly() {
PartTree tree = new PartTree("findByUsernameLike", User.class);
ConvertingParameterAccessor accessor = getAccessor(converter, "*");
Query query = new MongoQueryCreator(tree, accessor, context).createQuery();
assertThat(query).isEqualTo(query(where("username").regex(".*")));
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-jdbc by spring-projects.
the class ParameterMetadataProviderUnitTests method getParameterMetadata.
private ParameterMetadata getParameterMetadata(String methodName, Object value) throws Exception {
Method method = UserRepository.class.getMethod(methodName, String.class);
ParameterMetadataProvider provider = new ParameterMetadataProvider(new RelationalParametersParameterAccessor(new RelationalQueryMethod(method, new DefaultRepositoryMetadata(UserRepository.class), new SpelAwareProxyProjectionFactory()), new Object[] { value }));
PartTree tree = new PartTree(methodName, User.class);
return provider.next(tree.getParts().iterator().next());
}
Aggregations