use of org.springframework.data.domain.ExampleMatcher in project spring-data-mongodb by spring-projects.
the class UntypedExampleMatcherUnitTests method shouldCompareUsingHashCodeAndEquals.
// DATAMONGO-1768
@Test
public void shouldCompareUsingHashCodeAndEquals() {
matcher = //
UntypedExampleMatcher.matching().withIgnorePaths("foo", "bar", //
"baz").withNullHandler(//
NullHandler.IGNORE).withIgnoreCase(//
"ignored-case").withMatcher("hello", //
ExampleMatcher.GenericPropertyMatchers.contains().caseSensitive()).withMatcher("world", matcher -> matcher.endsWith());
ExampleMatcher sameAsMatcher = //
UntypedExampleMatcher.matching().withIgnorePaths("foo", "bar", //
"baz").withNullHandler(//
NullHandler.IGNORE).withIgnoreCase(//
"ignored-case").withMatcher("hello", //
ExampleMatcher.GenericPropertyMatchers.contains().caseSensitive()).withMatcher("world", matcher -> matcher.endsWith());
ExampleMatcher different = //
UntypedExampleMatcher.matching().withIgnorePaths("foo", "bar", //
"baz").withNullHandler(//
NullHandler.IGNORE).withMatcher("hello", ExampleMatcher.GenericPropertyMatchers.contains().ignoreCase());
assertThat(matcher.hashCode()).isEqualTo(sameAsMatcher.hashCode());
assertThat(matcher.hashCode()).isNotEqualTo(different.hashCode());
assertThat(matcher).isEqualTo(sameAsMatcher);
assertThat(matcher).isNotEqualTo(different);
}
use of org.springframework.data.domain.ExampleMatcher in project spring-data-mongodb by spring-projects.
the class UntypedExampleMatcherUnitTests method withCreatesNewInstance.
// DATAMONGO-1768
@Test
public void withCreatesNewInstance() {
matcher = UntypedExampleMatcher.matching().withIgnorePaths("foo", "bar", "foo");
ExampleMatcher configuredExampleSpec = matcher.withIgnoreCase();
assertThat(matcher).isNotSameAs(configuredExampleSpec);
assertThat(matcher.getIgnoredPaths()).hasSize(2);
assertThat(matcher.isIgnoreCaseEnabled()).isFalse();
assertThat(configuredExampleSpec.getIgnoredPaths()).hasSize(2);
assertThat(configuredExampleSpec.isIgnoreCaseEnabled()).isTrue();
}
use of org.springframework.data.domain.ExampleMatcher in project spring-data-jdbc by spring-projects.
the class RelationalExampleMapperTests method queryByExampleWithFirstnameWithStringMatchingAtTheBeginningIncludingNull.
// GH-929
@Test
void queryByExampleWithFirstnameWithStringMatchingAtTheBeginningIncludingNull() {
Person person = new Person();
person.setFirstname("Fro");
ExampleMatcher matcher = matching().withStringMatcher(STARTING).withIncludeNullValues();
Example<Person> example = Example.of(person, matcher);
Query query = exampleMapper.getMappedExample(example);
//
assertThat(query.getCriteria()).map(//
Object::toString).hasValue("(firstname IS NULL OR firstname LIKE 'Fro%')");
}
use of org.springframework.data.domain.ExampleMatcher in project spring-data-jdbc by spring-projects.
the class RelationalExampleMapperTests method queryByExampleWithFirstnameAndLastnameIgnoringFirstname.
// GH-929
@Test
void queryByExampleWithFirstnameAndLastnameIgnoringFirstname() {
Person person = new Person();
person.setFirstname("Frodo");
person.setLastname("Baggins");
ExampleMatcher matcher = matching().withIgnorePaths("firstname");
Example<Person> example = Example.of(person, matcher);
Query query = exampleMapper.getMappedExample(example);
//
assertThat(query.getCriteria()).map(//
Object::toString).hasValue("(lastname = 'Baggins')");
}
use of org.springframework.data.domain.ExampleMatcher in project spring-data-jdbc by spring-projects.
the class RelationalExampleMapperTests method queryByExampleWithFirstnameWithStringMatchingContaining.
// GH-929
@Test
void queryByExampleWithFirstnameWithStringMatchingContaining() {
Person person = new Person();
person.setFirstname("do");
ExampleMatcher matcher = matching().withStringMatcher(CONTAINING);
Example<Person> example = Example.of(person, matcher);
Query query = exampleMapper.getMappedExample(example);
//
assertThat(query.getCriteria()).map(//
Object::toString).hasValue("(firstname LIKE '%do%')");
}
Aggregations