Search in sources :

Example 26 with ExampleMatcher

use of org.springframework.data.domain.ExampleMatcher in project spring-data-jdbc by spring-projects.

the class RelationalExampleMapperTests method queryByExampleWithFirstnameAndLastnameWithNullMatchingIgnoringFirstName.

// GH-929
@Test
void queryByExampleWithFirstnameAndLastnameWithNullMatchingIgnoringFirstName() {
    Person person = new Person();
    person.setFirstname("Frodo");
    person.setLastname("Baggins");
    ExampleMatcher matcher = matching().withIncludeNullValues().withIgnorePaths("firstname");
    Example<Person> example = Example.of(person, matcher);
    Query query = exampleMapper.getMappedExample(example);
    // 
    assertThat(query.getCriteria()).map(// 
    Object::toString).hasValue("(lastname IS NULL OR 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 27 with ExampleMatcher

use of org.springframework.data.domain.ExampleMatcher in project spring-data-jdbc by spring-projects.

the class RelationalExampleMapperTests method queryByExampleWithFirstnameWithStringMatchingRegEx.

// GH-929
@Test
void queryByExampleWithFirstnameWithStringMatchingRegEx() {
    Person person = new Person();
    person.setFirstname("do");
    ExampleMatcher matcher = matching().withStringMatcher(ExampleMatcher.StringMatcher.REGEX);
    Example<Person> example = Example.of(person, matcher);
    assertThatIllegalStateException().isThrownBy(() -> exampleMapper.getMappedExample(example)).withMessageContaining("REGEX is not supported!");
}
Also used : ExampleMatcher(org.springframework.data.domain.ExampleMatcher) Test(org.junit.jupiter.api.Test)

Example 28 with ExampleMatcher

use of org.springframework.data.domain.ExampleMatcher in project spring-data-jdbc by spring-projects.

the class RelationalExampleMapperTests method queryByExampleWithFirstnameWithStringMatchingAtTheBeginning.

// GH-929
@Test
void queryByExampleWithFirstnameWithStringMatchingAtTheBeginning() {
    Person person = new Person();
    person.setFirstname("Fro");
    ExampleMatcher matcher = matching().withStringMatcher(STARTING);
    Example<Person> example = Example.of(person, matcher);
    Query query = exampleMapper.getMappedExample(example);
    // 
    assertThat(query.getCriteria()).map(// 
    Object::toString).hasValue("(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 29 with ExampleMatcher

use of org.springframework.data.domain.ExampleMatcher in project spring-data-jdbc by spring-projects.

the class RelationalExampleMapperTests method queryByExampleWithFirstnameWithFieldSpecificStringMatcherEndsWith.

// GH-929
@Test
void queryByExampleWithFirstnameWithFieldSpecificStringMatcherEndsWith() {
    Person person = new Person();
    person.setFirstname("do");
    ExampleMatcher matcher = matching().withMatcher("firstname", endsWith());
    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)

Example 30 with ExampleMatcher

use of org.springframework.data.domain.ExampleMatcher in project spring-data-jdbc by spring-projects.

the class RelationalExampleMapperTests method queryByExampleWithFirstnameIgnoreCase.

// GH-929
@Test
void queryByExampleWithFirstnameIgnoreCase() {
    Person person = new Person();
    person.setFirstname("Frodo");
    ExampleMatcher matcher = matching().withIgnoreCase(true);
    Example<Person> example = Example.of(person, matcher);
    Query query = exampleMapper.getMappedExample(example);
    // 
    assertThat(query.getCriteria()).map(// 
    Object::toString).hasValue("(firstname = 'Frodo')");
    assertThat(example.getMatcher().isIgnoreCaseEnabled()).isTrue();
}
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