Example usage for org.springframework.data.mongodb.core.mapping Person setAccounts

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

Introduction

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

Prototype

public void setAccounts(List<Account> accounts) 

Source Link

Usage

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

@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testWriteEntity() {

    Address addr = new Address();
    addr.setLines(new String[] { "1234 W. 1st Street", "Apt. 12" });
    addr.setCity("Anytown");
    addr.setPostalCode(12345);/*w w  w.j a v  a2  s.  c  o m*/
    addr.setCountry("USA");

    Account acct = new Account();
    acct.setBalance(1000.00f);
    template.insert(acct, "account");

    List<Account> accounts = new ArrayList<Account>();
    accounts.add(acct);

    Person p = new Person(123456789, "John", "Doe", 37, addr);
    p.setAccounts(accounts);
    template.insert(p, "person");

    Account newAcct = new Account();
    newAcct.setBalance(10000.00f);
    template.insert(newAcct, "account");

    accounts.add(newAcct);
    template.save(p, "person");

    assertNotNull(p.getId());

    List<Person> result = template.find(new Query(Criteria.where("ssn").is(123456789)), Person.class);
    assertThat(result.size(), is(1));
    assertThat(result.get(0).getAddress().getCountry(), is("USA"));
    assertThat(result.get(0).getAccounts(), notNullValue());
}