Search in sources :

Example 6 with ExampleMatcher

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);
}
Also used : Test(org.junit.jupiter.api.Test) NullHandler(org.springframework.data.domain.ExampleMatcher.NullHandler) BeforeEach(org.junit.jupiter.api.BeforeEach) StringMatcher(org.springframework.data.domain.ExampleMatcher.StringMatcher) Assertions(org.assertj.core.api.Assertions) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) Test(org.junit.jupiter.api.Test)

Example 7 with ExampleMatcher

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();
}
Also used : ExampleMatcher(org.springframework.data.domain.ExampleMatcher) Test(org.junit.jupiter.api.Test)

Example 8 with ExampleMatcher

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%')");
}
Also used : Query(org.springframework.data.relational.core.query.Query) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) Test(org.junit.jupiter.api.Test)

Example 9 with ExampleMatcher

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')");
}
Also used : Query(org.springframework.data.relational.core.query.Query) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) Test(org.junit.jupiter.api.Test)

Example 10 with ExampleMatcher

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%')");
}
Also used : Query(org.springframework.data.relational.core.query.Query) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) Test(org.junit.jupiter.api.Test)

Aggregations

ExampleMatcher (org.springframework.data.domain.ExampleMatcher)33 Test (org.junit.jupiter.api.Test)20 Query (org.springframework.data.relational.core.query.Query)17 NoSuchElementException (java.util.NoSuchElementException)9 OperationFailedException (me.kadarh.mecaworks.service.exceptions.OperationFailedException)9 ResourceNotFoundException (me.kadarh.mecaworks.service.exceptions.ResourceNotFoundException)9 Objects (java.util.Objects)2 Classe (me.kadarh.mecaworks.domain.others.Classe)2 Marque (me.kadarh.mecaworks.domain.others.Marque)2 SousFamille (me.kadarh.mecaworks.domain.others.SousFamille)2 Assertions (org.assertj.core.api.Assertions)2 Test (org.junit.Test)2 Example (org.springframework.data.domain.Example)2 BaseEntity (com.google.cloud.datastore.BaseEntity)1 BaseKey (com.google.cloud.datastore.BaseKey)1 Cursor (com.google.cloud.datastore.Cursor)1 Datastore (com.google.cloud.datastore.Datastore)1 DatastoreReaderWriter (com.google.cloud.datastore.DatastoreReaderWriter)1 Entity (com.google.cloud.datastore.Entity)1 Builder (com.google.cloud.datastore.Entity.Builder)1