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

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

Introduction

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

Prototype

@Override
    public String getLastName() 

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);//from  w w w  .  jav  a  2 s. co m

    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"));
}