Example usage for org.springframework.data.domain Example of

List of usage examples for org.springframework.data.domain Example of

Introduction

In this page you can find the example usage for org.springframework.data.domain Example of.

Prototype

static <T> Example<T> of(T probe) 

Source Link

Document

Create a new Example including all non-null properties by default.

Usage

From source file:example.ContactRepositoryIntegrationTests.java

@Test
public void countByConcreteSubtypeExample() {

    Example<Person> example = Example.of(new Person(null, null, null));

    assertThat(userRepository.count(example), is(3L));
}

From source file:example.springdata.mongodb.querybyexample.ContactRepositoryIntegrationTests.java

/**
 * @see #153/*from  ww w.  ja  v a  2s  .  com*/
 */
@Test
public void countByConcreteSubtypeExample() {

    Example<Person> example = Example.of(new Person(null, null, null));

    assertThat(userRepository.count(example), is(3L));
}

From source file:com._4dconcept.springframework.data.marklogic.core.query.QueryBuilderTest.java

@Test
public void buildQueryFromEmptyExample() {
    Person person = new Person();
    Query query = new QueryBuilder().alike(Example.of(person)).build();

    assertThat(query, notNullValue());/*from ww w. j  av a  2s  .c  om*/
    assertThat(query.getCriteria(), nullValue());
}

From source file:com._4dconcept.springframework.data.marklogic.repository.support.RepositoryIntegrationTests.java

@Test
public void countBySample() {
    Person samplePerson = new Person();
    samplePerson.setLastname("Toussaint");
    assertThat(repository.count(Example.of(samplePerson)), is(1L));
}

From source file:com._4dconcept.springframework.data.marklogic.core.query.QueryBuilderTest.java

@Test
@SuppressWarnings("unchecked")
public void buildQueryFromFilledExample() {
    Person person = new Person();
    person.setFirstname("Me");
    person.setAge(38);// w w w. j a v  a 2s.  c om

    Address address = new Address();
    address.setTown("Paris");
    address.setCountry("France");
    person.setAddress(address);

    Query query = new QueryBuilder().alike(Example.of(person)).build();

    assertThat(query, notNullValue());
    assertThat(query.getCollection(), is("Person"));
    assertThat(query.getCriteria(), notNullValue());
    assertThat(query.getCriteria().getOperator(), is(Criteria.Operator.and));
    assertThat(query.getCriteria().getCriteriaObject(), instanceOf(List.class));

    List<Criteria> criteriaList = (List<Criteria>) query.getCriteria().getCriteriaObject();
    assertThat(criteriaList, notNullValue());
    assertThat(criteriaList, hasSize(3));
    assertThat(criteriaList.get(0).getCriteriaObject(), is("Me"));
    assertThat(criteriaList.get(1).getCriteriaObject(), is(38));
    assertThat(criteriaList.get(2).getOperator(), is(Criteria.Operator.and));
}

From source file:com._4dconcept.springframework.data.marklogic.repository.support.RepositoryIntegrationTests.java

@Test
public void checkPersonExistsBySample() {
    Person samplePerson = new Person();
    samplePerson.setLastname("Toussaint");
    assertThat(repository.exists(Example.of(samplePerson)), is(true));
}

From source file:com._4dconcept.springframework.data.marklogic.repository.support.RepositoryIntegrationTests.java

@Test
public void findOnePersonByExample() {
    Person person = new Person();
    person.setLastname("Toussaint");
    final Person result = repository.findOne(Example.of(person)).orElse(null);
    assertThat(result, notNullValue());/*from   w w w.ja  v a 2  s .  c  om*/
    assertThat(result.getId(), is(stephId));
    assertThat(result.getFirstname(), is("Stphane"));
}

From source file:com._4dconcept.springframework.data.marklogic.core.query.QueryBuilderTest.java

@Test
@SuppressWarnings("unchecked")
public void considerCollectionValuesAsOrQuery() {
    Person person = new Person();
    person.setSkills(Arrays.asList("java", "xml"));
    person.setAge(38);/*from w  w  w  . java  2  s  .c  o m*/

    Query query = new QueryBuilder().alike(Example.of(person)).build();

    assertThat(query, notNullValue());
    assertThat(query.getCollection(), is("Person"));
    assertThat(query.getCriteria(), notNullValue());
    assertThat(query.getCriteria().getOperator(), is(Criteria.Operator.and));
    assertThat(query.getCriteria().getCriteriaObject(), instanceOf(List.class));

    List<Criteria> criteriaList = (List<Criteria>) query.getCriteria().getCriteriaObject();
    assertThat(criteriaList, hasSize(2));

}

From source file:com._4dconcept.springframework.data.marklogic.repository.support.RepositoryIntegrationTests.java

@Test
public void throwExceptionWhenFindOneReturnMultiplePersons() {
    thrown.expect(IncorrectResultSizeDataAccessException.class);
    thrown.expectMessage("Incorrect result size: expected 1, actual 2");

    Person person = new Person();
    Address address = new Address();
    address.setCountry("France");
    person.setAddress(address);//from   w w w .  j  av  a2 s  .  c o m

    repository.findOne(Example.of(person));
}

From source file:com._4dconcept.springframework.data.marklogic.core.query.QueryBuilderTest.java

@Test
public void buildQueryWithExplicitCollection() {
    Person person = new Person();

    Query query = new QueryBuilder().alike(Example.of(person)).options(new MarklogicOperationOptions() {
        @Override//  w  w w.  java 2  s .  co m
        public String defaultCollection() {
            return "contact";
        }
    }).build();

    assertThat(query.getCollection(), is("contact"));
}