@Test
public void mapToExistingFlatDoc() throws ConflictException {

    Map<String, Object> map = new HashMap<String, Object>();
    map.put(DocumentUtil.TAG_ID, "client-assigned-id");
    map.put(DocumentUtil.TAG_REV, "1");
    map.put("firstname", "Sam");
    map.put("lastname", "Iam");
    map.put("telephone", "(555) 123-4567");
    map.put("age", 20);
    map.put("longnumber", Long.MAX_VALUE);
    map.put("amount", Float.valueOf(12345678.89f));
    map.put("present", Boolean.FALSE);
    map.put("somedate", new Date());
    
    // An existing document to get updated from the map
    ODocument existingDoc = new ODocument(db, orientDocClass);
    existingDoc.field(DocumentUtil.ORIENTDB_PRIMARY_KEY, "client-assigned-id");
    // firstname and lastname deliberately not in the existing doc
    existingDoc.field("fieldtoberemoved", "ABC");
    existingDoc.field("telephone", "(999) 999-9999");
    existingDoc.field("age", 20);
    existingDoc.field("longnumber", 0);
    existingDoc.field("amount", Float.valueOf(12345678.89f));
    existingDoc.field("present", Boolean.FALSE);
    existingDoc.field("somedate", new Date());
    existingDoc.field("AnotherFieldToBeRemoved", new Date());
    
    ODocument result = DocumentUtil.toDocument(map, existingDoc, db, orientDocClass);
    
    assertEquals(result.field(DocumentUtil.ORIENTDB_PRIMARY_KEY), "client-assigned-id", "unexpected ID");
    assertEquals(result.field("firstname"), "Sam", "unexpected firstname");
    assertEquals(result.field("lastname"), "Iam", "unexpected lastname");
    assertEquals(result.field("telephone"), "(555) 123-4567", "unexpected telephone");
    assertEquals(result.field("age"), 20, "unexpected age");
    assertEquals(result.field("longnumber"), Long.MAX_VALUE, "unexpected longnumber");
    assertEquals(result.field("amount"), 12345678.89f, "unexpected amount");
    assertEquals(result.field("present"), false, "unexpected present boolean");
    assertFalse(result.containsField("fieldtoberemoved"), "Field 'fieldtoberemoved' not removed as expected");
    assertFalse(result.containsField("AnotherFieldToBeRemoved"), "Field 'AnotherFieldToBeRemoved' not removed as expected");
    assertEquals(result.getVersion(), 1, "Version not as expected");
    Object somedate = result.field("somedate");
    assertNotNull(somedate, "somedate entry null");
    assertTrue((somedate instanceof Date), "Date not of expected type.");
}