Example usage for org.springframework.data.mongodb.core.mapping PersonCustomIdName PersonCustomIdName

List of usage examples for org.springframework.data.mongodb.core.mapping PersonCustomIdName PersonCustomIdName

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.mapping PersonCustomIdName PersonCustomIdName.

Prototype

@PersistenceConstructor
    public PersonCustomIdName(Integer ssn, String firstName, String lastName) 

Source Link

Usage

From source file:org.springframework.data.mongodb.core.mapping.MappingTests.java

@Test
public void testPersonWithCustomIdName() {

    PersonCustomIdName p = new PersonCustomIdName(123456, "Custom Id", null);
    template.insert(p);/*w ww .j  a  va  2 s.  com*/

    List<PersonCustomIdName> result = template.find(new Query(Criteria.where("lastName").is(p.getLastName())),
            PersonCustomIdName.class);
    assertThat(result.size(), is(1));
    assertThat(result.get(0).getFirstName(), is("Custom Id"));

    PersonCustomIdName p2 = new PersonCustomIdName(654321, "Custom Id", "LastName");
    template.insert(p2);

    List<PersonCustomIdName> result2 = template.find(new Query(Criteria.where("lastName").is("LastName")),
            PersonCustomIdName.class);
    assertThat(result2.size(), is(1));
    assertNotNull(result2.get(0).getLastName());
    assertThat(result2.get(0).getLastName(), is("LastName"));

    // Test "in" query
    List<PersonCustomIdName> result3 = template.find(new Query(Criteria.where("lastName").in("LastName")),
            PersonCustomIdName.class);
    assertThat(result3.size(), is(1));
    assertNotNull(result3.get(0).getLastName());
    assertThat(result3.get(0).getLastName(), is("LastName"));
}