@Test
public void mapToExistingEmbeddedDoc() throws ConflictException {

    Map<String, Object> map = new HashMap<String, Object>();
    map.put(DocumentUtil.TAG_ID, "client-assigned-id");
    // deliberately remove the firstname
    map.put("lastname", "Doe");
    // deliberately remove the city 
    Map<String, Object> phone = new HashMap<String, Object>();
    //remove the home number, change the mobile, add a work number
    phone.put("mobile", "555-111-2229");
    phone.put("work","666-777-8888");
    map.put("phonenumbers", phone);
    
    ODocument existingDoc = new ODocument();
    existingDoc.field(DocumentUtil.ORIENTDB_PRIMARY_KEY, "client-assigned-id");
    existingDoc.field("firstname", "Johnathan");
    // lastname deliberately not in existing doc
    existingDoc.field("city", new ODocument().field("name","Paris").field("country", "France"));
    existingDoc.field("phonenumbers", new ODocument().field("home","555-666-7777").field("mobile", "555-111-2222"), OType.EMBEDDED);
    
    ODocument result = DocumentUtil.toDocument(map, null, db, orientDocClass);
    
    assertEquals(result.field(DocumentUtil.ORIENTDB_PRIMARY_KEY), "client-assigned-id", "unexpected ID");
    assertFalse(result.containsField("firstname"), "Firstname should have been removed but is present");
    assertEquals(result.field("lastname"), "Doe", "unexpected lastname");
    assertEquals(result.getVersion(), 0, "Version not as expected");
    assertFalse(result.containsField("city"), "City map should have been removed but is present.");
    
    ODocument phonenumbers = (ODocument)result.field("phonenumbers");
    assertNotNull(phonenumbers, "phonenumbers map entry null");
    assertEquals(phonenumbers.field("work"), "666-777-8888", "unexpected work phone");
    assertEquals(phonenumbers.field("mobile"), "555-111-2229", "unexpected mobile phone");
    assertFalse(phonenumbers.containsField("home"), "Home phone should have been removed but is present.");
    assertThat((ODocument)phonenumbers)
            .hasSize(2);
}