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

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

Introduction

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

Prototype

public PersonMapProperty(Integer ssn, String firstName, String lastName) 

Source Link

Usage

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

@Test
public void testPersonMapProperty() {
    PersonMapProperty p = new PersonMapProperty(1234567, "Map", "PropertyPath");
    Map<String, AccountPojo> accounts = new HashMap<String, AccountPojo>();

    AccountPojo checking = new AccountPojo("checking", 1000.0f);
    AccountPojo savings = new AccountPojo("savings", 10000.0f);

    accounts.put("checking", checking);
    accounts.put("savings", savings);
    p.setAccounts(accounts);/* w w w . j a v  a  2  s .  c  om*/

    template.insert(p);
    assertNotNull(p.getId());

    List<PersonMapProperty> result = template.find(new Query(Criteria.where("ssn").is(1234567)),
            PersonMapProperty.class);
    assertThat(result.size(), is(1));
    assertThat(result.get(0).getAccounts().size(), is(2));
    assertThat(result.get(0).getAccounts().get("checking").getBalance(), is(1000.0f));
}