Fixtures.deleteAllModels();
Fixtures.loadModels("pc.yml");
Parent father = Parent.find("byName", "parent").first();
Parent mother = Parent.find("byName", "mother").first();
Person tutor = Person.find("byUserName", "tutor").first();
Person newTutor = Person.find("byUserName", "new_tutor").first();
Child child = Child.find("byName", "child_2").first();
assertNotNull(father);
assertNotNull(mother);
assertNotNull(child);
assertNotNull(tutor);
assertEquals(father, child.father);
assertEquals(mother, child.mother);
assertEquals(tutor, child.tutor);
Map<String, String> params = new HashMap<String, String>();
params.put("child.id", child.id.toString());
params.put("child.father.code", mother.code);
params.put("child.mother.code", father.code);
params.put("child.tutor.id", newTutor.getId().toString());
Response response = POST(Router.reverse("DataBinding.saveChild").url, params);
assertContentEquals("{\"name\":\"child_2\", \"father\":\"mother\", \"mother\":\"parent\", \"tutor\":\"new_tutor\"}", response);
params.clear();
params.put("child.id", child.id.toString());
params.put("child.father", mother.code);
params.put("child.mother", father.code);
params.put("child.tutor", newTutor.getId().toString());
response = POST(Router.reverse("DataBinding.saveChild").url, params);
assertContentEquals("{\"name\":\"child_2\", \"father\":\"null\", \"mother\":\"null\", \"tutor\":\"null\"}", response);
}