public void testDeepMergeExistingSubclass() {
final ClassDescriptor d = resolver.getClassDescriptor("Department");
final Department d1 = context.newObject(Department.class);
d1.setName("D1");
// need to do double commit as Ashwood sorter blows on Employees/Departments
// ordering...
context.commitChanges();
Employee e1 = context.newObject(Employee.class);
e1.setName("E1");
e1.setPersonType("EE");
d1.addToEmployees(e1);
Manager e2 = context.newObject(Manager.class);
e2.setName("E2");
e2.setPersonType("EM");
d1.addToEmployees(e2);
context.commitChanges();
// need to make sure source relationship is resolved as a result of some Ashwood
// strangeness...
d1.getEmployees().size();
// resolve Employees
context1.performQuery(new SelectQuery(Employee.class));
final DeepMergeOperation op = new DeepMergeOperation(context1);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
Department d2 = (Department) op.merge(d1, d);
assertNotNull(d2);
assertEquals(PersistenceState.COMMITTED, d2.getPersistenceState());
for (Employee ex : d2.getEmployees()) {
if ("E2".equals(ex.getName())) {
assertTrue(ex instanceof Manager);
}
else {
assertFalse(ex instanceof Manager);